blob: 3229c23331858df5e60a54523d000f71f0596dea [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);
Tobin Ehlis31289162016-08-17 14:57:58 -06005109 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005110 m_commandBuffer->EndRenderPass();
5111 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005113 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5114 vkDestroyBuffer(m_device->device(), buffer, NULL);
5115 // Attempt to submit cmd buffer
5116 VkSubmitInfo submit_info = {};
5117 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5118 submit_info.commandBufferCount = 1;
5119 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5120 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5121 m_errorMonitor->VerifyFound();
5122 // Cleanup
5123 vkFreeMemory(m_device->device(), mem, NULL);
5124
5125 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5127 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5128}
5129
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005130TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5131 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5132 "due to a bound descriptor sets with a combined image "
5133 "sampler having their image, sampler, and descriptor set "
5134 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005135 "submit associated cmd buffers. Attempt to destroy a "
5136 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005137 ASSERT_NO_FATAL_FAILURE(InitState());
5138 ASSERT_NO_FATAL_FAILURE(InitViewport());
5139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5140
5141 VkDescriptorPoolSize ds_type_count = {};
5142 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5143 ds_type_count.descriptorCount = 1;
5144
5145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5147 ds_pool_ci.pNext = NULL;
5148 ds_pool_ci.maxSets = 1;
5149 ds_pool_ci.poolSizeCount = 1;
5150 ds_pool_ci.pPoolSizes = &ds_type_count;
5151
5152 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005153 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005154 ASSERT_VK_SUCCESS(err);
5155
5156 VkDescriptorSetLayoutBinding dsl_binding = {};
5157 dsl_binding.binding = 0;
5158 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5159 dsl_binding.descriptorCount = 1;
5160 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5161 dsl_binding.pImmutableSamplers = NULL;
5162
5163 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5164 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5165 ds_layout_ci.pNext = NULL;
5166 ds_layout_ci.bindingCount = 1;
5167 ds_layout_ci.pBindings = &dsl_binding;
5168 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005169 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005170 ASSERT_VK_SUCCESS(err);
5171
5172 VkDescriptorSet descriptorSet;
5173 VkDescriptorSetAllocateInfo alloc_info = {};
5174 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5175 alloc_info.descriptorSetCount = 1;
5176 alloc_info.descriptorPool = ds_pool;
5177 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005178 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005179 ASSERT_VK_SUCCESS(err);
5180
5181 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5182 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5183 pipeline_layout_ci.pNext = NULL;
5184 pipeline_layout_ci.setLayoutCount = 1;
5185 pipeline_layout_ci.pSetLayouts = &ds_layout;
5186
5187 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005188 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005189 ASSERT_VK_SUCCESS(err);
5190
5191 // Create images to update the descriptor with
5192 VkImage image;
5193 VkImage image2;
5194 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5195 const int32_t tex_width = 32;
5196 const int32_t tex_height = 32;
5197 VkImageCreateInfo image_create_info = {};
5198 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5199 image_create_info.pNext = NULL;
5200 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5201 image_create_info.format = tex_format;
5202 image_create_info.extent.width = tex_width;
5203 image_create_info.extent.height = tex_height;
5204 image_create_info.extent.depth = 1;
5205 image_create_info.mipLevels = 1;
5206 image_create_info.arrayLayers = 1;
5207 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5208 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5209 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5210 image_create_info.flags = 0;
5211 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5212 ASSERT_VK_SUCCESS(err);
5213 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5214 ASSERT_VK_SUCCESS(err);
5215
5216 VkMemoryRequirements memory_reqs;
5217 VkDeviceMemory image_memory;
5218 bool pass;
5219 VkMemoryAllocateInfo memory_info = {};
5220 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5221 memory_info.pNext = NULL;
5222 memory_info.allocationSize = 0;
5223 memory_info.memoryTypeIndex = 0;
5224 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5225 // Allocate enough memory for both images
5226 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005227 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005228 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005229 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005230 ASSERT_VK_SUCCESS(err);
5231 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5232 ASSERT_VK_SUCCESS(err);
5233 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005234 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005235 ASSERT_VK_SUCCESS(err);
5236
5237 VkImageViewCreateInfo image_view_create_info = {};
5238 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5239 image_view_create_info.image = image;
5240 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5241 image_view_create_info.format = tex_format;
5242 image_view_create_info.subresourceRange.layerCount = 1;
5243 image_view_create_info.subresourceRange.baseMipLevel = 0;
5244 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005245 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005246
5247 VkImageView view;
5248 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005249 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005250 ASSERT_VK_SUCCESS(err);
5251 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005252 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005253 ASSERT_VK_SUCCESS(err);
5254 // Create Samplers
5255 VkSamplerCreateInfo sampler_ci = {};
5256 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5257 sampler_ci.pNext = NULL;
5258 sampler_ci.magFilter = VK_FILTER_NEAREST;
5259 sampler_ci.minFilter = VK_FILTER_NEAREST;
5260 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5261 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5262 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5263 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5264 sampler_ci.mipLodBias = 1.0;
5265 sampler_ci.anisotropyEnable = VK_FALSE;
5266 sampler_ci.maxAnisotropy = 1;
5267 sampler_ci.compareEnable = VK_FALSE;
5268 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5269 sampler_ci.minLod = 1.0;
5270 sampler_ci.maxLod = 1.0;
5271 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5272 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5273 VkSampler sampler;
5274 VkSampler sampler2;
5275 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5276 ASSERT_VK_SUCCESS(err);
5277 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5278 ASSERT_VK_SUCCESS(err);
5279 // Update descriptor with image and sampler
5280 VkDescriptorImageInfo img_info = {};
5281 img_info.sampler = sampler;
5282 img_info.imageView = view;
5283 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5284
5285 VkWriteDescriptorSet descriptor_write;
5286 memset(&descriptor_write, 0, sizeof(descriptor_write));
5287 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5288 descriptor_write.dstSet = descriptorSet;
5289 descriptor_write.dstBinding = 0;
5290 descriptor_write.descriptorCount = 1;
5291 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5292 descriptor_write.pImageInfo = &img_info;
5293
5294 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5295
5296 // Create PSO to be used for draw-time errors below
5297 char const *vsSource = "#version 450\n"
5298 "\n"
5299 "out gl_PerVertex { \n"
5300 " vec4 gl_Position;\n"
5301 "};\n"
5302 "void main(){\n"
5303 " gl_Position = vec4(1);\n"
5304 "}\n";
5305 char const *fsSource = "#version 450\n"
5306 "\n"
5307 "layout(set=0, binding=0) uniform sampler2D s;\n"
5308 "layout(location=0) out vec4 x;\n"
5309 "void main(){\n"
5310 " x = texture(s, vec2(1));\n"
5311 "}\n";
5312 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5313 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5314 VkPipelineObj pipe(m_device);
5315 pipe.AddShader(&vs);
5316 pipe.AddShader(&fs);
5317 pipe.AddColorAttachment();
5318 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5319
5320 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005322 m_commandBuffer->BeginCommandBuffer();
5323 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005324 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5325 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5326 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005327 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005328 m_commandBuffer->EndRenderPass();
5329 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005330 // Destroy sampler invalidates the cmd buffer, causing error on submit
5331 vkDestroySampler(m_device->device(), sampler, NULL);
5332 // Attempt to submit cmd buffer
5333 VkSubmitInfo submit_info = {};
5334 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5335 submit_info.commandBufferCount = 1;
5336 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5337 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5338 m_errorMonitor->VerifyFound();
5339 // Now re-update descriptor with valid sampler and delete image
5340 img_info.sampler = sampler2;
5341 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005343 m_commandBuffer->BeginCommandBuffer();
5344 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005345 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5346 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5347 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005348 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005349 m_commandBuffer->EndRenderPass();
5350 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005351 // Destroy image invalidates the cmd buffer, causing error on submit
5352 vkDestroyImage(m_device->device(), image, NULL);
5353 // Attempt to submit cmd buffer
5354 submit_info = {};
5355 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5356 submit_info.commandBufferCount = 1;
5357 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5358 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5359 m_errorMonitor->VerifyFound();
5360 // Now update descriptor to be valid, but then free descriptor
5361 img_info.imageView = view2;
5362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005364 m_commandBuffer->BeginCommandBuffer();
5365 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005366 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5367 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5368 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005369 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005370 m_commandBuffer->EndRenderPass();
5371 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005372 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005374 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005375 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005376 // Attempt to submit cmd buffer
5377 submit_info = {};
5378 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5379 submit_info.commandBufferCount = 1;
5380 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5381 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5382 m_errorMonitor->VerifyFound();
5383 // Cleanup
5384 vkFreeMemory(m_device->device(), image_memory, NULL);
5385 vkDestroySampler(m_device->device(), sampler2, NULL);
5386 vkDestroyImage(m_device->device(), image2, NULL);
5387 vkDestroyImageView(m_device->device(), view, NULL);
5388 vkDestroyImageView(m_device->device(), view2, NULL);
5389 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5390 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5391 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5392}
5393
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005394TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5395 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5396 ASSERT_NO_FATAL_FAILURE(InitState());
5397 ASSERT_NO_FATAL_FAILURE(InitViewport());
5398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5399
5400 VkDescriptorPoolSize ds_type_count = {};
5401 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5402 ds_type_count.descriptorCount = 1;
5403
5404 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5405 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5406 ds_pool_ci.pNext = NULL;
5407 ds_pool_ci.maxSets = 1;
5408 ds_pool_ci.poolSizeCount = 1;
5409 ds_pool_ci.pPoolSizes = &ds_type_count;
5410
5411 VkDescriptorPool ds_pool;
5412 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5413 ASSERT_VK_SUCCESS(err);
5414
5415 VkDescriptorSetLayoutBinding dsl_binding = {};
5416 dsl_binding.binding = 0;
5417 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5418 dsl_binding.descriptorCount = 1;
5419 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5420 dsl_binding.pImmutableSamplers = NULL;
5421
5422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5424 ds_layout_ci.pNext = NULL;
5425 ds_layout_ci.bindingCount = 1;
5426 ds_layout_ci.pBindings = &dsl_binding;
5427 VkDescriptorSetLayout ds_layout;
5428 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5429 ASSERT_VK_SUCCESS(err);
5430
5431 VkDescriptorSet descriptor_set;
5432 VkDescriptorSetAllocateInfo alloc_info = {};
5433 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5434 alloc_info.descriptorSetCount = 1;
5435 alloc_info.descriptorPool = ds_pool;
5436 alloc_info.pSetLayouts = &ds_layout;
5437 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5438 ASSERT_VK_SUCCESS(err);
5439
5440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5442 pipeline_layout_ci.pNext = NULL;
5443 pipeline_layout_ci.setLayoutCount = 1;
5444 pipeline_layout_ci.pSetLayouts = &ds_layout;
5445
5446 VkPipelineLayout pipeline_layout;
5447 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5448 ASSERT_VK_SUCCESS(err);
5449
5450 // Create image to update the descriptor with
5451 VkImageObj image(m_device);
5452 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5453 ASSERT_TRUE(image.initialized());
5454
5455 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5456 // Create Sampler
5457 VkSamplerCreateInfo sampler_ci = {};
5458 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5459 sampler_ci.pNext = NULL;
5460 sampler_ci.magFilter = VK_FILTER_NEAREST;
5461 sampler_ci.minFilter = VK_FILTER_NEAREST;
5462 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5463 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5464 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5465 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5466 sampler_ci.mipLodBias = 1.0;
5467 sampler_ci.anisotropyEnable = VK_FALSE;
5468 sampler_ci.maxAnisotropy = 1;
5469 sampler_ci.compareEnable = VK_FALSE;
5470 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5471 sampler_ci.minLod = 1.0;
5472 sampler_ci.maxLod = 1.0;
5473 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5474 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5475 VkSampler sampler;
5476 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5477 ASSERT_VK_SUCCESS(err);
5478 // Update descriptor with image and sampler
5479 VkDescriptorImageInfo img_info = {};
5480 img_info.sampler = sampler;
5481 img_info.imageView = view;
5482 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5483
5484 VkWriteDescriptorSet descriptor_write;
5485 memset(&descriptor_write, 0, sizeof(descriptor_write));
5486 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5487 descriptor_write.dstSet = descriptor_set;
5488 descriptor_write.dstBinding = 0;
5489 descriptor_write.descriptorCount = 1;
5490 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5491 descriptor_write.pImageInfo = &img_info;
5492
5493 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5494
5495 // Create PSO to be used for draw-time errors below
5496 char const *vsSource = "#version 450\n"
5497 "\n"
5498 "out gl_PerVertex { \n"
5499 " vec4 gl_Position;\n"
5500 "};\n"
5501 "void main(){\n"
5502 " gl_Position = vec4(1);\n"
5503 "}\n";
5504 char const *fsSource = "#version 450\n"
5505 "\n"
5506 "layout(set=0, binding=0) uniform sampler2D s;\n"
5507 "layout(location=0) out vec4 x;\n"
5508 "void main(){\n"
5509 " x = texture(s, vec2(1));\n"
5510 "}\n";
5511 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5512 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5513 VkPipelineObj pipe(m_device);
5514 pipe.AddShader(&vs);
5515 pipe.AddShader(&fs);
5516 pipe.AddColorAttachment();
5517 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5518
Tony Barbour552f6c02016-12-21 14:34:07 -07005519 m_commandBuffer->BeginCommandBuffer();
5520 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005521 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5522 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5523 &descriptor_set, 0, NULL);
5524 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005525 m_commandBuffer->EndRenderPass();
5526 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005527 // Submit cmd buffer to put pool in-flight
5528 VkSubmitInfo submit_info = {};
5529 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5530 submit_info.commandBufferCount = 1;
5531 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5532 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5533 // Destroy pool while in-flight, causing error
5534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5535 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5536 m_errorMonitor->VerifyFound();
5537 vkQueueWaitIdle(m_device->m_queue);
5538 // Cleanup
5539 vkDestroySampler(m_device->device(), sampler, NULL);
5540 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5541 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5542 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5543}
5544
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005545TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5546 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5547 ASSERT_NO_FATAL_FAILURE(InitState());
5548 ASSERT_NO_FATAL_FAILURE(InitViewport());
5549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5550
5551 VkDescriptorPoolSize ds_type_count = {};
5552 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5553 ds_type_count.descriptorCount = 1;
5554
5555 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5556 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5557 ds_pool_ci.pNext = NULL;
5558 ds_pool_ci.maxSets = 1;
5559 ds_pool_ci.poolSizeCount = 1;
5560 ds_pool_ci.pPoolSizes = &ds_type_count;
5561
5562 VkDescriptorPool ds_pool;
5563 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5564 ASSERT_VK_SUCCESS(err);
5565
5566 VkDescriptorSetLayoutBinding dsl_binding = {};
5567 dsl_binding.binding = 0;
5568 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5569 dsl_binding.descriptorCount = 1;
5570 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5571 dsl_binding.pImmutableSamplers = NULL;
5572
5573 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5574 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5575 ds_layout_ci.pNext = NULL;
5576 ds_layout_ci.bindingCount = 1;
5577 ds_layout_ci.pBindings = &dsl_binding;
5578 VkDescriptorSetLayout ds_layout;
5579 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5580 ASSERT_VK_SUCCESS(err);
5581
5582 VkDescriptorSet descriptorSet;
5583 VkDescriptorSetAllocateInfo alloc_info = {};
5584 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5585 alloc_info.descriptorSetCount = 1;
5586 alloc_info.descriptorPool = ds_pool;
5587 alloc_info.pSetLayouts = &ds_layout;
5588 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5589 ASSERT_VK_SUCCESS(err);
5590
5591 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5592 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5593 pipeline_layout_ci.pNext = NULL;
5594 pipeline_layout_ci.setLayoutCount = 1;
5595 pipeline_layout_ci.pSetLayouts = &ds_layout;
5596
5597 VkPipelineLayout pipeline_layout;
5598 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5599 ASSERT_VK_SUCCESS(err);
5600
5601 // Create images to update the descriptor with
5602 VkImage image;
5603 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5604 const int32_t tex_width = 32;
5605 const int32_t tex_height = 32;
5606 VkImageCreateInfo image_create_info = {};
5607 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5608 image_create_info.pNext = NULL;
5609 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5610 image_create_info.format = tex_format;
5611 image_create_info.extent.width = tex_width;
5612 image_create_info.extent.height = tex_height;
5613 image_create_info.extent.depth = 1;
5614 image_create_info.mipLevels = 1;
5615 image_create_info.arrayLayers = 1;
5616 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5617 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5618 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5619 image_create_info.flags = 0;
5620 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5621 ASSERT_VK_SUCCESS(err);
5622 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5623 VkMemoryRequirements memory_reqs;
5624 VkDeviceMemory image_memory;
5625 bool pass;
5626 VkMemoryAllocateInfo memory_info = {};
5627 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5628 memory_info.pNext = NULL;
5629 memory_info.allocationSize = 0;
5630 memory_info.memoryTypeIndex = 0;
5631 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5632 // Allocate enough memory for image
5633 memory_info.allocationSize = memory_reqs.size;
5634 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5635 ASSERT_TRUE(pass);
5636 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5637 ASSERT_VK_SUCCESS(err);
5638 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5639 ASSERT_VK_SUCCESS(err);
5640
5641 VkImageViewCreateInfo image_view_create_info = {};
5642 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5643 image_view_create_info.image = image;
5644 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5645 image_view_create_info.format = tex_format;
5646 image_view_create_info.subresourceRange.layerCount = 1;
5647 image_view_create_info.subresourceRange.baseMipLevel = 0;
5648 image_view_create_info.subresourceRange.levelCount = 1;
5649 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5650
5651 VkImageView view;
5652 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5653 ASSERT_VK_SUCCESS(err);
5654 // Create Samplers
5655 VkSamplerCreateInfo sampler_ci = {};
5656 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5657 sampler_ci.pNext = NULL;
5658 sampler_ci.magFilter = VK_FILTER_NEAREST;
5659 sampler_ci.minFilter = VK_FILTER_NEAREST;
5660 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5661 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5662 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5663 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5664 sampler_ci.mipLodBias = 1.0;
5665 sampler_ci.anisotropyEnable = VK_FALSE;
5666 sampler_ci.maxAnisotropy = 1;
5667 sampler_ci.compareEnable = VK_FALSE;
5668 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5669 sampler_ci.minLod = 1.0;
5670 sampler_ci.maxLod = 1.0;
5671 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5672 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5673 VkSampler sampler;
5674 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5675 ASSERT_VK_SUCCESS(err);
5676 // Update descriptor with image and sampler
5677 VkDescriptorImageInfo img_info = {};
5678 img_info.sampler = sampler;
5679 img_info.imageView = view;
5680 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5681
5682 VkWriteDescriptorSet descriptor_write;
5683 memset(&descriptor_write, 0, sizeof(descriptor_write));
5684 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5685 descriptor_write.dstSet = descriptorSet;
5686 descriptor_write.dstBinding = 0;
5687 descriptor_write.descriptorCount = 1;
5688 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5689 descriptor_write.pImageInfo = &img_info;
5690 // Break memory binding and attempt update
5691 vkFreeMemory(m_device->device(), image_memory, nullptr);
5692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005693 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5695 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5696 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5697 m_errorMonitor->VerifyFound();
5698 // Cleanup
5699 vkDestroyImage(m_device->device(), image, NULL);
5700 vkDestroySampler(m_device->device(), sampler, NULL);
5701 vkDestroyImageView(m_device->device(), view, NULL);
5702 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5703 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5704 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5705}
5706
Karl Schultz6addd812016-02-02 17:17:23 -07005707TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005708 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5709 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005710 // Create a valid cmd buffer
5711 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005712 uint64_t fake_pipeline_handle = 0xbaad6001;
5713 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005714 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5716
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005718 m_commandBuffer->BeginCommandBuffer();
5719 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005720 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005721 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005722
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005723 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005724 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 -06005725 Draw(1, 0, 0, 0);
5726 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005727
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005728 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005729 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 +12005730 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005731 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5732 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005733}
5734
Karl Schultz6addd812016-02-02 17:17:23 -07005735TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005736 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005737 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005738
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005740
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005741 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005742 ASSERT_NO_FATAL_FAILURE(InitViewport());
5743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005744 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005745 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5746 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005747
5748 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005749 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5750 ds_pool_ci.pNext = NULL;
5751 ds_pool_ci.maxSets = 1;
5752 ds_pool_ci.poolSizeCount = 1;
5753 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005754
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005755 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005756 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005757 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005758
Tony Barboureb254902015-07-15 12:50:33 -06005759 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005760 dsl_binding.binding = 0;
5761 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5762 dsl_binding.descriptorCount = 1;
5763 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5764 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005765
Tony Barboureb254902015-07-15 12:50:33 -06005766 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005767 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5768 ds_layout_ci.pNext = NULL;
5769 ds_layout_ci.bindingCount = 1;
5770 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005771 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005772 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005773 ASSERT_VK_SUCCESS(err);
5774
5775 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005776 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005777 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005778 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005779 alloc_info.descriptorPool = ds_pool;
5780 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005781 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005782 ASSERT_VK_SUCCESS(err);
5783
Tony Barboureb254902015-07-15 12:50:33 -06005784 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005785 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5786 pipeline_layout_ci.pNext = NULL;
5787 pipeline_layout_ci.setLayoutCount = 1;
5788 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005789
5790 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005791 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005792 ASSERT_VK_SUCCESS(err);
5793
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005794 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005795 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005796 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005797 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005798
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005799 VkPipelineObj pipe(m_device);
5800 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005801 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005802 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005803 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005804
Tony Barbour552f6c02016-12-21 14:34:07 -07005805 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005806 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5807 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5808 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005809
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005810 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005811
Chia-I Wuf7458c52015-10-26 21:10:41 +08005812 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5813 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5814 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005815}
5816
Karl Schultz6addd812016-02-02 17:17:23 -07005817TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005818 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005819 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005820
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005822
5823 ASSERT_NO_FATAL_FAILURE(InitState());
5824 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005825 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5826 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005827
5828 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005829 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5830 ds_pool_ci.pNext = NULL;
5831 ds_pool_ci.maxSets = 1;
5832 ds_pool_ci.poolSizeCount = 1;
5833 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005834
5835 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005836 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005837 ASSERT_VK_SUCCESS(err);
5838
5839 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005840 dsl_binding.binding = 0;
5841 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5842 dsl_binding.descriptorCount = 1;
5843 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5844 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005845
5846 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005847 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5848 ds_layout_ci.pNext = NULL;
5849 ds_layout_ci.bindingCount = 1;
5850 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005851 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005852 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005853 ASSERT_VK_SUCCESS(err);
5854
5855 VkDescriptorSet descriptorSet;
5856 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005857 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005858 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005859 alloc_info.descriptorPool = ds_pool;
5860 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005861 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005862 ASSERT_VK_SUCCESS(err);
5863
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005864 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005865 VkWriteDescriptorSet descriptor_write;
5866 memset(&descriptor_write, 0, sizeof(descriptor_write));
5867 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5868 descriptor_write.dstSet = descriptorSet;
5869 descriptor_write.dstBinding = 0;
5870 descriptor_write.descriptorCount = 1;
5871 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5872 descriptor_write.pTexelBufferView = &view;
5873
5874 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5875
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005876 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005877
5878 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5879 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5880}
5881
Mark Youngd339ba32016-05-30 13:28:35 -06005882TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005883 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 -06005884
5885 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005887 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005888
5889 ASSERT_NO_FATAL_FAILURE(InitState());
5890
5891 // Create a buffer with no bound memory and then attempt to create
5892 // a buffer view.
5893 VkBufferCreateInfo buff_ci = {};
5894 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005895 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005896 buff_ci.size = 256;
5897 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5898 VkBuffer buffer;
5899 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5900 ASSERT_VK_SUCCESS(err);
5901
5902 VkBufferViewCreateInfo buff_view_ci = {};
5903 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5904 buff_view_ci.buffer = buffer;
5905 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5906 buff_view_ci.range = VK_WHOLE_SIZE;
5907 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005908 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005909
5910 m_errorMonitor->VerifyFound();
5911 vkDestroyBuffer(m_device->device(), buffer, NULL);
5912 // If last error is success, it still created the view, so delete it.
5913 if (err == VK_SUCCESS) {
5914 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5915 }
5916}
5917
Karl Schultz6addd812016-02-02 17:17:23 -07005918TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5919 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5920 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005921 // 1. No dynamicOffset supplied
5922 // 2. Too many dynamicOffsets supplied
5923 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005924 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5926 "0 dynamicOffsets are left in "
5927 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005928
5929 ASSERT_NO_FATAL_FAILURE(InitState());
5930 ASSERT_NO_FATAL_FAILURE(InitViewport());
5931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5932
5933 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005934 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5935 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005936
5937 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005938 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5939 ds_pool_ci.pNext = NULL;
5940 ds_pool_ci.maxSets = 1;
5941 ds_pool_ci.poolSizeCount = 1;
5942 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005943
5944 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005945 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005946 ASSERT_VK_SUCCESS(err);
5947
5948 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005949 dsl_binding.binding = 0;
5950 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5951 dsl_binding.descriptorCount = 1;
5952 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5953 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005954
5955 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005956 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5957 ds_layout_ci.pNext = NULL;
5958 ds_layout_ci.bindingCount = 1;
5959 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005960 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005961 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005962 ASSERT_VK_SUCCESS(err);
5963
5964 VkDescriptorSet descriptorSet;
5965 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005966 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005967 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005968 alloc_info.descriptorPool = ds_pool;
5969 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005970 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005971 ASSERT_VK_SUCCESS(err);
5972
5973 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005974 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5975 pipeline_layout_ci.pNext = NULL;
5976 pipeline_layout_ci.setLayoutCount = 1;
5977 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005978
5979 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005980 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005981 ASSERT_VK_SUCCESS(err);
5982
5983 // Create a buffer to update the descriptor with
5984 uint32_t qfi = 0;
5985 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005986 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5987 buffCI.size = 1024;
5988 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5989 buffCI.queueFamilyIndexCount = 1;
5990 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005991
5992 VkBuffer dyub;
5993 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5994 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005995 // Allocate memory and bind to buffer so we can make it to the appropriate
5996 // error
5997 VkMemoryAllocateInfo mem_alloc = {};
5998 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5999 mem_alloc.pNext = NULL;
6000 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006001 mem_alloc.memoryTypeIndex = 0;
6002
6003 VkMemoryRequirements memReqs;
6004 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006005 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006006 if (!pass) {
6007 vkDestroyBuffer(m_device->device(), dyub, NULL);
6008 return;
6009 }
6010
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006011 VkDeviceMemory mem;
6012 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6013 ASSERT_VK_SUCCESS(err);
6014 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6015 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006016 // Correctly update descriptor to avoid "NOT_UPDATED" error
6017 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006018 buffInfo.buffer = dyub;
6019 buffInfo.offset = 0;
6020 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006021
6022 VkWriteDescriptorSet descriptor_write;
6023 memset(&descriptor_write, 0, sizeof(descriptor_write));
6024 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6025 descriptor_write.dstSet = descriptorSet;
6026 descriptor_write.dstBinding = 0;
6027 descriptor_write.descriptorCount = 1;
6028 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6029 descriptor_write.pBufferInfo = &buffInfo;
6030
6031 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6032
Tony Barbour552f6c02016-12-21 14:34:07 -07006033 m_commandBuffer->BeginCommandBuffer();
6034 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006035 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6036 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006037 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006038 uint32_t pDynOff[2] = {512, 756};
6039 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6041 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6042 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6043 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006044 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006045 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6047 "offset 0 and range 1024 that "
6048 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006049 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006050 char const *vsSource = "#version 450\n"
6051 "\n"
6052 "out gl_PerVertex { \n"
6053 " vec4 gl_Position;\n"
6054 "};\n"
6055 "void main(){\n"
6056 " gl_Position = vec4(1);\n"
6057 "}\n";
6058 char const *fsSource = "#version 450\n"
6059 "\n"
6060 "layout(location=0) out vec4 x;\n"
6061 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6062 "void main(){\n"
6063 " x = vec4(bar.y);\n"
6064 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006065 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6066 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6067 VkPipelineObj pipe(m_device);
6068 pipe.AddShader(&vs);
6069 pipe.AddShader(&fs);
6070 pipe.AddColorAttachment();
6071 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6072
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006073 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6074 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6075 VkRect2D scissor = {{0, 0}, {16, 16}};
6076 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6077
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006078 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006079 // This update should succeed, but offset size of 512 will overstep buffer
6080 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006081 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6082 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006083 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006084 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006085
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006086 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006087 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006088
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006089 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006090 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006091 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6092}
6093
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006094TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6095 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6096 "that doesn't have memory bound");
6097 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006099 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6101 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006102
6103 ASSERT_NO_FATAL_FAILURE(InitState());
6104 ASSERT_NO_FATAL_FAILURE(InitViewport());
6105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6106
6107 VkDescriptorPoolSize ds_type_count = {};
6108 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6109 ds_type_count.descriptorCount = 1;
6110
6111 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6112 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6113 ds_pool_ci.pNext = NULL;
6114 ds_pool_ci.maxSets = 1;
6115 ds_pool_ci.poolSizeCount = 1;
6116 ds_pool_ci.pPoolSizes = &ds_type_count;
6117
6118 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006119 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006120 ASSERT_VK_SUCCESS(err);
6121
6122 VkDescriptorSetLayoutBinding dsl_binding = {};
6123 dsl_binding.binding = 0;
6124 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6125 dsl_binding.descriptorCount = 1;
6126 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6127 dsl_binding.pImmutableSamplers = NULL;
6128
6129 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6130 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6131 ds_layout_ci.pNext = NULL;
6132 ds_layout_ci.bindingCount = 1;
6133 ds_layout_ci.pBindings = &dsl_binding;
6134 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006135 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006136 ASSERT_VK_SUCCESS(err);
6137
6138 VkDescriptorSet descriptorSet;
6139 VkDescriptorSetAllocateInfo alloc_info = {};
6140 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6141 alloc_info.descriptorSetCount = 1;
6142 alloc_info.descriptorPool = ds_pool;
6143 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006144 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006145 ASSERT_VK_SUCCESS(err);
6146
6147 // Create a buffer to update the descriptor with
6148 uint32_t qfi = 0;
6149 VkBufferCreateInfo buffCI = {};
6150 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6151 buffCI.size = 1024;
6152 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6153 buffCI.queueFamilyIndexCount = 1;
6154 buffCI.pQueueFamilyIndices = &qfi;
6155
6156 VkBuffer dyub;
6157 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6158 ASSERT_VK_SUCCESS(err);
6159
6160 // Attempt to update descriptor without binding memory to it
6161 VkDescriptorBufferInfo buffInfo = {};
6162 buffInfo.buffer = dyub;
6163 buffInfo.offset = 0;
6164 buffInfo.range = 1024;
6165
6166 VkWriteDescriptorSet descriptor_write;
6167 memset(&descriptor_write, 0, sizeof(descriptor_write));
6168 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6169 descriptor_write.dstSet = descriptorSet;
6170 descriptor_write.dstBinding = 0;
6171 descriptor_write.descriptorCount = 1;
6172 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6173 descriptor_write.pBufferInfo = &buffInfo;
6174
6175 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6176 m_errorMonitor->VerifyFound();
6177
6178 vkDestroyBuffer(m_device->device(), dyub, NULL);
6179 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6180 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6181}
6182
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006183TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006184 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006185 ASSERT_NO_FATAL_FAILURE(InitState());
6186 ASSERT_NO_FATAL_FAILURE(InitViewport());
6187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6188
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006189 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006190 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006191 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6192 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6193 pipeline_layout_ci.pushConstantRangeCount = 1;
6194 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6195
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006196 //
6197 // Check for invalid push constant ranges in pipeline layouts.
6198 //
6199 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006200 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006201 char const *msg;
6202 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006203
Karl Schultzc81037d2016-05-12 08:11:23 -06006204 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6205 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6206 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6207 "vkCreatePipelineLayout() call has push constants index 0 with "
6208 "size 0."},
6209 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6210 "vkCreatePipelineLayout() call has push constants index 0 with "
6211 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006212 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006213 "vkCreatePipelineLayout() call has push constants index 0 with "
6214 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006215 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006216 "vkCreatePipelineLayout() call has push constants index 0 with "
6217 "size 0."},
6218 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6219 "vkCreatePipelineLayout() call has push constants index 0 with "
6220 "offset 1. Offset must"},
6221 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6222 "vkCreatePipelineLayout() call has push constants index 0 "
6223 "with offset "},
6224 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6225 "vkCreatePipelineLayout() call has push constants "
6226 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006227 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006228 "vkCreatePipelineLayout() call has push constants index 0 "
6229 "with offset "},
6230 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6231 "vkCreatePipelineLayout() call has push "
6232 "constants index 0 with offset "},
6233 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6234 "vkCreatePipelineLayout() call has push "
6235 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006236 }};
6237
6238 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006239 for (const auto &iter : range_tests) {
6240 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6242 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006243 m_errorMonitor->VerifyFound();
6244 if (VK_SUCCESS == err) {
6245 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6246 }
6247 }
6248
6249 // Check for invalid stage flag
6250 pc_range.offset = 0;
6251 pc_range.size = 16;
6252 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006253 m_errorMonitor->SetDesiredFailureMsg(
6254 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6255 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006256 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006257 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006258 if (VK_SUCCESS == err) {
6259 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6260 }
6261
6262 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006263 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006264 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006265 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006266 char const *msg;
6267 };
6268
Karl Schultzc81037d2016-05-12 08:11:23 -06006269 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006270 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6271 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6272 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6273 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6274 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006275 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006276 {
6277 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6278 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6279 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6280 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6281 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006282 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006283 },
6284 {
6285 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6286 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6287 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6288 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6289 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006290 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006291 },
6292 {
6293 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6294 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6295 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6296 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6297 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006298 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006299 },
6300 {
6301 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6302 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6303 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6304 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6305 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006306 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006307 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006308
Karl Schultzc81037d2016-05-12 08:11:23 -06006309 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006310 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006311 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6313 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006314 m_errorMonitor->VerifyFound();
6315 if (VK_SUCCESS == err) {
6316 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6317 }
6318 }
6319
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006320 //
6321 // CmdPushConstants tests
6322 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006323 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006324
6325 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006326 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6327 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006328 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006329 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6330 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006331 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006332 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6333 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006334 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006335 "vkCmdPushConstants() call has push constants with offset 1. "
6336 "Offset must be a multiple of 4."},
6337 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6338 "vkCmdPushConstants() call has push constants with offset 1. "
6339 "Offset must be a multiple of 4."},
6340 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6341 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6342 "0x1 not within flag-matching ranges in pipeline layout"},
6343 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6344 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6345 "0x1 not within flag-matching ranges in pipeline layout"},
6346 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6347 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6348 "0x1 not within flag-matching ranges in pipeline layout"},
6349 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6350 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6351 "0x1 not within flag-matching ranges in pipeline layout"},
6352 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6353 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6354 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006355 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006356 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6357 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006358 }};
6359
Tony Barbour552f6c02016-12-21 14:34:07 -07006360 m_commandBuffer->BeginCommandBuffer();
6361 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006362
6363 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006364 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006365 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006366 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006367 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006368 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006369 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006370 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006371 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6373 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006374 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006375 m_errorMonitor->VerifyFound();
6376 }
6377
6378 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006380 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006381 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006382 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006383
Karl Schultzc81037d2016-05-12 08:11:23 -06006384 // overlapping range tests with cmd
6385 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6386 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6387 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6388 "0x1 not within flag-matching ranges in pipeline layout"},
6389 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6390 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6391 "0x1 not within flag-matching ranges in pipeline layout"},
6392 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6393 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6394 "0x1 not within flag-matching ranges in pipeline layout"},
6395 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006396 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006397 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006398 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6399 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006400 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006401 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006402 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006403 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006404 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006405 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6407 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006408 iter.range.size, dummy_values);
6409 m_errorMonitor->VerifyFound();
6410 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006411 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6412
Tony Barbour552f6c02016-12-21 14:34:07 -07006413 m_commandBuffer->EndRenderPass();
6414 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006415}
6416
Karl Schultz6addd812016-02-02 17:17:23 -07006417TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006418 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006419 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006420
6421 ASSERT_NO_FATAL_FAILURE(InitState());
6422 ASSERT_NO_FATAL_FAILURE(InitViewport());
6423 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6424
Mike Stroyanb8a61002016-06-20 16:00:28 -06006425 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6426 VkImageTiling tiling;
6427 VkFormatProperties format_properties;
6428 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006429 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006430 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006431 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006432 tiling = VK_IMAGE_TILING_OPTIMAL;
6433 } else {
6434 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6435 "skipped.\n");
6436 return;
6437 }
6438
Tobin Ehlis559c6382015-11-05 09:52:49 -07006439 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6440 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006441 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6442 ds_type_count[0].descriptorCount = 10;
6443 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6444 ds_type_count[1].descriptorCount = 2;
6445 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6446 ds_type_count[2].descriptorCount = 2;
6447 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6448 ds_type_count[3].descriptorCount = 5;
6449 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6450 // type
6451 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6452 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6453 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006454
6455 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006456 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6457 ds_pool_ci.pNext = NULL;
6458 ds_pool_ci.maxSets = 5;
6459 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6460 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006461
6462 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006463 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006464 ASSERT_VK_SUCCESS(err);
6465
6466 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6467 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006468 dsl_binding[0].binding = 0;
6469 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6470 dsl_binding[0].descriptorCount = 5;
6471 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6472 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006473
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006474 // Create layout identical to set0 layout but w/ different stageFlags
6475 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006476 dsl_fs_stage_only.binding = 0;
6477 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6478 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006479 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6480 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006481 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006482 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006483 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6484 ds_layout_ci.pNext = NULL;
6485 ds_layout_ci.bindingCount = 1;
6486 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006487 static const uint32_t NUM_LAYOUTS = 4;
6488 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006489 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006490 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6491 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006492 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006493 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006494 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006495 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006496 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006497 dsl_binding[0].binding = 0;
6498 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006499 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006500 dsl_binding[1].binding = 1;
6501 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6502 dsl_binding[1].descriptorCount = 2;
6503 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6504 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006505 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006506 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006507 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006508 ASSERT_VK_SUCCESS(err);
6509 dsl_binding[0].binding = 0;
6510 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006511 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006512 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006513 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006514 ASSERT_VK_SUCCESS(err);
6515 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006516 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006517 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006518 ASSERT_VK_SUCCESS(err);
6519
6520 static const uint32_t NUM_SETS = 4;
6521 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6522 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006523 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006524 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006525 alloc_info.descriptorPool = ds_pool;
6526 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006528 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006529 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006530 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006531 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006532 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006533 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006534
6535 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006536 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6537 pipeline_layout_ci.pNext = NULL;
6538 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6539 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006540
6541 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006542 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006543 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006544 // Create pipelineLayout with only one setLayout
6545 pipeline_layout_ci.setLayoutCount = 1;
6546 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006547 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006548 ASSERT_VK_SUCCESS(err);
6549 // Create pipelineLayout with 2 descriptor setLayout at index 0
6550 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6551 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006552 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006553 ASSERT_VK_SUCCESS(err);
6554 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6555 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6556 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006557 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006558 ASSERT_VK_SUCCESS(err);
6559 // Create pipelineLayout with UB type, but stageFlags for FS only
6560 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6561 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006563 ASSERT_VK_SUCCESS(err);
6564 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6565 VkDescriptorSetLayout pl_bad_s0[2] = {};
6566 pl_bad_s0[0] = ds_layout_fs_only;
6567 pl_bad_s0[1] = ds_layout[1];
6568 pipeline_layout_ci.setLayoutCount = 2;
6569 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6570 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006571 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006572 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006573
6574 // Create a buffer to update the descriptor with
6575 uint32_t qfi = 0;
6576 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006577 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6578 buffCI.size = 1024;
6579 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6580 buffCI.queueFamilyIndexCount = 1;
6581 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006582
6583 VkBuffer dyub;
6584 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6585 ASSERT_VK_SUCCESS(err);
6586 // Correctly update descriptor to avoid "NOT_UPDATED" error
6587 static const uint32_t NUM_BUFFS = 5;
6588 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006589 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006590 buffInfo[i].buffer = dyub;
6591 buffInfo[i].offset = 0;
6592 buffInfo[i].range = 1024;
6593 }
Karl Schultz6addd812016-02-02 17:17:23 -07006594 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006595 const int32_t tex_width = 32;
6596 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006597 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006598 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6599 image_create_info.pNext = NULL;
6600 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6601 image_create_info.format = tex_format;
6602 image_create_info.extent.width = tex_width;
6603 image_create_info.extent.height = tex_height;
6604 image_create_info.extent.depth = 1;
6605 image_create_info.mipLevels = 1;
6606 image_create_info.arrayLayers = 1;
6607 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006608 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006609 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006610 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006611 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6612 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006613
Karl Schultz6addd812016-02-02 17:17:23 -07006614 VkMemoryRequirements memReqs;
6615 VkDeviceMemory imageMem;
6616 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006617 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006618 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6619 memAlloc.pNext = NULL;
6620 memAlloc.allocationSize = 0;
6621 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006622 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6623 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006624 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006625 ASSERT_TRUE(pass);
6626 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6627 ASSERT_VK_SUCCESS(err);
6628 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6629 ASSERT_VK_SUCCESS(err);
6630
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006631 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006632 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6633 image_view_create_info.image = image;
6634 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6635 image_view_create_info.format = tex_format;
6636 image_view_create_info.subresourceRange.layerCount = 1;
6637 image_view_create_info.subresourceRange.baseMipLevel = 0;
6638 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006639 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006640
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006641 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006642 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006643 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006644 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006645 imageInfo[0].imageView = view;
6646 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6647 imageInfo[1].imageView = view;
6648 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006649 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006650 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006651 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006652 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006653
6654 static const uint32_t NUM_SET_UPDATES = 3;
6655 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6656 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6657 descriptor_write[0].dstSet = descriptorSet[0];
6658 descriptor_write[0].dstBinding = 0;
6659 descriptor_write[0].descriptorCount = 5;
6660 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6661 descriptor_write[0].pBufferInfo = buffInfo;
6662 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6663 descriptor_write[1].dstSet = descriptorSet[1];
6664 descriptor_write[1].dstBinding = 0;
6665 descriptor_write[1].descriptorCount = 2;
6666 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6667 descriptor_write[1].pImageInfo = imageInfo;
6668 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6669 descriptor_write[2].dstSet = descriptorSet[1];
6670 descriptor_write[2].dstBinding = 1;
6671 descriptor_write[2].descriptorCount = 2;
6672 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006673 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006674
6675 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006676
Tobin Ehlis88452832015-12-03 09:40:56 -07006677 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006678 char const *vsSource = "#version 450\n"
6679 "\n"
6680 "out gl_PerVertex {\n"
6681 " vec4 gl_Position;\n"
6682 "};\n"
6683 "void main(){\n"
6684 " gl_Position = vec4(1);\n"
6685 "}\n";
6686 char const *fsSource = "#version 450\n"
6687 "\n"
6688 "layout(location=0) out vec4 x;\n"
6689 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6690 "void main(){\n"
6691 " x = vec4(bar.y);\n"
6692 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006693 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6694 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006695 VkPipelineObj pipe(m_device);
6696 pipe.AddShader(&vs);
6697 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006698 pipe.AddColorAttachment();
6699 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006700
Tony Barbour552f6c02016-12-21 14:34:07 -07006701 m_commandBuffer->BeginCommandBuffer();
6702 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006703
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006704 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006705 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6706 // of PSO
6707 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6708 // cmd_pipeline.c
6709 // due to the fact that cmd_alloc_dset_data() has not been called in
6710 // cmd_bind_graphics_pipeline()
6711 // TODO : Want to cause various binding incompatibility issues here to test
6712 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006713 // First cause various verify_layout_compatibility() fails
6714 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006715 // verify_set_layout_compatibility fail cases:
6716 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006718 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6719 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006720 m_errorMonitor->VerifyFound();
6721
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006722 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6724 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6725 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006726 m_errorMonitor->VerifyFound();
6727
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006728 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006729 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6730 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6732 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6733 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006734 m_errorMonitor->VerifyFound();
6735
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006736 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6737 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6739 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6740 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006741 m_errorMonitor->VerifyFound();
6742
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006743 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6744 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6746 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6747 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6748 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006749 m_errorMonitor->VerifyFound();
6750
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006751 // Cause INFO messages due to disturbing previously bound Sets
6752 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006753 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6754 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006755 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6757 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6758 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006759 m_errorMonitor->VerifyFound();
6760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006761 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6762 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006763 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6765 "any subsequent sets were disturbed ");
6766 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6767 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006768 m_errorMonitor->VerifyFound();
6769
Tobin Ehlis10fad692016-07-07 12:00:36 -06006770 // Now that we're done actively using the pipelineLayout that gfx pipeline
6771 // was created with, we should be able to delete it. Do that now to verify
6772 // that validation obeys pipelineLayout lifetime
6773 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6774
Tobin Ehlis88452832015-12-03 09:40:56 -07006775 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006776 // 1. Error due to not binding required set (we actually use same code as
6777 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006778 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6779 &descriptorSet[0], 0, NULL);
6780 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6781 &descriptorSet[1], 0, NULL);
6782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006783 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006784 m_errorMonitor->VerifyFound();
6785
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006786 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006787 // 2. Error due to bound set not being compatible with PSO's
6788 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006789 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6790 &descriptorSet[0], 0, NULL);
6791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006792 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006793 m_errorMonitor->VerifyFound();
6794
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006795 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006796 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006797 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6798 }
6799 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006800 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006801 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6802 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006803 vkFreeMemory(m_device->device(), imageMem, NULL);
6804 vkDestroyImage(m_device->device(), image, NULL);
6805 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006806}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006807
Karl Schultz6addd812016-02-02 17:17:23 -07006808TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006809
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6811 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006812
6813 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006814 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006815 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006816 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006817
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006818 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006819}
6820
Karl Schultz6addd812016-02-02 17:17:23 -07006821TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6822 VkResult err;
6823 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006824
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006826
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006827 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006828
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006829 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006830 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006831 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006832 cmd.commandPool = m_commandPool;
6833 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006834 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006835
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006836 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006837 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006838
6839 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006840 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006841 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006842 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006843 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006844 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 -07006845 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006846
6847 // The error should be caught by validation of the BeginCommandBuffer call
6848 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6849
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006850 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006851 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006852}
6853
Karl Schultz6addd812016-02-02 17:17:23 -07006854TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006855 // Cause error due to Begin while recording CB
6856 // Then cause 2 errors for attempting to reset CB w/o having
6857 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6858 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006860
6861 ASSERT_NO_FATAL_FAILURE(InitState());
6862
6863 // Calls AllocateCommandBuffers
6864 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6865
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006866 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07006867 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006868 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6869 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006870 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6871 cmd_buf_info.pNext = NULL;
6872 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006873 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006874
6875 // Begin CB to transition to recording state
6876 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6877 // Can't re-begin. This should trigger error
6878 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006879 m_errorMonitor->VerifyFound();
6880
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006882 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6883 // Reset attempt will trigger error due to incorrect CommandPool state
6884 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006885 m_errorMonitor->VerifyFound();
6886
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006888 // Transition CB to RECORDED state
6889 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6890 // Now attempting to Begin will implicitly reset, which triggers error
6891 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006892 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006893}
6894
Karl Schultz6addd812016-02-02 17:17:23 -07006895TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006896 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006897 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006898
Mike Weiblencce7ec72016-10-17 19:33:05 -06006899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006900
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006901 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006903
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006904 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006905 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6906 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006907
6908 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006909 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6910 ds_pool_ci.pNext = NULL;
6911 ds_pool_ci.maxSets = 1;
6912 ds_pool_ci.poolSizeCount = 1;
6913 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006914
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006915 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006916 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006917 ASSERT_VK_SUCCESS(err);
6918
Tony Barboureb254902015-07-15 12:50:33 -06006919 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006920 dsl_binding.binding = 0;
6921 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6922 dsl_binding.descriptorCount = 1;
6923 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6924 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006925
Tony Barboureb254902015-07-15 12:50:33 -06006926 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006927 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6928 ds_layout_ci.pNext = NULL;
6929 ds_layout_ci.bindingCount = 1;
6930 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006931
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006932 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006934 ASSERT_VK_SUCCESS(err);
6935
6936 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006937 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006938 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006939 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006940 alloc_info.descriptorPool = ds_pool;
6941 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006942 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006943 ASSERT_VK_SUCCESS(err);
6944
Tony Barboureb254902015-07-15 12:50:33 -06006945 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006946 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6947 pipeline_layout_ci.setLayoutCount = 1;
6948 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006949
6950 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006951 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006952 ASSERT_VK_SUCCESS(err);
6953
Tobin Ehlise68360f2015-10-01 11:15:13 -06006954 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006955 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006956
6957 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006958 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6959 vp_state_ci.scissorCount = 1;
6960 vp_state_ci.pScissors = &sc;
6961 vp_state_ci.viewportCount = 1;
6962 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006963
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006964 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6965 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6966 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6967 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6968 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6969 rs_state_ci.depthClampEnable = VK_FALSE;
6970 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6971 rs_state_ci.depthBiasEnable = VK_FALSE;
6972
Tony Barboureb254902015-07-15 12:50:33 -06006973 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006974 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6975 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006976 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006977 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6978 gp_ci.layout = pipeline_layout;
6979 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006980
6981 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006982 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6983 pc_ci.initialDataSize = 0;
6984 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006985
6986 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006987 VkPipelineCache pipelineCache;
6988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006989 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006990 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006991 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006992
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006993 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006994
Chia-I Wuf7458c52015-10-26 21:10:41 +08006995 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6996 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6997 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6998 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006999}
Tobin Ehlis912df022015-09-17 08:46:18 -06007000/*// TODO : This test should be good, but needs Tess support in compiler to run
7001TEST_F(VkLayerTest, InvalidPatchControlPoints)
7002{
7003 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007004 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007005
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007007 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7008primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007009
Tobin Ehlis912df022015-09-17 08:46:18 -06007010 ASSERT_NO_FATAL_FAILURE(InitState());
7011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007012
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007013 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007014 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007015 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007016
7017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7019 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007020 ds_pool_ci.poolSizeCount = 1;
7021 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007022
7023 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007024 err = vkCreateDescriptorPool(m_device->device(),
7025VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007026 ASSERT_VK_SUCCESS(err);
7027
7028 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007029 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007030 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007031 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007032 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7033 dsl_binding.pImmutableSamplers = NULL;
7034
7035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007036 ds_layout_ci.sType =
7037VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007038 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007039 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007040 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007041
7042 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007043 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7044&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007045 ASSERT_VK_SUCCESS(err);
7046
7047 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007048 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7049VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007050 ASSERT_VK_SUCCESS(err);
7051
7052 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007053 pipeline_layout_ci.sType =
7054VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007055 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007056 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007057 pipeline_layout_ci.pSetLayouts = &ds_layout;
7058
7059 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007060 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7061&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007062 ASSERT_VK_SUCCESS(err);
7063
7064 VkPipelineShaderStageCreateInfo shaderStages[3];
7065 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7066
Karl Schultz6addd812016-02-02 17:17:23 -07007067 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7068this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007069 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007070 VkShaderObj
7071tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7072this);
7073 VkShaderObj
7074te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7075this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007076
Karl Schultz6addd812016-02-02 17:17:23 -07007077 shaderStages[0].sType =
7078VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007079 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007080 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007081 shaderStages[1].sType =
7082VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007083 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007084 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007085 shaderStages[2].sType =
7086VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007087 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007088 shaderStages[2].shader = te.handle();
7089
7090 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007091 iaCI.sType =
7092VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007093 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007094
7095 VkPipelineTessellationStateCreateInfo tsCI = {};
7096 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7097 tsCI.patchControlPoints = 0; // This will cause an error
7098
7099 VkGraphicsPipelineCreateInfo gp_ci = {};
7100 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7101 gp_ci.pNext = NULL;
7102 gp_ci.stageCount = 3;
7103 gp_ci.pStages = shaderStages;
7104 gp_ci.pVertexInputState = NULL;
7105 gp_ci.pInputAssemblyState = &iaCI;
7106 gp_ci.pTessellationState = &tsCI;
7107 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007108 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007109 gp_ci.pMultisampleState = NULL;
7110 gp_ci.pDepthStencilState = NULL;
7111 gp_ci.pColorBlendState = NULL;
7112 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7113 gp_ci.layout = pipeline_layout;
7114 gp_ci.renderPass = renderPass();
7115
7116 VkPipelineCacheCreateInfo pc_ci = {};
7117 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7118 pc_ci.pNext = NULL;
7119 pc_ci.initialSize = 0;
7120 pc_ci.initialData = 0;
7121 pc_ci.maxSize = 0;
7122
7123 VkPipeline pipeline;
7124 VkPipelineCache pipelineCache;
7125
Karl Schultz6addd812016-02-02 17:17:23 -07007126 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7127&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007128 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007129 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7130&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007131
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007132 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007133
Chia-I Wuf7458c52015-10-26 21:10:41 +08007134 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7135 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7136 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7137 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007138}
7139*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007140
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007141TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007142 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007143
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007144 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007145
Tobin Ehlise68360f2015-10-01 11:15:13 -06007146 ASSERT_NO_FATAL_FAILURE(InitState());
7147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007148
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007149 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007150 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7151 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007152
7153 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007154 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7155 ds_pool_ci.maxSets = 1;
7156 ds_pool_ci.poolSizeCount = 1;
7157 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007158
7159 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007160 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161 ASSERT_VK_SUCCESS(err);
7162
7163 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007164 dsl_binding.binding = 0;
7165 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7166 dsl_binding.descriptorCount = 1;
7167 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007168
7169 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007170 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7171 ds_layout_ci.bindingCount = 1;
7172 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007173
7174 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176 ASSERT_VK_SUCCESS(err);
7177
7178 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007179 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007180 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007181 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007182 alloc_info.descriptorPool = ds_pool;
7183 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007184 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007185 ASSERT_VK_SUCCESS(err);
7186
7187 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007188 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7189 pipeline_layout_ci.setLayoutCount = 1;
7190 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007191
7192 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007193 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007194 ASSERT_VK_SUCCESS(err);
7195
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007196 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007197 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007198 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007199 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007200 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007201 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007202
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007203 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7204 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7205 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7206 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7207 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7208 rs_state_ci.depthClampEnable = VK_FALSE;
7209 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7210 rs_state_ci.depthBiasEnable = VK_FALSE;
7211
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007212 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7213 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7214 vi_ci.pNext = nullptr;
7215 vi_ci.vertexBindingDescriptionCount = 0;
7216 vi_ci.pVertexBindingDescriptions = nullptr;
7217 vi_ci.vertexAttributeDescriptionCount = 0;
7218 vi_ci.pVertexAttributeDescriptions = nullptr;
7219
7220 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7221 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7222 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7223
7224 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7225 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7226 pipe_ms_state_ci.pNext = NULL;
7227 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7228 pipe_ms_state_ci.sampleShadingEnable = 0;
7229 pipe_ms_state_ci.minSampleShading = 1.0;
7230 pipe_ms_state_ci.pSampleMask = NULL;
7231
Cody Northropeb3a6c12015-10-05 14:44:45 -06007232 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007233 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007234
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007236 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007237 shaderStages[0] = vs.GetStageCreateInfo();
7238 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007239
7240 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007241 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7242 gp_ci.stageCount = 2;
7243 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007244 gp_ci.pVertexInputState = &vi_ci;
7245 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007246 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007247 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007248 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007249 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7250 gp_ci.layout = pipeline_layout;
7251 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007252
7253 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007254 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007255
7256 VkPipeline pipeline;
7257 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007258 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007259 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007260
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007261 if (!m_device->phy().features().multiViewport) {
7262 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7263
7264 // Check case where multiViewport is disabled and viewport count is not 1
7265 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7268 vp_state_ci.scissorCount = 0;
7269 vp_state_ci.viewportCount = 0;
7270 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7271 m_errorMonitor->VerifyFound();
7272 } else {
7273 if (m_device->props.limits.maxViewports == 1) {
7274 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7275 } else {
7276 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7277
7278 // Check is that viewportcount and scissorcount match
7279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7280 vp_state_ci.scissorCount = 1;
7281 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7282 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7283 m_errorMonitor->VerifyFound();
7284
7285
7286 // Check case where multiViewport is enabled and viewport count is greater than max
7287 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7290 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7291 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7292 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7293 m_errorMonitor->VerifyFound();
7294 }
7295 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007296
Chia-I Wuf7458c52015-10-26 21:10:41 +08007297 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7298 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7299 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7300 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007301}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007302
7303// 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
7304// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007305TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007306 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007307
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007308 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7309
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007311
Tobin Ehlise68360f2015-10-01 11:15:13 -06007312 ASSERT_NO_FATAL_FAILURE(InitState());
7313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007314
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007315 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007316 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7317 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007318
7319 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007320 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7321 ds_pool_ci.maxSets = 1;
7322 ds_pool_ci.poolSizeCount = 1;
7323 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007324
7325 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007326 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007327 ASSERT_VK_SUCCESS(err);
7328
7329 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007330 dsl_binding.binding = 0;
7331 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7332 dsl_binding.descriptorCount = 1;
7333 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007334
7335 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007336 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7337 ds_layout_ci.bindingCount = 1;
7338 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007339
7340 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007341 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007342 ASSERT_VK_SUCCESS(err);
7343
7344 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007345 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007346 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007347 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007348 alloc_info.descriptorPool = ds_pool;
7349 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007350 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007351 ASSERT_VK_SUCCESS(err);
7352
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007353 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7354 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7355 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7356
7357 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7358 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7359 vi_ci.pNext = nullptr;
7360 vi_ci.vertexBindingDescriptionCount = 0;
7361 vi_ci.pVertexBindingDescriptions = nullptr;
7362 vi_ci.vertexAttributeDescriptionCount = 0;
7363 vi_ci.pVertexAttributeDescriptions = nullptr;
7364
7365 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7366 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7367 pipe_ms_state_ci.pNext = NULL;
7368 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7369 pipe_ms_state_ci.sampleShadingEnable = 0;
7370 pipe_ms_state_ci.minSampleShading = 1.0;
7371 pipe_ms_state_ci.pSampleMask = NULL;
7372
Tobin Ehlise68360f2015-10-01 11:15:13 -06007373 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007374 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7375 pipeline_layout_ci.setLayoutCount = 1;
7376 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007377
7378 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007379 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007380 ASSERT_VK_SUCCESS(err);
7381
7382 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7383 // Set scissor as dynamic to avoid second error
7384 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007385 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7386 dyn_state_ci.dynamicStateCount = 1;
7387 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388
Cody Northropeb3a6c12015-10-05 14:44:45 -06007389 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007390 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007392 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007393 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7394 // 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 +08007395 shaderStages[0] = vs.GetStageCreateInfo();
7396 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007397
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007398 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7399 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7400 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7401 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7402 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7403 rs_state_ci.depthClampEnable = VK_FALSE;
7404 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7405 rs_state_ci.depthBiasEnable = VK_FALSE;
7406
Tobin Ehlise68360f2015-10-01 11:15:13 -06007407 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007408 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7409 gp_ci.stageCount = 2;
7410 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007411 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007412 // Not setting VP state w/o dynamic vp state should cause validation error
7413 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007414 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007415 gp_ci.pVertexInputState = &vi_ci;
7416 gp_ci.pInputAssemblyState = &ia_ci;
7417 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007418 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7419 gp_ci.layout = pipeline_layout;
7420 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007421
7422 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007423 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007424
7425 VkPipeline pipeline;
7426 VkPipelineCache pipelineCache;
7427
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007428 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007429 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007430 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007431
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007432 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007433
Chia-I Wuf7458c52015-10-26 21:10:41 +08007434 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7435 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7436 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7437 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007438}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007439
7440// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7441// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007442TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7443 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007444
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007446
Tobin Ehlise68360f2015-10-01 11:15:13 -06007447 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007448
7449 if (!m_device->phy().features().multiViewport) {
7450 printf("Device does not support multiple viewports/scissors; skipped.\n");
7451 return;
7452 }
7453
Tobin Ehlise68360f2015-10-01 11:15:13 -06007454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007455
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007456 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007457 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7458 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007459
7460 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007461 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7462 ds_pool_ci.maxSets = 1;
7463 ds_pool_ci.poolSizeCount = 1;
7464 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007465
7466 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007467 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007468 ASSERT_VK_SUCCESS(err);
7469
7470 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007471 dsl_binding.binding = 0;
7472 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7473 dsl_binding.descriptorCount = 1;
7474 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007475
7476 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007477 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7478 ds_layout_ci.bindingCount = 1;
7479 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480
7481 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007482 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007483 ASSERT_VK_SUCCESS(err);
7484
7485 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007486 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007487 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007488 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007489 alloc_info.descriptorPool = ds_pool;
7490 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007491 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007492 ASSERT_VK_SUCCESS(err);
7493
7494 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007495 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7496 pipeline_layout_ci.setLayoutCount = 1;
7497 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007498
7499 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007500 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007501 ASSERT_VK_SUCCESS(err);
7502
7503 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007504 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7505 vp_state_ci.viewportCount = 1;
7506 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7507 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007508 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007509
7510 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7511 // Set scissor as dynamic to avoid that error
7512 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007513 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7514 dyn_state_ci.dynamicStateCount = 1;
7515 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007516
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007517 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7518 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7519 pipe_ms_state_ci.pNext = NULL;
7520 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7521 pipe_ms_state_ci.sampleShadingEnable = 0;
7522 pipe_ms_state_ci.minSampleShading = 1.0;
7523 pipe_ms_state_ci.pSampleMask = NULL;
7524
Cody Northropeb3a6c12015-10-05 14:44:45 -06007525 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007526 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007527
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007528 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007529 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7530 // 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 +08007531 shaderStages[0] = vs.GetStageCreateInfo();
7532 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007533
Cody Northropf6622dc2015-10-06 10:33:21 -06007534 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7535 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7536 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007537 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007538 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007539 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007540 vi_ci.pVertexAttributeDescriptions = nullptr;
7541
7542 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7543 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7544 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7545
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007546 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007547 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007548 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007549 rs_ci.pNext = nullptr;
7550
Mark Youngc89c6312016-03-31 16:03:20 -06007551 VkPipelineColorBlendAttachmentState att = {};
7552 att.blendEnable = VK_FALSE;
7553 att.colorWriteMask = 0xf;
7554
Cody Northropf6622dc2015-10-06 10:33:21 -06007555 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7556 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7557 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007558 cb_ci.attachmentCount = 1;
7559 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007560
Tobin Ehlise68360f2015-10-01 11:15:13 -06007561 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007562 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7563 gp_ci.stageCount = 2;
7564 gp_ci.pStages = shaderStages;
7565 gp_ci.pVertexInputState = &vi_ci;
7566 gp_ci.pInputAssemblyState = &ia_ci;
7567 gp_ci.pViewportState = &vp_state_ci;
7568 gp_ci.pRasterizationState = &rs_ci;
7569 gp_ci.pColorBlendState = &cb_ci;
7570 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007571 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007572 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7573 gp_ci.layout = pipeline_layout;
7574 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007575
7576 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007577 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007578
7579 VkPipeline pipeline;
7580 VkPipelineCache pipelineCache;
7581
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007582 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007583 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007585
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007586 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007587
Tobin Ehlisd332f282015-10-02 11:00:56 -06007588 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007589 // First need to successfully create the PSO from above by setting
7590 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007591 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 -07007592
7593 VkViewport vp = {}; // Just need dummy vp to point to
7594 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007595 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007596 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007597 m_commandBuffer->BeginCommandBuffer();
7598 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007599 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007600 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007601 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007602 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007603 Draw(1, 0, 0, 0);
7604
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007605 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007606
7607 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7608 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7609 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7610 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007611 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007612}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007613
7614// 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 -07007615// viewportCount
7616TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7617 VkResult err;
7618
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007620
7621 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007622
7623 if (!m_device->phy().features().multiViewport) {
7624 printf("Device does not support multiple viewports/scissors; skipped.\n");
7625 return;
7626 }
7627
Karl Schultz6addd812016-02-02 17:17:23 -07007628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7629
7630 VkDescriptorPoolSize ds_type_count = {};
7631 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7632 ds_type_count.descriptorCount = 1;
7633
7634 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7635 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7636 ds_pool_ci.maxSets = 1;
7637 ds_pool_ci.poolSizeCount = 1;
7638 ds_pool_ci.pPoolSizes = &ds_type_count;
7639
7640 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007641 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007642 ASSERT_VK_SUCCESS(err);
7643
7644 VkDescriptorSetLayoutBinding dsl_binding = {};
7645 dsl_binding.binding = 0;
7646 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7647 dsl_binding.descriptorCount = 1;
7648 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7649
7650 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7651 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7652 ds_layout_ci.bindingCount = 1;
7653 ds_layout_ci.pBindings = &dsl_binding;
7654
7655 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007656 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007657 ASSERT_VK_SUCCESS(err);
7658
7659 VkDescriptorSet descriptorSet;
7660 VkDescriptorSetAllocateInfo alloc_info = {};
7661 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7662 alloc_info.descriptorSetCount = 1;
7663 alloc_info.descriptorPool = ds_pool;
7664 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007665 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007666 ASSERT_VK_SUCCESS(err);
7667
7668 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7669 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7670 pipeline_layout_ci.setLayoutCount = 1;
7671 pipeline_layout_ci.pSetLayouts = &ds_layout;
7672
7673 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007674 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007675 ASSERT_VK_SUCCESS(err);
7676
7677 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7678 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7679 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007680 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007681 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007682 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007683
7684 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7685 // Set scissor as dynamic to avoid that error
7686 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7687 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7688 dyn_state_ci.dynamicStateCount = 1;
7689 dyn_state_ci.pDynamicStates = &vp_state;
7690
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007691 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7692 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7693 pipe_ms_state_ci.pNext = NULL;
7694 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7695 pipe_ms_state_ci.sampleShadingEnable = 0;
7696 pipe_ms_state_ci.minSampleShading = 1.0;
7697 pipe_ms_state_ci.pSampleMask = NULL;
7698
Karl Schultz6addd812016-02-02 17:17:23 -07007699 VkPipelineShaderStageCreateInfo shaderStages[2];
7700 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007702 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007703 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7704 // 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 -07007705 shaderStages[0] = vs.GetStageCreateInfo();
7706 shaderStages[1] = fs.GetStageCreateInfo();
7707
7708 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7709 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7710 vi_ci.pNext = nullptr;
7711 vi_ci.vertexBindingDescriptionCount = 0;
7712 vi_ci.pVertexBindingDescriptions = nullptr;
7713 vi_ci.vertexAttributeDescriptionCount = 0;
7714 vi_ci.pVertexAttributeDescriptions = nullptr;
7715
7716 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7717 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7718 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7719
7720 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7721 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007722 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007723 rs_ci.pNext = nullptr;
7724
Mark Youngc89c6312016-03-31 16:03:20 -06007725 VkPipelineColorBlendAttachmentState att = {};
7726 att.blendEnable = VK_FALSE;
7727 att.colorWriteMask = 0xf;
7728
Karl Schultz6addd812016-02-02 17:17:23 -07007729 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7730 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7731 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007732 cb_ci.attachmentCount = 1;
7733 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007734
7735 VkGraphicsPipelineCreateInfo gp_ci = {};
7736 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7737 gp_ci.stageCount = 2;
7738 gp_ci.pStages = shaderStages;
7739 gp_ci.pVertexInputState = &vi_ci;
7740 gp_ci.pInputAssemblyState = &ia_ci;
7741 gp_ci.pViewportState = &vp_state_ci;
7742 gp_ci.pRasterizationState = &rs_ci;
7743 gp_ci.pColorBlendState = &cb_ci;
7744 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007745 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007746 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7747 gp_ci.layout = pipeline_layout;
7748 gp_ci.renderPass = renderPass();
7749
7750 VkPipelineCacheCreateInfo pc_ci = {};
7751 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7752
7753 VkPipeline pipeline;
7754 VkPipelineCache pipelineCache;
7755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007756 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007757 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007758 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007759
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007760 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007761
7762 // Now hit second fail case where we set scissor w/ different count than PSO
7763 // First need to successfully create the PSO from above by setting
7764 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007765 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 -06007766
Tobin Ehlisd332f282015-10-02 11:00:56 -06007767 VkRect2D sc = {}; // Just need dummy vp to point to
7768 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007769 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007770 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007771 m_commandBuffer->BeginCommandBuffer();
7772 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007773 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007774 VkViewport viewports[1] = {};
7775 viewports[0].width = 8;
7776 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007777 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007778 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007779 Draw(1, 0, 0, 0);
7780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007781 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007782
Chia-I Wuf7458c52015-10-26 21:10:41 +08007783 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7784 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7785 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7786 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007787 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007788}
7789
Mark Young7394fdd2016-03-31 14:56:43 -06007790TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7791 VkResult err;
7792
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007794
7795 ASSERT_NO_FATAL_FAILURE(InitState());
7796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7797
7798 VkDescriptorPoolSize ds_type_count = {};
7799 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7800 ds_type_count.descriptorCount = 1;
7801
7802 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7803 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7804 ds_pool_ci.maxSets = 1;
7805 ds_pool_ci.poolSizeCount = 1;
7806 ds_pool_ci.pPoolSizes = &ds_type_count;
7807
7808 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007809 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007810 ASSERT_VK_SUCCESS(err);
7811
7812 VkDescriptorSetLayoutBinding dsl_binding = {};
7813 dsl_binding.binding = 0;
7814 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7815 dsl_binding.descriptorCount = 1;
7816 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7817
7818 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7819 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7820 ds_layout_ci.bindingCount = 1;
7821 ds_layout_ci.pBindings = &dsl_binding;
7822
7823 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007824 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007825 ASSERT_VK_SUCCESS(err);
7826
7827 VkDescriptorSet descriptorSet;
7828 VkDescriptorSetAllocateInfo alloc_info = {};
7829 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7830 alloc_info.descriptorSetCount = 1;
7831 alloc_info.descriptorPool = ds_pool;
7832 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007833 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007834 ASSERT_VK_SUCCESS(err);
7835
7836 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7837 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7838 pipeline_layout_ci.setLayoutCount = 1;
7839 pipeline_layout_ci.pSetLayouts = &ds_layout;
7840
7841 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007843 ASSERT_VK_SUCCESS(err);
7844
7845 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7846 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7847 vp_state_ci.scissorCount = 1;
7848 vp_state_ci.pScissors = NULL;
7849 vp_state_ci.viewportCount = 1;
7850 vp_state_ci.pViewports = NULL;
7851
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007852 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007853 // Set scissor as dynamic to avoid that error
7854 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7855 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7856 dyn_state_ci.dynamicStateCount = 2;
7857 dyn_state_ci.pDynamicStates = dynamic_states;
7858
7859 VkPipelineShaderStageCreateInfo shaderStages[2];
7860 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007862 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7863 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007864 this); // TODO - We shouldn't need a fragment shader
7865 // but add it to be able to run on more devices
7866 shaderStages[0] = vs.GetStageCreateInfo();
7867 shaderStages[1] = fs.GetStageCreateInfo();
7868
7869 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7870 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7871 vi_ci.pNext = nullptr;
7872 vi_ci.vertexBindingDescriptionCount = 0;
7873 vi_ci.pVertexBindingDescriptions = nullptr;
7874 vi_ci.vertexAttributeDescriptionCount = 0;
7875 vi_ci.pVertexAttributeDescriptions = nullptr;
7876
7877 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7878 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7879 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7880
7881 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7882 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7883 rs_ci.pNext = nullptr;
7884
Mark Young47107952016-05-02 15:59:55 -06007885 // Check too low (line width of -1.0f).
7886 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007887
7888 VkPipelineColorBlendAttachmentState att = {};
7889 att.blendEnable = VK_FALSE;
7890 att.colorWriteMask = 0xf;
7891
7892 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7893 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7894 cb_ci.pNext = nullptr;
7895 cb_ci.attachmentCount = 1;
7896 cb_ci.pAttachments = &att;
7897
7898 VkGraphicsPipelineCreateInfo gp_ci = {};
7899 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7900 gp_ci.stageCount = 2;
7901 gp_ci.pStages = shaderStages;
7902 gp_ci.pVertexInputState = &vi_ci;
7903 gp_ci.pInputAssemblyState = &ia_ci;
7904 gp_ci.pViewportState = &vp_state_ci;
7905 gp_ci.pRasterizationState = &rs_ci;
7906 gp_ci.pColorBlendState = &cb_ci;
7907 gp_ci.pDynamicState = &dyn_state_ci;
7908 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7909 gp_ci.layout = pipeline_layout;
7910 gp_ci.renderPass = renderPass();
7911
7912 VkPipelineCacheCreateInfo pc_ci = {};
7913 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7914
7915 VkPipeline pipeline;
7916 VkPipelineCache pipelineCache;
7917
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007918 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007919 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007920 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007921
7922 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007923 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007924
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007926
7927 // Check too high (line width of 65536.0f).
7928 rs_ci.lineWidth = 65536.0f;
7929
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007930 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007931 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007932 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007933
7934 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007935 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007936
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007938
7939 dyn_state_ci.dynamicStateCount = 3;
7940
7941 rs_ci.lineWidth = 1.0f;
7942
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007943 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007944 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007945 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07007946 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007947 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007948
7949 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007950 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007951 m_errorMonitor->VerifyFound();
7952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007954
7955 // Check too high with dynamic setting.
7956 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7957 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07007958 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06007959
7960 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7961 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7962 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7963 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007964 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007965}
7966
Karl Schultz6addd812016-02-02 17:17:23 -07007967TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007968 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07007970 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007971
7972 ASSERT_NO_FATAL_FAILURE(InitState());
7973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007974
Tony Barbour552f6c02016-12-21 14:34:07 -07007975 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007976 // Don't care about RenderPass handle b/c error should be flagged before
7977 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007978 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007979
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007980 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007981}
7982
Karl Schultz6addd812016-02-02 17:17:23 -07007983TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007984 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7986 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007987
7988 ASSERT_NO_FATAL_FAILURE(InitState());
7989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007990
Tony Barbour552f6c02016-12-21 14:34:07 -07007991 m_commandBuffer->BeginCommandBuffer();
7992 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07007993 // Just create a dummy Renderpass that's non-NULL so we can get to the
7994 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007995 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007996
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007997 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007998}
7999
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008000TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
8001 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
8002 "the number of renderPass attachments that use loadOp"
8003 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8004
8005 ASSERT_NO_FATAL_FAILURE(InitState());
8006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8007
8008 // Create a renderPass with a single attachment that uses loadOp CLEAR
8009 VkAttachmentReference attach = {};
8010 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8011 VkSubpassDescription subpass = {};
8012 subpass.inputAttachmentCount = 1;
8013 subpass.pInputAttachments = &attach;
8014 VkRenderPassCreateInfo rpci = {};
8015 rpci.subpassCount = 1;
8016 rpci.pSubpasses = &subpass;
8017 rpci.attachmentCount = 1;
8018 VkAttachmentDescription attach_desc = {};
8019 attach_desc.format = VK_FORMAT_UNDEFINED;
8020 // Set loadOp to CLEAR
8021 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8022 rpci.pAttachments = &attach_desc;
8023 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8024 VkRenderPass rp;
8025 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8026
8027 VkCommandBufferInheritanceInfo hinfo = {};
8028 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8029 hinfo.renderPass = VK_NULL_HANDLE;
8030 hinfo.subpass = 0;
8031 hinfo.framebuffer = VK_NULL_HANDLE;
8032 hinfo.occlusionQueryEnable = VK_FALSE;
8033 hinfo.queryFlags = 0;
8034 hinfo.pipelineStatistics = 0;
8035 VkCommandBufferBeginInfo info = {};
8036 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8037 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8038 info.pInheritanceInfo = &hinfo;
8039
8040 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8041 VkRenderPassBeginInfo rp_begin = {};
8042 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8043 rp_begin.pNext = NULL;
8044 rp_begin.renderPass = renderPass();
8045 rp_begin.framebuffer = framebuffer();
8046 rp_begin.clearValueCount = 0; // Should be 1
8047
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008050 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008051
8052 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008053
8054 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008055}
8056
Slawomir Cygan0808f392016-11-28 17:53:23 +01008057TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
8058 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
8059 "the number of renderPass attachments that use loadOp"
8060 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8061
8062 ASSERT_NO_FATAL_FAILURE(InitState());
8063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8064
8065 // Create a renderPass with a single attachment that uses loadOp CLEAR
8066 VkAttachmentReference attach = {};
8067 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8068 VkSubpassDescription subpass = {};
8069 subpass.inputAttachmentCount = 1;
8070 subpass.pInputAttachments = &attach;
8071 VkRenderPassCreateInfo rpci = {};
8072 rpci.subpassCount = 1;
8073 rpci.pSubpasses = &subpass;
8074 rpci.attachmentCount = 1;
8075 VkAttachmentDescription attach_desc = {};
8076 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8077 // Set loadOp to CLEAR
8078 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8079 rpci.pAttachments = &attach_desc;
8080 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8081 VkRenderPass rp;
8082 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8083
8084 VkCommandBufferBeginInfo info = {};
8085 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8086 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8087
8088 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8089 VkRenderPassBeginInfo rp_begin = {};
8090 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8091 rp_begin.pNext = NULL;
8092 rp_begin.renderPass = renderPass();
8093 rp_begin.framebuffer = framebuffer();
8094 rp_begin.clearValueCount = 2; // Should be 1
8095
8096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8097 " 2 but only first 1 entries in pClearValues array are used");
8098
8099 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8100
8101 m_errorMonitor->VerifyFound();
8102
8103 vkDestroyRenderPass(m_device->device(), rp, NULL);
8104}
8105
8106
Cody Northrop3bb4d962016-05-09 16:15:57 -06008107TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8108
8109 TEST_DESCRIPTION("End a command buffer with an active render pass");
8110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8112 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008113
8114 ASSERT_NO_FATAL_FAILURE(InitState());
8115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8116
Tony Barbour552f6c02016-12-21 14:34:07 -07008117 m_commandBuffer->BeginCommandBuffer();
8118 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8119 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008120
8121 m_errorMonitor->VerifyFound();
8122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008123 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8124 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008125}
8126
Karl Schultz6addd812016-02-02 17:17:23 -07008127TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008128 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8130 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008131
8132 ASSERT_NO_FATAL_FAILURE(InitState());
8133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008134
Tony Barbour552f6c02016-12-21 14:34:07 -07008135 m_commandBuffer->BeginCommandBuffer();
8136 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008137
8138 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008139 vk_testing::Buffer dstBuffer;
8140 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008141
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008142 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008143
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008144 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008145}
8146
Karl Schultz6addd812016-02-02 17:17:23 -07008147TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008148 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8150 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008151
8152 ASSERT_NO_FATAL_FAILURE(InitState());
8153 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008154
Tony Barbour552f6c02016-12-21 14:34:07 -07008155 m_commandBuffer->BeginCommandBuffer();
8156 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008157
8158 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008159 vk_testing::Buffer dstBuffer;
8160 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008161
Karl Schultz6addd812016-02-02 17:17:23 -07008162 VkDeviceSize dstOffset = 0;
8163 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008164 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008166 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008167
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008168 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008169}
8170
Karl Schultz6addd812016-02-02 17:17:23 -07008171TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008172 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8174 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008175
8176 ASSERT_NO_FATAL_FAILURE(InitState());
8177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008178
Tony Barbour552f6c02016-12-21 14:34:07 -07008179 m_commandBuffer->BeginCommandBuffer();
8180 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008181
Michael Lentine0a369f62016-02-03 16:51:46 -06008182 VkClearColorValue clear_color;
8183 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008184 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8185 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8186 const int32_t tex_width = 32;
8187 const int32_t tex_height = 32;
8188 VkImageCreateInfo image_create_info = {};
8189 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8190 image_create_info.pNext = NULL;
8191 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8192 image_create_info.format = tex_format;
8193 image_create_info.extent.width = tex_width;
8194 image_create_info.extent.height = tex_height;
8195 image_create_info.extent.depth = 1;
8196 image_create_info.mipLevels = 1;
8197 image_create_info.arrayLayers = 1;
8198 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8199 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8200 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008201
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008202 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008203 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008205 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008206
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008207 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008208
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008209 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008210}
8211
Karl Schultz6addd812016-02-02 17:17:23 -07008212TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008213 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8215 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008216
8217 ASSERT_NO_FATAL_FAILURE(InitState());
8218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008219
Tony Barbour552f6c02016-12-21 14:34:07 -07008220 m_commandBuffer->BeginCommandBuffer();
8221 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008222
8223 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008224 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008225 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8226 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8227 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8228 image_create_info.extent.width = 64;
8229 image_create_info.extent.height = 64;
8230 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8231 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008232
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008233 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008234 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008236 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008237
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008238 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8239 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008240
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008241 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008242}
8243
Karl Schultz6addd812016-02-02 17:17:23 -07008244TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008245 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008246 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008247
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8249 "must be issued inside an active "
8250 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008251
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008252 ASSERT_NO_FATAL_FAILURE(InitState());
8253 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008254
8255 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008256 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008257 ASSERT_VK_SUCCESS(err);
8258
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008259 VkClearAttachment color_attachment;
8260 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8261 color_attachment.clearValue.color.float32[0] = 0;
8262 color_attachment.clearValue.color.float32[1] = 0;
8263 color_attachment.clearValue.color.float32[2] = 0;
8264 color_attachment.clearValue.color.float32[3] = 0;
8265 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008266 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008267 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008268
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008269 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008270}
8271
Chris Forbes3b97e932016-09-07 11:29:24 +12008272TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8273 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8274 "called too many times in a renderpass instance");
8275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8277 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008278
8279 ASSERT_NO_FATAL_FAILURE(InitState());
8280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8281
Tony Barbour552f6c02016-12-21 14:34:07 -07008282 m_commandBuffer->BeginCommandBuffer();
8283 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008284
8285 // error here.
8286 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8287 m_errorMonitor->VerifyFound();
8288
Tony Barbour552f6c02016-12-21 14:34:07 -07008289 m_commandBuffer->EndRenderPass();
8290 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008291}
8292
Chris Forbes6d624702016-09-07 13:57:05 +12008293TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8294 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8295 "called before the final subpass has been reached");
8296
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8298 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008299
8300 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008301 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8302 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008303
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008304 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008305
8306 VkRenderPass rp;
8307 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8308 ASSERT_VK_SUCCESS(err);
8309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008310 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008311
8312 VkFramebuffer fb;
8313 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8314 ASSERT_VK_SUCCESS(err);
8315
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008317
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008318 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 +12008319
8320 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8321
8322 // Error here.
8323 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8324 m_errorMonitor->VerifyFound();
8325
8326 // Clean up.
8327 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8328 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8329}
8330
Karl Schultz9e66a292016-04-21 15:57:51 -06008331TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8332 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8334 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008335
8336 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008337 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008338
8339 VkBufferMemoryBarrier buf_barrier = {};
8340 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8341 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8342 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8343 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8344 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8345 buf_barrier.buffer = VK_NULL_HANDLE;
8346 buf_barrier.offset = 0;
8347 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008348 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8349 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008350
8351 m_errorMonitor->VerifyFound();
8352}
8353
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008354TEST_F(VkLayerTest, InvalidBarriers) {
8355 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8356
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008358
8359 ASSERT_NO_FATAL_FAILURE(InitState());
8360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8361
8362 VkMemoryBarrier mem_barrier = {};
8363 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8364 mem_barrier.pNext = NULL;
8365 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8366 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008367 m_commandBuffer->BeginCommandBuffer();
8368 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008369 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008370 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008371 &mem_barrier, 0, nullptr, 0, nullptr);
8372 m_errorMonitor->VerifyFound();
8373
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008375 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008376 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 -06008377 ASSERT_TRUE(image.initialized());
8378 VkImageMemoryBarrier img_barrier = {};
8379 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8380 img_barrier.pNext = NULL;
8381 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8382 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8383 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8384 // New layout can't be UNDEFINED
8385 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8386 img_barrier.image = image.handle();
8387 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8388 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8389 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8390 img_barrier.subresourceRange.baseArrayLayer = 0;
8391 img_barrier.subresourceRange.baseMipLevel = 0;
8392 img_barrier.subresourceRange.layerCount = 1;
8393 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008394 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8395 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008396 m_errorMonitor->VerifyFound();
8397 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8398
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8400 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008401 // baseArrayLayer + layerCount must be <= image's arrayLayers
8402 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008403 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8404 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008405 m_errorMonitor->VerifyFound();
8406 img_barrier.subresourceRange.baseArrayLayer = 0;
8407
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008409 // baseMipLevel + levelCount must be <= image's mipLevels
8410 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008411 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8412 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008413 m_errorMonitor->VerifyFound();
8414 img_barrier.subresourceRange.baseMipLevel = 0;
8415
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008416 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 -06008417 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008418 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8419 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008420 VkBufferMemoryBarrier buf_barrier = {};
8421 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8422 buf_barrier.pNext = NULL;
8423 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8424 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8425 buf_barrier.buffer = buffer.handle();
8426 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8427 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8428 buf_barrier.offset = 0;
8429 buf_barrier.size = VK_WHOLE_SIZE;
8430 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008431 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8432 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008433 m_errorMonitor->VerifyFound();
8434 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8435
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008437 buf_barrier.offset = 257;
8438 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008439 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8440 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008441 m_errorMonitor->VerifyFound();
8442 buf_barrier.offset = 0;
8443
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008445 buf_barrier.size = 257;
8446 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008447 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8448 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008449 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008450
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008451 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008452 m_errorMonitor->SetDesiredFailureMsg(
8453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8454 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8455 m_errorMonitor->SetDesiredFailureMsg(
8456 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8457 "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 -06008458 VkDepthStencilObj ds_image(m_device);
8459 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8460 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008461 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8462 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008463 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008464 // Use of COLOR aspect on DS image is error
8465 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008466 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8467 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008468 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008469 // Now test depth-only
8470 VkFormatProperties format_props;
8471
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008472 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8473 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8475 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8477 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008478 VkDepthStencilObj d_image(m_device);
8479 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8480 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008482 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008483 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008484 // Use of COLOR aspect on depth image is error
8485 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008486 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8487 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008488 m_errorMonitor->VerifyFound();
8489 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008490 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8491 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008492 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8494 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008495 VkDepthStencilObj s_image(m_device);
8496 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8497 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008498 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008499 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008500 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008501 // Use of COLOR aspect on depth image is error
8502 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008503 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8504 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008505 m_errorMonitor->VerifyFound();
8506 }
8507 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8509 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8511 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008512 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 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 -06008514 ASSERT_TRUE(c_image.initialized());
8515 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8516 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8517 img_barrier.image = c_image.handle();
8518 // Set aspect to depth (non-color)
8519 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008520 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8521 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008522 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008523
8524 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8525
8526 // Create command pool with incompatible queueflags
8527 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8528 uint32_t queue_family_index = UINT32_MAX;
8529 for (uint32_t i = 0; i < queue_props.size(); i++) {
8530 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8531 queue_family_index = i;
8532 break;
8533 }
8534 }
8535 if (queue_family_index == UINT32_MAX) {
8536 printf("No non-compute queue found; skipped.\n");
8537 return;
8538 }
8539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8540
8541 VkCommandPool command_pool;
8542 VkCommandPoolCreateInfo pool_create_info{};
8543 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8544 pool_create_info.queueFamilyIndex = queue_family_index;
8545 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8546 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8547
8548 // Allocate a command buffer
8549 VkCommandBuffer bad_command_buffer;
8550 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8551 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8552 command_buffer_allocate_info.commandPool = command_pool;
8553 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8554 command_buffer_allocate_info.commandBufferCount = 1;
8555 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8556
8557 VkCommandBufferBeginInfo cbbi = {};
8558 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8559 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8560 buf_barrier.offset = 0;
8561 buf_barrier.size = VK_WHOLE_SIZE;
8562 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8563 &buf_barrier, 0, nullptr);
8564 m_errorMonitor->VerifyFound();
8565
8566 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8567 vkEndCommandBuffer(bad_command_buffer);
8568 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8569 printf("The non-compute queue does not support graphics; skipped.\n");
8570 return;
8571 }
8572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8573 VkEvent event;
8574 VkEventCreateInfo event_create_info{};
8575 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8576 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8577 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8578 nullptr, 0, nullptr);
8579 m_errorMonitor->VerifyFound();
8580
8581 vkEndCommandBuffer(bad_command_buffer);
8582 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008583}
8584
Tony Barbour18ba25c2016-09-29 13:42:40 -06008585TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8586 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8587
8588 m_errorMonitor->SetDesiredFailureMsg(
8589 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8590 "must have required access bit");
8591 ASSERT_NO_FATAL_FAILURE(InitState());
8592 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008593 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 -06008594 ASSERT_TRUE(image.initialized());
8595
8596 VkImageMemoryBarrier barrier = {};
8597 VkImageSubresourceRange range;
8598 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8599 barrier.srcAccessMask = 0;
8600 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8601 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8602 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8603 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8604 barrier.image = image.handle();
8605 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8606 range.baseMipLevel = 0;
8607 range.levelCount = 1;
8608 range.baseArrayLayer = 0;
8609 range.layerCount = 1;
8610 barrier.subresourceRange = range;
8611 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8612 cmdbuf.BeginCommandBuffer();
8613 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8614 &barrier);
8615 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8616 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8617 barrier.srcAccessMask = 0;
8618 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8619 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8620 &barrier);
8621
8622 m_errorMonitor->VerifyFound();
8623}
8624
Karl Schultz6addd812016-02-02 17:17:23 -07008625TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008626 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008627 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008628
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008630
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008631 ASSERT_NO_FATAL_FAILURE(InitState());
8632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008633 uint32_t qfi = 0;
8634 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008635 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8636 buffCI.size = 1024;
8637 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8638 buffCI.queueFamilyIndexCount = 1;
8639 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008640
8641 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008642 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008643 ASSERT_VK_SUCCESS(err);
8644
Tony Barbour552f6c02016-12-21 14:34:07 -07008645 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008646 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008647 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8648 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008649 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008650 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008651
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008652 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008653
Chia-I Wuf7458c52015-10-26 21:10:41 +08008654 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008655}
8656
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008657TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8658 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8660 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8661 "of the indices specified when the device was created, via the "
8662 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008663
8664 ASSERT_NO_FATAL_FAILURE(InitState());
8665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8666 VkBufferCreateInfo buffCI = {};
8667 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8668 buffCI.size = 1024;
8669 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8670 buffCI.queueFamilyIndexCount = 1;
8671 // Introduce failure by specifying invalid queue_family_index
8672 uint32_t qfi = 777;
8673 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008674 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008675
8676 VkBuffer ib;
8677 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8678
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008679 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008680 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008681}
8682
Karl Schultz6addd812016-02-02 17:17:23 -07008683TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008684TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008685 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008686
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008687 ASSERT_NO_FATAL_FAILURE(InitState());
8688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008689
Chris Forbesf29a84f2016-10-06 18:39:28 +13008690 // An empty primary command buffer
8691 VkCommandBufferObj cb(m_device, m_commandPool);
8692 cb.BeginCommandBuffer();
8693 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008694
Chris Forbesf29a84f2016-10-06 18:39:28 +13008695 m_commandBuffer->BeginCommandBuffer();
8696 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8697 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008698
Chris Forbesf29a84f2016-10-06 18:39:28 +13008699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8700 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008701 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008702}
8703
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008704TEST_F(VkLayerTest, DSUsageBitsErrors) {
8705 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8706 "that do not have correct usage bits sets.");
8707 VkResult err;
8708
8709 ASSERT_NO_FATAL_FAILURE(InitState());
8710 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8711 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8712 ds_type_count[i].type = VkDescriptorType(i);
8713 ds_type_count[i].descriptorCount = 1;
8714 }
8715 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8716 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8717 ds_pool_ci.pNext = NULL;
8718 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8719 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8720 ds_pool_ci.pPoolSizes = ds_type_count;
8721
8722 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008723 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008724 ASSERT_VK_SUCCESS(err);
8725
8726 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008727 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008728 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8729 dsl_binding[i].binding = 0;
8730 dsl_binding[i].descriptorType = VkDescriptorType(i);
8731 dsl_binding[i].descriptorCount = 1;
8732 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8733 dsl_binding[i].pImmutableSamplers = NULL;
8734 }
8735
8736 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8737 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8738 ds_layout_ci.pNext = NULL;
8739 ds_layout_ci.bindingCount = 1;
8740 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8741 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8742 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008743 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008744 ASSERT_VK_SUCCESS(err);
8745 }
8746 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8747 VkDescriptorSetAllocateInfo alloc_info = {};
8748 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8749 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8750 alloc_info.descriptorPool = ds_pool;
8751 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008752 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008753 ASSERT_VK_SUCCESS(err);
8754
8755 // Create a buffer & bufferView to be used for invalid updates
8756 VkBufferCreateInfo buff_ci = {};
8757 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8758 // This usage is not valid for any descriptor type
8759 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8760 buff_ci.size = 256;
8761 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8762 VkBuffer buffer;
8763 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8764 ASSERT_VK_SUCCESS(err);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008765 VkMemoryRequirements mem_reqs;
8766 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8767 VkMemoryAllocateInfo mem_alloc_info = {};
8768 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8769 mem_alloc_info.pNext = NULL;
8770 mem_alloc_info.memoryTypeIndex = 0;
8771 mem_alloc_info.allocationSize = mem_reqs.size;
8772 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8773 if (!pass) {
8774 vkDestroyBuffer(m_device->device(), buffer, NULL);
8775 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8776 return;
8777 }
8778 VkDeviceMemory mem;
8779 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
8780 ASSERT_VK_SUCCESS(err);
8781 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8782 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008783
8784 VkBufferViewCreateInfo buff_view_ci = {};
8785 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8786 buff_view_ci.buffer = buffer;
8787 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8788 buff_view_ci.range = VK_WHOLE_SIZE;
8789 VkBufferView buff_view;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008790 // 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 -06008791 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008792 ASSERT_VK_SUCCESS(err);
8793
8794 // Create an image to be used for invalid updates
8795 VkImageCreateInfo image_ci = {};
8796 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8797 image_ci.imageType = VK_IMAGE_TYPE_2D;
8798 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8799 image_ci.extent.width = 64;
8800 image_ci.extent.height = 64;
8801 image_ci.extent.depth = 1;
8802 image_ci.mipLevels = 1;
8803 image_ci.arrayLayers = 1;
8804 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8805 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8806 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8807 // This usage is not valid for any descriptor type
8808 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8809 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8810 VkImage image;
8811 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8812 ASSERT_VK_SUCCESS(err);
8813 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008814 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008815
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008816 VkMemoryAllocateInfo mem_alloc = {};
8817 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8818 mem_alloc.pNext = NULL;
8819 mem_alloc.allocationSize = 0;
8820 mem_alloc.memoryTypeIndex = 0;
8821 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8822 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008824 ASSERT_TRUE(pass);
8825 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8826 ASSERT_VK_SUCCESS(err);
8827 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8828 ASSERT_VK_SUCCESS(err);
8829 // Now create view for image
8830 VkImageViewCreateInfo image_view_ci = {};
8831 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8832 image_view_ci.image = image;
8833 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8834 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8835 image_view_ci.subresourceRange.layerCount = 1;
8836 image_view_ci.subresourceRange.baseArrayLayer = 0;
8837 image_view_ci.subresourceRange.levelCount = 1;
8838 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8839 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008840 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008841 ASSERT_VK_SUCCESS(err);
8842
8843 VkDescriptorBufferInfo buff_info = {};
8844 buff_info.buffer = buffer;
8845 VkDescriptorImageInfo img_info = {};
8846 img_info.imageView = image_view;
8847 VkWriteDescriptorSet descriptor_write = {};
8848 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8849 descriptor_write.dstBinding = 0;
8850 descriptor_write.descriptorCount = 1;
8851 descriptor_write.pTexelBufferView = &buff_view;
8852 descriptor_write.pBufferInfo = &buff_info;
8853 descriptor_write.pImageInfo = &img_info;
8854
8855 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008856 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
8857 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
8858 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
8859 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
8860 VALIDATION_ERROR_00943, // STORAGE_IMAGE
8861 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
8862 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
8863 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
8864 VALIDATION_ERROR_00947, // STORAGE_BUFFER
8865 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
8866 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
8867 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
8868 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008869 // Start loop at 1 as SAMPLER desc type has no usage bit error
8870 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8871 descriptor_write.descriptorType = VkDescriptorType(i);
8872 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008874
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008875 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008876
8877 m_errorMonitor->VerifyFound();
8878 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8879 }
8880 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8881 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008882 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008883 vkDestroyImageView(m_device->device(), image_view, NULL);
8884 vkDestroyBuffer(m_device->device(), buffer, NULL);
8885 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008886 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008887 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8888}
8889
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008890TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008891 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8892 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8893 "1. offset value greater than buffer size\n"
8894 "2. range value of 0\n"
8895 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008896 VkResult err;
8897
8898 ASSERT_NO_FATAL_FAILURE(InitState());
8899 VkDescriptorPoolSize ds_type_count = {};
8900 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8901 ds_type_count.descriptorCount = 1;
8902
8903 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8904 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8905 ds_pool_ci.pNext = NULL;
8906 ds_pool_ci.maxSets = 1;
8907 ds_pool_ci.poolSizeCount = 1;
8908 ds_pool_ci.pPoolSizes = &ds_type_count;
8909
8910 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008911 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008912 ASSERT_VK_SUCCESS(err);
8913
8914 // Create layout with single uniform buffer descriptor
8915 VkDescriptorSetLayoutBinding dsl_binding = {};
8916 dsl_binding.binding = 0;
8917 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8918 dsl_binding.descriptorCount = 1;
8919 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8920 dsl_binding.pImmutableSamplers = NULL;
8921
8922 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8923 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8924 ds_layout_ci.pNext = NULL;
8925 ds_layout_ci.bindingCount = 1;
8926 ds_layout_ci.pBindings = &dsl_binding;
8927 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008928 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008929 ASSERT_VK_SUCCESS(err);
8930
8931 VkDescriptorSet descriptor_set = {};
8932 VkDescriptorSetAllocateInfo alloc_info = {};
8933 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8934 alloc_info.descriptorSetCount = 1;
8935 alloc_info.descriptorPool = ds_pool;
8936 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008937 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008938 ASSERT_VK_SUCCESS(err);
8939
8940 // Create a buffer to be used for invalid updates
8941 VkBufferCreateInfo buff_ci = {};
8942 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8943 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8944 buff_ci.size = 256;
8945 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8946 VkBuffer buffer;
8947 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8948 ASSERT_VK_SUCCESS(err);
8949 // Have to bind memory to buffer before descriptor update
8950 VkMemoryAllocateInfo mem_alloc = {};
8951 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8952 mem_alloc.pNext = NULL;
8953 mem_alloc.allocationSize = 256;
8954 mem_alloc.memoryTypeIndex = 0;
8955
8956 VkMemoryRequirements mem_reqs;
8957 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008958 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008959 if (!pass) {
8960 vkDestroyBuffer(m_device->device(), buffer, NULL);
8961 return;
8962 }
8963
8964 VkDeviceMemory mem;
8965 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8966 ASSERT_VK_SUCCESS(err);
8967 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8968 ASSERT_VK_SUCCESS(err);
8969
8970 VkDescriptorBufferInfo buff_info = {};
8971 buff_info.buffer = buffer;
8972 // First make offset 1 larger than buffer size
8973 buff_info.offset = 257;
8974 buff_info.range = VK_WHOLE_SIZE;
8975 VkWriteDescriptorSet descriptor_write = {};
8976 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8977 descriptor_write.dstBinding = 0;
8978 descriptor_write.descriptorCount = 1;
8979 descriptor_write.pTexelBufferView = nullptr;
8980 descriptor_write.pBufferInfo = &buff_info;
8981 descriptor_write.pImageInfo = nullptr;
8982
8983 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8984 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008986
8987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8988
8989 m_errorMonitor->VerifyFound();
8990 // Now cause error due to range of 0
8991 buff_info.offset = 0;
8992 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008994
8995 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8996
8997 m_errorMonitor->VerifyFound();
8998 // Now cause error due to range exceeding buffer size - offset
8999 buff_info.offset = 128;
9000 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009002
9003 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9004
9005 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009006 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009007 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9008 vkDestroyBuffer(m_device->device(), buffer, NULL);
9009 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9010 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9011}
9012
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009013TEST_F(VkLayerTest, DSAspectBitsErrors) {
9014 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9015 // are set, but could expand this test to hit more cases.
9016 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
9017 "that do not have correct aspect bits sets.");
9018 VkResult err;
9019
9020 ASSERT_NO_FATAL_FAILURE(InitState());
9021 VkDescriptorPoolSize ds_type_count = {};
9022 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9023 ds_type_count.descriptorCount = 1;
9024
9025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9027 ds_pool_ci.pNext = NULL;
9028 ds_pool_ci.maxSets = 5;
9029 ds_pool_ci.poolSizeCount = 1;
9030 ds_pool_ci.pPoolSizes = &ds_type_count;
9031
9032 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009033 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009034 ASSERT_VK_SUCCESS(err);
9035
9036 VkDescriptorSetLayoutBinding dsl_binding = {};
9037 dsl_binding.binding = 0;
9038 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9039 dsl_binding.descriptorCount = 1;
9040 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9041 dsl_binding.pImmutableSamplers = NULL;
9042
9043 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9044 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9045 ds_layout_ci.pNext = NULL;
9046 ds_layout_ci.bindingCount = 1;
9047 ds_layout_ci.pBindings = &dsl_binding;
9048 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009049 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009050 ASSERT_VK_SUCCESS(err);
9051
9052 VkDescriptorSet descriptor_set = {};
9053 VkDescriptorSetAllocateInfo alloc_info = {};
9054 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9055 alloc_info.descriptorSetCount = 1;
9056 alloc_info.descriptorPool = ds_pool;
9057 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009058 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009059 ASSERT_VK_SUCCESS(err);
9060
9061 // Create an image to be used for invalid updates
9062 VkImageCreateInfo image_ci = {};
9063 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9064 image_ci.imageType = VK_IMAGE_TYPE_2D;
9065 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9066 image_ci.extent.width = 64;
9067 image_ci.extent.height = 64;
9068 image_ci.extent.depth = 1;
9069 image_ci.mipLevels = 1;
9070 image_ci.arrayLayers = 1;
9071 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9072 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9073 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9074 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9075 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9076 VkImage image;
9077 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9078 ASSERT_VK_SUCCESS(err);
9079 // Bind memory to image
9080 VkMemoryRequirements mem_reqs;
9081 VkDeviceMemory image_mem;
9082 bool pass;
9083 VkMemoryAllocateInfo mem_alloc = {};
9084 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9085 mem_alloc.pNext = NULL;
9086 mem_alloc.allocationSize = 0;
9087 mem_alloc.memoryTypeIndex = 0;
9088 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9089 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009090 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009091 ASSERT_TRUE(pass);
9092 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9093 ASSERT_VK_SUCCESS(err);
9094 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9095 ASSERT_VK_SUCCESS(err);
9096 // Now create view for image
9097 VkImageViewCreateInfo image_view_ci = {};
9098 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9099 image_view_ci.image = image;
9100 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9101 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9102 image_view_ci.subresourceRange.layerCount = 1;
9103 image_view_ci.subresourceRange.baseArrayLayer = 0;
9104 image_view_ci.subresourceRange.levelCount = 1;
9105 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009106 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009107
9108 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009109 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009110 ASSERT_VK_SUCCESS(err);
9111
9112 VkDescriptorImageInfo img_info = {};
9113 img_info.imageView = image_view;
9114 VkWriteDescriptorSet descriptor_write = {};
9115 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9116 descriptor_write.dstBinding = 0;
9117 descriptor_write.descriptorCount = 1;
9118 descriptor_write.pTexelBufferView = NULL;
9119 descriptor_write.pBufferInfo = NULL;
9120 descriptor_write.pImageInfo = &img_info;
9121 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9122 descriptor_write.dstSet = descriptor_set;
9123 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9124 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009126
9127 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9128
9129 m_errorMonitor->VerifyFound();
9130 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9131 vkDestroyImage(m_device->device(), image, NULL);
9132 vkFreeMemory(m_device->device(), image_mem, NULL);
9133 vkDestroyImageView(m_device->device(), image_view, NULL);
9134 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9135 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9136}
9137
Karl Schultz6addd812016-02-02 17:17:23 -07009138TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009139 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009140 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9143 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9144 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009145
Tobin Ehlis3b780662015-05-28 12:11:26 -06009146 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009147 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009148 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009149 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9150 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009151
9152 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009153 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9154 ds_pool_ci.pNext = NULL;
9155 ds_pool_ci.maxSets = 1;
9156 ds_pool_ci.poolSizeCount = 1;
9157 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009158
Tobin Ehlis3b780662015-05-28 12:11:26 -06009159 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009160 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009161 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009162 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009163 dsl_binding.binding = 0;
9164 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9165 dsl_binding.descriptorCount = 1;
9166 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9167 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009168
Tony Barboureb254902015-07-15 12:50:33 -06009169 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009170 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9171 ds_layout_ci.pNext = NULL;
9172 ds_layout_ci.bindingCount = 1;
9173 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009174
Tobin Ehlis3b780662015-05-28 12:11:26 -06009175 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009177 ASSERT_VK_SUCCESS(err);
9178
9179 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009180 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009181 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009182 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009183 alloc_info.descriptorPool = ds_pool;
9184 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009185 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009186 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009187
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009188 VkSamplerCreateInfo sampler_ci = {};
9189 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9190 sampler_ci.pNext = NULL;
9191 sampler_ci.magFilter = VK_FILTER_NEAREST;
9192 sampler_ci.minFilter = VK_FILTER_NEAREST;
9193 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9194 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9195 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9196 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9197 sampler_ci.mipLodBias = 1.0;
9198 sampler_ci.anisotropyEnable = VK_FALSE;
9199 sampler_ci.maxAnisotropy = 1;
9200 sampler_ci.compareEnable = VK_FALSE;
9201 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9202 sampler_ci.minLod = 1.0;
9203 sampler_ci.maxLod = 1.0;
9204 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9205 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9206 VkSampler sampler;
9207 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9208 ASSERT_VK_SUCCESS(err);
9209
9210 VkDescriptorImageInfo info = {};
9211 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009212
9213 VkWriteDescriptorSet descriptor_write;
9214 memset(&descriptor_write, 0, sizeof(descriptor_write));
9215 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009216 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009217 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009218 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009219 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009220 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009221
9222 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9223
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009224 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009225
Chia-I Wuf7458c52015-10-26 21:10:41 +08009226 vkDestroySampler(m_device->device(), sampler, NULL);
9227 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9228 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009229}
9230
Karl Schultz6addd812016-02-02 17:17:23 -07009231TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009232 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009233 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009234
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009236
Tobin Ehlis3b780662015-05-28 12:11:26 -06009237 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009238 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009239 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009240 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9241 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009242
9243 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009244 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9245 ds_pool_ci.pNext = NULL;
9246 ds_pool_ci.maxSets = 1;
9247 ds_pool_ci.poolSizeCount = 1;
9248 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009249
Tobin Ehlis3b780662015-05-28 12:11:26 -06009250 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009251 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009252 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009253
Tony Barboureb254902015-07-15 12:50:33 -06009254 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009255 dsl_binding.binding = 0;
9256 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9257 dsl_binding.descriptorCount = 1;
9258 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9259 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009260
9261 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009262 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9263 ds_layout_ci.pNext = NULL;
9264 ds_layout_ci.bindingCount = 1;
9265 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009266
Tobin Ehlis3b780662015-05-28 12:11:26 -06009267 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009268 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009269 ASSERT_VK_SUCCESS(err);
9270
9271 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009272 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009273 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009274 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009275 alloc_info.descriptorPool = ds_pool;
9276 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009277 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009278 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009279
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009280 // Correctly update descriptor to avoid "NOT_UPDATED" error
9281 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009282 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009283 buff_info.offset = 0;
9284 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009285
9286 VkWriteDescriptorSet descriptor_write;
9287 memset(&descriptor_write, 0, sizeof(descriptor_write));
9288 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009289 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009290 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009291 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009292 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9293 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009294
9295 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009297 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009298
Chia-I Wuf7458c52015-10-26 21:10:41 +08009299 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9300 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009301}
9302
Karl Schultz6addd812016-02-02 17:17:23 -07009303TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009304 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009305 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009306
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009308
Tobin Ehlis3b780662015-05-28 12:11:26 -06009309 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009310 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009311 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009312 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9313 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009314
9315 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009316 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9317 ds_pool_ci.pNext = NULL;
9318 ds_pool_ci.maxSets = 1;
9319 ds_pool_ci.poolSizeCount = 1;
9320 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009321
Tobin Ehlis3b780662015-05-28 12:11:26 -06009322 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009323 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009324 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009325
Tony Barboureb254902015-07-15 12:50:33 -06009326 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009327 dsl_binding.binding = 0;
9328 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9329 dsl_binding.descriptorCount = 1;
9330 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9331 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009332
9333 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009334 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9335 ds_layout_ci.pNext = NULL;
9336 ds_layout_ci.bindingCount = 1;
9337 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009338 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009339 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009340 ASSERT_VK_SUCCESS(err);
9341
9342 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009343 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009344 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009345 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009346 alloc_info.descriptorPool = ds_pool;
9347 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009348 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009349 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009350
Tony Barboureb254902015-07-15 12:50:33 -06009351 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009352 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9353 sampler_ci.pNext = NULL;
9354 sampler_ci.magFilter = VK_FILTER_NEAREST;
9355 sampler_ci.minFilter = VK_FILTER_NEAREST;
9356 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9357 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9358 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9359 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9360 sampler_ci.mipLodBias = 1.0;
9361 sampler_ci.anisotropyEnable = VK_FALSE;
9362 sampler_ci.maxAnisotropy = 1;
9363 sampler_ci.compareEnable = VK_FALSE;
9364 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9365 sampler_ci.minLod = 1.0;
9366 sampler_ci.maxLod = 1.0;
9367 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9368 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009369
Tobin Ehlis3b780662015-05-28 12:11:26 -06009370 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009371 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009372 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009373
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009374 VkDescriptorImageInfo info = {};
9375 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009376
9377 VkWriteDescriptorSet descriptor_write;
9378 memset(&descriptor_write, 0, sizeof(descriptor_write));
9379 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009380 descriptor_write.dstSet = descriptorSet;
9381 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009382 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009383 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009384 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009385 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009386
9387 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9388
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009389 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009390
Chia-I Wuf7458c52015-10-26 21:10:41 +08009391 vkDestroySampler(m_device->device(), sampler, NULL);
9392 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9393 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009394}
9395
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009396TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9397 // Create layout w/ empty binding and attempt to update it
9398 VkResult err;
9399
9400 ASSERT_NO_FATAL_FAILURE(InitState());
9401
9402 VkDescriptorPoolSize ds_type_count = {};
9403 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9404 ds_type_count.descriptorCount = 1;
9405
9406 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9407 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9408 ds_pool_ci.pNext = NULL;
9409 ds_pool_ci.maxSets = 1;
9410 ds_pool_ci.poolSizeCount = 1;
9411 ds_pool_ci.pPoolSizes = &ds_type_count;
9412
9413 VkDescriptorPool ds_pool;
9414 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9415 ASSERT_VK_SUCCESS(err);
9416
9417 VkDescriptorSetLayoutBinding dsl_binding = {};
9418 dsl_binding.binding = 0;
9419 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9420 dsl_binding.descriptorCount = 0;
9421 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9422 dsl_binding.pImmutableSamplers = NULL;
9423
9424 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9425 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9426 ds_layout_ci.pNext = NULL;
9427 ds_layout_ci.bindingCount = 1;
9428 ds_layout_ci.pBindings = &dsl_binding;
9429 VkDescriptorSetLayout ds_layout;
9430 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9431 ASSERT_VK_SUCCESS(err);
9432
9433 VkDescriptorSet descriptor_set;
9434 VkDescriptorSetAllocateInfo alloc_info = {};
9435 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9436 alloc_info.descriptorSetCount = 1;
9437 alloc_info.descriptorPool = ds_pool;
9438 alloc_info.pSetLayouts = &ds_layout;
9439 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9440 ASSERT_VK_SUCCESS(err);
9441
9442 VkSamplerCreateInfo sampler_ci = {};
9443 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9444 sampler_ci.magFilter = VK_FILTER_NEAREST;
9445 sampler_ci.minFilter = VK_FILTER_NEAREST;
9446 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9447 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9448 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9449 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9450 sampler_ci.mipLodBias = 1.0;
9451 sampler_ci.maxAnisotropy = 1;
9452 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9453 sampler_ci.minLod = 1.0;
9454 sampler_ci.maxLod = 1.0;
9455 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9456
9457 VkSampler sampler;
9458 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9459 ASSERT_VK_SUCCESS(err);
9460
9461 VkDescriptorImageInfo info = {};
9462 info.sampler = sampler;
9463
9464 VkWriteDescriptorSet descriptor_write;
9465 memset(&descriptor_write, 0, sizeof(descriptor_write));
9466 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9467 descriptor_write.dstSet = descriptor_set;
9468 descriptor_write.dstBinding = 0;
9469 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9470 // This is the wrong type, but empty binding error will be flagged first
9471 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9472 descriptor_write.pImageInfo = &info;
9473
9474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9475 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9476 m_errorMonitor->VerifyFound();
9477
9478 vkDestroySampler(m_device->device(), sampler, NULL);
9479 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9480 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9481}
9482
Karl Schultz6addd812016-02-02 17:17:23 -07009483TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9484 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9485 // types
9486 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009487
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009488 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 -06009489
Tobin Ehlis3b780662015-05-28 12:11:26 -06009490 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009491
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009492 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009493 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9494 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009495
9496 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009497 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9498 ds_pool_ci.pNext = NULL;
9499 ds_pool_ci.maxSets = 1;
9500 ds_pool_ci.poolSizeCount = 1;
9501 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009502
Tobin Ehlis3b780662015-05-28 12:11:26 -06009503 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009504 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009505 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009506 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009507 dsl_binding.binding = 0;
9508 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9509 dsl_binding.descriptorCount = 1;
9510 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9511 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009512
Tony Barboureb254902015-07-15 12:50:33 -06009513 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009514 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9515 ds_layout_ci.pNext = NULL;
9516 ds_layout_ci.bindingCount = 1;
9517 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009518
Tobin Ehlis3b780662015-05-28 12:11:26 -06009519 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009520 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009521 ASSERT_VK_SUCCESS(err);
9522
9523 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009524 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009525 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009526 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009527 alloc_info.descriptorPool = ds_pool;
9528 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009529 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009530 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009531
Tony Barboureb254902015-07-15 12:50:33 -06009532 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009533 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9534 sampler_ci.pNext = NULL;
9535 sampler_ci.magFilter = VK_FILTER_NEAREST;
9536 sampler_ci.minFilter = VK_FILTER_NEAREST;
9537 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9538 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9539 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9540 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9541 sampler_ci.mipLodBias = 1.0;
9542 sampler_ci.anisotropyEnable = VK_FALSE;
9543 sampler_ci.maxAnisotropy = 1;
9544 sampler_ci.compareEnable = VK_FALSE;
9545 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9546 sampler_ci.minLod = 1.0;
9547 sampler_ci.maxLod = 1.0;
9548 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9549 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009550 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009551 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009552 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009553
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009554 VkDescriptorImageInfo info = {};
9555 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009556
9557 VkWriteDescriptorSet descriptor_write;
9558 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009559 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009560 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009561 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009562 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009563 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009564 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009565
9566 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009568 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009569
Chia-I Wuf7458c52015-10-26 21:10:41 +08009570 vkDestroySampler(m_device->device(), sampler, NULL);
9571 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9572 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009573}
9574
Karl Schultz6addd812016-02-02 17:17:23 -07009575TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009576 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009577 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009578
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009580
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009581 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009582 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9583 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009584 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009585 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9586 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009587
9588 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009589 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9590 ds_pool_ci.pNext = NULL;
9591 ds_pool_ci.maxSets = 1;
9592 ds_pool_ci.poolSizeCount = 1;
9593 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009594
9595 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009596 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009597 ASSERT_VK_SUCCESS(err);
9598
9599 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009600 dsl_binding.binding = 0;
9601 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9602 dsl_binding.descriptorCount = 1;
9603 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9604 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009605
9606 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009607 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9608 ds_layout_ci.pNext = NULL;
9609 ds_layout_ci.bindingCount = 1;
9610 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009611 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009612 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009613 ASSERT_VK_SUCCESS(err);
9614
9615 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009616 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009617 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009618 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009619 alloc_info.descriptorPool = ds_pool;
9620 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009621 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009622 ASSERT_VK_SUCCESS(err);
9623
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009624 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009625
9626 VkDescriptorImageInfo descriptor_info;
9627 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9628 descriptor_info.sampler = sampler;
9629
9630 VkWriteDescriptorSet descriptor_write;
9631 memset(&descriptor_write, 0, sizeof(descriptor_write));
9632 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009633 descriptor_write.dstSet = descriptorSet;
9634 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009635 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009636 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9637 descriptor_write.pImageInfo = &descriptor_info;
9638
9639 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9640
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009641 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009642
Chia-I Wuf7458c52015-10-26 21:10:41 +08009643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009645}
9646
Karl Schultz6addd812016-02-02 17:17:23 -07009647TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9648 // Create a single combined Image/Sampler descriptor and send it an invalid
9649 // imageView
9650 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009651
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009653
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009654 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009655 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009656 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9657 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009658
9659 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009660 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9661 ds_pool_ci.pNext = NULL;
9662 ds_pool_ci.maxSets = 1;
9663 ds_pool_ci.poolSizeCount = 1;
9664 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009665
9666 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009667 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009668 ASSERT_VK_SUCCESS(err);
9669
9670 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009671 dsl_binding.binding = 0;
9672 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9673 dsl_binding.descriptorCount = 1;
9674 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9675 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009676
9677 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009678 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9679 ds_layout_ci.pNext = NULL;
9680 ds_layout_ci.bindingCount = 1;
9681 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009682 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009683 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009684 ASSERT_VK_SUCCESS(err);
9685
9686 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009687 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009688 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009689 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009690 alloc_info.descriptorPool = ds_pool;
9691 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009692 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009693 ASSERT_VK_SUCCESS(err);
9694
9695 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009696 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9697 sampler_ci.pNext = NULL;
9698 sampler_ci.magFilter = VK_FILTER_NEAREST;
9699 sampler_ci.minFilter = VK_FILTER_NEAREST;
9700 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9701 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9702 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9703 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9704 sampler_ci.mipLodBias = 1.0;
9705 sampler_ci.anisotropyEnable = VK_FALSE;
9706 sampler_ci.maxAnisotropy = 1;
9707 sampler_ci.compareEnable = VK_FALSE;
9708 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9709 sampler_ci.minLod = 1.0;
9710 sampler_ci.maxLod = 1.0;
9711 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9712 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009713
9714 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009715 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009716 ASSERT_VK_SUCCESS(err);
9717
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009718 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009719
9720 VkDescriptorImageInfo descriptor_info;
9721 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9722 descriptor_info.sampler = sampler;
9723 descriptor_info.imageView = view;
9724
9725 VkWriteDescriptorSet descriptor_write;
9726 memset(&descriptor_write, 0, sizeof(descriptor_write));
9727 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009728 descriptor_write.dstSet = descriptorSet;
9729 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009730 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009731 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9732 descriptor_write.pImageInfo = &descriptor_info;
9733
9734 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9735
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009736 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009737
Chia-I Wuf7458c52015-10-26 21:10:41 +08009738 vkDestroySampler(m_device->device(), sampler, NULL);
9739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009741}
9742
Karl Schultz6addd812016-02-02 17:17:23 -07009743TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9744 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9745 // into the other
9746 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9749 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9750 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009751
Tobin Ehlis04356f92015-10-27 16:35:27 -06009752 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009753 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009754 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009755 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9756 ds_type_count[0].descriptorCount = 1;
9757 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9758 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009759
9760 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009761 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9762 ds_pool_ci.pNext = NULL;
9763 ds_pool_ci.maxSets = 1;
9764 ds_pool_ci.poolSizeCount = 2;
9765 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009766
9767 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009768 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009769 ASSERT_VK_SUCCESS(err);
9770 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009771 dsl_binding[0].binding = 0;
9772 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9773 dsl_binding[0].descriptorCount = 1;
9774 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9775 dsl_binding[0].pImmutableSamplers = NULL;
9776 dsl_binding[1].binding = 1;
9777 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9778 dsl_binding[1].descriptorCount = 1;
9779 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9780 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009781
9782 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009783 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9784 ds_layout_ci.pNext = NULL;
9785 ds_layout_ci.bindingCount = 2;
9786 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009787
9788 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009789 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009790 ASSERT_VK_SUCCESS(err);
9791
9792 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009793 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009794 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009795 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009796 alloc_info.descriptorPool = ds_pool;
9797 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009798 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009799 ASSERT_VK_SUCCESS(err);
9800
9801 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009802 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9803 sampler_ci.pNext = NULL;
9804 sampler_ci.magFilter = VK_FILTER_NEAREST;
9805 sampler_ci.minFilter = VK_FILTER_NEAREST;
9806 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9807 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9808 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9809 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9810 sampler_ci.mipLodBias = 1.0;
9811 sampler_ci.anisotropyEnable = VK_FALSE;
9812 sampler_ci.maxAnisotropy = 1;
9813 sampler_ci.compareEnable = VK_FALSE;
9814 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9815 sampler_ci.minLod = 1.0;
9816 sampler_ci.maxLod = 1.0;
9817 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9818 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009819
9820 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009821 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009822 ASSERT_VK_SUCCESS(err);
9823
9824 VkDescriptorImageInfo info = {};
9825 info.sampler = sampler;
9826
9827 VkWriteDescriptorSet descriptor_write;
9828 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9829 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009830 descriptor_write.dstSet = descriptorSet;
9831 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009832 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009833 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9834 descriptor_write.pImageInfo = &info;
9835 // This write update should succeed
9836 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9837 // Now perform a copy update that fails due to type mismatch
9838 VkCopyDescriptorSet copy_ds_update;
9839 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9840 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9841 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009842 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009843 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009844 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009845 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009846 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9847
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009848 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009849 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009850 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 -06009851 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9852 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9853 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009854 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009855 copy_ds_update.dstSet = descriptorSet;
9856 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009857 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009858 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9859
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009860 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009861
Tobin Ehlis04356f92015-10-27 16:35:27 -06009862 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9864 "update array offset of 0 and update of "
9865 "5 descriptors oversteps total number "
9866 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009867
Tobin Ehlis04356f92015-10-27 16:35:27 -06009868 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9869 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9870 copy_ds_update.srcSet = descriptorSet;
9871 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009872 copy_ds_update.dstSet = descriptorSet;
9873 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009874 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009875 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9876
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009877 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009878
Chia-I Wuf7458c52015-10-26 21:10:41 +08009879 vkDestroySampler(m_device->device(), sampler, NULL);
9880 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9881 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009882}
9883
Karl Schultz6addd812016-02-02 17:17:23 -07009884TEST_F(VkLayerTest, NumSamplesMismatch) {
9885 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9886 // sampleCount
9887 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009888
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009890
Tobin Ehlis3b780662015-05-28 12:11:26 -06009891 ASSERT_NO_FATAL_FAILURE(InitState());
9892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009893 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009894 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009895 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009896
9897 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009898 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9899 ds_pool_ci.pNext = NULL;
9900 ds_pool_ci.maxSets = 1;
9901 ds_pool_ci.poolSizeCount = 1;
9902 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009903
Tobin Ehlis3b780662015-05-28 12:11:26 -06009904 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009905 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009906 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009907
Tony Barboureb254902015-07-15 12:50:33 -06009908 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009909 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009910 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009911 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009912 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9913 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009914
Tony Barboureb254902015-07-15 12:50:33 -06009915 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9916 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9917 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009918 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009919 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009920
Tobin Ehlis3b780662015-05-28 12:11:26 -06009921 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009922 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009923 ASSERT_VK_SUCCESS(err);
9924
9925 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009926 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009927 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009928 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009929 alloc_info.descriptorPool = ds_pool;
9930 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009931 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009932 ASSERT_VK_SUCCESS(err);
9933
Tony Barboureb254902015-07-15 12:50:33 -06009934 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009935 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009936 pipe_ms_state_ci.pNext = NULL;
9937 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9938 pipe_ms_state_ci.sampleShadingEnable = 0;
9939 pipe_ms_state_ci.minSampleShading = 1.0;
9940 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009941
Tony Barboureb254902015-07-15 12:50:33 -06009942 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009943 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9944 pipeline_layout_ci.pNext = NULL;
9945 pipeline_layout_ci.setLayoutCount = 1;
9946 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009947
9948 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009949 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009950 ASSERT_VK_SUCCESS(err);
9951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9953 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9954 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009955 VkPipelineObj pipe(m_device);
9956 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009957 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009958 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009959 pipe.SetMSAA(&pipe_ms_state_ci);
9960 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009961
Tony Barbour552f6c02016-12-21 14:34:07 -07009962 m_commandBuffer->BeginCommandBuffer();
9963 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009964 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009965
Mark Young29927482016-05-04 14:38:51 -06009966 // Render triangle (the error should trigger on the attempt to draw).
9967 Draw(3, 1, 0, 0);
9968
9969 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -07009970 m_commandBuffer->EndRenderPass();
9971 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -06009972
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009973 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009974
Chia-I Wuf7458c52015-10-26 21:10:41 +08009975 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9976 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9977 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009978}
Mark Young29927482016-05-04 14:38:51 -06009979
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009980TEST_F(VkLayerTest, RenderPassIncompatible) {
9981 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9982 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009983 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009984 VkResult err;
9985
9986 ASSERT_NO_FATAL_FAILURE(InitState());
9987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9988
9989 VkDescriptorSetLayoutBinding dsl_binding = {};
9990 dsl_binding.binding = 0;
9991 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9992 dsl_binding.descriptorCount = 1;
9993 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9994 dsl_binding.pImmutableSamplers = NULL;
9995
9996 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9997 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9998 ds_layout_ci.pNext = NULL;
9999 ds_layout_ci.bindingCount = 1;
10000 ds_layout_ci.pBindings = &dsl_binding;
10001
10002 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010003 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010004 ASSERT_VK_SUCCESS(err);
10005
10006 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10007 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10008 pipeline_layout_ci.pNext = NULL;
10009 pipeline_layout_ci.setLayoutCount = 1;
10010 pipeline_layout_ci.pSetLayouts = &ds_layout;
10011
10012 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010013 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010014 ASSERT_VK_SUCCESS(err);
10015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010016 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10017 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10018 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010019 // Create a renderpass that will be incompatible with default renderpass
10020 VkAttachmentReference attach = {};
10021 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10022 VkAttachmentReference color_att = {};
10023 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10024 VkSubpassDescription subpass = {};
10025 subpass.inputAttachmentCount = 1;
10026 subpass.pInputAttachments = &attach;
10027 subpass.colorAttachmentCount = 1;
10028 subpass.pColorAttachments = &color_att;
10029 VkRenderPassCreateInfo rpci = {};
10030 rpci.subpassCount = 1;
10031 rpci.pSubpasses = &subpass;
10032 rpci.attachmentCount = 1;
10033 VkAttachmentDescription attach_desc = {};
10034 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010035 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10036 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010037 rpci.pAttachments = &attach_desc;
10038 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10039 VkRenderPass rp;
10040 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10041 VkPipelineObj pipe(m_device);
10042 pipe.AddShader(&vs);
10043 pipe.AddShader(&fs);
10044 pipe.AddColorAttachment();
10045 VkViewport view_port = {};
10046 m_viewports.push_back(view_port);
10047 pipe.SetViewport(m_viewports);
10048 VkRect2D rect = {};
10049 m_scissors.push_back(rect);
10050 pipe.SetScissor(m_scissors);
10051 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10052
10053 VkCommandBufferInheritanceInfo cbii = {};
10054 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10055 cbii.renderPass = rp;
10056 cbii.subpass = 0;
10057 VkCommandBufferBeginInfo cbbi = {};
10058 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10059 cbbi.pInheritanceInfo = &cbii;
10060 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10061 VkRenderPassBeginInfo rpbi = {};
10062 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10063 rpbi.framebuffer = m_framebuffer;
10064 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010065 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10066 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010069 // Render triangle (the error should trigger on the attempt to draw).
10070 Draw(3, 1, 0, 0);
10071
10072 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010073 m_commandBuffer->EndRenderPass();
10074 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010075
10076 m_errorMonitor->VerifyFound();
10077
10078 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10079 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10080 vkDestroyRenderPass(m_device->device(), rp, NULL);
10081}
10082
Mark Youngc89c6312016-03-31 16:03:20 -060010083TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10084 // Create Pipeline where the number of blend attachments doesn't match the
10085 // number of color attachments. In this case, we don't add any color
10086 // blend attachments even though we have a color attachment.
10087 VkResult err;
10088
10089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010090 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010091
10092 ASSERT_NO_FATAL_FAILURE(InitState());
10093 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10094 VkDescriptorPoolSize ds_type_count = {};
10095 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10096 ds_type_count.descriptorCount = 1;
10097
10098 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10099 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10100 ds_pool_ci.pNext = NULL;
10101 ds_pool_ci.maxSets = 1;
10102 ds_pool_ci.poolSizeCount = 1;
10103 ds_pool_ci.pPoolSizes = &ds_type_count;
10104
10105 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010106 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010107 ASSERT_VK_SUCCESS(err);
10108
10109 VkDescriptorSetLayoutBinding dsl_binding = {};
10110 dsl_binding.binding = 0;
10111 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10112 dsl_binding.descriptorCount = 1;
10113 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10114 dsl_binding.pImmutableSamplers = NULL;
10115
10116 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10117 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10118 ds_layout_ci.pNext = NULL;
10119 ds_layout_ci.bindingCount = 1;
10120 ds_layout_ci.pBindings = &dsl_binding;
10121
10122 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010123 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010124 ASSERT_VK_SUCCESS(err);
10125
10126 VkDescriptorSet descriptorSet;
10127 VkDescriptorSetAllocateInfo alloc_info = {};
10128 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10129 alloc_info.descriptorSetCount = 1;
10130 alloc_info.descriptorPool = ds_pool;
10131 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010132 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010133 ASSERT_VK_SUCCESS(err);
10134
10135 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010136 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010137 pipe_ms_state_ci.pNext = NULL;
10138 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10139 pipe_ms_state_ci.sampleShadingEnable = 0;
10140 pipe_ms_state_ci.minSampleShading = 1.0;
10141 pipe_ms_state_ci.pSampleMask = NULL;
10142
10143 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10144 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10145 pipeline_layout_ci.pNext = NULL;
10146 pipeline_layout_ci.setLayoutCount = 1;
10147 pipeline_layout_ci.pSetLayouts = &ds_layout;
10148
10149 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010150 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010151 ASSERT_VK_SUCCESS(err);
10152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010153 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10154 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10155 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010156 VkPipelineObj pipe(m_device);
10157 pipe.AddShader(&vs);
10158 pipe.AddShader(&fs);
10159 pipe.SetMSAA(&pipe_ms_state_ci);
10160 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10161
Tony Barbour552f6c02016-12-21 14:34:07 -070010162 m_commandBuffer->BeginCommandBuffer();
10163 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010164 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010165
Mark Young29927482016-05-04 14:38:51 -060010166 // Render triangle (the error should trigger on the attempt to draw).
10167 Draw(3, 1, 0, 0);
10168
10169 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010170 m_commandBuffer->EndRenderPass();
10171 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010172
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010173 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010174
10175 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10176 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10177 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10178}
Mark Young29927482016-05-04 14:38:51 -060010179
Mark Muellerd4914412016-06-13 17:52:06 -060010180TEST_F(VkLayerTest, MissingClearAttachment) {
10181 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10182 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010183 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010185
10186 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10187 m_errorMonitor->VerifyFound();
10188}
10189
Karl Schultz6addd812016-02-02 17:17:23 -070010190TEST_F(VkLayerTest, ClearCmdNoDraw) {
10191 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10192 // to issuing a Draw
10193 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010196 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010197
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010198 ASSERT_NO_FATAL_FAILURE(InitState());
10199 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010200
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010201 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010202 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10203 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010204
10205 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010206 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10207 ds_pool_ci.pNext = NULL;
10208 ds_pool_ci.maxSets = 1;
10209 ds_pool_ci.poolSizeCount = 1;
10210 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010211
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010212 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010213 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010214 ASSERT_VK_SUCCESS(err);
10215
Tony Barboureb254902015-07-15 12:50:33 -060010216 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010217 dsl_binding.binding = 0;
10218 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10219 dsl_binding.descriptorCount = 1;
10220 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10221 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010222
Tony Barboureb254902015-07-15 12:50:33 -060010223 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010224 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10225 ds_layout_ci.pNext = NULL;
10226 ds_layout_ci.bindingCount = 1;
10227 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010228
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010229 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010230 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010231 ASSERT_VK_SUCCESS(err);
10232
10233 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010234 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010235 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010236 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010237 alloc_info.descriptorPool = ds_pool;
10238 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010239 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010240 ASSERT_VK_SUCCESS(err);
10241
Tony Barboureb254902015-07-15 12:50:33 -060010242 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010243 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010244 pipe_ms_state_ci.pNext = NULL;
10245 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10246 pipe_ms_state_ci.sampleShadingEnable = 0;
10247 pipe_ms_state_ci.minSampleShading = 1.0;
10248 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010249
Tony Barboureb254902015-07-15 12:50:33 -060010250 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010251 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10252 pipeline_layout_ci.pNext = NULL;
10253 pipeline_layout_ci.setLayoutCount = 1;
10254 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010255
10256 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010257 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010258 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010260 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010261 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010262 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010263 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010264
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010265 VkPipelineObj pipe(m_device);
10266 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010267 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010268 pipe.SetMSAA(&pipe_ms_state_ci);
10269 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010270
Tony Barbour552f6c02016-12-21 14:34:07 -070010271 m_commandBuffer->BeginCommandBuffer();
10272 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010273
Karl Schultz6addd812016-02-02 17:17:23 -070010274 // Main thing we care about for this test is that the VkImage obj we're
10275 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010276 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010277 VkClearAttachment color_attachment;
10278 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10279 color_attachment.clearValue.color.float32[0] = 1.0;
10280 color_attachment.clearValue.color.float32[1] = 1.0;
10281 color_attachment.clearValue.color.float32[2] = 1.0;
10282 color_attachment.clearValue.color.float32[3] = 1.0;
10283 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010284 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010286 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010287
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010288 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010289
Chia-I Wuf7458c52015-10-26 21:10:41 +080010290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010293}
10294
Karl Schultz6addd812016-02-02 17:17:23 -070010295TEST_F(VkLayerTest, VtxBufferBadIndex) {
10296 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10299 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010300
Tobin Ehlis502480b2015-06-24 15:53:07 -060010301 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010302 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010304
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010305 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010306 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10307 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010308
10309 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010310 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10311 ds_pool_ci.pNext = NULL;
10312 ds_pool_ci.maxSets = 1;
10313 ds_pool_ci.poolSizeCount = 1;
10314 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010315
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010316 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010317 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010318 ASSERT_VK_SUCCESS(err);
10319
Tony Barboureb254902015-07-15 12:50:33 -060010320 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010321 dsl_binding.binding = 0;
10322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10323 dsl_binding.descriptorCount = 1;
10324 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10325 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010326
Tony Barboureb254902015-07-15 12:50:33 -060010327 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010328 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10329 ds_layout_ci.pNext = NULL;
10330 ds_layout_ci.bindingCount = 1;
10331 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010332
Tobin Ehlis502480b2015-06-24 15:53:07 -060010333 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010334 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010335 ASSERT_VK_SUCCESS(err);
10336
10337 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010338 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010339 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010340 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010341 alloc_info.descriptorPool = ds_pool;
10342 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010344 ASSERT_VK_SUCCESS(err);
10345
Tony Barboureb254902015-07-15 12:50:33 -060010346 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010347 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010348 pipe_ms_state_ci.pNext = NULL;
10349 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10350 pipe_ms_state_ci.sampleShadingEnable = 0;
10351 pipe_ms_state_ci.minSampleShading = 1.0;
10352 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010353
Tony Barboureb254902015-07-15 12:50:33 -060010354 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010355 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10356 pipeline_layout_ci.pNext = NULL;
10357 pipeline_layout_ci.setLayoutCount = 1;
10358 pipeline_layout_ci.pSetLayouts = &ds_layout;
10359 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010360
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010361 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010362 ASSERT_VK_SUCCESS(err);
10363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010364 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10365 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10366 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010367 VkPipelineObj pipe(m_device);
10368 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010369 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010370 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010371 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010372 pipe.SetViewport(m_viewports);
10373 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010374 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010375
Tony Barbour552f6c02016-12-21 14:34:07 -070010376 m_commandBuffer->BeginCommandBuffer();
10377 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010378 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010379 // Don't care about actual data, just need to get to draw to flag error
10380 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010381 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010382 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010383 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010384
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010385 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010386
Chia-I Wuf7458c52015-10-26 21:10:41 +080010387 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10388 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10389 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010390}
Mark Muellerdfe37552016-07-07 14:47:42 -060010391
Mark Mueller2ee294f2016-08-04 12:59:48 -060010392TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10393 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10394 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010395 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010397 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10398 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010399
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010400 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10401 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010403 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010406 // The following test fails with recent NVidia drivers.
10407 // By the time core_validation is reached, the NVidia
10408 // driver has sanitized the invalid condition and core_validation
10409 // is not introduced to the failure condition. This is not the case
10410 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010411 // uint32_t count = static_cast<uint32_t>(~0);
10412 // VkPhysicalDevice physical_device;
10413 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10414 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010415
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010417 float queue_priority = 0.0;
10418
10419 VkDeviceQueueCreateInfo queue_create_info = {};
10420 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10421 queue_create_info.queueCount = 1;
10422 queue_create_info.pQueuePriorities = &queue_priority;
10423 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10424
10425 VkPhysicalDeviceFeatures features = m_device->phy().features();
10426 VkDevice testDevice;
10427 VkDeviceCreateInfo device_create_info = {};
10428 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10429 device_create_info.queueCreateInfoCount = 1;
10430 device_create_info.pQueueCreateInfos = &queue_create_info;
10431 device_create_info.pEnabledFeatures = &features;
10432 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10433 m_errorMonitor->VerifyFound();
10434
10435 queue_create_info.queueFamilyIndex = 1;
10436
10437 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10438 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10439 for (unsigned i = 0; i < feature_count; i++) {
10440 if (VK_FALSE == feature_array[i]) {
10441 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010443 device_create_info.pEnabledFeatures = &features;
10444 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10445 m_errorMonitor->VerifyFound();
10446 break;
10447 }
10448 }
10449}
10450
Tobin Ehlis16edf082016-11-21 12:33:49 -070010451TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10452 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10453
10454 ASSERT_NO_FATAL_FAILURE(InitState());
10455
10456 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10457 std::vector<VkDeviceQueueCreateInfo> queue_info;
10458 queue_info.reserve(queue_props.size());
10459 std::vector<std::vector<float>> queue_priorities;
10460 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10461 VkDeviceQueueCreateInfo qi{};
10462 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10463 qi.queueFamilyIndex = i;
10464 qi.queueCount = queue_props[i].queueCount;
10465 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10466 qi.pQueuePriorities = queue_priorities[i].data();
10467 queue_info.push_back(qi);
10468 }
10469
10470 std::vector<const char *> device_extension_names;
10471
10472 VkDevice local_device;
10473 VkDeviceCreateInfo device_create_info = {};
10474 auto features = m_device->phy().features();
10475 // Intentionally disable pipeline stats
10476 features.pipelineStatisticsQuery = VK_FALSE;
10477 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10478 device_create_info.pNext = NULL;
10479 device_create_info.queueCreateInfoCount = queue_info.size();
10480 device_create_info.pQueueCreateInfos = queue_info.data();
10481 device_create_info.enabledLayerCount = 0;
10482 device_create_info.ppEnabledLayerNames = NULL;
10483 device_create_info.pEnabledFeatures = &features;
10484 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10485 ASSERT_VK_SUCCESS(err);
10486
10487 VkQueryPoolCreateInfo qpci{};
10488 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10489 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10490 qpci.queryCount = 1;
10491 VkQueryPool query_pool;
10492
10493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10494 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10495 m_errorMonitor->VerifyFound();
10496
10497 vkDestroyDevice(local_device, nullptr);
10498}
10499
Mark Mueller2ee294f2016-08-04 12:59:48 -060010500TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10501 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10502 "End a command buffer with a query still in progress.");
10503
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010504 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10505 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10506 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010508 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010511
10512 ASSERT_NO_FATAL_FAILURE(InitState());
10513
10514 VkEvent event;
10515 VkEventCreateInfo event_create_info{};
10516 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10517 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10518
Mark Mueller2ee294f2016-08-04 12:59:48 -060010519 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010520 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010521
Tony Barbour552f6c02016-12-21 14:34:07 -070010522 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010523
10524 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010525 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 -060010526 ASSERT_TRUE(image.initialized());
10527 VkImageMemoryBarrier img_barrier = {};
10528 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10529 img_barrier.pNext = NULL;
10530 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10531 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10532 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10533 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10534 img_barrier.image = image.handle();
10535 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010536
10537 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10538 // that layer validation catches the case when it is not.
10539 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010540 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10541 img_barrier.subresourceRange.baseArrayLayer = 0;
10542 img_barrier.subresourceRange.baseMipLevel = 0;
10543 img_barrier.subresourceRange.layerCount = 1;
10544 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010545 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10546 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010547 m_errorMonitor->VerifyFound();
10548
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010550
10551 VkQueryPool query_pool;
10552 VkQueryPoolCreateInfo query_pool_create_info = {};
10553 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10554 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10555 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010556 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010559 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10560
10561 vkEndCommandBuffer(m_commandBuffer->handle());
10562 m_errorMonitor->VerifyFound();
10563
10564 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10565 vkDestroyEvent(m_device->device(), event, nullptr);
10566}
10567
Mark Muellerdfe37552016-07-07 14:47:42 -060010568TEST_F(VkLayerTest, VertexBufferInvalid) {
10569 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10570 "delete a buffer twice, use an invalid offset for each "
10571 "buffer type, and attempt to bind a null buffer");
10572
10573 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10574 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010575 const char *invalid_offset_message = "vkBindBufferMemory(): "
10576 "memoryOffset is 0x";
10577 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10578 "storage memoryOffset "
10579 "is 0x";
10580 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10581 "texel memoryOffset "
10582 "is 0x";
10583 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10584 "uniform memoryOffset "
10585 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010586
10587 ASSERT_NO_FATAL_FAILURE(InitState());
10588 ASSERT_NO_FATAL_FAILURE(InitViewport());
10589 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10590
10591 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010592 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010593 pipe_ms_state_ci.pNext = NULL;
10594 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10595 pipe_ms_state_ci.sampleShadingEnable = 0;
10596 pipe_ms_state_ci.minSampleShading = 1.0;
10597 pipe_ms_state_ci.pSampleMask = nullptr;
10598
10599 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10600 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10601 VkPipelineLayout pipeline_layout;
10602
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010604 ASSERT_VK_SUCCESS(err);
10605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010606 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10607 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010608 VkPipelineObj pipe(m_device);
10609 pipe.AddShader(&vs);
10610 pipe.AddShader(&fs);
10611 pipe.AddColorAttachment();
10612 pipe.SetMSAA(&pipe_ms_state_ci);
10613 pipe.SetViewport(m_viewports);
10614 pipe.SetScissor(m_scissors);
10615 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10616
Tony Barbour552f6c02016-12-21 14:34:07 -070010617 m_commandBuffer->BeginCommandBuffer();
10618 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010619 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010620
10621 {
10622 // Create and bind a vertex buffer in a reduced scope, which will cause
10623 // it to be deleted upon leaving this scope
10624 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010625 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010626 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10627 draw_verticies.AddVertexInputToPipe(pipe);
10628 }
10629
10630 Draw(1, 0, 0, 0);
10631
Tony Barbour552f6c02016-12-21 14:34:07 -070010632 m_commandBuffer->EndRenderPass();
10633 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010636 QueueCommandBuffer(false);
10637 m_errorMonitor->VerifyFound();
10638
10639 {
10640 // Create and bind a vertex buffer in a reduced scope, and delete it
10641 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010642 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010644 buffer_test.TestDoubleDestroy();
10645 }
10646 m_errorMonitor->VerifyFound();
10647
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010648 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010649 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10651 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10652 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010653 m_errorMonitor->VerifyFound();
10654 }
10655
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010656 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10657 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010658 // Create and bind a memory buffer with an invalid offset again,
10659 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10661 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10662 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010663 m_errorMonitor->VerifyFound();
10664 }
10665
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010666 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010667 // Create and bind a memory buffer with an invalid offset again, but
10668 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10670 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10671 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010672 m_errorMonitor->VerifyFound();
10673 }
10674
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010675 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010676 // Create and bind a memory buffer with an invalid offset again, but
10677 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10679 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10680 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010681 m_errorMonitor->VerifyFound();
10682 }
10683
10684 {
10685 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010687 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10688 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010689 m_errorMonitor->VerifyFound();
10690 }
10691
10692 {
10693 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010695 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10696 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010697 }
10698 m_errorMonitor->VerifyFound();
10699
10700 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10701}
10702
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010703// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10704TEST_F(VkLayerTest, InvalidImageLayout) {
10705 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010706 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10707 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010708 // 3 in ValidateCmdBufImageLayouts
10709 // * -1 Attempt to submit cmd buf w/ deleted image
10710 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10711 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010712
10713 ASSERT_NO_FATAL_FAILURE(InitState());
10714 // Create src & dst images to use for copy operations
10715 VkImage src_image;
10716 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010717 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010718
10719 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10720 const int32_t tex_width = 32;
10721 const int32_t tex_height = 32;
10722
10723 VkImageCreateInfo image_create_info = {};
10724 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10725 image_create_info.pNext = NULL;
10726 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10727 image_create_info.format = tex_format;
10728 image_create_info.extent.width = tex_width;
10729 image_create_info.extent.height = tex_height;
10730 image_create_info.extent.depth = 1;
10731 image_create_info.mipLevels = 1;
10732 image_create_info.arrayLayers = 4;
10733 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10734 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10735 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010736 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010737 image_create_info.flags = 0;
10738
10739 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10740 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010741 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010742 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10743 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010744 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10745 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10746 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10747 ASSERT_VK_SUCCESS(err);
10748
10749 // Allocate memory
10750 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010751 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010752 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010753 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10754 mem_alloc.pNext = NULL;
10755 mem_alloc.allocationSize = 0;
10756 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010757
10758 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010759 mem_alloc.allocationSize = img_mem_reqs.size;
10760 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010761 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010762 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010763 ASSERT_VK_SUCCESS(err);
10764
10765 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010766 mem_alloc.allocationSize = img_mem_reqs.size;
10767 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010768 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010769 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010770 ASSERT_VK_SUCCESS(err);
10771
10772 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010773 mem_alloc.allocationSize = img_mem_reqs.size;
10774 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010775 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010776 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010777 ASSERT_VK_SUCCESS(err);
10778
10779 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10780 ASSERT_VK_SUCCESS(err);
10781 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10782 ASSERT_VK_SUCCESS(err);
10783 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10784 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010785
Tony Barbour552f6c02016-12-21 14:34:07 -070010786 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010787 VkImageCopy copy_region;
10788 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10789 copy_region.srcSubresource.mipLevel = 0;
10790 copy_region.srcSubresource.baseArrayLayer = 0;
10791 copy_region.srcSubresource.layerCount = 1;
10792 copy_region.srcOffset.x = 0;
10793 copy_region.srcOffset.y = 0;
10794 copy_region.srcOffset.z = 0;
10795 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10796 copy_region.dstSubresource.mipLevel = 0;
10797 copy_region.dstSubresource.baseArrayLayer = 0;
10798 copy_region.dstSubresource.layerCount = 1;
10799 copy_region.dstOffset.x = 0;
10800 copy_region.dstOffset.y = 0;
10801 copy_region.dstOffset.z = 0;
10802 copy_region.extent.width = 1;
10803 copy_region.extent.height = 1;
10804 copy_region.extent.depth = 1;
10805
10806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10807 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10808 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 -060010809 m_errorMonitor->VerifyFound();
10810 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10812 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10813 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010814 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 -060010815 m_errorMonitor->VerifyFound();
10816 // Final src error is due to bad layout type
10817 m_errorMonitor->SetDesiredFailureMsg(
10818 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10819 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010820 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 -060010821 m_errorMonitor->VerifyFound();
10822 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10824 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010825 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 -060010826 m_errorMonitor->VerifyFound();
10827 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10829 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10830 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010831 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 -060010832 m_errorMonitor->VerifyFound();
10833 m_errorMonitor->SetDesiredFailureMsg(
10834 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10835 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010836 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 -060010837 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010838
Cort3b021012016-12-07 12:00:57 -080010839 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10840 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10841 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10842 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10843 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10844 transfer_dst_image_barrier[0].srcAccessMask = 0;
10845 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10846 transfer_dst_image_barrier[0].image = dst_image;
10847 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10848 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10849 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10850 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10851 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10852 transfer_dst_image_barrier[0].image = depth_image;
10853 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10854 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10855 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10856
10857 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010858 VkClearColorValue color_clear_value = {};
10859 VkImageSubresourceRange clear_range;
10860 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10861 clear_range.baseMipLevel = 0;
10862 clear_range.baseArrayLayer = 0;
10863 clear_range.layerCount = 1;
10864 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010865
Cort3b021012016-12-07 12:00:57 -080010866 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10867 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010870 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010871 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010872 // Fail due to provided layout not matching actual current layout for color clear.
10873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010874 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010875 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010876
Cort530cf382016-12-08 09:59:47 -080010877 VkClearDepthStencilValue depth_clear_value = {};
10878 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010879
10880 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10881 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010884 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010885 m_errorMonitor->VerifyFound();
10886 // Fail due to provided layout not matching actual current layout for depth clear.
10887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010888 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010889 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010890
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010891 // Now cause error due to bad image layout transition in PipelineBarrier
10892 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010893 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010894 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010895 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010896 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010897 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10898 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010899 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10901 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10902 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10903 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10904 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010905 m_errorMonitor->VerifyFound();
10906
10907 // Finally some layout errors at RenderPass create time
10908 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10909 VkAttachmentReference attach = {};
10910 // perf warning for GENERAL layout w/ non-DS input attachment
10911 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10912 VkSubpassDescription subpass = {};
10913 subpass.inputAttachmentCount = 1;
10914 subpass.pInputAttachments = &attach;
10915 VkRenderPassCreateInfo rpci = {};
10916 rpci.subpassCount = 1;
10917 rpci.pSubpasses = &subpass;
10918 rpci.attachmentCount = 1;
10919 VkAttachmentDescription attach_desc = {};
10920 attach_desc.format = VK_FORMAT_UNDEFINED;
10921 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010922 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010923 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10925 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010926 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10927 m_errorMonitor->VerifyFound();
10928 // error w/ non-general layout
10929 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10930
10931 m_errorMonitor->SetDesiredFailureMsg(
10932 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10933 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10934 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10935 m_errorMonitor->VerifyFound();
10936 subpass.inputAttachmentCount = 0;
10937 subpass.colorAttachmentCount = 1;
10938 subpass.pColorAttachments = &attach;
10939 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10940 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10942 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010943 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10944 m_errorMonitor->VerifyFound();
10945 // error w/ non-color opt or GENERAL layout for color attachment
10946 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10947 m_errorMonitor->SetDesiredFailureMsg(
10948 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10949 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10950 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10951 m_errorMonitor->VerifyFound();
10952 subpass.colorAttachmentCount = 0;
10953 subpass.pDepthStencilAttachment = &attach;
10954 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10955 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10957 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010958 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10959 m_errorMonitor->VerifyFound();
10960 // error w/ non-ds opt or GENERAL layout for color attachment
10961 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10963 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10964 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010965 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10966 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010967 // For this error we need a valid renderpass so create default one
10968 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10969 attach.attachment = 0;
10970 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10971 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10972 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10973 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10974 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10975 // Can't do a CLEAR load on READ_ONLY initialLayout
10976 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10977 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10978 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10980 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10981 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010982 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10983 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010984
Cort3b021012016-12-07 12:00:57 -080010985 vkFreeMemory(m_device->device(), src_image_mem, NULL);
10986 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
10987 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010988 vkDestroyImage(m_device->device(), src_image, NULL);
10989 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080010990 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010991}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010992
Tobin Ehlise0936662016-10-11 08:10:51 -060010993TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10994 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10995 VkResult err;
10996
10997 ASSERT_NO_FATAL_FAILURE(InitState());
10998
10999 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11000 VkImageTiling tiling;
11001 VkFormatProperties format_properties;
11002 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11003 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11004 tiling = VK_IMAGE_TILING_LINEAR;
11005 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11006 tiling = VK_IMAGE_TILING_OPTIMAL;
11007 } else {
11008 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11009 "skipped.\n");
11010 return;
11011 }
11012
11013 VkDescriptorPoolSize ds_type = {};
11014 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11015 ds_type.descriptorCount = 1;
11016
11017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11019 ds_pool_ci.maxSets = 1;
11020 ds_pool_ci.poolSizeCount = 1;
11021 ds_pool_ci.pPoolSizes = &ds_type;
11022 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11023
11024 VkDescriptorPool ds_pool;
11025 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11026 ASSERT_VK_SUCCESS(err);
11027
11028 VkDescriptorSetLayoutBinding dsl_binding = {};
11029 dsl_binding.binding = 0;
11030 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11031 dsl_binding.descriptorCount = 1;
11032 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11033 dsl_binding.pImmutableSamplers = NULL;
11034
11035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11036 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11037 ds_layout_ci.pNext = NULL;
11038 ds_layout_ci.bindingCount = 1;
11039 ds_layout_ci.pBindings = &dsl_binding;
11040
11041 VkDescriptorSetLayout ds_layout;
11042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11043 ASSERT_VK_SUCCESS(err);
11044
11045 VkDescriptorSetAllocateInfo alloc_info = {};
11046 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11047 alloc_info.descriptorSetCount = 1;
11048 alloc_info.descriptorPool = ds_pool;
11049 alloc_info.pSetLayouts = &ds_layout;
11050 VkDescriptorSet descriptor_set;
11051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11052 ASSERT_VK_SUCCESS(err);
11053
11054 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11055 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11056 pipeline_layout_ci.pNext = NULL;
11057 pipeline_layout_ci.setLayoutCount = 1;
11058 pipeline_layout_ci.pSetLayouts = &ds_layout;
11059 VkPipelineLayout pipeline_layout;
11060 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11061 ASSERT_VK_SUCCESS(err);
11062
11063 VkImageObj image(m_device);
11064 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11065 ASSERT_TRUE(image.initialized());
11066 VkImageView view = image.targetView(tex_format);
11067
11068 VkDescriptorImageInfo image_info = {};
11069 image_info.imageView = view;
11070 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11071
11072 VkWriteDescriptorSet descriptor_write = {};
11073 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11074 descriptor_write.dstSet = descriptor_set;
11075 descriptor_write.dstBinding = 0;
11076 descriptor_write.descriptorCount = 1;
11077 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11078 descriptor_write.pImageInfo = &image_info;
11079
11080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11081 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11082 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11083 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11084 m_errorMonitor->VerifyFound();
11085
11086 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11087 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11088 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11089 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11090}
11091
Mark Mueller93b938f2016-08-18 10:27:40 -060011092TEST_F(VkLayerTest, SimultaneousUse) {
11093 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11094 "in primary and secondary command buffers.");
11095
11096 ASSERT_NO_FATAL_FAILURE(InitState());
11097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11098
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011099 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011100 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11101 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011102
11103 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011104 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011105 command_buffer_allocate_info.commandPool = m_commandPool;
11106 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11107 command_buffer_allocate_info.commandBufferCount = 1;
11108
11109 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011110 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011111 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11112 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011113 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011114 command_buffer_inheritance_info.renderPass = m_renderPass;
11115 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011116
Mark Mueller93b938f2016-08-18 10:27:40 -060011117 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011118 command_buffer_begin_info.flags =
11119 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011120 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11121
11122 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11123 vkEndCommandBuffer(secondary_command_buffer);
11124
Mark Mueller93b938f2016-08-18 10:27:40 -060011125 VkSubmitInfo submit_info = {};
11126 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11127 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011128 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011129
Mark Mueller4042b652016-09-05 22:52:21 -060011130 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011131 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11133 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011134 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011135 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011136 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11137 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011138
11139 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011140 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11141
Mark Mueller4042b652016-09-05 22:52:21 -060011142 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011143 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011144 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11147 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011148 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011149 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11150 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011151
11152 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011153}
11154
Mark Mueller917f6bc2016-08-30 10:57:19 -060011155TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11156 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11157 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011158 "Delete objects that are inuse. Call VkQueueSubmit "
11159 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011160
11161 ASSERT_NO_FATAL_FAILURE(InitState());
11162 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011164 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011165 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011166
Tony Barbour552f6c02016-12-21 14:34:07 -070011167 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011168
11169 VkEvent event;
11170 VkEventCreateInfo event_create_info = {};
11171 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11172 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011173 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011174
Tony Barbour552f6c02016-12-21 14:34:07 -070011175 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011176 vkDestroyEvent(m_device->device(), event, nullptr);
11177
11178 VkSubmitInfo submit_info = {};
11179 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11180 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011181 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011183 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11184 m_errorMonitor->VerifyFound();
11185
11186 m_errorMonitor->SetDesiredFailureMsg(0, "");
11187 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11188
11189 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11190
Mark Mueller917f6bc2016-08-30 10:57:19 -060011191 VkSemaphoreCreateInfo semaphore_create_info = {};
11192 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11193 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011194 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011195 VkFenceCreateInfo fence_create_info = {};
11196 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11197 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011199
11200 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011201 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011202 descriptor_pool_type_count.descriptorCount = 1;
11203
11204 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11205 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11206 descriptor_pool_create_info.maxSets = 1;
11207 descriptor_pool_create_info.poolSizeCount = 1;
11208 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011209 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011210
11211 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011213
11214 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011215 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011216 descriptorset_layout_binding.descriptorCount = 1;
11217 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11218
11219 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011220 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011221 descriptorset_layout_create_info.bindingCount = 1;
11222 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11223
11224 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011225 ASSERT_VK_SUCCESS(
11226 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011227
11228 VkDescriptorSet descriptorset;
11229 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011230 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011231 descriptorset_allocate_info.descriptorSetCount = 1;
11232 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11233 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011234 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011235
Mark Mueller4042b652016-09-05 22:52:21 -060011236 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11237
11238 VkDescriptorBufferInfo buffer_info = {};
11239 buffer_info.buffer = buffer_test.GetBuffer();
11240 buffer_info.offset = 0;
11241 buffer_info.range = 1024;
11242
11243 VkWriteDescriptorSet write_descriptor_set = {};
11244 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11245 write_descriptor_set.dstSet = descriptorset;
11246 write_descriptor_set.descriptorCount = 1;
11247 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11248 write_descriptor_set.pBufferInfo = &buffer_info;
11249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011250 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011251
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011252 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11253 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011254
11255 VkPipelineObj pipe(m_device);
11256 pipe.AddColorAttachment();
11257 pipe.AddShader(&vs);
11258 pipe.AddShader(&fs);
11259
11260 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011261 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011262 pipeline_layout_create_info.setLayoutCount = 1;
11263 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11264
11265 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011266 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011267
11268 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11269
Tony Barbour552f6c02016-12-21 14:34:07 -070011270 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011271 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011273 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11274 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11275 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011276
Tony Barbour552f6c02016-12-21 14:34:07 -070011277 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011278
Mark Mueller917f6bc2016-08-30 10:57:19 -060011279 submit_info.signalSemaphoreCount = 1;
11280 submit_info.pSignalSemaphores = &semaphore;
11281 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011282
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011284 vkDestroyEvent(m_device->device(), event, nullptr);
11285 m_errorMonitor->VerifyFound();
11286
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011288 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11289 m_errorMonitor->VerifyFound();
11290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011292 vkDestroyFence(m_device->device(), fence, nullptr);
11293 m_errorMonitor->VerifyFound();
11294
Tobin Ehlis122207b2016-09-01 08:50:06 -070011295 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011296 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11297 vkDestroyFence(m_device->device(), fence, nullptr);
11298 vkDestroyEvent(m_device->device(), event, nullptr);
11299 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011300 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011301 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11302}
11303
Tobin Ehlis2adda372016-09-01 08:51:06 -070011304TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11305 TEST_DESCRIPTION("Delete in-use query pool.");
11306
11307 ASSERT_NO_FATAL_FAILURE(InitState());
11308 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11309
11310 VkQueryPool query_pool;
11311 VkQueryPoolCreateInfo query_pool_ci{};
11312 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11313 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11314 query_pool_ci.queryCount = 1;
11315 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011316 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011317 // Reset query pool to create binding with cmd buffer
11318 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11319
Tony Barbour552f6c02016-12-21 14:34:07 -070011320 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011321
11322 VkSubmitInfo submit_info = {};
11323 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11324 submit_info.commandBufferCount = 1;
11325 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11326 // Submit cmd buffer and then destroy query pool while in-flight
11327 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11328
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011330 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11331 m_errorMonitor->VerifyFound();
11332
11333 vkQueueWaitIdle(m_device->m_queue);
11334 // Now that cmd buffer done we can safely destroy query_pool
11335 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11336}
11337
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011338TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11339 TEST_DESCRIPTION("Delete in-use pipeline.");
11340
11341 ASSERT_NO_FATAL_FAILURE(InitState());
11342 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11343
11344 // Empty pipeline layout used for binding PSO
11345 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11346 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11347 pipeline_layout_ci.setLayoutCount = 0;
11348 pipeline_layout_ci.pSetLayouts = NULL;
11349
11350 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011351 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011352 ASSERT_VK_SUCCESS(err);
11353
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011355 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011356 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11357 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011358 // Store pipeline handle so we can actually delete it before test finishes
11359 VkPipeline delete_this_pipeline;
11360 { // Scope pipeline so it will be auto-deleted
11361 VkPipelineObj pipe(m_device);
11362 pipe.AddShader(&vs);
11363 pipe.AddShader(&fs);
11364 pipe.AddColorAttachment();
11365 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11366 delete_this_pipeline = pipe.handle();
11367
Tony Barbour552f6c02016-12-21 14:34:07 -070011368 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011369 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011370 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011371
Tony Barbour552f6c02016-12-21 14:34:07 -070011372 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011373
11374 VkSubmitInfo submit_info = {};
11375 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11376 submit_info.commandBufferCount = 1;
11377 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11378 // Submit cmd buffer and then pipeline destroyed while in-flight
11379 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11380 } // Pipeline deletion triggered here
11381 m_errorMonitor->VerifyFound();
11382 // Make sure queue finished and then actually delete pipeline
11383 vkQueueWaitIdle(m_device->m_queue);
11384 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11385 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11386}
11387
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011388TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11389 TEST_DESCRIPTION("Delete in-use imageView.");
11390
11391 ASSERT_NO_FATAL_FAILURE(InitState());
11392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11393
11394 VkDescriptorPoolSize ds_type_count;
11395 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11396 ds_type_count.descriptorCount = 1;
11397
11398 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11399 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11400 ds_pool_ci.maxSets = 1;
11401 ds_pool_ci.poolSizeCount = 1;
11402 ds_pool_ci.pPoolSizes = &ds_type_count;
11403
11404 VkDescriptorPool ds_pool;
11405 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11406 ASSERT_VK_SUCCESS(err);
11407
11408 VkSamplerCreateInfo sampler_ci = {};
11409 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11410 sampler_ci.pNext = NULL;
11411 sampler_ci.magFilter = VK_FILTER_NEAREST;
11412 sampler_ci.minFilter = VK_FILTER_NEAREST;
11413 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11414 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11415 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11416 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11417 sampler_ci.mipLodBias = 1.0;
11418 sampler_ci.anisotropyEnable = VK_FALSE;
11419 sampler_ci.maxAnisotropy = 1;
11420 sampler_ci.compareEnable = VK_FALSE;
11421 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11422 sampler_ci.minLod = 1.0;
11423 sampler_ci.maxLod = 1.0;
11424 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11425 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11426 VkSampler sampler;
11427
11428 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11429 ASSERT_VK_SUCCESS(err);
11430
11431 VkDescriptorSetLayoutBinding layout_binding;
11432 layout_binding.binding = 0;
11433 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11434 layout_binding.descriptorCount = 1;
11435 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11436 layout_binding.pImmutableSamplers = NULL;
11437
11438 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11439 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11440 ds_layout_ci.bindingCount = 1;
11441 ds_layout_ci.pBindings = &layout_binding;
11442 VkDescriptorSetLayout ds_layout;
11443 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11444 ASSERT_VK_SUCCESS(err);
11445
11446 VkDescriptorSetAllocateInfo alloc_info = {};
11447 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11448 alloc_info.descriptorSetCount = 1;
11449 alloc_info.descriptorPool = ds_pool;
11450 alloc_info.pSetLayouts = &ds_layout;
11451 VkDescriptorSet descriptor_set;
11452 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11453 ASSERT_VK_SUCCESS(err);
11454
11455 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11456 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11457 pipeline_layout_ci.pNext = NULL;
11458 pipeline_layout_ci.setLayoutCount = 1;
11459 pipeline_layout_ci.pSetLayouts = &ds_layout;
11460
11461 VkPipelineLayout pipeline_layout;
11462 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11463 ASSERT_VK_SUCCESS(err);
11464
11465 VkImageObj image(m_device);
11466 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11467 ASSERT_TRUE(image.initialized());
11468
11469 VkImageView view;
11470 VkImageViewCreateInfo ivci = {};
11471 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11472 ivci.image = image.handle();
11473 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11474 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11475 ivci.subresourceRange.layerCount = 1;
11476 ivci.subresourceRange.baseMipLevel = 0;
11477 ivci.subresourceRange.levelCount = 1;
11478 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11479
11480 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11481 ASSERT_VK_SUCCESS(err);
11482
11483 VkDescriptorImageInfo image_info{};
11484 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11485 image_info.imageView = view;
11486 image_info.sampler = sampler;
11487
11488 VkWriteDescriptorSet descriptor_write = {};
11489 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11490 descriptor_write.dstSet = descriptor_set;
11491 descriptor_write.dstBinding = 0;
11492 descriptor_write.descriptorCount = 1;
11493 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11494 descriptor_write.pImageInfo = &image_info;
11495
11496 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11497
11498 // Create PSO to use the sampler
11499 char const *vsSource = "#version 450\n"
11500 "\n"
11501 "out gl_PerVertex { \n"
11502 " vec4 gl_Position;\n"
11503 "};\n"
11504 "void main(){\n"
11505 " gl_Position = vec4(1);\n"
11506 "}\n";
11507 char const *fsSource = "#version 450\n"
11508 "\n"
11509 "layout(set=0, binding=0) uniform sampler2D s;\n"
11510 "layout(location=0) out vec4 x;\n"
11511 "void main(){\n"
11512 " x = texture(s, vec2(1));\n"
11513 "}\n";
11514 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11515 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11516 VkPipelineObj pipe(m_device);
11517 pipe.AddShader(&vs);
11518 pipe.AddShader(&fs);
11519 pipe.AddColorAttachment();
11520 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11521
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011523
Tony Barbour552f6c02016-12-21 14:34:07 -070011524 m_commandBuffer->BeginCommandBuffer();
11525 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011526 // Bind pipeline to cmd buffer
11527 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11528 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11529 &descriptor_set, 0, nullptr);
11530 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011531 m_commandBuffer->EndRenderPass();
11532 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011533 // Submit cmd buffer then destroy sampler
11534 VkSubmitInfo submit_info = {};
11535 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11536 submit_info.commandBufferCount = 1;
11537 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11538 // Submit cmd buffer and then destroy imageView while in-flight
11539 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11540
11541 vkDestroyImageView(m_device->device(), view, nullptr);
11542 m_errorMonitor->VerifyFound();
11543 vkQueueWaitIdle(m_device->m_queue);
11544 // Now we can actually destroy imageView
11545 vkDestroyImageView(m_device->device(), view, NULL);
11546 vkDestroySampler(m_device->device(), sampler, nullptr);
11547 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11548 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11550}
11551
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011552TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11553 TEST_DESCRIPTION("Delete in-use bufferView.");
11554
11555 ASSERT_NO_FATAL_FAILURE(InitState());
11556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11557
11558 VkDescriptorPoolSize ds_type_count;
11559 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11560 ds_type_count.descriptorCount = 1;
11561
11562 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11563 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11564 ds_pool_ci.maxSets = 1;
11565 ds_pool_ci.poolSizeCount = 1;
11566 ds_pool_ci.pPoolSizes = &ds_type_count;
11567
11568 VkDescriptorPool ds_pool;
11569 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11570 ASSERT_VK_SUCCESS(err);
11571
11572 VkDescriptorSetLayoutBinding layout_binding;
11573 layout_binding.binding = 0;
11574 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11575 layout_binding.descriptorCount = 1;
11576 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11577 layout_binding.pImmutableSamplers = NULL;
11578
11579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11581 ds_layout_ci.bindingCount = 1;
11582 ds_layout_ci.pBindings = &layout_binding;
11583 VkDescriptorSetLayout ds_layout;
11584 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11585 ASSERT_VK_SUCCESS(err);
11586
11587 VkDescriptorSetAllocateInfo alloc_info = {};
11588 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11589 alloc_info.descriptorSetCount = 1;
11590 alloc_info.descriptorPool = ds_pool;
11591 alloc_info.pSetLayouts = &ds_layout;
11592 VkDescriptorSet descriptor_set;
11593 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11594 ASSERT_VK_SUCCESS(err);
11595
11596 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11597 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11598 pipeline_layout_ci.pNext = NULL;
11599 pipeline_layout_ci.setLayoutCount = 1;
11600 pipeline_layout_ci.pSetLayouts = &ds_layout;
11601
11602 VkPipelineLayout pipeline_layout;
11603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11604 ASSERT_VK_SUCCESS(err);
11605
11606 VkBuffer buffer;
11607 uint32_t queue_family_index = 0;
11608 VkBufferCreateInfo buffer_create_info = {};
11609 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11610 buffer_create_info.size = 1024;
11611 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11612 buffer_create_info.queueFamilyIndexCount = 1;
11613 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11614
11615 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11616 ASSERT_VK_SUCCESS(err);
11617
11618 VkMemoryRequirements memory_reqs;
11619 VkDeviceMemory buffer_memory;
11620
11621 VkMemoryAllocateInfo memory_info = {};
11622 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11623 memory_info.allocationSize = 0;
11624 memory_info.memoryTypeIndex = 0;
11625
11626 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11627 memory_info.allocationSize = memory_reqs.size;
11628 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11629 ASSERT_TRUE(pass);
11630
11631 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11632 ASSERT_VK_SUCCESS(err);
11633 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11634 ASSERT_VK_SUCCESS(err);
11635
11636 VkBufferView view;
11637 VkBufferViewCreateInfo bvci = {};
11638 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11639 bvci.buffer = buffer;
11640 bvci.format = VK_FORMAT_R8_UNORM;
11641 bvci.range = VK_WHOLE_SIZE;
11642
11643 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11644 ASSERT_VK_SUCCESS(err);
11645
11646 VkWriteDescriptorSet descriptor_write = {};
11647 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11648 descriptor_write.dstSet = descriptor_set;
11649 descriptor_write.dstBinding = 0;
11650 descriptor_write.descriptorCount = 1;
11651 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11652 descriptor_write.pTexelBufferView = &view;
11653
11654 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11655
11656 char const *vsSource = "#version 450\n"
11657 "\n"
11658 "out gl_PerVertex { \n"
11659 " vec4 gl_Position;\n"
11660 "};\n"
11661 "void main(){\n"
11662 " gl_Position = vec4(1);\n"
11663 "}\n";
11664 char const *fsSource = "#version 450\n"
11665 "\n"
11666 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11667 "layout(location=0) out vec4 x;\n"
11668 "void main(){\n"
11669 " x = imageLoad(s, 0);\n"
11670 "}\n";
11671 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11672 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11673 VkPipelineObj pipe(m_device);
11674 pipe.AddShader(&vs);
11675 pipe.AddShader(&fs);
11676 pipe.AddColorAttachment();
11677 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11678
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011680
Tony Barbour552f6c02016-12-21 14:34:07 -070011681 m_commandBuffer->BeginCommandBuffer();
11682 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011683 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11684 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11685 VkRect2D scissor = {{0, 0}, {16, 16}};
11686 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11687 // Bind pipeline to cmd buffer
11688 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11689 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11690 &descriptor_set, 0, nullptr);
11691 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011692 m_commandBuffer->EndRenderPass();
11693 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011694
11695 VkSubmitInfo submit_info = {};
11696 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11697 submit_info.commandBufferCount = 1;
11698 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11699 // Submit cmd buffer and then destroy bufferView while in-flight
11700 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11701
11702 vkDestroyBufferView(m_device->device(), view, nullptr);
11703 m_errorMonitor->VerifyFound();
11704 vkQueueWaitIdle(m_device->m_queue);
11705 // Now we can actually destroy bufferView
11706 vkDestroyBufferView(m_device->device(), view, NULL);
11707 vkDestroyBuffer(m_device->device(), buffer, NULL);
11708 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11709 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11710 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11711 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11712}
11713
Tobin Ehlis209532e2016-09-07 13:52:18 -060011714TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11715 TEST_DESCRIPTION("Delete in-use sampler.");
11716
11717 ASSERT_NO_FATAL_FAILURE(InitState());
11718 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11719
11720 VkDescriptorPoolSize ds_type_count;
11721 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11722 ds_type_count.descriptorCount = 1;
11723
11724 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11725 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11726 ds_pool_ci.maxSets = 1;
11727 ds_pool_ci.poolSizeCount = 1;
11728 ds_pool_ci.pPoolSizes = &ds_type_count;
11729
11730 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011731 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011732 ASSERT_VK_SUCCESS(err);
11733
11734 VkSamplerCreateInfo sampler_ci = {};
11735 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11736 sampler_ci.pNext = NULL;
11737 sampler_ci.magFilter = VK_FILTER_NEAREST;
11738 sampler_ci.minFilter = VK_FILTER_NEAREST;
11739 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11740 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11741 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11742 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11743 sampler_ci.mipLodBias = 1.0;
11744 sampler_ci.anisotropyEnable = VK_FALSE;
11745 sampler_ci.maxAnisotropy = 1;
11746 sampler_ci.compareEnable = VK_FALSE;
11747 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11748 sampler_ci.minLod = 1.0;
11749 sampler_ci.maxLod = 1.0;
11750 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11751 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11752 VkSampler sampler;
11753
11754 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11755 ASSERT_VK_SUCCESS(err);
11756
11757 VkDescriptorSetLayoutBinding layout_binding;
11758 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011759 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011760 layout_binding.descriptorCount = 1;
11761 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11762 layout_binding.pImmutableSamplers = NULL;
11763
11764 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11765 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11766 ds_layout_ci.bindingCount = 1;
11767 ds_layout_ci.pBindings = &layout_binding;
11768 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011770 ASSERT_VK_SUCCESS(err);
11771
11772 VkDescriptorSetAllocateInfo alloc_info = {};
11773 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11774 alloc_info.descriptorSetCount = 1;
11775 alloc_info.descriptorPool = ds_pool;
11776 alloc_info.pSetLayouts = &ds_layout;
11777 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011779 ASSERT_VK_SUCCESS(err);
11780
11781 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11782 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11783 pipeline_layout_ci.pNext = NULL;
11784 pipeline_layout_ci.setLayoutCount = 1;
11785 pipeline_layout_ci.pSetLayouts = &ds_layout;
11786
11787 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011788 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011789 ASSERT_VK_SUCCESS(err);
11790
11791 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011792 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 -060011793 ASSERT_TRUE(image.initialized());
11794
11795 VkImageView view;
11796 VkImageViewCreateInfo ivci = {};
11797 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11798 ivci.image = image.handle();
11799 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11800 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11801 ivci.subresourceRange.layerCount = 1;
11802 ivci.subresourceRange.baseMipLevel = 0;
11803 ivci.subresourceRange.levelCount = 1;
11804 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11805
11806 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11807 ASSERT_VK_SUCCESS(err);
11808
11809 VkDescriptorImageInfo image_info{};
11810 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11811 image_info.imageView = view;
11812 image_info.sampler = sampler;
11813
11814 VkWriteDescriptorSet descriptor_write = {};
11815 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11816 descriptor_write.dstSet = descriptor_set;
11817 descriptor_write.dstBinding = 0;
11818 descriptor_write.descriptorCount = 1;
11819 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11820 descriptor_write.pImageInfo = &image_info;
11821
11822 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11823
11824 // Create PSO to use the sampler
11825 char const *vsSource = "#version 450\n"
11826 "\n"
11827 "out gl_PerVertex { \n"
11828 " vec4 gl_Position;\n"
11829 "};\n"
11830 "void main(){\n"
11831 " gl_Position = vec4(1);\n"
11832 "}\n";
11833 char const *fsSource = "#version 450\n"
11834 "\n"
11835 "layout(set=0, binding=0) uniform sampler2D s;\n"
11836 "layout(location=0) out vec4 x;\n"
11837 "void main(){\n"
11838 " x = texture(s, vec2(1));\n"
11839 "}\n";
11840 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11841 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11842 VkPipelineObj pipe(m_device);
11843 pipe.AddShader(&vs);
11844 pipe.AddShader(&fs);
11845 pipe.AddColorAttachment();
11846 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11847
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011849
Tony Barbour552f6c02016-12-21 14:34:07 -070011850 m_commandBuffer->BeginCommandBuffer();
11851 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011852 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011853 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11854 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11855 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011856 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011857 m_commandBuffer->EndRenderPass();
11858 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060011859 // Submit cmd buffer then destroy sampler
11860 VkSubmitInfo submit_info = {};
11861 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11862 submit_info.commandBufferCount = 1;
11863 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11864 // Submit cmd buffer and then destroy sampler while in-flight
11865 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11866
11867 vkDestroySampler(m_device->device(), sampler, nullptr);
11868 m_errorMonitor->VerifyFound();
11869 vkQueueWaitIdle(m_device->m_queue);
11870 // Now we can actually destroy sampler
11871 vkDestroySampler(m_device->device(), sampler, nullptr);
11872 vkDestroyImageView(m_device->device(), view, NULL);
11873 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11874 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11875 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11876}
11877
Mark Mueller1cd9f412016-08-25 13:23:52 -060011878TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011879 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011880 "signaled but not waited on by the queue. Wait on a "
11881 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011882
11883 ASSERT_NO_FATAL_FAILURE(InitState());
11884 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11885
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011886 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11887 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11888 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011889
Tony Barbour552f6c02016-12-21 14:34:07 -070011890 m_commandBuffer->BeginCommandBuffer();
11891 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060011892
11893 VkSemaphoreCreateInfo semaphore_create_info = {};
11894 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11895 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011896 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011897 VkSubmitInfo submit_info = {};
11898 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11899 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011900 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011901 submit_info.signalSemaphoreCount = 1;
11902 submit_info.pSignalSemaphores = &semaphore;
11903 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11904 m_errorMonitor->SetDesiredFailureMsg(0, "");
11905 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011906 m_commandBuffer->BeginCommandBuffer();
11907 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011909 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11910 m_errorMonitor->VerifyFound();
11911
Mark Mueller1cd9f412016-08-25 13:23:52 -060011912 VkFenceCreateInfo fence_create_info = {};
11913 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11914 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011915 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011918 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11919 m_errorMonitor->VerifyFound();
11920
Mark Mueller4042b652016-09-05 22:52:21 -060011921 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011922 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011923 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11924}
11925
Tobin Ehlis4af23302016-07-19 10:50:30 -060011926TEST_F(VkLayerTest, FramebufferIncompatible) {
11927 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11928 "that does not match the framebuffer for the active "
11929 "renderpass.");
11930 ASSERT_NO_FATAL_FAILURE(InitState());
11931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11932
11933 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011934 VkAttachmentDescription attachment = {0,
11935 VK_FORMAT_B8G8R8A8_UNORM,
11936 VK_SAMPLE_COUNT_1_BIT,
11937 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11938 VK_ATTACHMENT_STORE_OP_STORE,
11939 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11940 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11941 VK_IMAGE_LAYOUT_UNDEFINED,
11942 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011944 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011946 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011947
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011948 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011949
11950 VkRenderPass rp;
11951 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11952 ASSERT_VK_SUCCESS(err);
11953
11954 // A compatible framebuffer.
11955 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011956 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 -060011957 ASSERT_TRUE(image.initialized());
11958
11959 VkImageViewCreateInfo ivci = {
11960 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11961 nullptr,
11962 0,
11963 image.handle(),
11964 VK_IMAGE_VIEW_TYPE_2D,
11965 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011966 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11967 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011968 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11969 };
11970 VkImageView view;
11971 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11972 ASSERT_VK_SUCCESS(err);
11973
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011974 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011975 VkFramebuffer fb;
11976 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11977 ASSERT_VK_SUCCESS(err);
11978
11979 VkCommandBufferAllocateInfo cbai = {};
11980 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11981 cbai.commandPool = m_commandPool;
11982 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11983 cbai.commandBufferCount = 1;
11984
11985 VkCommandBuffer sec_cb;
11986 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11987 ASSERT_VK_SUCCESS(err);
11988 VkCommandBufferBeginInfo cbbi = {};
11989 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130011990 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060011991 cbii.renderPass = renderPass();
11992 cbii.framebuffer = fb;
11993 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11994 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011995 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 -060011996 cbbi.pInheritanceInfo = &cbii;
11997 vkBeginCommandBuffer(sec_cb, &cbbi);
11998 vkEndCommandBuffer(sec_cb);
11999
Chris Forbes3400bc52016-09-13 18:10:34 +120012000 VkCommandBufferBeginInfo cbbi2 = {
12001 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12002 0, nullptr
12003 };
12004 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12005 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012008 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012009 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12010 m_errorMonitor->VerifyFound();
12011 // Cleanup
12012 vkDestroyImageView(m_device->device(), view, NULL);
12013 vkDestroyRenderPass(m_device->device(), rp, NULL);
12014 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12015}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012016
12017TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
12018 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
12019 "invalid value. If logicOp is not available, attempt to "
12020 "use it and verify that we see the correct error.");
12021 ASSERT_NO_FATAL_FAILURE(InitState());
12022 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12023
12024 auto features = m_device->phy().features();
12025 // Set the expected error depending on whether or not logicOp available
12026 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
12028 "enabled, logicOpEnable must be "
12029 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012030 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012032 }
12033 // Create a pipeline using logicOp
12034 VkResult err;
12035
12036 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12037 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12038
12039 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012040 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012041 ASSERT_VK_SUCCESS(err);
12042
12043 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12044 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12045 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012046 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012047 vp_state_ci.pViewports = &vp;
12048 vp_state_ci.scissorCount = 1;
12049 VkRect2D scissors = {}; // Dummy scissors to point to
12050 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012051
12052 VkPipelineShaderStageCreateInfo shaderStages[2];
12053 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12054
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012055 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12056 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012057 shaderStages[0] = vs.GetStageCreateInfo();
12058 shaderStages[1] = fs.GetStageCreateInfo();
12059
12060 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12061 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12062
12063 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12064 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12065 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12066
12067 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12068 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012069 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012070
12071 VkPipelineColorBlendAttachmentState att = {};
12072 att.blendEnable = VK_FALSE;
12073 att.colorWriteMask = 0xf;
12074
12075 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12076 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12077 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12078 cb_ci.logicOpEnable = VK_TRUE;
12079 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
12080 cb_ci.attachmentCount = 1;
12081 cb_ci.pAttachments = &att;
12082
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012083 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12084 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12085 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12086
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012087 VkGraphicsPipelineCreateInfo gp_ci = {};
12088 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12089 gp_ci.stageCount = 2;
12090 gp_ci.pStages = shaderStages;
12091 gp_ci.pVertexInputState = &vi_ci;
12092 gp_ci.pInputAssemblyState = &ia_ci;
12093 gp_ci.pViewportState = &vp_state_ci;
12094 gp_ci.pRasterizationState = &rs_ci;
12095 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012096 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012097 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12098 gp_ci.layout = pipeline_layout;
12099 gp_ci.renderPass = renderPass();
12100
12101 VkPipelineCacheCreateInfo pc_ci = {};
12102 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12103
12104 VkPipeline pipeline;
12105 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012106 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012107 ASSERT_VK_SUCCESS(err);
12108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012109 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012110 m_errorMonitor->VerifyFound();
12111 if (VK_SUCCESS == err) {
12112 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12113 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012114 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12115 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12116}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012117#endif // DRAW_STATE_TESTS
12118
Tobin Ehlis0788f522015-05-26 16:11:58 -060012119#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012120#if GTEST_IS_THREADSAFE
12121struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012122 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012123 VkEvent event;
12124 bool bailout;
12125};
12126
Karl Schultz6addd812016-02-02 17:17:23 -070012127extern "C" void *AddToCommandBuffer(void *arg) {
12128 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012129
Mike Stroyana6d14942016-07-13 15:10:05 -060012130 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012131 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012132 if (data->bailout) {
12133 break;
12134 }
12135 }
12136 return NULL;
12137}
12138
Karl Schultz6addd812016-02-02 17:17:23 -070012139TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012140 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012141
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012143
Mike Stroyanaccf7692015-05-12 16:00:45 -060012144 ASSERT_NO_FATAL_FAILURE(InitState());
12145 ASSERT_NO_FATAL_FAILURE(InitViewport());
12146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12147
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012148 // Calls AllocateCommandBuffers
12149 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012150
12151 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012152 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012153
12154 VkEventCreateInfo event_info;
12155 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012156 VkResult err;
12157
12158 memset(&event_info, 0, sizeof(event_info));
12159 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12160
Chia-I Wuf7458c52015-10-26 21:10:41 +080012161 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012162 ASSERT_VK_SUCCESS(err);
12163
Mike Stroyanaccf7692015-05-12 16:00:45 -060012164 err = vkResetEvent(device(), event);
12165 ASSERT_VK_SUCCESS(err);
12166
12167 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012168 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012169 data.event = event;
12170 data.bailout = false;
12171 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012172
12173 // First do some correct operations using multiple threads.
12174 // Add many entries to command buffer from another thread.
12175 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12176 // Make non-conflicting calls from this thread at the same time.
12177 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012178 uint32_t count;
12179 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012180 }
12181 test_platform_thread_join(thread, NULL);
12182
12183 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012184 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012185 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012186 // Add many entries to command buffer from this thread at the same time.
12187 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012188
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012189 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012190 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012191
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012192 m_errorMonitor->SetBailout(NULL);
12193
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012194 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012195
Chia-I Wuf7458c52015-10-26 21:10:41 +080012196 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012197}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012198#endif // GTEST_IS_THREADSAFE
12199#endif // THREADING_TESTS
12200
Chris Forbes9f7ff632015-05-25 11:13:08 +120012201#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012202TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012203 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12204 "with an impossible code size");
12205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012207
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012208 ASSERT_NO_FATAL_FAILURE(InitState());
12209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12210
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012211 VkShaderModule module;
12212 VkShaderModuleCreateInfo moduleCreateInfo;
12213 struct icd_spv_header spv;
12214
12215 spv.magic = ICD_SPV_MAGIC;
12216 spv.version = ICD_SPV_VERSION;
12217 spv.gen_magic = 0;
12218
12219 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12220 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012221 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012222 moduleCreateInfo.codeSize = 4;
12223 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012224 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012225
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012226 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012227}
12228
Karl Schultz6addd812016-02-02 17:17:23 -070012229TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012230 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12231 "with a bad magic number");
12232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012234
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012235 ASSERT_NO_FATAL_FAILURE(InitState());
12236 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12237
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012238 VkShaderModule module;
12239 VkShaderModuleCreateInfo moduleCreateInfo;
12240 struct icd_spv_header spv;
12241
12242 spv.magic = ~ICD_SPV_MAGIC;
12243 spv.version = ICD_SPV_VERSION;
12244 spv.gen_magic = 0;
12245
12246 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12247 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012248 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012249 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12250 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012251 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012252
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012253 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012254}
12255
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012256#if 0
12257// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012258TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012260 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012261
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012262 ASSERT_NO_FATAL_FAILURE(InitState());
12263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12264
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012265 VkShaderModule module;
12266 VkShaderModuleCreateInfo moduleCreateInfo;
12267 struct icd_spv_header spv;
12268
12269 spv.magic = ICD_SPV_MAGIC;
12270 spv.version = ~ICD_SPV_VERSION;
12271 spv.gen_magic = 0;
12272
12273 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12274 moduleCreateInfo.pNext = NULL;
12275
Karl Schultz6addd812016-02-02 17:17:23 -070012276 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012277 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12278 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012279 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012280
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012281 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012282}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012283#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012284
Karl Schultz6addd812016-02-02 17:17:23 -070012285TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012286 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12287 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012289
Chris Forbes9f7ff632015-05-25 11:13:08 +120012290 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012293 char const *vsSource = "#version 450\n"
12294 "\n"
12295 "layout(location=0) out float x;\n"
12296 "out gl_PerVertex {\n"
12297 " vec4 gl_Position;\n"
12298 "};\n"
12299 "void main(){\n"
12300 " gl_Position = vec4(1);\n"
12301 " x = 0;\n"
12302 "}\n";
12303 char const *fsSource = "#version 450\n"
12304 "\n"
12305 "layout(location=0) out vec4 color;\n"
12306 "void main(){\n"
12307 " color = vec4(1);\n"
12308 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012309
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012310 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12311 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012312
12313 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012314 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012315 pipe.AddShader(&vs);
12316 pipe.AddShader(&fs);
12317
Chris Forbes9f7ff632015-05-25 11:13:08 +120012318 VkDescriptorSetObj descriptorSet(m_device);
12319 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012320 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012321
Tony Barbour5781e8f2015-08-04 16:23:11 -060012322 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012323
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012324 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012325}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012326
Mark Mueller098c9cb2016-09-08 09:01:57 -060012327TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12328 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12329
12330 ASSERT_NO_FATAL_FAILURE(InitState());
12331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12332
12333 const char *bad_specialization_message =
12334 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12335
12336 char const *vsSource =
12337 "#version 450\n"
12338 "\n"
12339 "out gl_PerVertex {\n"
12340 " vec4 gl_Position;\n"
12341 "};\n"
12342 "void main(){\n"
12343 " gl_Position = vec4(1);\n"
12344 "}\n";
12345
12346 char const *fsSource =
12347 "#version 450\n"
12348 "\n"
12349 "layout (constant_id = 0) const float r = 0.0f;\n"
12350 "layout(location = 0) out vec4 uFragColor;\n"
12351 "void main(){\n"
12352 " uFragColor = vec4(r,1,0,1);\n"
12353 "}\n";
12354
12355 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12356 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12357
12358 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12359 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12360
12361 VkPipelineLayout pipeline_layout;
12362 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12363
12364 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12365 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12366 vp_state_create_info.viewportCount = 1;
12367 VkViewport viewport = {};
12368 vp_state_create_info.pViewports = &viewport;
12369 vp_state_create_info.scissorCount = 1;
12370 VkRect2D scissors = {};
12371 vp_state_create_info.pScissors = &scissors;
12372
12373 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12374
12375 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12376 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12377 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12378 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12379
12380 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12381 vs.GetStageCreateInfo(),
12382 fs.GetStageCreateInfo()
12383 };
12384
12385 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12386 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12387
12388 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12389 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12390 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12391
12392 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12393 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12394 rasterization_state_create_info.pNext = nullptr;
12395 rasterization_state_create_info.lineWidth = 1.0f;
12396 rasterization_state_create_info.rasterizerDiscardEnable = true;
12397
12398 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12399 color_blend_attachment_state.blendEnable = VK_FALSE;
12400 color_blend_attachment_state.colorWriteMask = 0xf;
12401
12402 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12403 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12404 color_blend_state_create_info.attachmentCount = 1;
12405 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12406
12407 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12408 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12409 graphicspipe_create_info.stageCount = 2;
12410 graphicspipe_create_info.pStages = shader_stage_create_info;
12411 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12412 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12413 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12414 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12415 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12416 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12417 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12418 graphicspipe_create_info.layout = pipeline_layout;
12419 graphicspipe_create_info.renderPass = renderPass();
12420
12421 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12422 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12423
12424 VkPipelineCache pipelineCache;
12425 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12426
12427 // This structure maps constant ids to data locations.
12428 const VkSpecializationMapEntry entry =
12429 // id, offset, size
12430 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12431
12432 uint32_t data = 1;
12433
12434 // Set up the info describing spec map and data
12435 const VkSpecializationInfo specialization_info = {
12436 1,
12437 &entry,
12438 1 * sizeof(float),
12439 &data,
12440 };
12441 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12442
12443 VkPipeline pipeline;
12444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12445 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12446 m_errorMonitor->VerifyFound();
12447
12448 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12449 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12450}
12451
12452TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12453 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12454
12455 ASSERT_NO_FATAL_FAILURE(InitState());
12456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12457
12458 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12459
12460 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12461 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12462 descriptor_pool_type_count[0].descriptorCount = 1;
12463 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12464 descriptor_pool_type_count[1].descriptorCount = 1;
12465
12466 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12467 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12468 descriptor_pool_create_info.maxSets = 1;
12469 descriptor_pool_create_info.poolSizeCount = 2;
12470 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12471 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12472
12473 VkDescriptorPool descriptorset_pool;
12474 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12475
12476 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12477 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12478 descriptorset_layout_binding.descriptorCount = 1;
12479 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12480
12481 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12482 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12483 descriptorset_layout_create_info.bindingCount = 1;
12484 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12485
12486 VkDescriptorSetLayout descriptorset_layout;
12487 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12488
12489 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12490 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12491 descriptorset_allocate_info.descriptorSetCount = 1;
12492 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12493 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12494 VkDescriptorSet descriptorset;
12495 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12496
12497 // Challenge core_validation with a non uniform buffer type.
12498 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12499
Mark Mueller098c9cb2016-09-08 09:01:57 -060012500 char const *vsSource =
12501 "#version 450\n"
12502 "\n"
12503 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12504 " mat4 mvp;\n"
12505 "} ubuf;\n"
12506 "out gl_PerVertex {\n"
12507 " vec4 gl_Position;\n"
12508 "};\n"
12509 "void main(){\n"
12510 " gl_Position = ubuf.mvp * vec4(1);\n"
12511 "}\n";
12512
12513 char const *fsSource =
12514 "#version 450\n"
12515 "\n"
12516 "layout(location = 0) out vec4 uFragColor;\n"
12517 "void main(){\n"
12518 " uFragColor = vec4(0,1,0,1);\n"
12519 "}\n";
12520
12521 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12522 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12523
12524 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12525 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12526 pipeline_layout_create_info.setLayoutCount = 1;
12527 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12528
12529 VkPipelineLayout pipeline_layout;
12530 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12531
12532 VkPipelineObj pipe(m_device);
12533 pipe.AddColorAttachment();
12534 pipe.AddShader(&vs);
12535 pipe.AddShader(&fs);
12536
12537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12538 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12539 m_errorMonitor->VerifyFound();
12540
12541 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12542 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12543 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12544}
12545
12546TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12547 TEST_DESCRIPTION(
12548 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12549
12550 ASSERT_NO_FATAL_FAILURE(InitState());
12551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12552
12553 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12554
12555 VkDescriptorPoolSize descriptor_pool_type_count = {};
12556 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12557 descriptor_pool_type_count.descriptorCount = 1;
12558
12559 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12560 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12561 descriptor_pool_create_info.maxSets = 1;
12562 descriptor_pool_create_info.poolSizeCount = 1;
12563 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12564 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12565
12566 VkDescriptorPool descriptorset_pool;
12567 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12568
12569 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12570 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12571 descriptorset_layout_binding.descriptorCount = 1;
12572 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12573 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12574
12575 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12576 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12577 descriptorset_layout_create_info.bindingCount = 1;
12578 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12579
12580 VkDescriptorSetLayout descriptorset_layout;
12581 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12582 nullptr, &descriptorset_layout));
12583
12584 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12585 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12586 descriptorset_allocate_info.descriptorSetCount = 1;
12587 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12588 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12589 VkDescriptorSet descriptorset;
12590 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12591
12592 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12593
Mark Mueller098c9cb2016-09-08 09:01:57 -060012594 char const *vsSource =
12595 "#version 450\n"
12596 "\n"
12597 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12598 " mat4 mvp;\n"
12599 "} ubuf;\n"
12600 "out gl_PerVertex {\n"
12601 " vec4 gl_Position;\n"
12602 "};\n"
12603 "void main(){\n"
12604 " gl_Position = ubuf.mvp * vec4(1);\n"
12605 "}\n";
12606
12607 char const *fsSource =
12608 "#version 450\n"
12609 "\n"
12610 "layout(location = 0) out vec4 uFragColor;\n"
12611 "void main(){\n"
12612 " uFragColor = vec4(0,1,0,1);\n"
12613 "}\n";
12614
12615 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12616 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12617
12618 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12619 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12620 pipeline_layout_create_info.setLayoutCount = 1;
12621 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12622
12623 VkPipelineLayout pipeline_layout;
12624 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12625
12626 VkPipelineObj pipe(m_device);
12627 pipe.AddColorAttachment();
12628 pipe.AddShader(&vs);
12629 pipe.AddShader(&fs);
12630
12631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12632 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12633 m_errorMonitor->VerifyFound();
12634
12635 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12636 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12637 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12638}
12639
12640TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12641 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12642 "accessible from the current shader stage.");
12643
12644 ASSERT_NO_FATAL_FAILURE(InitState());
12645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12646
12647 const char *push_constant_not_accessible_message =
12648 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12649
12650 char const *vsSource =
12651 "#version 450\n"
12652 "\n"
12653 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12654 "out gl_PerVertex {\n"
12655 " vec4 gl_Position;\n"
12656 "};\n"
12657 "void main(){\n"
12658 " gl_Position = vec4(consts.x);\n"
12659 "}\n";
12660
12661 char const *fsSource =
12662 "#version 450\n"
12663 "\n"
12664 "layout(location = 0) out vec4 uFragColor;\n"
12665 "void main(){\n"
12666 " uFragColor = vec4(0,1,0,1);\n"
12667 "}\n";
12668
12669 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12670 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12671
12672 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12673 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12674
12675 // Set up a push constant range
12676 VkPushConstantRange push_constant_ranges = {};
12677 // Set to the wrong stage to challenge core_validation
12678 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12679 push_constant_ranges.size = 4;
12680
12681 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12682 pipeline_layout_create_info.pushConstantRangeCount = 1;
12683
12684 VkPipelineLayout pipeline_layout;
12685 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12686
12687 VkPipelineObj pipe(m_device);
12688 pipe.AddColorAttachment();
12689 pipe.AddShader(&vs);
12690 pipe.AddShader(&fs);
12691
12692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12693 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12694 m_errorMonitor->VerifyFound();
12695
12696 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12697}
12698
12699TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12700 TEST_DESCRIPTION(
12701 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12702
12703 ASSERT_NO_FATAL_FAILURE(InitState());
12704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12705
12706 const char *feature_not_enabled_message =
12707 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12708
12709 // Some awkward steps are required to test with custom device features.
12710 std::vector<const char *> device_extension_names;
12711 auto features = m_device->phy().features();
12712 // Disable support for 64 bit floats
12713 features.shaderFloat64 = false;
12714 // The sacrificial device object
12715 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12716
12717 char const *vsSource = "#version 450\n"
12718 "\n"
12719 "out gl_PerVertex {\n"
12720 " vec4 gl_Position;\n"
12721 "};\n"
12722 "void main(){\n"
12723 " gl_Position = vec4(1);\n"
12724 "}\n";
12725 char const *fsSource = "#version 450\n"
12726 "\n"
12727 "layout(location=0) out vec4 color;\n"
12728 "void main(){\n"
12729 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12730 " color = vec4(green);\n"
12731 "}\n";
12732
12733 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12734 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12735
12736 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012737
12738 VkPipelineObj pipe(&test_device);
12739 pipe.AddColorAttachment();
12740 pipe.AddShader(&vs);
12741 pipe.AddShader(&fs);
12742
12743 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12744 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12745 VkPipelineLayout pipeline_layout;
12746 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12747
12748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12749 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12750 m_errorMonitor->VerifyFound();
12751
12752 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12753}
12754
12755TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12756 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12757
12758 ASSERT_NO_FATAL_FAILURE(InitState());
12759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12760
12761 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12762
12763 char const *vsSource = "#version 450\n"
12764 "\n"
12765 "out gl_PerVertex {\n"
12766 " vec4 gl_Position;\n"
12767 "};\n"
12768 "layout(xfb_buffer = 1) out;"
12769 "void main(){\n"
12770 " gl_Position = vec4(1);\n"
12771 "}\n";
12772 char const *fsSource = "#version 450\n"
12773 "\n"
12774 "layout(location=0) out vec4 color;\n"
12775 "void main(){\n"
12776 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12777 " color = vec4(green);\n"
12778 "}\n";
12779
12780 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12781 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12782
12783 VkPipelineObj pipe(m_device);
12784 pipe.AddColorAttachment();
12785 pipe.AddShader(&vs);
12786 pipe.AddShader(&fs);
12787
12788 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12789 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12790 VkPipelineLayout pipeline_layout;
12791 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12792
12793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12794 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12795 m_errorMonitor->VerifyFound();
12796
12797 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12798}
12799
Karl Schultz6addd812016-02-02 17:17:23 -070012800TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012801 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12802 "which is not present in the outputs of the previous stage");
12803
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012805
Chris Forbes59cb88d2015-05-25 11:13:13 +120012806 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012809 char const *vsSource = "#version 450\n"
12810 "\n"
12811 "out gl_PerVertex {\n"
12812 " vec4 gl_Position;\n"
12813 "};\n"
12814 "void main(){\n"
12815 " gl_Position = vec4(1);\n"
12816 "}\n";
12817 char const *fsSource = "#version 450\n"
12818 "\n"
12819 "layout(location=0) in float x;\n"
12820 "layout(location=0) out vec4 color;\n"
12821 "void main(){\n"
12822 " color = vec4(x);\n"
12823 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012824
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012825 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12826 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012827
12828 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012829 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012830 pipe.AddShader(&vs);
12831 pipe.AddShader(&fs);
12832
Chris Forbes59cb88d2015-05-25 11:13:13 +120012833 VkDescriptorSetObj descriptorSet(m_device);
12834 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012835 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012836
Tony Barbour5781e8f2015-08-04 16:23:11 -060012837 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012838
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012839 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012840}
12841
Karl Schultz6addd812016-02-02 17:17:23 -070012842TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012843 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12844 "within an interace block, which is not present in the outputs "
12845 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012847
12848 ASSERT_NO_FATAL_FAILURE(InitState());
12849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12850
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012851 char const *vsSource = "#version 450\n"
12852 "\n"
12853 "out gl_PerVertex {\n"
12854 " vec4 gl_Position;\n"
12855 "};\n"
12856 "void main(){\n"
12857 " gl_Position = vec4(1);\n"
12858 "}\n";
12859 char const *fsSource = "#version 450\n"
12860 "\n"
12861 "in block { layout(location=0) float x; } ins;\n"
12862 "layout(location=0) out vec4 color;\n"
12863 "void main(){\n"
12864 " color = vec4(ins.x);\n"
12865 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012866
12867 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12868 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12869
12870 VkPipelineObj pipe(m_device);
12871 pipe.AddColorAttachment();
12872 pipe.AddShader(&vs);
12873 pipe.AddShader(&fs);
12874
12875 VkDescriptorSetObj descriptorSet(m_device);
12876 descriptorSet.AppendDummy();
12877 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12878
12879 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12880
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012881 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012882}
12883
Karl Schultz6addd812016-02-02 17:17:23 -070012884TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012885 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012886 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12888 "output arr[2] of float32' vs 'ptr to "
12889 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012890
12891 ASSERT_NO_FATAL_FAILURE(InitState());
12892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012894 char const *vsSource = "#version 450\n"
12895 "\n"
12896 "layout(location=0) out float x[2];\n"
12897 "out gl_PerVertex {\n"
12898 " vec4 gl_Position;\n"
12899 "};\n"
12900 "void main(){\n"
12901 " x[0] = 0; x[1] = 0;\n"
12902 " gl_Position = vec4(1);\n"
12903 "}\n";
12904 char const *fsSource = "#version 450\n"
12905 "\n"
12906 "layout(location=0) in float x[3];\n"
12907 "layout(location=0) out vec4 color;\n"
12908 "void main(){\n"
12909 " color = vec4(x[0] + x[1] + x[2]);\n"
12910 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012911
12912 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12913 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12914
12915 VkPipelineObj pipe(m_device);
12916 pipe.AddColorAttachment();
12917 pipe.AddShader(&vs);
12918 pipe.AddShader(&fs);
12919
12920 VkDescriptorSetObj descriptorSet(m_device);
12921 descriptorSet.AppendDummy();
12922 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12923
12924 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12925
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012926 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012927}
12928
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012929
Karl Schultz6addd812016-02-02 17:17:23 -070012930TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012931 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012932 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012934
Chris Forbesb56af562015-05-25 11:13:17 +120012935 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012937
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012938 char const *vsSource = "#version 450\n"
12939 "\n"
12940 "layout(location=0) out int x;\n"
12941 "out gl_PerVertex {\n"
12942 " vec4 gl_Position;\n"
12943 "};\n"
12944 "void main(){\n"
12945 " x = 0;\n"
12946 " gl_Position = vec4(1);\n"
12947 "}\n";
12948 char const *fsSource = "#version 450\n"
12949 "\n"
12950 "layout(location=0) in float x;\n" /* VS writes int */
12951 "layout(location=0) out vec4 color;\n"
12952 "void main(){\n"
12953 " color = vec4(x);\n"
12954 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012955
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012956 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12957 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012958
12959 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012960 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012961 pipe.AddShader(&vs);
12962 pipe.AddShader(&fs);
12963
Chris Forbesb56af562015-05-25 11:13:17 +120012964 VkDescriptorSetObj descriptorSet(m_device);
12965 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012966 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012967
Tony Barbour5781e8f2015-08-04 16:23:11 -060012968 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012969
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012970 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012971}
12972
Karl Schultz6addd812016-02-02 17:17:23 -070012973TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012974 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012975 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012976 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012978
12979 ASSERT_NO_FATAL_FAILURE(InitState());
12980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012982 char const *vsSource = "#version 450\n"
12983 "\n"
12984 "out block { layout(location=0) int x; } outs;\n"
12985 "out gl_PerVertex {\n"
12986 " vec4 gl_Position;\n"
12987 "};\n"
12988 "void main(){\n"
12989 " outs.x = 0;\n"
12990 " gl_Position = vec4(1);\n"
12991 "}\n";
12992 char const *fsSource = "#version 450\n"
12993 "\n"
12994 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12995 "layout(location=0) out vec4 color;\n"
12996 "void main(){\n"
12997 " color = vec4(ins.x);\n"
12998 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012999
13000 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13001 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13002
13003 VkPipelineObj pipe(m_device);
13004 pipe.AddColorAttachment();
13005 pipe.AddShader(&vs);
13006 pipe.AddShader(&fs);
13007
13008 VkDescriptorSetObj descriptorSet(m_device);
13009 descriptorSet.AppendDummy();
13010 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13011
13012 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13013
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013014 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013015}
13016
13017TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013018 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013019 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120013020 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013021 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 +130013022
13023 ASSERT_NO_FATAL_FAILURE(InitState());
13024 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13025
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013026 char const *vsSource = "#version 450\n"
13027 "\n"
13028 "out block { layout(location=1) float x; } outs;\n"
13029 "out gl_PerVertex {\n"
13030 " vec4 gl_Position;\n"
13031 "};\n"
13032 "void main(){\n"
13033 " outs.x = 0;\n"
13034 " gl_Position = vec4(1);\n"
13035 "}\n";
13036 char const *fsSource = "#version 450\n"
13037 "\n"
13038 "in block { layout(location=0) float x; } ins;\n"
13039 "layout(location=0) out vec4 color;\n"
13040 "void main(){\n"
13041 " color = vec4(ins.x);\n"
13042 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013043
13044 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13045 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13046
13047 VkPipelineObj pipe(m_device);
13048 pipe.AddColorAttachment();
13049 pipe.AddShader(&vs);
13050 pipe.AddShader(&fs);
13051
13052 VkDescriptorSetObj descriptorSet(m_device);
13053 descriptorSet.AppendDummy();
13054 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13055
13056 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13057
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013058 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013059}
13060
13061TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013062 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013063 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120013064 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013065 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 +130013066
13067 ASSERT_NO_FATAL_FAILURE(InitState());
13068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013070 char const *vsSource = "#version 450\n"
13071 "\n"
13072 "out block { layout(location=0, component=0) float x; } outs;\n"
13073 "out gl_PerVertex {\n"
13074 " vec4 gl_Position;\n"
13075 "};\n"
13076 "void main(){\n"
13077 " outs.x = 0;\n"
13078 " gl_Position = vec4(1);\n"
13079 "}\n";
13080 char const *fsSource = "#version 450\n"
13081 "\n"
13082 "in block { layout(location=0, component=1) float x; } ins;\n"
13083 "layout(location=0) out vec4 color;\n"
13084 "void main(){\n"
13085 " color = vec4(ins.x);\n"
13086 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013087
13088 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13089 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13090
13091 VkPipelineObj pipe(m_device);
13092 pipe.AddColorAttachment();
13093 pipe.AddShader(&vs);
13094 pipe.AddShader(&fs);
13095
13096 VkDescriptorSetObj descriptorSet(m_device);
13097 descriptorSet.AppendDummy();
13098 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13099
13100 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13101
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013102 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013103}
13104
Chris Forbes1f3b0152016-11-30 12:48:40 +130013105TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13106 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13107
13108 ASSERT_NO_FATAL_FAILURE(InitState());
13109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13110
13111 char const *vsSource = "#version 450\n"
13112 "layout(location=0) out mediump float x;\n"
13113 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13114 char const *fsSource = "#version 450\n"
13115 "layout(location=0) in highp float x;\n"
13116 "layout(location=0) out vec4 color;\n"
13117 "void main() { color = vec4(x); }\n";
13118
13119 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13120 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13121
13122 VkPipelineObj pipe(m_device);
13123 pipe.AddColorAttachment();
13124 pipe.AddShader(&vs);
13125 pipe.AddShader(&fs);
13126
13127 VkDescriptorSetObj descriptorSet(m_device);
13128 descriptorSet.AppendDummy();
13129 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13130
13131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13132
13133 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13134
13135 m_errorMonitor->VerifyFound();
13136}
13137
Chris Forbes870a39e2016-11-30 12:55:56 +130013138TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13139 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13140
13141 ASSERT_NO_FATAL_FAILURE(InitState());
13142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13143
13144 char const *vsSource = "#version 450\n"
13145 "out block { layout(location=0) mediump float x; };\n"
13146 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13147 char const *fsSource = "#version 450\n"
13148 "in block { layout(location=0) highp float x; };\n"
13149 "layout(location=0) out vec4 color;\n"
13150 "void main() { color = vec4(x); }\n";
13151
13152 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13153 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13154
13155 VkPipelineObj pipe(m_device);
13156 pipe.AddColorAttachment();
13157 pipe.AddShader(&vs);
13158 pipe.AddShader(&fs);
13159
13160 VkDescriptorSetObj descriptorSet(m_device);
13161 descriptorSet.AppendDummy();
13162 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13163
13164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13165
13166 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13167
13168 m_errorMonitor->VerifyFound();
13169}
13170
Karl Schultz6addd812016-02-02 17:17:23 -070013171TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013172 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13173 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013175
Chris Forbesde136e02015-05-25 11:13:28 +120013176 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013178
13179 VkVertexInputBindingDescription input_binding;
13180 memset(&input_binding, 0, sizeof(input_binding));
13181
13182 VkVertexInputAttributeDescription input_attrib;
13183 memset(&input_attrib, 0, sizeof(input_attrib));
13184 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013186 char const *vsSource = "#version 450\n"
13187 "\n"
13188 "out gl_PerVertex {\n"
13189 " vec4 gl_Position;\n"
13190 "};\n"
13191 "void main(){\n"
13192 " gl_Position = vec4(1);\n"
13193 "}\n";
13194 char const *fsSource = "#version 450\n"
13195 "\n"
13196 "layout(location=0) out vec4 color;\n"
13197 "void main(){\n"
13198 " color = vec4(1);\n"
13199 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013200
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013201 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13202 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013203
13204 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013205 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013206 pipe.AddShader(&vs);
13207 pipe.AddShader(&fs);
13208
13209 pipe.AddVertexInputBindings(&input_binding, 1);
13210 pipe.AddVertexInputAttribs(&input_attrib, 1);
13211
Chris Forbesde136e02015-05-25 11:13:28 +120013212 VkDescriptorSetObj descriptorSet(m_device);
13213 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013214 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013215
Tony Barbour5781e8f2015-08-04 16:23:11 -060013216 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013217
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013218 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013219}
13220
Karl Schultz6addd812016-02-02 17:17:23 -070013221TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013222 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13223 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013225
13226 ASSERT_NO_FATAL_FAILURE(InitState());
13227 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13228
13229 VkVertexInputBindingDescription input_binding;
13230 memset(&input_binding, 0, sizeof(input_binding));
13231
13232 VkVertexInputAttributeDescription input_attrib;
13233 memset(&input_attrib, 0, sizeof(input_attrib));
13234 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013236 char const *vsSource = "#version 450\n"
13237 "\n"
13238 "layout(location=1) in float x;\n"
13239 "out gl_PerVertex {\n"
13240 " vec4 gl_Position;\n"
13241 "};\n"
13242 "void main(){\n"
13243 " gl_Position = vec4(x);\n"
13244 "}\n";
13245 char const *fsSource = "#version 450\n"
13246 "\n"
13247 "layout(location=0) out vec4 color;\n"
13248 "void main(){\n"
13249 " color = vec4(1);\n"
13250 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013251
13252 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13253 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13254
13255 VkPipelineObj pipe(m_device);
13256 pipe.AddColorAttachment();
13257 pipe.AddShader(&vs);
13258 pipe.AddShader(&fs);
13259
13260 pipe.AddVertexInputBindings(&input_binding, 1);
13261 pipe.AddVertexInputAttribs(&input_attrib, 1);
13262
13263 VkDescriptorSetObj descriptorSet(m_device);
13264 descriptorSet.AppendDummy();
13265 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13266
13267 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13268
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013269 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013270}
13271
Karl Schultz6addd812016-02-02 17:17:23 -070013272TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013273 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013274 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013275 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 -060013276
Chris Forbes62e8e502015-05-25 11:13:29 +120013277 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013279
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013280 char const *vsSource = "#version 450\n"
13281 "\n"
13282 "layout(location=0) in vec4 x;\n" /* not provided */
13283 "out gl_PerVertex {\n"
13284 " vec4 gl_Position;\n"
13285 "};\n"
13286 "void main(){\n"
13287 " gl_Position = x;\n"
13288 "}\n";
13289 char const *fsSource = "#version 450\n"
13290 "\n"
13291 "layout(location=0) out vec4 color;\n"
13292 "void main(){\n"
13293 " color = vec4(1);\n"
13294 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013295
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013296 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13297 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013298
13299 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013300 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013301 pipe.AddShader(&vs);
13302 pipe.AddShader(&fs);
13303
Chris Forbes62e8e502015-05-25 11:13:29 +120013304 VkDescriptorSetObj descriptorSet(m_device);
13305 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013306 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013307
Tony Barbour5781e8f2015-08-04 16:23:11 -060013308 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013309
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013310 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013311}
13312
Karl Schultz6addd812016-02-02 17:17:23 -070013313TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013314 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13315 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013316 "vertex shader input that consumes it");
13317 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 -060013318
Chris Forbesc97d98e2015-05-25 11:13:31 +120013319 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013320 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013321
13322 VkVertexInputBindingDescription input_binding;
13323 memset(&input_binding, 0, sizeof(input_binding));
13324
13325 VkVertexInputAttributeDescription input_attrib;
13326 memset(&input_attrib, 0, sizeof(input_attrib));
13327 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013329 char const *vsSource = "#version 450\n"
13330 "\n"
13331 "layout(location=0) in int x;\n" /* attrib provided float */
13332 "out gl_PerVertex {\n"
13333 " vec4 gl_Position;\n"
13334 "};\n"
13335 "void main(){\n"
13336 " gl_Position = vec4(x);\n"
13337 "}\n";
13338 char const *fsSource = "#version 450\n"
13339 "\n"
13340 "layout(location=0) out vec4 color;\n"
13341 "void main(){\n"
13342 " color = vec4(1);\n"
13343 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013344
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013345 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13346 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013347
13348 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013349 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013350 pipe.AddShader(&vs);
13351 pipe.AddShader(&fs);
13352
13353 pipe.AddVertexInputBindings(&input_binding, 1);
13354 pipe.AddVertexInputAttribs(&input_attrib, 1);
13355
Chris Forbesc97d98e2015-05-25 11:13:31 +120013356 VkDescriptorSetObj descriptorSet(m_device);
13357 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013358 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013359
Tony Barbour5781e8f2015-08-04 16:23:11 -060013360 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013361
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013362 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013363}
13364
Chris Forbesc68b43c2016-04-06 11:18:47 +120013365TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013366 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13367 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13369 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013370
13371 ASSERT_NO_FATAL_FAILURE(InitState());
13372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13373
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013374 char const *vsSource = "#version 450\n"
13375 "\n"
13376 "out gl_PerVertex {\n"
13377 " vec4 gl_Position;\n"
13378 "};\n"
13379 "void main(){\n"
13380 " gl_Position = vec4(1);\n"
13381 "}\n";
13382 char const *fsSource = "#version 450\n"
13383 "\n"
13384 "layout(location=0) out vec4 color;\n"
13385 "void main(){\n"
13386 " color = vec4(1);\n"
13387 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013388
13389 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13390 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13391
13392 VkPipelineObj pipe(m_device);
13393 pipe.AddColorAttachment();
13394 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013395 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013396 pipe.AddShader(&fs);
13397
13398 VkDescriptorSetObj descriptorSet(m_device);
13399 descriptorSet.AppendDummy();
13400 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13401
13402 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13403
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013404 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013405}
13406
Chris Forbes82ff92a2016-09-09 10:50:24 +120013407TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13409 "No entrypoint found named `foo`");
13410
13411 ASSERT_NO_FATAL_FAILURE(InitState());
13412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13413
13414 char const *vsSource = "#version 450\n"
13415 "out gl_PerVertex {\n"
13416 " vec4 gl_Position;\n"
13417 "};\n"
13418 "void main(){\n"
13419 " gl_Position = vec4(0);\n"
13420 "}\n";
13421 char const *fsSource = "#version 450\n"
13422 "\n"
13423 "layout(location=0) out vec4 color;\n"
13424 "void main(){\n"
13425 " color = vec4(1);\n"
13426 "}\n";
13427
13428 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13429 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13430
13431 VkPipelineObj pipe(m_device);
13432 pipe.AddColorAttachment();
13433 pipe.AddShader(&vs);
13434 pipe.AddShader(&fs);
13435
13436 VkDescriptorSetObj descriptorSet(m_device);
13437 descriptorSet.AppendDummy();
13438 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13439
13440 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13441
13442 m_errorMonitor->VerifyFound();
13443}
13444
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013445TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13446 m_errorMonitor->SetDesiredFailureMsg(
13447 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13448 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13449 "uses a depth/stencil attachment");
13450
13451 ASSERT_NO_FATAL_FAILURE(InitState());
13452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13453
13454 char const *vsSource = "#version 450\n"
13455 "void main(){ gl_Position = vec4(0); }\n";
13456 char const *fsSource = "#version 450\n"
13457 "\n"
13458 "layout(location=0) out vec4 color;\n"
13459 "void main(){\n"
13460 " color = vec4(1);\n"
13461 "}\n";
13462
13463 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13464 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13465
13466 VkPipelineObj pipe(m_device);
13467 pipe.AddColorAttachment();
13468 pipe.AddShader(&vs);
13469 pipe.AddShader(&fs);
13470
13471 VkDescriptorSetObj descriptorSet(m_device);
13472 descriptorSet.AppendDummy();
13473 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13474
13475 VkAttachmentDescription attachments[] = {
13476 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13477 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13478 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13479 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13480 },
13481 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13482 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13483 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13484 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13485 },
13486 };
13487 VkAttachmentReference refs[] = {
13488 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13489 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13490 };
13491 VkSubpassDescription subpass = {
13492 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13493 1, &refs[0], nullptr, &refs[1],
13494 0, nullptr
13495 };
13496 VkRenderPassCreateInfo rpci = {
13497 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13498 0, 2, attachments, 1, &subpass, 0, nullptr
13499 };
13500 VkRenderPass rp;
13501 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13502 ASSERT_VK_SUCCESS(err);
13503
13504 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13505
13506 m_errorMonitor->VerifyFound();
13507
13508 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13509}
13510
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013511TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013512 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13513 "the TCS without the patch decoration, but consumed in the TES "
13514 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13516 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013517
13518 ASSERT_NO_FATAL_FAILURE(InitState());
13519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13520
Chris Forbesc1e852d2016-04-04 19:26:42 +120013521 if (!m_device->phy().features().tessellationShader) {
13522 printf("Device does not support tessellation shaders; skipped.\n");
13523 return;
13524 }
13525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013526 char const *vsSource = "#version 450\n"
13527 "void main(){}\n";
13528 char const *tcsSource = "#version 450\n"
13529 "layout(location=0) out int x[];\n"
13530 "layout(vertices=3) out;\n"
13531 "void main(){\n"
13532 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13533 " gl_TessLevelInner[0] = 1;\n"
13534 " x[gl_InvocationID] = gl_InvocationID;\n"
13535 "}\n";
13536 char const *tesSource = "#version 450\n"
13537 "layout(triangles, equal_spacing, cw) in;\n"
13538 "layout(location=0) patch in int x;\n"
13539 "out gl_PerVertex { vec4 gl_Position; };\n"
13540 "void main(){\n"
13541 " gl_Position.xyz = gl_TessCoord;\n"
13542 " gl_Position.w = x;\n"
13543 "}\n";
13544 char const *fsSource = "#version 450\n"
13545 "layout(location=0) out vec4 color;\n"
13546 "void main(){\n"
13547 " color = vec4(1);\n"
13548 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013549
13550 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13551 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13552 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13553 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13554
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013555 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13556 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013558 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013559
13560 VkPipelineObj pipe(m_device);
13561 pipe.SetInputAssembly(&iasci);
13562 pipe.SetTessellation(&tsci);
13563 pipe.AddColorAttachment();
13564 pipe.AddShader(&vs);
13565 pipe.AddShader(&tcs);
13566 pipe.AddShader(&tes);
13567 pipe.AddShader(&fs);
13568
13569 VkDescriptorSetObj descriptorSet(m_device);
13570 descriptorSet.AppendDummy();
13571 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13572
13573 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13574
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013575 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013576}
13577
Karl Schultz6addd812016-02-02 17:17:23 -070013578TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013579 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13580 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13582 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013583
Chris Forbes280ba2c2015-06-12 11:16:41 +120013584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013586
13587 /* Two binding descriptions for binding 0 */
13588 VkVertexInputBindingDescription input_bindings[2];
13589 memset(input_bindings, 0, sizeof(input_bindings));
13590
13591 VkVertexInputAttributeDescription input_attrib;
13592 memset(&input_attrib, 0, sizeof(input_attrib));
13593 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013595 char const *vsSource = "#version 450\n"
13596 "\n"
13597 "layout(location=0) in float x;\n" /* attrib provided float */
13598 "out gl_PerVertex {\n"
13599 " vec4 gl_Position;\n"
13600 "};\n"
13601 "void main(){\n"
13602 " gl_Position = vec4(x);\n"
13603 "}\n";
13604 char const *fsSource = "#version 450\n"
13605 "\n"
13606 "layout(location=0) out vec4 color;\n"
13607 "void main(){\n"
13608 " color = vec4(1);\n"
13609 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013610
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013611 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13612 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013613
13614 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013615 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013616 pipe.AddShader(&vs);
13617 pipe.AddShader(&fs);
13618
13619 pipe.AddVertexInputBindings(input_bindings, 2);
13620 pipe.AddVertexInputAttribs(&input_attrib, 1);
13621
Chris Forbes280ba2c2015-06-12 11:16:41 +120013622 VkDescriptorSetObj descriptorSet(m_device);
13623 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013624 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013625
Tony Barbour5781e8f2015-08-04 16:23:11 -060013626 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013627
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013628 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013629}
Chris Forbes8f68b562015-05-25 11:13:32 +120013630
Karl Schultz6addd812016-02-02 17:17:23 -070013631TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013632 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013633 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013635
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013636 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013637
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013638 char const *vsSource = "#version 450\n"
13639 "\n"
13640 "out gl_PerVertex {\n"
13641 " vec4 gl_Position;\n"
13642 "};\n"
13643 "void main(){\n"
13644 " gl_Position = vec4(1);\n"
13645 "}\n";
13646 char const *fsSource = "#version 450\n"
13647 "\n"
13648 "void main(){\n"
13649 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013650
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013651 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013653
13654 VkPipelineObj pipe(m_device);
13655 pipe.AddShader(&vs);
13656 pipe.AddShader(&fs);
13657
Chia-I Wu08accc62015-07-07 11:50:03 +080013658 /* set up CB 0, not written */
13659 pipe.AddColorAttachment();
13660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013661
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013662 VkDescriptorSetObj descriptorSet(m_device);
13663 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013664 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013665
Tony Barbour5781e8f2015-08-04 16:23:11 -060013666 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013667
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013668 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013669}
13670
Karl Schultz6addd812016-02-02 17:17:23 -070013671TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013672 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013673 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013675 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013676
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013677 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013678
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013679 char const *vsSource = "#version 450\n"
13680 "\n"
13681 "out gl_PerVertex {\n"
13682 " vec4 gl_Position;\n"
13683 "};\n"
13684 "void main(){\n"
13685 " gl_Position = vec4(1);\n"
13686 "}\n";
13687 char const *fsSource = "#version 450\n"
13688 "\n"
13689 "layout(location=0) out vec4 x;\n"
13690 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13691 "void main(){\n"
13692 " x = vec4(1);\n"
13693 " y = vec4(1);\n"
13694 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013695
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013696 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13697 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013698
13699 VkPipelineObj pipe(m_device);
13700 pipe.AddShader(&vs);
13701 pipe.AddShader(&fs);
13702
Chia-I Wu08accc62015-07-07 11:50:03 +080013703 /* set up CB 0, not written */
13704 pipe.AddColorAttachment();
13705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013706 /* FS writes CB 1, but we don't configure it */
13707
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013708 VkDescriptorSetObj descriptorSet(m_device);
13709 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013710 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013711
Tony Barbour5781e8f2015-08-04 16:23:11 -060013712 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013713
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013714 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013715}
13716
Karl Schultz6addd812016-02-02 17:17:23 -070013717TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013718 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013719 "type of an fragment shader output variable, and the format of the corresponding attachment");
13720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013721
Chris Forbesa36d69e2015-05-25 11:13:44 +120013722 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013724 char const *vsSource = "#version 450\n"
13725 "\n"
13726 "out gl_PerVertex {\n"
13727 " vec4 gl_Position;\n"
13728 "};\n"
13729 "void main(){\n"
13730 " gl_Position = vec4(1);\n"
13731 "}\n";
13732 char const *fsSource = "#version 450\n"
13733 "\n"
13734 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13735 "void main(){\n"
13736 " x = ivec4(1);\n"
13737 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013738
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013739 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13740 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013741
13742 VkPipelineObj pipe(m_device);
13743 pipe.AddShader(&vs);
13744 pipe.AddShader(&fs);
13745
Chia-I Wu08accc62015-07-07 11:50:03 +080013746 /* set up CB 0; type is UNORM by default */
13747 pipe.AddColorAttachment();
13748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013749
Chris Forbesa36d69e2015-05-25 11:13:44 +120013750 VkDescriptorSetObj descriptorSet(m_device);
13751 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013752 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013753
Tony Barbour5781e8f2015-08-04 16:23:11 -060013754 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013755
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013756 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013757}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013758
Karl Schultz6addd812016-02-02 17:17:23 -070013759TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013760 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13761 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013763
Chris Forbes556c76c2015-08-14 12:04:59 +120013764 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013765
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013766 char const *vsSource = "#version 450\n"
13767 "\n"
13768 "out gl_PerVertex {\n"
13769 " vec4 gl_Position;\n"
13770 "};\n"
13771 "void main(){\n"
13772 " gl_Position = vec4(1);\n"
13773 "}\n";
13774 char const *fsSource = "#version 450\n"
13775 "\n"
13776 "layout(location=0) out vec4 x;\n"
13777 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13778 "void main(){\n"
13779 " x = vec4(bar.y);\n"
13780 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013781
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013782 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13783 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013784
Chris Forbes556c76c2015-08-14 12:04:59 +120013785 VkPipelineObj pipe(m_device);
13786 pipe.AddShader(&vs);
13787 pipe.AddShader(&fs);
13788
13789 /* set up CB 0; type is UNORM by default */
13790 pipe.AddColorAttachment();
13791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13792
13793 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013794 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013795
13796 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13797
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013798 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013799}
13800
Chris Forbes5c59e902016-02-26 16:56:09 +130013801TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013802 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13803 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013805
13806 ASSERT_NO_FATAL_FAILURE(InitState());
13807
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013808 char const *vsSource = "#version 450\n"
13809 "\n"
13810 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13811 "out gl_PerVertex {\n"
13812 " vec4 gl_Position;\n"
13813 "};\n"
13814 "void main(){\n"
13815 " gl_Position = vec4(consts.x);\n"
13816 "}\n";
13817 char const *fsSource = "#version 450\n"
13818 "\n"
13819 "layout(location=0) out vec4 x;\n"
13820 "void main(){\n"
13821 " x = vec4(1);\n"
13822 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013823
13824 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13825 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13826
13827 VkPipelineObj pipe(m_device);
13828 pipe.AddShader(&vs);
13829 pipe.AddShader(&fs);
13830
13831 /* set up CB 0; type is UNORM by default */
13832 pipe.AddColorAttachment();
13833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13834
13835 VkDescriptorSetObj descriptorSet(m_device);
13836 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13837
13838 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13839
13840 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013841 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013842}
13843
Chris Forbes3fb17902016-08-22 14:57:55 +120013844TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13845 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13846 "which is not included in the subpass description");
13847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13848 "consumes input attachment index 0 but not provided in subpass");
13849
13850 ASSERT_NO_FATAL_FAILURE(InitState());
13851
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013852 char const *vsSource = "#version 450\n"
13853 "\n"
13854 "out gl_PerVertex {\n"
13855 " vec4 gl_Position;\n"
13856 "};\n"
13857 "void main(){\n"
13858 " gl_Position = vec4(1);\n"
13859 "}\n";
13860 char const *fsSource = "#version 450\n"
13861 "\n"
13862 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13863 "layout(location=0) out vec4 color;\n"
13864 "void main() {\n"
13865 " color = subpassLoad(x);\n"
13866 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013867
13868 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13869 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13870
13871 VkPipelineObj pipe(m_device);
13872 pipe.AddShader(&vs);
13873 pipe.AddShader(&fs);
13874 pipe.AddColorAttachment();
13875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013877 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13878 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013879 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013880 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013881 ASSERT_VK_SUCCESS(err);
13882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013883 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013884 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013885 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013886 ASSERT_VK_SUCCESS(err);
13887
13888 // error here.
13889 pipe.CreateVKPipeline(pl, renderPass());
13890
13891 m_errorMonitor->VerifyFound();
13892
13893 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13894 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13895}
13896
Chris Forbes5a9a0472016-08-22 16:02:09 +120013897TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13898 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13899 "with a format having a different fundamental type");
13900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13901 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13902
13903 ASSERT_NO_FATAL_FAILURE(InitState());
13904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013905 char const *vsSource = "#version 450\n"
13906 "\n"
13907 "out gl_PerVertex {\n"
13908 " vec4 gl_Position;\n"
13909 "};\n"
13910 "void main(){\n"
13911 " gl_Position = vec4(1);\n"
13912 "}\n";
13913 char const *fsSource = "#version 450\n"
13914 "\n"
13915 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13916 "layout(location=0) out vec4 color;\n"
13917 "void main() {\n"
13918 " color = subpassLoad(x);\n"
13919 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013920
13921 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13922 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13923
13924 VkPipelineObj pipe(m_device);
13925 pipe.AddShader(&vs);
13926 pipe.AddShader(&fs);
13927 pipe.AddColorAttachment();
13928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13929
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013930 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13931 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013932 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013933 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013934 ASSERT_VK_SUCCESS(err);
13935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013936 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013937 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013938 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013939 ASSERT_VK_SUCCESS(err);
13940
13941 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013942 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13943 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13944 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13945 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13946 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 +120013947 };
13948 VkAttachmentReference color = {
13949 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13950 };
13951 VkAttachmentReference input = {
13952 1, VK_IMAGE_LAYOUT_GENERAL,
13953 };
13954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013955 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013957 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013958 VkRenderPass rp;
13959 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13960 ASSERT_VK_SUCCESS(err);
13961
13962 // error here.
13963 pipe.CreateVKPipeline(pl, rp);
13964
13965 m_errorMonitor->VerifyFound();
13966
13967 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13968 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13969 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13970}
13971
Chris Forbes541f7b02016-08-22 15:30:27 +120013972TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13973 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13974 "which is not included in the subpass description -- array case");
13975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13976 "consumes input attachment index 1 but not provided in subpass");
13977
13978 ASSERT_NO_FATAL_FAILURE(InitState());
13979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013980 char const *vsSource = "#version 450\n"
13981 "\n"
13982 "out gl_PerVertex {\n"
13983 " vec4 gl_Position;\n"
13984 "};\n"
13985 "void main(){\n"
13986 " gl_Position = vec4(1);\n"
13987 "}\n";
13988 char const *fsSource = "#version 450\n"
13989 "\n"
13990 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13991 "layout(location=0) out vec4 color;\n"
13992 "void main() {\n"
13993 " color = subpassLoad(xs[1]);\n"
13994 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013995
13996 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13997 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13998
13999 VkPipelineObj pipe(m_device);
14000 pipe.AddShader(&vs);
14001 pipe.AddShader(&fs);
14002 pipe.AddColorAttachment();
14003 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14004
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014005 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14006 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014007 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014008 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014009 ASSERT_VK_SUCCESS(err);
14010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014011 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014012 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014013 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014014 ASSERT_VK_SUCCESS(err);
14015
14016 // error here.
14017 pipe.CreateVKPipeline(pl, renderPass());
14018
14019 m_errorMonitor->VerifyFound();
14020
14021 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14022 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14023}
14024
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014025TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014026 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
14027 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014029
14030 ASSERT_NO_FATAL_FAILURE(InitState());
14031
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014032 char const *csSource = "#version 450\n"
14033 "\n"
14034 "layout(local_size_x=1) in;\n"
14035 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14036 "void main(){\n"
14037 " x = vec4(1);\n"
14038 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014039
14040 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14041
14042 VkDescriptorSetObj descriptorSet(m_device);
14043 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014045 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14046 nullptr,
14047 0,
14048 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14049 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14050 descriptorSet.GetPipelineLayout(),
14051 VK_NULL_HANDLE,
14052 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014053
14054 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014055 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014056
14057 m_errorMonitor->VerifyFound();
14058
14059 if (err == VK_SUCCESS) {
14060 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14061 }
14062}
14063
Chris Forbes22a9b092016-07-19 14:34:05 +120014064TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014065 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
14066 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14068 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014069
14070 ASSERT_NO_FATAL_FAILURE(InitState());
14071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014072 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14073 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014074 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014075 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014076 ASSERT_VK_SUCCESS(err);
14077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014078 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014079 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014080 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014081 ASSERT_VK_SUCCESS(err);
14082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014083 char const *csSource = "#version 450\n"
14084 "\n"
14085 "layout(local_size_x=1) in;\n"
14086 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14087 "void main() {\n"
14088 " x.x = 1.0f;\n"
14089 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014090 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014092 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14093 nullptr,
14094 0,
14095 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14096 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14097 pl,
14098 VK_NULL_HANDLE,
14099 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014100
14101 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014102 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014103
14104 m_errorMonitor->VerifyFound();
14105
14106 if (err == VK_SUCCESS) {
14107 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14108 }
14109
14110 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14111 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14112}
14113
Chris Forbes50020592016-07-27 13:52:41 +120014114TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14115 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14116 "does not match the dimensionality declared in the shader");
14117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014118 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 +120014119
14120 ASSERT_NO_FATAL_FAILURE(InitState());
14121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014123 char const *vsSource = "#version 450\n"
14124 "\n"
14125 "out gl_PerVertex { vec4 gl_Position; };\n"
14126 "void main() { gl_Position = vec4(0); }\n";
14127 char const *fsSource = "#version 450\n"
14128 "\n"
14129 "layout(set=0, binding=0) uniform sampler3D s;\n"
14130 "layout(location=0) out vec4 color;\n"
14131 "void main() {\n"
14132 " color = texture(s, vec3(0));\n"
14133 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014134 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14135 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14136
14137 VkPipelineObj pipe(m_device);
14138 pipe.AddShader(&vs);
14139 pipe.AddShader(&fs);
14140 pipe.AddColorAttachment();
14141
14142 VkTextureObj texture(m_device, nullptr);
14143 VkSamplerObj sampler(m_device);
14144
14145 VkDescriptorSetObj descriptorSet(m_device);
14146 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14147 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14148
14149 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14150 ASSERT_VK_SUCCESS(err);
14151
Tony Barbour552f6c02016-12-21 14:34:07 -070014152 m_commandBuffer->BeginCommandBuffer();
14153 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014154
14155 m_commandBuffer->BindPipeline(pipe);
14156 m_commandBuffer->BindDescriptorSet(descriptorSet);
14157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014158 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014159 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014160 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014161 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14162
14163 // error produced here.
14164 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14165
14166 m_errorMonitor->VerifyFound();
14167
Tony Barbour552f6c02016-12-21 14:34:07 -070014168 m_commandBuffer->EndRenderPass();
14169 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014170}
14171
Chris Forbes5533bfc2016-07-27 14:12:34 +120014172TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14173 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14174 "are consumed via singlesample images types in the shader, or vice versa.");
14175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014177
14178 ASSERT_NO_FATAL_FAILURE(InitState());
14179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014181 char const *vsSource = "#version 450\n"
14182 "\n"
14183 "out gl_PerVertex { vec4 gl_Position; };\n"
14184 "void main() { gl_Position = vec4(0); }\n";
14185 char const *fsSource = "#version 450\n"
14186 "\n"
14187 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14188 "layout(location=0) out vec4 color;\n"
14189 "void main() {\n"
14190 " color = texelFetch(s, ivec2(0), 0);\n"
14191 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014192 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14193 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14194
14195 VkPipelineObj pipe(m_device);
14196 pipe.AddShader(&vs);
14197 pipe.AddShader(&fs);
14198 pipe.AddColorAttachment();
14199
14200 VkTextureObj texture(m_device, nullptr);
14201 VkSamplerObj sampler(m_device);
14202
14203 VkDescriptorSetObj descriptorSet(m_device);
14204 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14205 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14206
14207 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14208 ASSERT_VK_SUCCESS(err);
14209
Tony Barbour552f6c02016-12-21 14:34:07 -070014210 m_commandBuffer->BeginCommandBuffer();
14211 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014212
14213 m_commandBuffer->BindPipeline(pipe);
14214 m_commandBuffer->BindDescriptorSet(descriptorSet);
14215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014216 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014217 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014218 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014219 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14220
14221 // error produced here.
14222 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14223
14224 m_errorMonitor->VerifyFound();
14225
Tony Barbour552f6c02016-12-21 14:34:07 -070014226 m_commandBuffer->EndRenderPass();
14227 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014228}
14229
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014230#endif // SHADER_CHECKER_TESTS
14231
14232#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014233TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014235
14236 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014237
14238 // Create an image
14239 VkImage image;
14240
Karl Schultz6addd812016-02-02 17:17:23 -070014241 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14242 const int32_t tex_width = 32;
14243 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014244
14245 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014246 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14247 image_create_info.pNext = NULL;
14248 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14249 image_create_info.format = tex_format;
14250 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014251 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014252 image_create_info.extent.depth = 1;
14253 image_create_info.mipLevels = 1;
14254 image_create_info.arrayLayers = 1;
14255 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14256 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14257 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14258 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014259
14260 // Introduce error by sending down a bogus width extent
14261 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014262 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014263
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014264 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014265}
14266
Mark Youngc48c4c12016-04-11 14:26:49 -060014267TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14269 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014270
14271 ASSERT_NO_FATAL_FAILURE(InitState());
14272
14273 // Create an image
14274 VkImage image;
14275
14276 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14277 const int32_t tex_width = 32;
14278 const int32_t tex_height = 32;
14279
14280 VkImageCreateInfo image_create_info = {};
14281 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14282 image_create_info.pNext = NULL;
14283 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14284 image_create_info.format = tex_format;
14285 image_create_info.extent.width = tex_width;
14286 image_create_info.extent.height = tex_height;
14287 image_create_info.extent.depth = 1;
14288 image_create_info.mipLevels = 1;
14289 image_create_info.arrayLayers = 1;
14290 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14291 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14292 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14293 image_create_info.flags = 0;
14294
14295 // Introduce error by sending down a bogus width extent
14296 image_create_info.extent.width = 0;
14297 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14298
14299 m_errorMonitor->VerifyFound();
14300}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014301#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014302
Tobin Ehliscde08892015-09-22 10:11:37 -060014303#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014304
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014305TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14306 TEST_DESCRIPTION("Create a render pass with an attachment description "
14307 "format set to VK_FORMAT_UNDEFINED");
14308
14309 ASSERT_NO_FATAL_FAILURE(InitState());
14310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14311
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014313
14314 VkAttachmentReference color_attach = {};
14315 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14316 color_attach.attachment = 0;
14317 VkSubpassDescription subpass = {};
14318 subpass.colorAttachmentCount = 1;
14319 subpass.pColorAttachments = &color_attach;
14320
14321 VkRenderPassCreateInfo rpci = {};
14322 rpci.subpassCount = 1;
14323 rpci.pSubpasses = &subpass;
14324 rpci.attachmentCount = 1;
14325 VkAttachmentDescription attach_desc = {};
14326 attach_desc.format = VK_FORMAT_UNDEFINED;
14327 rpci.pAttachments = &attach_desc;
14328 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14329 VkRenderPass rp;
14330 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14331
14332 m_errorMonitor->VerifyFound();
14333
14334 if (result == VK_SUCCESS) {
14335 vkDestroyRenderPass(m_device->device(), rp, NULL);
14336 }
14337}
14338
Karl Schultz6addd812016-02-02 17:17:23 -070014339TEST_F(VkLayerTest, InvalidImageView) {
14340 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014341
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014343
Tobin Ehliscde08892015-09-22 10:11:37 -060014344 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014345
Mike Stroyana3082432015-09-25 13:39:21 -060014346 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014347 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014348
Karl Schultz6addd812016-02-02 17:17:23 -070014349 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14350 const int32_t tex_width = 32;
14351 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014352
14353 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014354 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14355 image_create_info.pNext = NULL;
14356 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14357 image_create_info.format = tex_format;
14358 image_create_info.extent.width = tex_width;
14359 image_create_info.extent.height = tex_height;
14360 image_create_info.extent.depth = 1;
14361 image_create_info.mipLevels = 1;
14362 image_create_info.arrayLayers = 1;
14363 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14364 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14365 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14366 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014367
Chia-I Wuf7458c52015-10-26 21:10:41 +080014368 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014369 ASSERT_VK_SUCCESS(err);
14370
14371 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014372 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014373 image_view_create_info.image = image;
14374 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14375 image_view_create_info.format = tex_format;
14376 image_view_create_info.subresourceRange.layerCount = 1;
14377 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14378 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014379 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014380
14381 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014382 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014383
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014384 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014385 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014386}
Mike Stroyana3082432015-09-25 13:39:21 -060014387
Mark Youngd339ba32016-05-30 13:28:35 -060014388TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14389 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014391 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014392
14393 ASSERT_NO_FATAL_FAILURE(InitState());
14394
14395 // Create an image and try to create a view with no memory backing the image
14396 VkImage image;
14397
14398 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14399 const int32_t tex_width = 32;
14400 const int32_t tex_height = 32;
14401
14402 VkImageCreateInfo image_create_info = {};
14403 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14404 image_create_info.pNext = NULL;
14405 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14406 image_create_info.format = tex_format;
14407 image_create_info.extent.width = tex_width;
14408 image_create_info.extent.height = tex_height;
14409 image_create_info.extent.depth = 1;
14410 image_create_info.mipLevels = 1;
14411 image_create_info.arrayLayers = 1;
14412 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14413 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14414 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14415 image_create_info.flags = 0;
14416
14417 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14418 ASSERT_VK_SUCCESS(err);
14419
14420 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014421 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014422 image_view_create_info.image = image;
14423 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14424 image_view_create_info.format = tex_format;
14425 image_view_create_info.subresourceRange.layerCount = 1;
14426 image_view_create_info.subresourceRange.baseMipLevel = 0;
14427 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014428 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014429
14430 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014431 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014432
14433 m_errorMonitor->VerifyFound();
14434 vkDestroyImage(m_device->device(), image, NULL);
14435 // If last error is success, it still created the view, so delete it.
14436 if (err == VK_SUCCESS) {
14437 vkDestroyImageView(m_device->device(), view, NULL);
14438 }
Mark Youngd339ba32016-05-30 13:28:35 -060014439}
14440
Karl Schultz6addd812016-02-02 17:17:23 -070014441TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014442 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014444
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014445 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014446
Karl Schultz6addd812016-02-02 17:17:23 -070014447 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014448 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014449 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014450 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014451
14452 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014453 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014454 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014455 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14456 image_view_create_info.format = tex_format;
14457 image_view_create_info.subresourceRange.baseMipLevel = 0;
14458 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014459 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014460 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014461 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014462
14463 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014464 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014465
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014466 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014467}
14468
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014469TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014470 VkResult err;
14471 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014472
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014474
Mike Stroyana3082432015-09-25 13:39:21 -060014475 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014476
14477 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014478 VkImage srcImage;
14479 VkImage dstImage;
14480 VkDeviceMemory srcMem;
14481 VkDeviceMemory destMem;
14482 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014483
14484 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014485 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14486 image_create_info.pNext = NULL;
14487 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14488 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14489 image_create_info.extent.width = 32;
14490 image_create_info.extent.height = 32;
14491 image_create_info.extent.depth = 1;
14492 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014493 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014494 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14495 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14496 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14497 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014498
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014499 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014500 ASSERT_VK_SUCCESS(err);
14501
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014502 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014503 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014504 ASSERT_VK_SUCCESS(err);
14505
14506 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014507 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014508 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14509 memAlloc.pNext = NULL;
14510 memAlloc.allocationSize = 0;
14511 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014512
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014513 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014514 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014515 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014516 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014517 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014518 ASSERT_VK_SUCCESS(err);
14519
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014520 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014521 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014522 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014523 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014524 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014525 ASSERT_VK_SUCCESS(err);
14526
14527 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14528 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014529 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014530 ASSERT_VK_SUCCESS(err);
14531
Tony Barbour552f6c02016-12-21 14:34:07 -070014532 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014533 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014534 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014535 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014536 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014537 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014538 copyRegion.srcOffset.x = 0;
14539 copyRegion.srcOffset.y = 0;
14540 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014541 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014542 copyRegion.dstSubresource.mipLevel = 0;
14543 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014544 // Introduce failure by forcing the dst layerCount to differ from src
14545 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014546 copyRegion.dstOffset.x = 0;
14547 copyRegion.dstOffset.y = 0;
14548 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014549 copyRegion.extent.width = 1;
14550 copyRegion.extent.height = 1;
14551 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014552 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070014553 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014554
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014555 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014556
Chia-I Wuf7458c52015-10-26 21:10:41 +080014557 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014558 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014559 vkFreeMemory(m_device->device(), srcMem, NULL);
14560 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014561}
14562
Tony Barbourd6673642016-05-05 14:46:39 -060014563TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14564
14565 TEST_DESCRIPTION("Creating images with unsuported formats ");
14566
14567 ASSERT_NO_FATAL_FAILURE(InitState());
14568 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14569 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014570 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 -060014571 VK_IMAGE_TILING_OPTIMAL, 0);
14572 ASSERT_TRUE(image.initialized());
14573
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014574 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014575 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014576 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014577 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14578 image_create_info.format = VK_FORMAT_UNDEFINED;
14579 image_create_info.extent.width = 32;
14580 image_create_info.extent.height = 32;
14581 image_create_info.extent.depth = 1;
14582 image_create_info.mipLevels = 1;
14583 image_create_info.arrayLayers = 1;
14584 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14585 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14586 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14589 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014590
14591 VkImage localImage;
14592 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14593 m_errorMonitor->VerifyFound();
14594
Tony Barbourd6673642016-05-05 14:46:39 -060014595 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014596 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014597 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14598 VkFormat format = static_cast<VkFormat>(f);
14599 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014600 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014601 unsupported = format;
14602 break;
14603 }
14604 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014605
Tony Barbourd6673642016-05-05 14:46:39 -060014606 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014607 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014609
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014610 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014611 m_errorMonitor->VerifyFound();
14612 }
14613}
14614
14615TEST_F(VkLayerTest, ImageLayerViewTests) {
14616 VkResult ret;
14617 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14618
14619 ASSERT_NO_FATAL_FAILURE(InitState());
14620
14621 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014622 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 -060014623 VK_IMAGE_TILING_OPTIMAL, 0);
14624 ASSERT_TRUE(image.initialized());
14625
14626 VkImageView imgView;
14627 VkImageViewCreateInfo imgViewInfo = {};
14628 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14629 imgViewInfo.image = image.handle();
14630 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14631 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14632 imgViewInfo.subresourceRange.layerCount = 1;
14633 imgViewInfo.subresourceRange.baseMipLevel = 0;
14634 imgViewInfo.subresourceRange.levelCount = 1;
14635 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14636
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014638 // View can't have baseMipLevel >= image's mipLevels - Expect
14639 // VIEW_CREATE_ERROR
14640 imgViewInfo.subresourceRange.baseMipLevel = 1;
14641 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14642 m_errorMonitor->VerifyFound();
14643 imgViewInfo.subresourceRange.baseMipLevel = 0;
14644
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060014646 // View can't have baseArrayLayer >= image's arraySize - Expect
14647 // VIEW_CREATE_ERROR
14648 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14649 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14650 m_errorMonitor->VerifyFound();
14651 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14654 "pCreateInfo->subresourceRange."
14655 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014656 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14657 imgViewInfo.subresourceRange.levelCount = 0;
14658 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14659 m_errorMonitor->VerifyFound();
14660 imgViewInfo.subresourceRange.levelCount = 1;
14661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14663 "pCreateInfo->subresourceRange."
14664 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014665 m_errorMonitor->SetDesiredFailureMsg(
14666 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14667 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014668 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14669 imgViewInfo.subresourceRange.layerCount = 0;
14670 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14671 m_errorMonitor->VerifyFound();
14672 imgViewInfo.subresourceRange.layerCount = 1;
14673
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14676 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14677 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014678 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14679 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14680 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14681 m_errorMonitor->VerifyFound();
14682 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14683
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060014685 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14686 // VIEW_CREATE_ERROR
14687 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14688 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14689 m_errorMonitor->VerifyFound();
14690 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14691
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014693 // TODO: Update framework to easily passing mutable flag into ImageObj init
14694 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070014695 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
14696 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14697 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014698 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14699 // VIEW_CREATE_ERROR
14700 VkImageCreateInfo mutImgInfo = image.create_info();
14701 VkImage mutImage;
14702 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014703 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014704 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14705 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14706 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14707 ASSERT_VK_SUCCESS(ret);
14708 imgViewInfo.image = mutImage;
14709 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14710 m_errorMonitor->VerifyFound();
14711 imgViewInfo.image = image.handle();
14712 vkDestroyImage(m_device->handle(), mutImage, NULL);
14713}
14714
14715TEST_F(VkLayerTest, MiscImageLayerTests) {
14716
14717 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14718
14719 ASSERT_NO_FATAL_FAILURE(InitState());
14720
Rene Lindsay135204f2016-12-22 17:11:09 -070014721 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060014722 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070014723 image.init(128, 128, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14724 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060014725 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060014726 vk_testing::Buffer buffer;
14727 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070014728 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060014729 VkBufferImageCopy region = {};
14730 region.bufferRowLength = 128;
14731 region.bufferImageHeight = 128;
14732 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14733 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014734 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014735 region.imageExtent.height = 4;
14736 region.imageExtent.width = 4;
14737 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070014738
14739 VkImageObj image2(m_device);
14740 image2.init(128, 128, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14741 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
14742 ASSERT_TRUE(image2.initialized());
14743 vk_testing::Buffer buffer2;
14744 VkMemoryPropertyFlags reqs2 = 0;
14745 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
14746 VkBufferImageCopy region2 = {};
14747 region2.bufferRowLength = 128;
14748 region2.bufferImageHeight = 128;
14749 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14750 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14751 region2.imageSubresource.layerCount = 1;
14752 region2.imageExtent.height = 4;
14753 region2.imageExtent.width = 4;
14754 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014755 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014756
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014757 // Image must have offset.z of 0 and extent.depth of 1
14758 // Introduce failure by setting imageExtent.depth to 0
14759 region.imageExtent.depth = 0;
14760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14761 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14762 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14763 m_errorMonitor->VerifyFound();
14764
14765 region.imageExtent.depth = 1;
14766
14767 // Image must have offset.z of 0 and extent.depth of 1
14768 // Introduce failure by setting imageOffset.z to 4
14769 region.imageOffset.z = 4;
14770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14771 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14772 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14773 m_errorMonitor->VerifyFound();
14774
14775 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014776 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14777 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070014778 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014780 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14781 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014782 m_errorMonitor->VerifyFound();
14783
14784 // BufferOffset must be a multiple of 4
14785 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070014786 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070014788 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
14789 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014790 m_errorMonitor->VerifyFound();
14791
14792 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14793 region.bufferOffset = 0;
14794 region.imageExtent.height = 128;
14795 region.imageExtent.width = 128;
14796 // Introduce failure by setting bufferRowLength > 0 but less than width
14797 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014799 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14800 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014801 m_errorMonitor->VerifyFound();
14802
14803 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14804 region.bufferRowLength = 128;
14805 // Introduce failure by setting bufferRowHeight > 0 but less than height
14806 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014808 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14809 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014810 m_errorMonitor->VerifyFound();
14811
14812 region.bufferImageHeight = 128;
Dave Houlton34df4cb2016-12-01 16:43:06 -070014813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014814 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014815 // Expect INVALID_FILTER
14816 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014817 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
14818 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014819 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014820 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14821 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014822 VkImageBlit blitRegion = {};
14823 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14824 blitRegion.srcSubresource.baseArrayLayer = 0;
14825 blitRegion.srcSubresource.layerCount = 1;
14826 blitRegion.srcSubresource.mipLevel = 0;
14827 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14828 blitRegion.dstSubresource.baseArrayLayer = 0;
14829 blitRegion.dstSubresource.layerCount = 1;
14830 blitRegion.dstSubresource.mipLevel = 0;
14831
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014832 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014833 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014834 m_errorMonitor->VerifyFound();
14835
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014836 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14838 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14839 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014840 m_errorMonitor->VerifyFound();
14841
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014843 VkImageMemoryBarrier img_barrier;
14844 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14845 img_barrier.pNext = NULL;
14846 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14847 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14848 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14849 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14850 img_barrier.image = image.handle();
14851 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14852 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14853 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14854 img_barrier.subresourceRange.baseArrayLayer = 0;
14855 img_barrier.subresourceRange.baseMipLevel = 0;
14856 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14857 img_barrier.subresourceRange.layerCount = 0;
14858 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014859 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14860 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014861 m_errorMonitor->VerifyFound();
14862 img_barrier.subresourceRange.layerCount = 1;
14863}
14864
14865TEST_F(VkLayerTest, ImageFormatLimits) {
14866
14867 TEST_DESCRIPTION("Exceed the limits of image format ");
14868
Cody Northropc31a84f2016-08-22 10:41:47 -060014869 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014871 VkImageCreateInfo image_create_info = {};
14872 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14873 image_create_info.pNext = NULL;
14874 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14875 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14876 image_create_info.extent.width = 32;
14877 image_create_info.extent.height = 32;
14878 image_create_info.extent.depth = 1;
14879 image_create_info.mipLevels = 1;
14880 image_create_info.arrayLayers = 1;
14881 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14882 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14883 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14884 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14885 image_create_info.flags = 0;
14886
14887 VkImage nullImg;
14888 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014889 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14890 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070014891 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014892 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14893 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14894 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070014895 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014898 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14899 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14900 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14901 m_errorMonitor->VerifyFound();
14902 image_create_info.mipLevels = 1;
14903
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014905 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14906 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14907 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14908 m_errorMonitor->VerifyFound();
14909 image_create_info.arrayLayers = 1;
14910
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014912 int samples = imgFmtProps.sampleCounts >> 1;
14913 image_create_info.samples = (VkSampleCountFlagBits)samples;
14914 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14915 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14916 m_errorMonitor->VerifyFound();
14917 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14920 "VK_IMAGE_LAYOUT_UNDEFINED or "
14921 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014922 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14923 // Expect INVALID_LAYOUT
14924 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14925 m_errorMonitor->VerifyFound();
14926 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14927}
14928
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014929TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14930
14931 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014933
14934 ASSERT_NO_FATAL_FAILURE(InitState());
14935
14936 VkImageObj src_image(m_device);
14937 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14938 VkImageObj dst_image(m_device);
14939 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14940
Tony Barbour552f6c02016-12-21 14:34:07 -070014941 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014942 VkImageCopy copy_region;
14943 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14944 copy_region.srcSubresource.mipLevel = 0;
14945 copy_region.srcSubresource.baseArrayLayer = 0;
14946 copy_region.srcSubresource.layerCount = 0;
14947 copy_region.srcOffset.x = 0;
14948 copy_region.srcOffset.y = 0;
14949 copy_region.srcOffset.z = 0;
14950 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14951 copy_region.dstSubresource.mipLevel = 0;
14952 copy_region.dstSubresource.baseArrayLayer = 0;
14953 copy_region.dstSubresource.layerCount = 0;
14954 copy_region.dstOffset.x = 0;
14955 copy_region.dstOffset.y = 0;
14956 copy_region.dstOffset.z = 0;
14957 copy_region.extent.width = 64;
14958 copy_region.extent.height = 64;
14959 copy_region.extent.depth = 1;
14960 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14961 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070014962 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014963
14964 m_errorMonitor->VerifyFound();
14965}
14966
14967TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14968
14969 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014971
14972 ASSERT_NO_FATAL_FAILURE(InitState());
14973
14974 VkImageObj src_image(m_device);
14975 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14976 VkImageObj dst_image(m_device);
14977 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14978
Tony Barbour552f6c02016-12-21 14:34:07 -070014979 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014980 VkImageCopy copy_region;
14981 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14982 copy_region.srcSubresource.mipLevel = 0;
14983 copy_region.srcSubresource.baseArrayLayer = 0;
14984 copy_region.srcSubresource.layerCount = 0;
14985 copy_region.srcOffset.x = 0;
14986 copy_region.srcOffset.y = 0;
14987 copy_region.srcOffset.z = 0;
14988 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14989 copy_region.dstSubresource.mipLevel = 0;
14990 copy_region.dstSubresource.baseArrayLayer = 0;
14991 copy_region.dstSubresource.layerCount = 0;
14992 copy_region.dstOffset.x = 0;
14993 copy_region.dstOffset.y = 0;
14994 copy_region.dstOffset.z = 0;
14995 copy_region.extent.width = 64;
14996 copy_region.extent.height = 64;
14997 copy_region.extent.depth = 1;
14998 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14999 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015000 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015001
15002 m_errorMonitor->VerifyFound();
15003}
15004
Karl Schultz6addd812016-02-02 17:17:23 -070015005TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015006 VkResult err;
15007 bool pass;
15008
15009 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015011
15012 ASSERT_NO_FATAL_FAILURE(InitState());
15013
15014 // Create two images of different types and try to copy between them
15015 VkImage srcImage;
15016 VkImage dstImage;
15017 VkDeviceMemory srcMem;
15018 VkDeviceMemory destMem;
15019 VkMemoryRequirements memReqs;
15020
15021 VkImageCreateInfo image_create_info = {};
15022 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15023 image_create_info.pNext = NULL;
15024 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15025 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15026 image_create_info.extent.width = 32;
15027 image_create_info.extent.height = 32;
15028 image_create_info.extent.depth = 1;
15029 image_create_info.mipLevels = 1;
15030 image_create_info.arrayLayers = 1;
15031 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15032 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15033 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15034 image_create_info.flags = 0;
15035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015036 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015037 ASSERT_VK_SUCCESS(err);
15038
15039 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15040 // Introduce failure by creating second image with a different-sized format.
15041 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015043 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015044 ASSERT_VK_SUCCESS(err);
15045
15046 // Allocate memory
15047 VkMemoryAllocateInfo memAlloc = {};
15048 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15049 memAlloc.pNext = NULL;
15050 memAlloc.allocationSize = 0;
15051 memAlloc.memoryTypeIndex = 0;
15052
15053 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15054 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015055 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015056 ASSERT_TRUE(pass);
15057 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15058 ASSERT_VK_SUCCESS(err);
15059
15060 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15061 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015062 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015063 ASSERT_TRUE(pass);
15064 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15065 ASSERT_VK_SUCCESS(err);
15066
15067 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15068 ASSERT_VK_SUCCESS(err);
15069 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15070 ASSERT_VK_SUCCESS(err);
15071
Tony Barbour552f6c02016-12-21 14:34:07 -070015072 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015073 VkImageCopy copyRegion;
15074 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15075 copyRegion.srcSubresource.mipLevel = 0;
15076 copyRegion.srcSubresource.baseArrayLayer = 0;
15077 copyRegion.srcSubresource.layerCount = 0;
15078 copyRegion.srcOffset.x = 0;
15079 copyRegion.srcOffset.y = 0;
15080 copyRegion.srcOffset.z = 0;
15081 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15082 copyRegion.dstSubresource.mipLevel = 0;
15083 copyRegion.dstSubresource.baseArrayLayer = 0;
15084 copyRegion.dstSubresource.layerCount = 0;
15085 copyRegion.dstOffset.x = 0;
15086 copyRegion.dstOffset.y = 0;
15087 copyRegion.dstOffset.z = 0;
15088 copyRegion.extent.width = 1;
15089 copyRegion.extent.height = 1;
15090 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015091 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015092 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015093
15094 m_errorMonitor->VerifyFound();
15095
15096 vkDestroyImage(m_device->device(), srcImage, NULL);
15097 vkDestroyImage(m_device->device(), dstImage, NULL);
15098 vkFreeMemory(m_device->device(), srcMem, NULL);
15099 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015100}
15101
Karl Schultz6addd812016-02-02 17:17:23 -070015102TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15103 VkResult err;
15104 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015105
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015106 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15108 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015109
Mike Stroyana3082432015-09-25 13:39:21 -060015110 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015111
15112 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015113 VkImage srcImage;
15114 VkImage dstImage;
15115 VkDeviceMemory srcMem;
15116 VkDeviceMemory destMem;
15117 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015118
15119 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015120 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15121 image_create_info.pNext = NULL;
15122 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15123 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15124 image_create_info.extent.width = 32;
15125 image_create_info.extent.height = 32;
15126 image_create_info.extent.depth = 1;
15127 image_create_info.mipLevels = 1;
15128 image_create_info.arrayLayers = 1;
15129 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15130 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15131 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15132 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015134 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015135 ASSERT_VK_SUCCESS(err);
15136
Karl Schultzbdb75952016-04-19 11:36:49 -060015137 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15138
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015139 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015140 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015141 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015142 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015144 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015145 ASSERT_VK_SUCCESS(err);
15146
15147 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015148 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015149 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15150 memAlloc.pNext = NULL;
15151 memAlloc.allocationSize = 0;
15152 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015153
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015154 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015155 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015156 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015157 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015158 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015159 ASSERT_VK_SUCCESS(err);
15160
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015161 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015162 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015163 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015164 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015165 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015166 ASSERT_VK_SUCCESS(err);
15167
15168 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15169 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015170 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015171 ASSERT_VK_SUCCESS(err);
15172
Tony Barbour552f6c02016-12-21 14:34:07 -070015173 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015174 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015175 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015176 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015177 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015178 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015179 copyRegion.srcOffset.x = 0;
15180 copyRegion.srcOffset.y = 0;
15181 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015182 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015183 copyRegion.dstSubresource.mipLevel = 0;
15184 copyRegion.dstSubresource.baseArrayLayer = 0;
15185 copyRegion.dstSubresource.layerCount = 0;
15186 copyRegion.dstOffset.x = 0;
15187 copyRegion.dstOffset.y = 0;
15188 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015189 copyRegion.extent.width = 1;
15190 copyRegion.extent.height = 1;
15191 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015192 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015193 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015194
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015195 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015196
Chia-I Wuf7458c52015-10-26 21:10:41 +080015197 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015198 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015199 vkFreeMemory(m_device->device(), srcMem, NULL);
15200 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015201}
15202
Karl Schultz6addd812016-02-02 17:17:23 -070015203TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15204 VkResult err;
15205 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15208 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015209
Mike Stroyana3082432015-09-25 13:39:21 -060015210 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015211
15212 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015213 VkImage srcImage;
15214 VkImage dstImage;
15215 VkDeviceMemory srcMem;
15216 VkDeviceMemory destMem;
15217 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015218
15219 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015220 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15221 image_create_info.pNext = NULL;
15222 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15223 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15224 image_create_info.extent.width = 32;
15225 image_create_info.extent.height = 1;
15226 image_create_info.extent.depth = 1;
15227 image_create_info.mipLevels = 1;
15228 image_create_info.arrayLayers = 1;
15229 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15230 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15231 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15232 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015234 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015235 ASSERT_VK_SUCCESS(err);
15236
Karl Schultz6addd812016-02-02 17:17:23 -070015237 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015239 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015240 ASSERT_VK_SUCCESS(err);
15241
15242 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015243 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015244 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15245 memAlloc.pNext = NULL;
15246 memAlloc.allocationSize = 0;
15247 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015248
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015249 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015250 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015251 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015252 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015253 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015254 ASSERT_VK_SUCCESS(err);
15255
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015256 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015257 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015258 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015259 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015260 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015261 ASSERT_VK_SUCCESS(err);
15262
15263 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15264 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015265 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015266 ASSERT_VK_SUCCESS(err);
15267
Tony Barbour552f6c02016-12-21 14:34:07 -070015268 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015269 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015270 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15271 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015272 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015273 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015274 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015275 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015276 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015277 resolveRegion.srcOffset.x = 0;
15278 resolveRegion.srcOffset.y = 0;
15279 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015280 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015281 resolveRegion.dstSubresource.mipLevel = 0;
15282 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015283 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015284 resolveRegion.dstOffset.x = 0;
15285 resolveRegion.dstOffset.y = 0;
15286 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015287 resolveRegion.extent.width = 1;
15288 resolveRegion.extent.height = 1;
15289 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015290 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015291 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015292
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015293 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015294
Chia-I Wuf7458c52015-10-26 21:10:41 +080015295 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015296 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015297 vkFreeMemory(m_device->device(), srcMem, NULL);
15298 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015299}
15300
Karl Schultz6addd812016-02-02 17:17:23 -070015301TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15302 VkResult err;
15303 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15306 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015307
Mike Stroyana3082432015-09-25 13:39:21 -060015308 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015309
Chris Forbesa7530692016-05-08 12:35:39 +120015310 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015311 VkImage srcImage;
15312 VkImage dstImage;
15313 VkDeviceMemory srcMem;
15314 VkDeviceMemory destMem;
15315 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015316
15317 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015318 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15319 image_create_info.pNext = NULL;
15320 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15321 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15322 image_create_info.extent.width = 32;
15323 image_create_info.extent.height = 1;
15324 image_create_info.extent.depth = 1;
15325 image_create_info.mipLevels = 1;
15326 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015327 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15329 // Note: Some implementations expect color attachment usage for any
15330 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015331 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015332 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015334 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015335 ASSERT_VK_SUCCESS(err);
15336
Karl Schultz6addd812016-02-02 17:17:23 -070015337 // Note: Some implementations expect color attachment usage for any
15338 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015339 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015341 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015342 ASSERT_VK_SUCCESS(err);
15343
15344 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015345 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015346 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15347 memAlloc.pNext = NULL;
15348 memAlloc.allocationSize = 0;
15349 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015350
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015351 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015352 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015353 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015354 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015355 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015356 ASSERT_VK_SUCCESS(err);
15357
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015358 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015359 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015360 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015361 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015362 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015363 ASSERT_VK_SUCCESS(err);
15364
15365 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15366 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015367 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015368 ASSERT_VK_SUCCESS(err);
15369
Tony Barbour552f6c02016-12-21 14:34:07 -070015370 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015371 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015372 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15373 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015374 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015375 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015376 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015377 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015378 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015379 resolveRegion.srcOffset.x = 0;
15380 resolveRegion.srcOffset.y = 0;
15381 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015382 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015383 resolveRegion.dstSubresource.mipLevel = 0;
15384 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015385 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015386 resolveRegion.dstOffset.x = 0;
15387 resolveRegion.dstOffset.y = 0;
15388 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015389 resolveRegion.extent.width = 1;
15390 resolveRegion.extent.height = 1;
15391 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015392 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015393 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015394
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015395 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015396
Chia-I Wuf7458c52015-10-26 21:10:41 +080015397 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015398 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015399 vkFreeMemory(m_device->device(), srcMem, NULL);
15400 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015401}
15402
Karl Schultz6addd812016-02-02 17:17:23 -070015403TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15404 VkResult err;
15405 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015406
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15408 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015409
Mike Stroyana3082432015-09-25 13:39:21 -060015410 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015411
15412 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015413 VkImage srcImage;
15414 VkImage dstImage;
15415 VkDeviceMemory srcMem;
15416 VkDeviceMemory destMem;
15417 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015418
15419 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015420 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15421 image_create_info.pNext = NULL;
15422 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15423 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15424 image_create_info.extent.width = 32;
15425 image_create_info.extent.height = 1;
15426 image_create_info.extent.depth = 1;
15427 image_create_info.mipLevels = 1;
15428 image_create_info.arrayLayers = 1;
15429 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15430 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15431 // Note: Some implementations expect color attachment usage for any
15432 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015433 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015434 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015436 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015437 ASSERT_VK_SUCCESS(err);
15438
Karl Schultz6addd812016-02-02 17:17:23 -070015439 // Set format to something other than source image
15440 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15441 // Note: Some implementations expect color attachment usage for any
15442 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015443 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015444 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015446 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015447 ASSERT_VK_SUCCESS(err);
15448
15449 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015450 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015451 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15452 memAlloc.pNext = NULL;
15453 memAlloc.allocationSize = 0;
15454 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015455
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015456 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015457 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015458 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015459 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015460 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015461 ASSERT_VK_SUCCESS(err);
15462
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015463 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015464 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015465 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015466 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015467 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015468 ASSERT_VK_SUCCESS(err);
15469
15470 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15471 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015472 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015473 ASSERT_VK_SUCCESS(err);
15474
Tony Barbour552f6c02016-12-21 14:34:07 -070015475 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015476 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015477 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15478 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015479 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015480 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015481 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015482 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015483 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015484 resolveRegion.srcOffset.x = 0;
15485 resolveRegion.srcOffset.y = 0;
15486 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015487 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015488 resolveRegion.dstSubresource.mipLevel = 0;
15489 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015490 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015491 resolveRegion.dstOffset.x = 0;
15492 resolveRegion.dstOffset.y = 0;
15493 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015494 resolveRegion.extent.width = 1;
15495 resolveRegion.extent.height = 1;
15496 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015497 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015498 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015499
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015500 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015501
Chia-I Wuf7458c52015-10-26 21:10:41 +080015502 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015503 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015504 vkFreeMemory(m_device->device(), srcMem, NULL);
15505 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015506}
15507
Karl Schultz6addd812016-02-02 17:17:23 -070015508TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15509 VkResult err;
15510 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015511
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15513 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015514
Mike Stroyana3082432015-09-25 13:39:21 -060015515 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015516
15517 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015518 VkImage srcImage;
15519 VkImage dstImage;
15520 VkDeviceMemory srcMem;
15521 VkDeviceMemory destMem;
15522 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015523
15524 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015525 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15526 image_create_info.pNext = NULL;
15527 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15528 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15529 image_create_info.extent.width = 32;
15530 image_create_info.extent.height = 1;
15531 image_create_info.extent.depth = 1;
15532 image_create_info.mipLevels = 1;
15533 image_create_info.arrayLayers = 1;
15534 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15535 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15536 // Note: Some implementations expect color attachment usage for any
15537 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015538 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015539 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015541 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015542 ASSERT_VK_SUCCESS(err);
15543
Karl Schultz6addd812016-02-02 17:17:23 -070015544 image_create_info.imageType = VK_IMAGE_TYPE_1D;
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_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015548 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
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, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015551 ASSERT_VK_SUCCESS(err);
15552
15553 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015554 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015555 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15556 memAlloc.pNext = NULL;
15557 memAlloc.allocationSize = 0;
15558 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015559
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015560 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015561 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015562 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015563 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015564 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015565 ASSERT_VK_SUCCESS(err);
15566
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015567 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015568 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015569 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015570 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015571 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015572 ASSERT_VK_SUCCESS(err);
15573
15574 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15575 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015576 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015577 ASSERT_VK_SUCCESS(err);
15578
Tony Barbour552f6c02016-12-21 14:34:07 -070015579 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015580 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015581 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15582 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015583 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015584 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015585 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015586 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015587 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015588 resolveRegion.srcOffset.x = 0;
15589 resolveRegion.srcOffset.y = 0;
15590 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015591 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015592 resolveRegion.dstSubresource.mipLevel = 0;
15593 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015594 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015595 resolveRegion.dstOffset.x = 0;
15596 resolveRegion.dstOffset.y = 0;
15597 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015598 resolveRegion.extent.width = 1;
15599 resolveRegion.extent.height = 1;
15600 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015601 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015602 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015603
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015604 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015605
Chia-I Wuf7458c52015-10-26 21:10:41 +080015606 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015607 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015608 vkFreeMemory(m_device->device(), srcMem, NULL);
15609 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015610}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015611
Karl Schultz6addd812016-02-02 17:17:23 -070015612TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015613 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015614 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15615 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015616 // The image format check comes 2nd in validation so we trigger it first,
15617 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015618 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015619
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15621 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015622
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015623 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015624
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015625 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015626 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15627 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015628
15629 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015630 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15631 ds_pool_ci.pNext = NULL;
15632 ds_pool_ci.maxSets = 1;
15633 ds_pool_ci.poolSizeCount = 1;
15634 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015635
15636 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015637 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015638 ASSERT_VK_SUCCESS(err);
15639
15640 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015641 dsl_binding.binding = 0;
15642 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15643 dsl_binding.descriptorCount = 1;
15644 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15645 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015646
15647 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015648 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15649 ds_layout_ci.pNext = NULL;
15650 ds_layout_ci.bindingCount = 1;
15651 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015652 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015653 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015654 ASSERT_VK_SUCCESS(err);
15655
15656 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015657 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015658 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015659 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015660 alloc_info.descriptorPool = ds_pool;
15661 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015662 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015663 ASSERT_VK_SUCCESS(err);
15664
Karl Schultz6addd812016-02-02 17:17:23 -070015665 VkImage image_bad;
15666 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015667 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015668 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015669 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015670 const int32_t tex_width = 32;
15671 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015672
15673 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015674 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15675 image_create_info.pNext = NULL;
15676 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15677 image_create_info.format = tex_format_bad;
15678 image_create_info.extent.width = tex_width;
15679 image_create_info.extent.height = tex_height;
15680 image_create_info.extent.depth = 1;
15681 image_create_info.mipLevels = 1;
15682 image_create_info.arrayLayers = 1;
15683 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15684 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015685 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015686 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015687
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015688 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015689 ASSERT_VK_SUCCESS(err);
15690 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015691 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15692 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015693 ASSERT_VK_SUCCESS(err);
15694
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015695 // ---Bind image memory---
15696 VkMemoryRequirements img_mem_reqs;
15697 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15698 VkMemoryAllocateInfo image_alloc_info = {};
15699 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15700 image_alloc_info.pNext = NULL;
15701 image_alloc_info.memoryTypeIndex = 0;
15702 image_alloc_info.allocationSize = img_mem_reqs.size;
15703 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &image_alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15704 ASSERT_TRUE(pass);
15705 VkDeviceMemory mem;
15706 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15707 ASSERT_VK_SUCCESS(err);
15708 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15709 ASSERT_VK_SUCCESS(err);
15710 // -----------------------
15711
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015712 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015713 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015714 image_view_create_info.image = image_bad;
15715 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15716 image_view_create_info.format = tex_format_bad;
15717 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15718 image_view_create_info.subresourceRange.baseMipLevel = 0;
15719 image_view_create_info.subresourceRange.layerCount = 1;
15720 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015721 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015722
15723 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015724 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015725
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015726 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015727
Chia-I Wuf7458c52015-10-26 21:10:41 +080015728 vkDestroyImage(m_device->device(), image_bad, NULL);
15729 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015730 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15731 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015732
15733 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015734}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015735
15736TEST_F(VkLayerTest, ClearImageErrors) {
15737 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15738 "ClearDepthStencilImage with a color image.");
15739
15740 ASSERT_NO_FATAL_FAILURE(InitState());
15741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15742
Tony Barbour552f6c02016-12-21 14:34:07 -070015743 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015744
15745 // Color image
15746 VkClearColorValue clear_color;
15747 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15748 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15749 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15750 const int32_t img_width = 32;
15751 const int32_t img_height = 32;
15752 VkImageCreateInfo image_create_info = {};
15753 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15754 image_create_info.pNext = NULL;
15755 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15756 image_create_info.format = color_format;
15757 image_create_info.extent.width = img_width;
15758 image_create_info.extent.height = img_height;
15759 image_create_info.extent.depth = 1;
15760 image_create_info.mipLevels = 1;
15761 image_create_info.arrayLayers = 1;
15762 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15763 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15764 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15765
15766 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015767 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015769 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015770
15771 // Depth/Stencil image
15772 VkClearDepthStencilValue clear_value = {0};
15773 reqs = 0; // don't need HOST_VISIBLE DS image
15774 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15775 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15776 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15777 ds_image_create_info.extent.width = 64;
15778 ds_image_create_info.extent.height = 64;
15779 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015780 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 -060015781
15782 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015783 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015785 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 -060015786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015788
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015789 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015790 &color_range);
15791
15792 m_errorMonitor->VerifyFound();
15793
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15795 "image created without "
15796 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015797
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015798 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015799 &color_range);
15800
15801 m_errorMonitor->VerifyFound();
15802
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015803 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15805 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015806
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015807 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015808 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015809
15810 m_errorMonitor->VerifyFound();
15811}
Tobin Ehliscde08892015-09-22 10:11:37 -060015812#endif // IMAGE_TESTS
15813
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015814
15815// WSI Enabled Tests
15816//
Chris Forbes09368e42016-10-13 11:59:22 +130015817#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015818TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15819
15820#if defined(VK_USE_PLATFORM_XCB_KHR)
15821 VkSurfaceKHR surface = VK_NULL_HANDLE;
15822
15823 VkResult err;
15824 bool pass;
15825 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15826 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15827 // uint32_t swapchain_image_count = 0;
15828 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15829 // uint32_t image_index = 0;
15830 // VkPresentInfoKHR present_info = {};
15831
15832 ASSERT_NO_FATAL_FAILURE(InitState());
15833
15834 // Use the create function from one of the VK_KHR_*_surface extension in
15835 // order to create a surface, testing all known errors in the process,
15836 // before successfully creating a surface:
15837 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15839 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15840 pass = (err != VK_SUCCESS);
15841 ASSERT_TRUE(pass);
15842 m_errorMonitor->VerifyFound();
15843
15844 // Next, try to create a surface with the wrong
15845 // VkXcbSurfaceCreateInfoKHR::sType:
15846 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15847 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15849 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15850 pass = (err != VK_SUCCESS);
15851 ASSERT_TRUE(pass);
15852 m_errorMonitor->VerifyFound();
15853
15854 // Create a native window, and then correctly create a surface:
15855 xcb_connection_t *connection;
15856 xcb_screen_t *screen;
15857 xcb_window_t xcb_window;
15858 xcb_intern_atom_reply_t *atom_wm_delete_window;
15859
15860 const xcb_setup_t *setup;
15861 xcb_screen_iterator_t iter;
15862 int scr;
15863 uint32_t value_mask, value_list[32];
15864 int width = 1;
15865 int height = 1;
15866
15867 connection = xcb_connect(NULL, &scr);
15868 ASSERT_TRUE(connection != NULL);
15869 setup = xcb_get_setup(connection);
15870 iter = xcb_setup_roots_iterator(setup);
15871 while (scr-- > 0)
15872 xcb_screen_next(&iter);
15873 screen = iter.data;
15874
15875 xcb_window = xcb_generate_id(connection);
15876
15877 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15878 value_list[0] = screen->black_pixel;
15879 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15880
15881 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15882 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15883
15884 /* Magic code that will send notification when window is destroyed */
15885 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15886 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15887
15888 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15889 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15890 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15891 free(reply);
15892
15893 xcb_map_window(connection, xcb_window);
15894
15895 // Force the x/y coordinates to 100,100 results are identical in consecutive
15896 // runs
15897 const uint32_t coords[] = { 100, 100 };
15898 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15899
15900 // Finally, try to correctly create a surface:
15901 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15902 xcb_create_info.pNext = NULL;
15903 xcb_create_info.flags = 0;
15904 xcb_create_info.connection = connection;
15905 xcb_create_info.window = xcb_window;
15906 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15907 pass = (err == VK_SUCCESS);
15908 ASSERT_TRUE(pass);
15909
15910 // Check if surface supports presentation:
15911
15912 // 1st, do so without having queried the queue families:
15913 VkBool32 supported = false;
15914 // TODO: Get the following error to come out:
15915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15916 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15917 "function");
15918 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15919 pass = (err != VK_SUCCESS);
15920 // ASSERT_TRUE(pass);
15921 // m_errorMonitor->VerifyFound();
15922
15923 // Next, query a queue family index that's too large:
15924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15925 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15926 pass = (err != VK_SUCCESS);
15927 ASSERT_TRUE(pass);
15928 m_errorMonitor->VerifyFound();
15929
15930 // Finally, do so correctly:
15931 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15932 // SUPPORTED
15933 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15934 pass = (err == VK_SUCCESS);
15935 ASSERT_TRUE(pass);
15936
15937 // Before proceeding, try to create a swapchain without having called
15938 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15939 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15940 swapchain_create_info.pNext = NULL;
15941 swapchain_create_info.flags = 0;
15942 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15943 swapchain_create_info.surface = surface;
15944 swapchain_create_info.imageArrayLayers = 1;
15945 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15946 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15948 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15949 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15950 pass = (err != VK_SUCCESS);
15951 ASSERT_TRUE(pass);
15952 m_errorMonitor->VerifyFound();
15953
15954 // Get the surface capabilities:
15955 VkSurfaceCapabilitiesKHR surface_capabilities;
15956
15957 // Do so correctly (only error logged by this entrypoint is if the
15958 // extension isn't enabled):
15959 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15960 pass = (err == VK_SUCCESS);
15961 ASSERT_TRUE(pass);
15962
15963 // Get the surface formats:
15964 uint32_t surface_format_count;
15965
15966 // First, try without a pointer to surface_format_count:
15967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15968 "specified as NULL");
15969 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15970 pass = (err == VK_SUCCESS);
15971 ASSERT_TRUE(pass);
15972 m_errorMonitor->VerifyFound();
15973
15974 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15975 // correctly done a 1st try (to get the count):
15976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15977 surface_format_count = 0;
15978 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15979 pass = (err == VK_SUCCESS);
15980 ASSERT_TRUE(pass);
15981 m_errorMonitor->VerifyFound();
15982
15983 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15984 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15985 pass = (err == VK_SUCCESS);
15986 ASSERT_TRUE(pass);
15987
15988 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15989 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15990
15991 // Next, do a 2nd try with surface_format_count being set too high:
15992 surface_format_count += 5;
15993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15994 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15995 pass = (err == VK_SUCCESS);
15996 ASSERT_TRUE(pass);
15997 m_errorMonitor->VerifyFound();
15998
15999 // Finally, do a correct 1st and 2nd try:
16000 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16001 pass = (err == VK_SUCCESS);
16002 ASSERT_TRUE(pass);
16003 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16004 pass = (err == VK_SUCCESS);
16005 ASSERT_TRUE(pass);
16006
16007 // Get the surface present modes:
16008 uint32_t surface_present_mode_count;
16009
16010 // First, try without a pointer to surface_format_count:
16011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16012 "specified as NULL");
16013
16014 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16015 pass = (err == VK_SUCCESS);
16016 ASSERT_TRUE(pass);
16017 m_errorMonitor->VerifyFound();
16018
16019 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16020 // correctly done a 1st try (to get the count):
16021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16022 surface_present_mode_count = 0;
16023 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16024 (VkPresentModeKHR *)&surface_present_mode_count);
16025 pass = (err == VK_SUCCESS);
16026 ASSERT_TRUE(pass);
16027 m_errorMonitor->VerifyFound();
16028
16029 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16030 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16031 pass = (err == VK_SUCCESS);
16032 ASSERT_TRUE(pass);
16033
16034 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16035 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16036
16037 // Next, do a 2nd try with surface_format_count being set too high:
16038 surface_present_mode_count += 5;
16039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16040 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16041 pass = (err == VK_SUCCESS);
16042 ASSERT_TRUE(pass);
16043 m_errorMonitor->VerifyFound();
16044
16045 // Finally, do a correct 1st and 2nd try:
16046 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16047 pass = (err == VK_SUCCESS);
16048 ASSERT_TRUE(pass);
16049 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16050 pass = (err == VK_SUCCESS);
16051 ASSERT_TRUE(pass);
16052
16053 // Create a swapchain:
16054
16055 // First, try without a pointer to swapchain_create_info:
16056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16057 "specified as NULL");
16058
16059 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16060 pass = (err != VK_SUCCESS);
16061 ASSERT_TRUE(pass);
16062 m_errorMonitor->VerifyFound();
16063
16064 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16065 // sType:
16066 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16068
16069 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16070 pass = (err != VK_SUCCESS);
16071 ASSERT_TRUE(pass);
16072 m_errorMonitor->VerifyFound();
16073
16074 // Next, call with a NULL swapchain pointer:
16075 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16076 swapchain_create_info.pNext = NULL;
16077 swapchain_create_info.flags = 0;
16078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16079 "specified as NULL");
16080
16081 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16082 pass = (err != VK_SUCCESS);
16083 ASSERT_TRUE(pass);
16084 m_errorMonitor->VerifyFound();
16085
16086 // TODO: Enhance swapchain layer so that
16087 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16088
16089 // Next, call with a queue family index that's too large:
16090 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16091 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16092 swapchain_create_info.queueFamilyIndexCount = 2;
16093 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16095 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16096 pass = (err != VK_SUCCESS);
16097 ASSERT_TRUE(pass);
16098 m_errorMonitor->VerifyFound();
16099
16100 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16101 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16102 swapchain_create_info.queueFamilyIndexCount = 1;
16103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16104 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16105 "pCreateInfo->pQueueFamilyIndices).");
16106 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16107 pass = (err != VK_SUCCESS);
16108 ASSERT_TRUE(pass);
16109 m_errorMonitor->VerifyFound();
16110
16111 // Next, call with an invalid imageSharingMode:
16112 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16113 swapchain_create_info.queueFamilyIndexCount = 1;
16114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16115 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16116 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16117 pass = (err != VK_SUCCESS);
16118 ASSERT_TRUE(pass);
16119 m_errorMonitor->VerifyFound();
16120 // Fix for the future:
16121 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16122 // SUPPORTED
16123 swapchain_create_info.queueFamilyIndexCount = 0;
16124 queueFamilyIndex[0] = 0;
16125 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16126
16127 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16128 // Get the images from a swapchain:
16129 // Acquire an image from a swapchain:
16130 // Present an image to a swapchain:
16131 // Destroy the swapchain:
16132
16133 // TODOs:
16134 //
16135 // - Try destroying the device without first destroying the swapchain
16136 //
16137 // - Try destroying the device without first destroying the surface
16138 //
16139 // - Try destroying the surface without first destroying the swapchain
16140
16141 // Destroy the surface:
16142 vkDestroySurfaceKHR(instance(), surface, NULL);
16143
16144 // Tear down the window:
16145 xcb_destroy_window(connection, xcb_window);
16146 xcb_disconnect(connection);
16147
16148#else // VK_USE_PLATFORM_XCB_KHR
16149 return;
16150#endif // VK_USE_PLATFORM_XCB_KHR
16151}
Chris Forbes09368e42016-10-13 11:59:22 +130016152#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016153
16154//
16155// POSITIVE VALIDATION TESTS
16156//
16157// These tests do not expect to encounter ANY validation errors pass only if this is true
16158
Tobin Ehlise0006882016-11-03 10:14:28 -060016159TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16160 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16161 "by a transition in the primary.");
16162 VkResult err;
16163 m_errorMonitor->ExpectSuccess();
16164 ASSERT_NO_FATAL_FAILURE(InitState());
16165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16166 // Allocate a secondary and primary cmd buffer
16167 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16168 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16169 command_buffer_allocate_info.commandPool = m_commandPool;
16170 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16171 command_buffer_allocate_info.commandBufferCount = 1;
16172
16173 VkCommandBuffer secondary_command_buffer;
16174 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16175 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16176 VkCommandBuffer primary_command_buffer;
16177 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16178 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16179 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16180 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16181 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16182 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16183 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16184
16185 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16186 ASSERT_VK_SUCCESS(err);
16187 VkImageObj image(m_device);
16188 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16189 ASSERT_TRUE(image.initialized());
16190 VkImageMemoryBarrier img_barrier = {};
16191 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16192 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16193 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16194 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16195 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16196 img_barrier.image = image.handle();
16197 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16198 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16199 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16200 img_barrier.subresourceRange.baseArrayLayer = 0;
16201 img_barrier.subresourceRange.baseMipLevel = 0;
16202 img_barrier.subresourceRange.layerCount = 1;
16203 img_barrier.subresourceRange.levelCount = 1;
16204 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16205 0, nullptr, 1, &img_barrier);
16206 err = vkEndCommandBuffer(secondary_command_buffer);
16207 ASSERT_VK_SUCCESS(err);
16208
16209 // Now update primary cmd buffer to execute secondary and transitions image
16210 command_buffer_begin_info.pInheritanceInfo = nullptr;
16211 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16212 ASSERT_VK_SUCCESS(err);
16213 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16214 VkImageMemoryBarrier img_barrier2 = {};
16215 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16216 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16217 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16218 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16219 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16220 img_barrier2.image = image.handle();
16221 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16222 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16223 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16224 img_barrier2.subresourceRange.baseArrayLayer = 0;
16225 img_barrier2.subresourceRange.baseMipLevel = 0;
16226 img_barrier2.subresourceRange.layerCount = 1;
16227 img_barrier2.subresourceRange.levelCount = 1;
16228 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16229 nullptr, 1, &img_barrier2);
16230 err = vkEndCommandBuffer(primary_command_buffer);
16231 ASSERT_VK_SUCCESS(err);
16232 VkSubmitInfo submit_info = {};
16233 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16234 submit_info.commandBufferCount = 1;
16235 submit_info.pCommandBuffers = &primary_command_buffer;
16236 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16237 ASSERT_VK_SUCCESS(err);
16238 m_errorMonitor->VerifyNotFound();
16239 err = vkDeviceWaitIdle(m_device->device());
16240 ASSERT_VK_SUCCESS(err);
16241 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16242 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16243}
16244
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016245// This is a positive test. No failures are expected.
16246TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16247 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16248 "is ignoring VkWriteDescriptorSet members that are not "
16249 "related to the descriptor type specified by "
16250 "VkWriteDescriptorSet::descriptorType. Correct "
16251 "validation behavior will result in the test running to "
16252 "completion without validation errors.");
16253
16254 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16255
16256 ASSERT_NO_FATAL_FAILURE(InitState());
16257
16258 // Image Case
16259 {
16260 m_errorMonitor->ExpectSuccess();
16261
16262 VkImage image;
16263 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16264 const int32_t tex_width = 32;
16265 const int32_t tex_height = 32;
16266 VkImageCreateInfo image_create_info = {};
16267 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16268 image_create_info.pNext = NULL;
16269 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16270 image_create_info.format = tex_format;
16271 image_create_info.extent.width = tex_width;
16272 image_create_info.extent.height = tex_height;
16273 image_create_info.extent.depth = 1;
16274 image_create_info.mipLevels = 1;
16275 image_create_info.arrayLayers = 1;
16276 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16277 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16278 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16279 image_create_info.flags = 0;
16280 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16281 ASSERT_VK_SUCCESS(err);
16282
16283 VkMemoryRequirements memory_reqs;
16284 VkDeviceMemory image_memory;
16285 bool pass;
16286 VkMemoryAllocateInfo memory_info = {};
16287 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16288 memory_info.pNext = NULL;
16289 memory_info.allocationSize = 0;
16290 memory_info.memoryTypeIndex = 0;
16291 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16292 memory_info.allocationSize = memory_reqs.size;
16293 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16294 ASSERT_TRUE(pass);
16295 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16296 ASSERT_VK_SUCCESS(err);
16297 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16298 ASSERT_VK_SUCCESS(err);
16299
16300 VkImageViewCreateInfo image_view_create_info = {};
16301 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16302 image_view_create_info.image = image;
16303 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16304 image_view_create_info.format = tex_format;
16305 image_view_create_info.subresourceRange.layerCount = 1;
16306 image_view_create_info.subresourceRange.baseMipLevel = 0;
16307 image_view_create_info.subresourceRange.levelCount = 1;
16308 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16309
16310 VkImageView view;
16311 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16312 ASSERT_VK_SUCCESS(err);
16313
16314 VkDescriptorPoolSize ds_type_count = {};
16315 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16316 ds_type_count.descriptorCount = 1;
16317
16318 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16319 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16320 ds_pool_ci.pNext = NULL;
16321 ds_pool_ci.maxSets = 1;
16322 ds_pool_ci.poolSizeCount = 1;
16323 ds_pool_ci.pPoolSizes = &ds_type_count;
16324
16325 VkDescriptorPool ds_pool;
16326 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16327 ASSERT_VK_SUCCESS(err);
16328
16329 VkDescriptorSetLayoutBinding dsl_binding = {};
16330 dsl_binding.binding = 0;
16331 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16332 dsl_binding.descriptorCount = 1;
16333 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16334 dsl_binding.pImmutableSamplers = NULL;
16335
16336 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16337 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16338 ds_layout_ci.pNext = NULL;
16339 ds_layout_ci.bindingCount = 1;
16340 ds_layout_ci.pBindings = &dsl_binding;
16341 VkDescriptorSetLayout ds_layout;
16342 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16343 ASSERT_VK_SUCCESS(err);
16344
16345 VkDescriptorSet descriptor_set;
16346 VkDescriptorSetAllocateInfo alloc_info = {};
16347 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16348 alloc_info.descriptorSetCount = 1;
16349 alloc_info.descriptorPool = ds_pool;
16350 alloc_info.pSetLayouts = &ds_layout;
16351 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16352 ASSERT_VK_SUCCESS(err);
16353
16354 VkDescriptorImageInfo image_info = {};
16355 image_info.imageView = view;
16356 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16357
16358 VkWriteDescriptorSet descriptor_write;
16359 memset(&descriptor_write, 0, sizeof(descriptor_write));
16360 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16361 descriptor_write.dstSet = descriptor_set;
16362 descriptor_write.dstBinding = 0;
16363 descriptor_write.descriptorCount = 1;
16364 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16365 descriptor_write.pImageInfo = &image_info;
16366
16367 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16368 // be
16369 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16370 // This will most likely produce a crash if the parameter_validation
16371 // layer
16372 // does not correctly ignore pBufferInfo.
16373 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16374 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16375
16376 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16377
16378 m_errorMonitor->VerifyNotFound();
16379
16380 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16381 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16382 vkDestroyImageView(m_device->device(), view, NULL);
16383 vkDestroyImage(m_device->device(), image, NULL);
16384 vkFreeMemory(m_device->device(), image_memory, NULL);
16385 }
16386
16387 // Buffer Case
16388 {
16389 m_errorMonitor->ExpectSuccess();
16390
16391 VkBuffer buffer;
16392 uint32_t queue_family_index = 0;
16393 VkBufferCreateInfo buffer_create_info = {};
16394 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16395 buffer_create_info.size = 1024;
16396 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16397 buffer_create_info.queueFamilyIndexCount = 1;
16398 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16399
16400 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16401 ASSERT_VK_SUCCESS(err);
16402
16403 VkMemoryRequirements memory_reqs;
16404 VkDeviceMemory buffer_memory;
16405 bool pass;
16406 VkMemoryAllocateInfo memory_info = {};
16407 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16408 memory_info.pNext = NULL;
16409 memory_info.allocationSize = 0;
16410 memory_info.memoryTypeIndex = 0;
16411
16412 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16413 memory_info.allocationSize = memory_reqs.size;
16414 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16415 ASSERT_TRUE(pass);
16416
16417 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16418 ASSERT_VK_SUCCESS(err);
16419 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16420 ASSERT_VK_SUCCESS(err);
16421
16422 VkDescriptorPoolSize ds_type_count = {};
16423 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16424 ds_type_count.descriptorCount = 1;
16425
16426 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16427 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16428 ds_pool_ci.pNext = NULL;
16429 ds_pool_ci.maxSets = 1;
16430 ds_pool_ci.poolSizeCount = 1;
16431 ds_pool_ci.pPoolSizes = &ds_type_count;
16432
16433 VkDescriptorPool ds_pool;
16434 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16435 ASSERT_VK_SUCCESS(err);
16436
16437 VkDescriptorSetLayoutBinding dsl_binding = {};
16438 dsl_binding.binding = 0;
16439 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16440 dsl_binding.descriptorCount = 1;
16441 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16442 dsl_binding.pImmutableSamplers = NULL;
16443
16444 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16445 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16446 ds_layout_ci.pNext = NULL;
16447 ds_layout_ci.bindingCount = 1;
16448 ds_layout_ci.pBindings = &dsl_binding;
16449 VkDescriptorSetLayout ds_layout;
16450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16451 ASSERT_VK_SUCCESS(err);
16452
16453 VkDescriptorSet descriptor_set;
16454 VkDescriptorSetAllocateInfo alloc_info = {};
16455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16456 alloc_info.descriptorSetCount = 1;
16457 alloc_info.descriptorPool = ds_pool;
16458 alloc_info.pSetLayouts = &ds_layout;
16459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16460 ASSERT_VK_SUCCESS(err);
16461
16462 VkDescriptorBufferInfo buffer_info = {};
16463 buffer_info.buffer = buffer;
16464 buffer_info.offset = 0;
16465 buffer_info.range = 1024;
16466
16467 VkWriteDescriptorSet descriptor_write;
16468 memset(&descriptor_write, 0, sizeof(descriptor_write));
16469 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16470 descriptor_write.dstSet = descriptor_set;
16471 descriptor_write.dstBinding = 0;
16472 descriptor_write.descriptorCount = 1;
16473 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16474 descriptor_write.pBufferInfo = &buffer_info;
16475
16476 // Set pImageInfo and pTexelBufferView to invalid values, which should
16477 // be
16478 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16479 // This will most likely produce a crash if the parameter_validation
16480 // layer
16481 // does not correctly ignore pImageInfo.
16482 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16483 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16484
16485 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16486
16487 m_errorMonitor->VerifyNotFound();
16488
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016489 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16490 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16491 vkDestroyBuffer(m_device->device(), buffer, NULL);
16492 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16493 }
16494
16495 // Texel Buffer Case
16496 {
16497 m_errorMonitor->ExpectSuccess();
16498
16499 VkBuffer buffer;
16500 uint32_t queue_family_index = 0;
16501 VkBufferCreateInfo buffer_create_info = {};
16502 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16503 buffer_create_info.size = 1024;
16504 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16505 buffer_create_info.queueFamilyIndexCount = 1;
16506 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16507
16508 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16509 ASSERT_VK_SUCCESS(err);
16510
16511 VkMemoryRequirements memory_reqs;
16512 VkDeviceMemory buffer_memory;
16513 bool pass;
16514 VkMemoryAllocateInfo memory_info = {};
16515 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16516 memory_info.pNext = NULL;
16517 memory_info.allocationSize = 0;
16518 memory_info.memoryTypeIndex = 0;
16519
16520 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16521 memory_info.allocationSize = memory_reqs.size;
16522 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16523 ASSERT_TRUE(pass);
16524
16525 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16526 ASSERT_VK_SUCCESS(err);
16527 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16528 ASSERT_VK_SUCCESS(err);
16529
16530 VkBufferViewCreateInfo buff_view_ci = {};
16531 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16532 buff_view_ci.buffer = buffer;
16533 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16534 buff_view_ci.range = VK_WHOLE_SIZE;
16535 VkBufferView buffer_view;
16536 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16537
16538 VkDescriptorPoolSize ds_type_count = {};
16539 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16540 ds_type_count.descriptorCount = 1;
16541
16542 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16543 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16544 ds_pool_ci.pNext = NULL;
16545 ds_pool_ci.maxSets = 1;
16546 ds_pool_ci.poolSizeCount = 1;
16547 ds_pool_ci.pPoolSizes = &ds_type_count;
16548
16549 VkDescriptorPool ds_pool;
16550 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16551 ASSERT_VK_SUCCESS(err);
16552
16553 VkDescriptorSetLayoutBinding dsl_binding = {};
16554 dsl_binding.binding = 0;
16555 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16556 dsl_binding.descriptorCount = 1;
16557 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16558 dsl_binding.pImmutableSamplers = NULL;
16559
16560 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16561 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16562 ds_layout_ci.pNext = NULL;
16563 ds_layout_ci.bindingCount = 1;
16564 ds_layout_ci.pBindings = &dsl_binding;
16565 VkDescriptorSetLayout ds_layout;
16566 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16567 ASSERT_VK_SUCCESS(err);
16568
16569 VkDescriptorSet descriptor_set;
16570 VkDescriptorSetAllocateInfo alloc_info = {};
16571 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16572 alloc_info.descriptorSetCount = 1;
16573 alloc_info.descriptorPool = ds_pool;
16574 alloc_info.pSetLayouts = &ds_layout;
16575 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16576 ASSERT_VK_SUCCESS(err);
16577
16578 VkWriteDescriptorSet descriptor_write;
16579 memset(&descriptor_write, 0, sizeof(descriptor_write));
16580 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16581 descriptor_write.dstSet = descriptor_set;
16582 descriptor_write.dstBinding = 0;
16583 descriptor_write.descriptorCount = 1;
16584 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16585 descriptor_write.pTexelBufferView = &buffer_view;
16586
16587 // Set pImageInfo and pBufferInfo to invalid values, which should be
16588 // ignored for descriptorType ==
16589 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16590 // This will most likely produce a crash if the parameter_validation
16591 // layer
16592 // does not correctly ignore pImageInfo and pBufferInfo.
16593 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16594 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16595
16596 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16597
16598 m_errorMonitor->VerifyNotFound();
16599
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016600 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16601 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16602 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16603 vkDestroyBuffer(m_device->device(), buffer, NULL);
16604 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16605 }
16606}
16607
Tobin Ehlisf7428442016-10-25 07:58:24 -060016608TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16609 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16610
16611 ASSERT_NO_FATAL_FAILURE(InitState());
16612 // Create layout where two binding #s are "1"
16613 static const uint32_t NUM_BINDINGS = 3;
16614 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16615 dsl_binding[0].binding = 1;
16616 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16617 dsl_binding[0].descriptorCount = 1;
16618 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16619 dsl_binding[0].pImmutableSamplers = NULL;
16620 dsl_binding[1].binding = 0;
16621 dsl_binding[1].descriptorCount = 1;
16622 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16623 dsl_binding[1].descriptorCount = 1;
16624 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16625 dsl_binding[1].pImmutableSamplers = NULL;
16626 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16627 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16628 dsl_binding[2].descriptorCount = 1;
16629 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16630 dsl_binding[2].pImmutableSamplers = NULL;
16631
16632 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16633 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16634 ds_layout_ci.pNext = NULL;
16635 ds_layout_ci.bindingCount = NUM_BINDINGS;
16636 ds_layout_ci.pBindings = dsl_binding;
16637 VkDescriptorSetLayout ds_layout;
16638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16639 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16640 m_errorMonitor->VerifyFound();
16641}
16642
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016643TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016644 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16645
16646 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016647
Tony Barbour552f6c02016-12-21 14:34:07 -070016648 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016649
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016650 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16651
16652 {
16653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16654 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16655 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16656 m_errorMonitor->VerifyFound();
16657 }
16658
16659 {
16660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16661 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16662 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16663 m_errorMonitor->VerifyFound();
16664 }
16665
16666 {
16667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16668 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16669 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16670 m_errorMonitor->VerifyFound();
16671 }
16672
16673 {
16674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16675 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16676 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16677 m_errorMonitor->VerifyFound();
16678 }
16679
16680 {
16681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16682 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16683 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16684 m_errorMonitor->VerifyFound();
16685 }
16686
16687 {
16688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16689 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16690 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16691 m_errorMonitor->VerifyFound();
16692 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016693
16694 {
16695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16696 VkRect2D scissor = {{-1, 0}, {16, 16}};
16697 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16698 m_errorMonitor->VerifyFound();
16699 }
16700
16701 {
16702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16703 VkRect2D scissor = {{0, -2}, {16, 16}};
16704 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16705 m_errorMonitor->VerifyFound();
16706 }
16707
16708 {
16709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16710 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16711 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16712 m_errorMonitor->VerifyFound();
16713 }
16714
16715 {
16716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16717 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16718 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16719 m_errorMonitor->VerifyFound();
16720 }
16721
Tony Barbour552f6c02016-12-21 14:34:07 -070016722 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016723}
16724
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016725// This is a positive test. No failures are expected.
16726TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16727 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16728 VkResult err;
16729
16730 ASSERT_NO_FATAL_FAILURE(InitState());
16731 m_errorMonitor->ExpectSuccess();
16732 VkDescriptorPoolSize ds_type_count = {};
16733 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16734 ds_type_count.descriptorCount = 2;
16735
16736 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16737 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16738 ds_pool_ci.pNext = NULL;
16739 ds_pool_ci.maxSets = 1;
16740 ds_pool_ci.poolSizeCount = 1;
16741 ds_pool_ci.pPoolSizes = &ds_type_count;
16742
16743 VkDescriptorPool ds_pool;
16744 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16745 ASSERT_VK_SUCCESS(err);
16746
16747 // Create layout with two uniform buffer descriptors w/ empty binding between them
16748 static const uint32_t NUM_BINDINGS = 3;
16749 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16750 dsl_binding[0].binding = 0;
16751 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16752 dsl_binding[0].descriptorCount = 1;
16753 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16754 dsl_binding[0].pImmutableSamplers = NULL;
16755 dsl_binding[1].binding = 1;
16756 dsl_binding[1].descriptorCount = 0; // empty binding
16757 dsl_binding[2].binding = 2;
16758 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16759 dsl_binding[2].descriptorCount = 1;
16760 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16761 dsl_binding[2].pImmutableSamplers = NULL;
16762
16763 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16764 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16765 ds_layout_ci.pNext = NULL;
16766 ds_layout_ci.bindingCount = NUM_BINDINGS;
16767 ds_layout_ci.pBindings = dsl_binding;
16768 VkDescriptorSetLayout ds_layout;
16769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16770 ASSERT_VK_SUCCESS(err);
16771
16772 VkDescriptorSet descriptor_set = {};
16773 VkDescriptorSetAllocateInfo alloc_info = {};
16774 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16775 alloc_info.descriptorSetCount = 1;
16776 alloc_info.descriptorPool = ds_pool;
16777 alloc_info.pSetLayouts = &ds_layout;
16778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16779 ASSERT_VK_SUCCESS(err);
16780
16781 // Create a buffer to be used for update
16782 VkBufferCreateInfo buff_ci = {};
16783 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16784 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16785 buff_ci.size = 256;
16786 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16787 VkBuffer buffer;
16788 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16789 ASSERT_VK_SUCCESS(err);
16790 // Have to bind memory to buffer before descriptor update
16791 VkMemoryAllocateInfo mem_alloc = {};
16792 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16793 mem_alloc.pNext = NULL;
16794 mem_alloc.allocationSize = 512; // one allocation for both buffers
16795 mem_alloc.memoryTypeIndex = 0;
16796
16797 VkMemoryRequirements mem_reqs;
16798 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16799 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16800 if (!pass) {
16801 vkDestroyBuffer(m_device->device(), buffer, NULL);
16802 return;
16803 }
16804
16805 VkDeviceMemory mem;
16806 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16807 ASSERT_VK_SUCCESS(err);
16808 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16809 ASSERT_VK_SUCCESS(err);
16810
16811 // Only update the descriptor at binding 2
16812 VkDescriptorBufferInfo buff_info = {};
16813 buff_info.buffer = buffer;
16814 buff_info.offset = 0;
16815 buff_info.range = VK_WHOLE_SIZE;
16816 VkWriteDescriptorSet descriptor_write = {};
16817 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16818 descriptor_write.dstBinding = 2;
16819 descriptor_write.descriptorCount = 1;
16820 descriptor_write.pTexelBufferView = nullptr;
16821 descriptor_write.pBufferInfo = &buff_info;
16822 descriptor_write.pImageInfo = nullptr;
16823 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16824 descriptor_write.dstSet = descriptor_set;
16825
16826 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16827
16828 m_errorMonitor->VerifyNotFound();
16829 // Cleanup
16830 vkFreeMemory(m_device->device(), mem, NULL);
16831 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16832 vkDestroyBuffer(m_device->device(), buffer, NULL);
16833 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16834}
16835
16836// This is a positive test. No failures are expected.
16837TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16838 VkResult err;
16839 bool pass;
16840
16841 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16842 "the buffer, create an image, and bind the same memory to "
16843 "it");
16844
16845 m_errorMonitor->ExpectSuccess();
16846
16847 ASSERT_NO_FATAL_FAILURE(InitState());
16848
16849 VkBuffer buffer;
16850 VkImage image;
16851 VkDeviceMemory mem;
16852 VkMemoryRequirements mem_reqs;
16853
16854 VkBufferCreateInfo buf_info = {};
16855 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16856 buf_info.pNext = NULL;
16857 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16858 buf_info.size = 256;
16859 buf_info.queueFamilyIndexCount = 0;
16860 buf_info.pQueueFamilyIndices = NULL;
16861 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16862 buf_info.flags = 0;
16863 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16864 ASSERT_VK_SUCCESS(err);
16865
16866 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16867
16868 VkMemoryAllocateInfo alloc_info = {};
16869 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16870 alloc_info.pNext = NULL;
16871 alloc_info.memoryTypeIndex = 0;
16872
16873 // Ensure memory is big enough for both bindings
16874 alloc_info.allocationSize = 0x10000;
16875
16876 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16877 if (!pass) {
16878 vkDestroyBuffer(m_device->device(), buffer, NULL);
16879 return;
16880 }
16881
16882 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16883 ASSERT_VK_SUCCESS(err);
16884
16885 uint8_t *pData;
16886 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16887 ASSERT_VK_SUCCESS(err);
16888
16889 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16890
16891 vkUnmapMemory(m_device->device(), mem);
16892
16893 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16894 ASSERT_VK_SUCCESS(err);
16895
16896 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16897 // memory. In fact, it was never used by the GPU.
16898 // Just be be sure, wait for idle.
16899 vkDestroyBuffer(m_device->device(), buffer, NULL);
16900 vkDeviceWaitIdle(m_device->device());
16901
Tobin Ehlis6a005702016-12-28 15:25:56 -070016902 // Use optimal as some platforms report linear support but then fail image creation
16903 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
16904 VkImageFormatProperties image_format_properties;
16905 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
16906 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
16907 if (image_format_properties.maxExtent.width == 0) {
16908 printf("Image format not supported; skipped.\n");
16909 vkFreeMemory(m_device->device(), mem, NULL);
16910 return;
16911 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016912 VkImageCreateInfo image_create_info = {};
16913 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16914 image_create_info.pNext = NULL;
16915 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16916 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16917 image_create_info.extent.width = 64;
16918 image_create_info.extent.height = 64;
16919 image_create_info.extent.depth = 1;
16920 image_create_info.mipLevels = 1;
16921 image_create_info.arrayLayers = 1;
16922 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070016923 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016924 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16925 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16926 image_create_info.queueFamilyIndexCount = 0;
16927 image_create_info.pQueueFamilyIndices = NULL;
16928 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16929 image_create_info.flags = 0;
16930
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016931 /* Create a mappable image. It will be the texture if linear images are ok
16932 * to be textures or it will be the staging image if they are not.
16933 */
16934 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16935 ASSERT_VK_SUCCESS(err);
16936
16937 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16938
Tobin Ehlis6a005702016-12-28 15:25:56 -070016939 VkMemoryAllocateInfo mem_alloc = {};
16940 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16941 mem_alloc.pNext = NULL;
16942 mem_alloc.allocationSize = 0;
16943 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016944 mem_alloc.allocationSize = mem_reqs.size;
16945
16946 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16947 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070016948 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016949 vkDestroyImage(m_device->device(), image, NULL);
16950 return;
16951 }
16952
16953 // VALIDATION FAILURE:
16954 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16955 ASSERT_VK_SUCCESS(err);
16956
16957 m_errorMonitor->VerifyNotFound();
16958
16959 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016960 vkDestroyImage(m_device->device(), image, NULL);
16961}
16962
Tobin Ehlis953e8392016-11-17 10:54:13 -070016963TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16964 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16965 // We previously had a bug where dynamic offset of inactive bindings was still being used
16966 VkResult err;
16967 m_errorMonitor->ExpectSuccess();
16968
16969 ASSERT_NO_FATAL_FAILURE(InitState());
16970 ASSERT_NO_FATAL_FAILURE(InitViewport());
16971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16972
16973 VkDescriptorPoolSize ds_type_count = {};
16974 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16975 ds_type_count.descriptorCount = 3;
16976
16977 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16978 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16979 ds_pool_ci.pNext = NULL;
16980 ds_pool_ci.maxSets = 1;
16981 ds_pool_ci.poolSizeCount = 1;
16982 ds_pool_ci.pPoolSizes = &ds_type_count;
16983
16984 VkDescriptorPool ds_pool;
16985 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16986 ASSERT_VK_SUCCESS(err);
16987
16988 const uint32_t BINDING_COUNT = 3;
16989 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016990 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016991 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16992 dsl_binding[0].descriptorCount = 1;
16993 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16994 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070016995 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070016996 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16997 dsl_binding[1].descriptorCount = 1;
16998 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16999 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017000 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017001 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17002 dsl_binding[2].descriptorCount = 1;
17003 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17004 dsl_binding[2].pImmutableSamplers = NULL;
17005
17006 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17007 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17008 ds_layout_ci.pNext = NULL;
17009 ds_layout_ci.bindingCount = BINDING_COUNT;
17010 ds_layout_ci.pBindings = dsl_binding;
17011 VkDescriptorSetLayout ds_layout;
17012 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17013 ASSERT_VK_SUCCESS(err);
17014
17015 VkDescriptorSet descriptor_set;
17016 VkDescriptorSetAllocateInfo alloc_info = {};
17017 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17018 alloc_info.descriptorSetCount = 1;
17019 alloc_info.descriptorPool = ds_pool;
17020 alloc_info.pSetLayouts = &ds_layout;
17021 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17022 ASSERT_VK_SUCCESS(err);
17023
17024 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17025 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17026 pipeline_layout_ci.pNext = NULL;
17027 pipeline_layout_ci.setLayoutCount = 1;
17028 pipeline_layout_ci.pSetLayouts = &ds_layout;
17029
17030 VkPipelineLayout pipeline_layout;
17031 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17032 ASSERT_VK_SUCCESS(err);
17033
17034 // Create two buffers to update the descriptors with
17035 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17036 uint32_t qfi = 0;
17037 VkBufferCreateInfo buffCI = {};
17038 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17039 buffCI.size = 2048;
17040 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17041 buffCI.queueFamilyIndexCount = 1;
17042 buffCI.pQueueFamilyIndices = &qfi;
17043
17044 VkBuffer dyub1;
17045 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17046 ASSERT_VK_SUCCESS(err);
17047 // buffer2
17048 buffCI.size = 1024;
17049 VkBuffer dyub2;
17050 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17051 ASSERT_VK_SUCCESS(err);
17052 // Allocate memory and bind to buffers
17053 VkMemoryAllocateInfo mem_alloc[2] = {};
17054 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17055 mem_alloc[0].pNext = NULL;
17056 mem_alloc[0].memoryTypeIndex = 0;
17057 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17058 mem_alloc[1].pNext = NULL;
17059 mem_alloc[1].memoryTypeIndex = 0;
17060
17061 VkMemoryRequirements mem_reqs1;
17062 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17063 VkMemoryRequirements mem_reqs2;
17064 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17065 mem_alloc[0].allocationSize = mem_reqs1.size;
17066 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17067 mem_alloc[1].allocationSize = mem_reqs2.size;
17068 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17069 if (!pass) {
17070 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17071 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17072 return;
17073 }
17074
17075 VkDeviceMemory mem1;
17076 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17077 ASSERT_VK_SUCCESS(err);
17078 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17079 ASSERT_VK_SUCCESS(err);
17080 VkDeviceMemory mem2;
17081 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17082 ASSERT_VK_SUCCESS(err);
17083 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17084 ASSERT_VK_SUCCESS(err);
17085 // Update descriptors
17086 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17087 buff_info[0].buffer = dyub1;
17088 buff_info[0].offset = 0;
17089 buff_info[0].range = 256;
17090 buff_info[1].buffer = dyub1;
17091 buff_info[1].offset = 256;
17092 buff_info[1].range = 512;
17093 buff_info[2].buffer = dyub2;
17094 buff_info[2].offset = 0;
17095 buff_info[2].range = 512;
17096
17097 VkWriteDescriptorSet descriptor_write;
17098 memset(&descriptor_write, 0, sizeof(descriptor_write));
17099 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17100 descriptor_write.dstSet = descriptor_set;
17101 descriptor_write.dstBinding = 0;
17102 descriptor_write.descriptorCount = BINDING_COUNT;
17103 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17104 descriptor_write.pBufferInfo = buff_info;
17105
17106 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17107
Tony Barbour552f6c02016-12-21 14:34:07 -070017108 m_commandBuffer->BeginCommandBuffer();
17109 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017110
17111 // Create PSO to be used for draw-time errors below
17112 char const *vsSource = "#version 450\n"
17113 "\n"
17114 "out gl_PerVertex { \n"
17115 " vec4 gl_Position;\n"
17116 "};\n"
17117 "void main(){\n"
17118 " gl_Position = vec4(1);\n"
17119 "}\n";
17120 char const *fsSource = "#version 450\n"
17121 "\n"
17122 "layout(location=0) out vec4 x;\n"
17123 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17124 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17125 "void main(){\n"
17126 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17127 "}\n";
17128 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17129 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17130 VkPipelineObj pipe(m_device);
17131 pipe.SetViewport(m_viewports);
17132 pipe.SetScissor(m_scissors);
17133 pipe.AddShader(&vs);
17134 pipe.AddShader(&fs);
17135 pipe.AddColorAttachment();
17136 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17137
17138 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17139 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17140 // we used to have a bug in this case.
17141 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17142 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17143 &descriptor_set, BINDING_COUNT, dyn_off);
17144 Draw(1, 0, 0, 0);
17145 m_errorMonitor->VerifyNotFound();
17146
17147 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17148 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17149 vkFreeMemory(m_device->device(), mem1, NULL);
17150 vkFreeMemory(m_device->device(), mem2, NULL);
17151
17152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17153 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17154 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17155}
17156
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017157TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17158
17159 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17160 "mapping while using VK_WHOLE_SIZE does not cause access "
17161 "violations");
17162 VkResult err;
17163 uint8_t *pData;
17164 ASSERT_NO_FATAL_FAILURE(InitState());
17165
17166 VkDeviceMemory mem;
17167 VkMemoryRequirements mem_reqs;
17168 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017169 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017170 VkMemoryAllocateInfo alloc_info = {};
17171 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17172 alloc_info.pNext = NULL;
17173 alloc_info.memoryTypeIndex = 0;
17174
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017175 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017176 alloc_info.allocationSize = allocation_size;
17177
17178 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17179 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17180 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17181 if (!pass) {
17182 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17183 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17184 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17185 if (!pass) {
17186 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17187 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17188 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17189 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17190 if (!pass) {
17191 return;
17192 }
17193 }
17194 }
17195
17196 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17197 ASSERT_VK_SUCCESS(err);
17198
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017199 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017200 m_errorMonitor->ExpectSuccess();
17201 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17202 ASSERT_VK_SUCCESS(err);
17203 VkMappedMemoryRange mmr = {};
17204 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17205 mmr.memory = mem;
17206 mmr.offset = 0;
17207 mmr.size = VK_WHOLE_SIZE;
17208 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17209 ASSERT_VK_SUCCESS(err);
17210 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17211 ASSERT_VK_SUCCESS(err);
17212 m_errorMonitor->VerifyNotFound();
17213 vkUnmapMemory(m_device->device(), mem);
17214
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017215 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017216 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017217 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017218 ASSERT_VK_SUCCESS(err);
17219 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17220 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017221 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017222 mmr.size = VK_WHOLE_SIZE;
17223 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17224 ASSERT_VK_SUCCESS(err);
17225 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17226 ASSERT_VK_SUCCESS(err);
17227 m_errorMonitor->VerifyNotFound();
17228 vkUnmapMemory(m_device->device(), mem);
17229
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017230 // Map with offset and size
17231 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017232 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017233 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017234 ASSERT_VK_SUCCESS(err);
17235 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17236 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017237 mmr.offset = 4 * atom_size;
17238 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017239 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17240 ASSERT_VK_SUCCESS(err);
17241 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17242 ASSERT_VK_SUCCESS(err);
17243 m_errorMonitor->VerifyNotFound();
17244 vkUnmapMemory(m_device->device(), mem);
17245
17246 // Map without offset and flush WHOLE_SIZE with two separate offsets
17247 m_errorMonitor->ExpectSuccess();
17248 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17249 ASSERT_VK_SUCCESS(err);
17250 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17251 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017252 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017253 mmr.size = VK_WHOLE_SIZE;
17254 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17255 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017256 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017257 mmr.size = VK_WHOLE_SIZE;
17258 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17259 ASSERT_VK_SUCCESS(err);
17260 m_errorMonitor->VerifyNotFound();
17261 vkUnmapMemory(m_device->device(), mem);
17262
17263 vkFreeMemory(m_device->device(), mem, NULL);
17264}
17265
17266// This is a positive test. We used to expect error in this case but spec now allows it
17267TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17268 m_errorMonitor->ExpectSuccess();
17269 vk_testing::Fence testFence;
17270 VkFenceCreateInfo fenceInfo = {};
17271 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17272 fenceInfo.pNext = NULL;
17273
17274 ASSERT_NO_FATAL_FAILURE(InitState());
17275 testFence.init(*m_device, fenceInfo);
17276 VkFence fences[1] = { testFence.handle() };
17277 VkResult result = vkResetFences(m_device->device(), 1, fences);
17278 ASSERT_VK_SUCCESS(result);
17279
17280 m_errorMonitor->VerifyNotFound();
17281}
17282
17283TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17284 m_errorMonitor->ExpectSuccess();
17285
17286 ASSERT_NO_FATAL_FAILURE(InitState());
17287 VkResult err;
17288
17289 // Record (empty!) command buffer that can be submitted multiple times
17290 // simultaneously.
17291 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17292 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17293 m_commandBuffer->BeginCommandBuffer(&cbbi);
17294 m_commandBuffer->EndCommandBuffer();
17295
17296 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17297 VkFence fence;
17298 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17299 ASSERT_VK_SUCCESS(err);
17300
17301 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17302 VkSemaphore s1, s2;
17303 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17304 ASSERT_VK_SUCCESS(err);
17305 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17306 ASSERT_VK_SUCCESS(err);
17307
17308 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17309 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17310 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17311 ASSERT_VK_SUCCESS(err);
17312
17313 // Submit CB again, signaling s2.
17314 si.pSignalSemaphores = &s2;
17315 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17316 ASSERT_VK_SUCCESS(err);
17317
17318 // Wait for fence.
17319 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17320 ASSERT_VK_SUCCESS(err);
17321
17322 // CB is still in flight from second submission, but semaphore s1 is no
17323 // longer in flight. delete it.
17324 vkDestroySemaphore(m_device->device(), s1, nullptr);
17325
17326 m_errorMonitor->VerifyNotFound();
17327
17328 // Force device idle and clean up remaining objects
17329 vkDeviceWaitIdle(m_device->device());
17330 vkDestroySemaphore(m_device->device(), s2, nullptr);
17331 vkDestroyFence(m_device->device(), fence, nullptr);
17332}
17333
17334TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17335 m_errorMonitor->ExpectSuccess();
17336
17337 ASSERT_NO_FATAL_FAILURE(InitState());
17338 VkResult err;
17339
17340 // A fence created signaled
17341 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17342 VkFence f1;
17343 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17344 ASSERT_VK_SUCCESS(err);
17345
17346 // A fence created not
17347 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17348 VkFence f2;
17349 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17350 ASSERT_VK_SUCCESS(err);
17351
17352 // Submit the unsignaled fence
17353 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17354 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17355
17356 // Wait on both fences, with signaled first.
17357 VkFence fences[] = { f1, f2 };
17358 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17359
17360 // Should have both retired!
17361 vkDestroyFence(m_device->device(), f1, nullptr);
17362 vkDestroyFence(m_device->device(), f2, nullptr);
17363
17364 m_errorMonitor->VerifyNotFound();
17365}
17366
17367TEST_F(VkPositiveLayerTest, ValidUsage) {
17368 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17369 "doesn't generate validation errors");
17370
17371 ASSERT_NO_FATAL_FAILURE(InitState());
17372
17373 m_errorMonitor->ExpectSuccess();
17374 // Verify that we can create a view with usage INPUT_ATTACHMENT
17375 VkImageObj image(m_device);
17376 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17377 ASSERT_TRUE(image.initialized());
17378 VkImageView imageView;
17379 VkImageViewCreateInfo ivci = {};
17380 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17381 ivci.image = image.handle();
17382 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17383 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17384 ivci.subresourceRange.layerCount = 1;
17385 ivci.subresourceRange.baseMipLevel = 0;
17386 ivci.subresourceRange.levelCount = 1;
17387 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17388
17389 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17390 m_errorMonitor->VerifyNotFound();
17391 vkDestroyImageView(m_device->device(), imageView, NULL);
17392}
17393
17394// This is a positive test. No failures are expected.
17395TEST_F(VkPositiveLayerTest, BindSparse) {
17396 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17397 "and then free the memory");
17398
17399 ASSERT_NO_FATAL_FAILURE(InitState());
17400
17401 auto index = m_device->graphics_queue_node_index_;
17402 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17403 return;
17404
17405 m_errorMonitor->ExpectSuccess();
17406
17407 VkImage image;
17408 VkImageCreateInfo image_create_info = {};
17409 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17410 image_create_info.pNext = NULL;
17411 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17412 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17413 image_create_info.extent.width = 64;
17414 image_create_info.extent.height = 64;
17415 image_create_info.extent.depth = 1;
17416 image_create_info.mipLevels = 1;
17417 image_create_info.arrayLayers = 1;
17418 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17419 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17420 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17421 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17422 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17423 ASSERT_VK_SUCCESS(err);
17424
17425 VkMemoryRequirements memory_reqs;
17426 VkDeviceMemory memory_one, memory_two;
17427 bool pass;
17428 VkMemoryAllocateInfo memory_info = {};
17429 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17430 memory_info.pNext = NULL;
17431 memory_info.allocationSize = 0;
17432 memory_info.memoryTypeIndex = 0;
17433 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17434 // Find an image big enough to allow sparse mapping of 2 memory regions
17435 // Increase the image size until it is at least twice the
17436 // size of the required alignment, to ensure we can bind both
17437 // allocated memory blocks to the image on aligned offsets.
17438 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17439 vkDestroyImage(m_device->device(), image, nullptr);
17440 image_create_info.extent.width *= 2;
17441 image_create_info.extent.height *= 2;
17442 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17443 ASSERT_VK_SUCCESS(err);
17444 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17445 }
17446 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17447 // at the end of the first
17448 memory_info.allocationSize = memory_reqs.alignment;
17449 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17450 ASSERT_TRUE(pass);
17451 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17452 ASSERT_VK_SUCCESS(err);
17453 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17454 ASSERT_VK_SUCCESS(err);
17455 VkSparseMemoryBind binds[2];
17456 binds[0].flags = 0;
17457 binds[0].memory = memory_one;
17458 binds[0].memoryOffset = 0;
17459 binds[0].resourceOffset = 0;
17460 binds[0].size = memory_info.allocationSize;
17461 binds[1].flags = 0;
17462 binds[1].memory = memory_two;
17463 binds[1].memoryOffset = 0;
17464 binds[1].resourceOffset = memory_info.allocationSize;
17465 binds[1].size = memory_info.allocationSize;
17466
17467 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17468 opaqueBindInfo.image = image;
17469 opaqueBindInfo.bindCount = 2;
17470 opaqueBindInfo.pBinds = binds;
17471
17472 VkFence fence = VK_NULL_HANDLE;
17473 VkBindSparseInfo bindSparseInfo = {};
17474 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17475 bindSparseInfo.imageOpaqueBindCount = 1;
17476 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17477
17478 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17479 vkQueueWaitIdle(m_device->m_queue);
17480 vkDestroyImage(m_device->device(), image, NULL);
17481 vkFreeMemory(m_device->device(), memory_one, NULL);
17482 vkFreeMemory(m_device->device(), memory_two, NULL);
17483 m_errorMonitor->VerifyNotFound();
17484}
17485
17486TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17487 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17488 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17489 "the command buffer has prior knowledge of that "
17490 "attachment's layout.");
17491
17492 m_errorMonitor->ExpectSuccess();
17493
17494 ASSERT_NO_FATAL_FAILURE(InitState());
17495
17496 // A renderpass with one color attachment.
17497 VkAttachmentDescription attachment = { 0,
17498 VK_FORMAT_R8G8B8A8_UNORM,
17499 VK_SAMPLE_COUNT_1_BIT,
17500 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17501 VK_ATTACHMENT_STORE_OP_STORE,
17502 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17503 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17504 VK_IMAGE_LAYOUT_UNDEFINED,
17505 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17506
17507 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17508
17509 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17510
17511 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17512
17513 VkRenderPass rp;
17514 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17515 ASSERT_VK_SUCCESS(err);
17516
17517 // A compatible framebuffer.
17518 VkImageObj image(m_device);
17519 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17520 ASSERT_TRUE(image.initialized());
17521
17522 VkImageViewCreateInfo ivci = {
17523 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17524 nullptr,
17525 0,
17526 image.handle(),
17527 VK_IMAGE_VIEW_TYPE_2D,
17528 VK_FORMAT_R8G8B8A8_UNORM,
17529 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17530 VK_COMPONENT_SWIZZLE_IDENTITY },
17531 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17532 };
17533 VkImageView view;
17534 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17535 ASSERT_VK_SUCCESS(err);
17536
17537 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17538 VkFramebuffer fb;
17539 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17540 ASSERT_VK_SUCCESS(err);
17541
17542 // Record a single command buffer which uses this renderpass twice. The
17543 // bug is triggered at the beginning of the second renderpass, when the
17544 // command buffer already has a layout recorded for the attachment.
17545 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 -070017546 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017547 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17548 vkCmdEndRenderPass(m_commandBuffer->handle());
17549 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17550
17551 m_errorMonitor->VerifyNotFound();
17552
17553 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017554 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017555
17556 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17557 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17558 vkDestroyImageView(m_device->device(), view, nullptr);
17559}
17560
17561TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17562 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17563 "command buffer, bind them together, then destroy "
17564 "command pool and framebuffer and verify there are no "
17565 "errors.");
17566
17567 m_errorMonitor->ExpectSuccess();
17568
17569 ASSERT_NO_FATAL_FAILURE(InitState());
17570
17571 // A renderpass with one color attachment.
17572 VkAttachmentDescription attachment = { 0,
17573 VK_FORMAT_R8G8B8A8_UNORM,
17574 VK_SAMPLE_COUNT_1_BIT,
17575 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17576 VK_ATTACHMENT_STORE_OP_STORE,
17577 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17578 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17579 VK_IMAGE_LAYOUT_UNDEFINED,
17580 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17581
17582 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17583
17584 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17585
17586 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17587
17588 VkRenderPass rp;
17589 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17590 ASSERT_VK_SUCCESS(err);
17591
17592 // A compatible framebuffer.
17593 VkImageObj image(m_device);
17594 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17595 ASSERT_TRUE(image.initialized());
17596
17597 VkImageViewCreateInfo ivci = {
17598 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17599 nullptr,
17600 0,
17601 image.handle(),
17602 VK_IMAGE_VIEW_TYPE_2D,
17603 VK_FORMAT_R8G8B8A8_UNORM,
17604 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17605 VK_COMPONENT_SWIZZLE_IDENTITY },
17606 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17607 };
17608 VkImageView view;
17609 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17610 ASSERT_VK_SUCCESS(err);
17611
17612 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17613 VkFramebuffer fb;
17614 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17615 ASSERT_VK_SUCCESS(err);
17616
17617 // Explicitly create a command buffer to bind the FB to so that we can then
17618 // destroy the command pool in order to implicitly free command buffer
17619 VkCommandPool command_pool;
17620 VkCommandPoolCreateInfo pool_create_info{};
17621 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17622 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17623 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17624 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17625
17626 VkCommandBuffer command_buffer;
17627 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17628 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17629 command_buffer_allocate_info.commandPool = command_pool;
17630 command_buffer_allocate_info.commandBufferCount = 1;
17631 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17632 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17633
17634 // Begin our cmd buffer with renderpass using our framebuffer
17635 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17636 VkCommandBufferBeginInfo begin_info{};
17637 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17638 vkBeginCommandBuffer(command_buffer, &begin_info);
17639
17640 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17641 vkCmdEndRenderPass(command_buffer);
17642 vkEndCommandBuffer(command_buffer);
17643 vkDestroyImageView(m_device->device(), view, nullptr);
17644 // Destroy command pool to implicitly free command buffer
17645 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17646 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17647 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17648 m_errorMonitor->VerifyNotFound();
17649}
17650
17651TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17652 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17653 "transitions for the first subpass");
17654
17655 m_errorMonitor->ExpectSuccess();
17656
17657 ASSERT_NO_FATAL_FAILURE(InitState());
17658
17659 // A renderpass with one color attachment.
17660 VkAttachmentDescription attachment = { 0,
17661 VK_FORMAT_R8G8B8A8_UNORM,
17662 VK_SAMPLE_COUNT_1_BIT,
17663 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17664 VK_ATTACHMENT_STORE_OP_STORE,
17665 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17666 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17667 VK_IMAGE_LAYOUT_UNDEFINED,
17668 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17669
17670 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17671
17672 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17673
17674 VkSubpassDependency dep = { 0,
17675 0,
17676 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17677 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17678 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17679 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17680 VK_DEPENDENCY_BY_REGION_BIT };
17681
17682 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17683
17684 VkResult err;
17685 VkRenderPass rp;
17686 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17687 ASSERT_VK_SUCCESS(err);
17688
17689 // A compatible framebuffer.
17690 VkImageObj image(m_device);
17691 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17692 ASSERT_TRUE(image.initialized());
17693
17694 VkImageViewCreateInfo ivci = {
17695 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17696 nullptr,
17697 0,
17698 image.handle(),
17699 VK_IMAGE_VIEW_TYPE_2D,
17700 VK_FORMAT_R8G8B8A8_UNORM,
17701 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17702 VK_COMPONENT_SWIZZLE_IDENTITY },
17703 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17704 };
17705 VkImageView view;
17706 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17707 ASSERT_VK_SUCCESS(err);
17708
17709 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17710 VkFramebuffer fb;
17711 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17712 ASSERT_VK_SUCCESS(err);
17713
17714 // Record a single command buffer which issues a pipeline barrier w/
17715 // image memory barrier for the attachment. This detects the previously
17716 // missing tracking of the subpass layout by throwing a validation error
17717 // if it doesn't occur.
17718 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 -070017719 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017720 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17721
17722 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17723 nullptr,
17724 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17725 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17726 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17727 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17728 VK_QUEUE_FAMILY_IGNORED,
17729 VK_QUEUE_FAMILY_IGNORED,
17730 image.handle(),
17731 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17732 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17733 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17734 &imb);
17735
17736 vkCmdEndRenderPass(m_commandBuffer->handle());
17737 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017738 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017739
17740 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17741 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17742 vkDestroyImageView(m_device->device(), view, nullptr);
17743}
17744
17745TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17746 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17747 "is used as a depth/stencil framebuffer attachment, the "
17748 "aspectMask is ignored and both depth and stencil image "
17749 "subresources are used.");
17750
17751 VkFormatProperties format_properties;
17752 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17753 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17754 return;
17755 }
17756
17757 m_errorMonitor->ExpectSuccess();
17758
17759 ASSERT_NO_FATAL_FAILURE(InitState());
17760
17761 VkAttachmentDescription attachment = { 0,
17762 VK_FORMAT_D32_SFLOAT_S8_UINT,
17763 VK_SAMPLE_COUNT_1_BIT,
17764 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17765 VK_ATTACHMENT_STORE_OP_STORE,
17766 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17767 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17768 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17769 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17770
17771 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17772
17773 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17774
17775 VkSubpassDependency dep = { 0,
17776 0,
17777 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17778 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17779 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17780 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17781 VK_DEPENDENCY_BY_REGION_BIT};
17782
17783 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17784
17785 VkResult err;
17786 VkRenderPass rp;
17787 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17788 ASSERT_VK_SUCCESS(err);
17789
17790 VkImageObj image(m_device);
17791 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17792 0x26, // usage
17793 VK_IMAGE_TILING_OPTIMAL, 0);
17794 ASSERT_TRUE(image.initialized());
17795 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17796
17797 VkImageViewCreateInfo ivci = {
17798 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17799 nullptr,
17800 0,
17801 image.handle(),
17802 VK_IMAGE_VIEW_TYPE_2D,
17803 VK_FORMAT_D32_SFLOAT_S8_UINT,
17804 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17805 { 0x2, 0, 1, 0, 1 },
17806 };
17807 VkImageView view;
17808 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17809 ASSERT_VK_SUCCESS(err);
17810
17811 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17812 VkFramebuffer fb;
17813 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17814 ASSERT_VK_SUCCESS(err);
17815
17816 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 -070017817 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017818 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17819
17820 VkImageMemoryBarrier imb = {};
17821 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17822 imb.pNext = nullptr;
17823 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17824 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17825 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17826 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17827 imb.srcQueueFamilyIndex = 0;
17828 imb.dstQueueFamilyIndex = 0;
17829 imb.image = image.handle();
17830 imb.subresourceRange.aspectMask = 0x6;
17831 imb.subresourceRange.baseMipLevel = 0;
17832 imb.subresourceRange.levelCount = 0x1;
17833 imb.subresourceRange.baseArrayLayer = 0;
17834 imb.subresourceRange.layerCount = 0x1;
17835
17836 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17837 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17838 &imb);
17839
17840 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017841 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017842 QueueCommandBuffer(false);
17843 m_errorMonitor->VerifyNotFound();
17844
17845 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17846 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17847 vkDestroyImageView(m_device->device(), view, nullptr);
17848}
17849
17850TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17851 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17852 "errors, when an attachment reference is "
17853 "VK_ATTACHMENT_UNUSED");
17854
17855 m_errorMonitor->ExpectSuccess();
17856
17857 ASSERT_NO_FATAL_FAILURE(InitState());
17858
17859 // A renderpass with no attachments
17860 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17861
17862 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17863
17864 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17865
17866 VkRenderPass rp;
17867 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17868 ASSERT_VK_SUCCESS(err);
17869
17870 // A compatible framebuffer.
17871 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17872 VkFramebuffer fb;
17873 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17874 ASSERT_VK_SUCCESS(err);
17875
17876 // Record a command buffer which just begins and ends the renderpass. The
17877 // bug manifests in BeginRenderPass.
17878 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 -070017879 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017880 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17881 vkCmdEndRenderPass(m_commandBuffer->handle());
17882 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017883 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017884
17885 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17886 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17887}
17888
17889// This is a positive test. No errors are expected.
17890TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17891 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17892 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17893 VkResult result = VK_SUCCESS;
17894 VkImageFormatProperties formatProps;
17895 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17896 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17897 &formatProps);
17898 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17899 return;
17900 }
17901
17902 ASSERT_NO_FATAL_FAILURE(InitState());
17903 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17904 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17905 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17906 VkAttachmentDescription att = {};
17907 VkAttachmentReference ref = {};
17908 att.format = depth_stencil_fmt;
17909 att.samples = VK_SAMPLE_COUNT_1_BIT;
17910 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17911 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17912 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17913 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17914 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17915 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17916
17917 VkClearValue clear;
17918 clear.depthStencil.depth = 1.0;
17919 clear.depthStencil.stencil = 0;
17920 ref.attachment = 0;
17921 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17922
17923 VkSubpassDescription subpass = {};
17924 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17925 subpass.flags = 0;
17926 subpass.inputAttachmentCount = 0;
17927 subpass.pInputAttachments = NULL;
17928 subpass.colorAttachmentCount = 0;
17929 subpass.pColorAttachments = NULL;
17930 subpass.pResolveAttachments = NULL;
17931 subpass.pDepthStencilAttachment = &ref;
17932 subpass.preserveAttachmentCount = 0;
17933 subpass.pPreserveAttachments = NULL;
17934
17935 VkRenderPass rp;
17936 VkRenderPassCreateInfo rp_info = {};
17937 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17938 rp_info.attachmentCount = 1;
17939 rp_info.pAttachments = &att;
17940 rp_info.subpassCount = 1;
17941 rp_info.pSubpasses = &subpass;
17942 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17943 ASSERT_VK_SUCCESS(result);
17944
17945 VkImageView *depthView = m_depthStencil->BindInfo();
17946 VkFramebufferCreateInfo fb_info = {};
17947 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17948 fb_info.pNext = NULL;
17949 fb_info.renderPass = rp;
17950 fb_info.attachmentCount = 1;
17951 fb_info.pAttachments = depthView;
17952 fb_info.width = 100;
17953 fb_info.height = 100;
17954 fb_info.layers = 1;
17955 VkFramebuffer fb;
17956 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17957 ASSERT_VK_SUCCESS(result);
17958
17959 VkRenderPassBeginInfo rpbinfo = {};
17960 rpbinfo.clearValueCount = 1;
17961 rpbinfo.pClearValues = &clear;
17962 rpbinfo.pNext = NULL;
17963 rpbinfo.renderPass = rp;
17964 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17965 rpbinfo.renderArea.extent.width = 100;
17966 rpbinfo.renderArea.extent.height = 100;
17967 rpbinfo.renderArea.offset.x = 0;
17968 rpbinfo.renderArea.offset.y = 0;
17969 rpbinfo.framebuffer = fb;
17970
17971 VkFence fence = {};
17972 VkFenceCreateInfo fence_ci = {};
17973 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17974 fence_ci.pNext = nullptr;
17975 fence_ci.flags = 0;
17976 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17977 ASSERT_VK_SUCCESS(result);
17978
17979 m_commandBuffer->BeginCommandBuffer();
17980 m_commandBuffer->BeginRenderPass(rpbinfo);
17981 m_commandBuffer->EndRenderPass();
17982 m_commandBuffer->EndCommandBuffer();
17983 m_commandBuffer->QueueCommandBuffer(fence);
17984
17985 VkImageObj destImage(m_device);
17986 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17987 VK_IMAGE_TILING_OPTIMAL, 0);
17988 VkImageMemoryBarrier barrier = {};
17989 VkImageSubresourceRange range;
17990 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17991 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17992 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17993 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17994 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17995 barrier.image = m_depthStencil->handle();
17996 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17997 range.baseMipLevel = 0;
17998 range.levelCount = 1;
17999 range.baseArrayLayer = 0;
18000 range.layerCount = 1;
18001 barrier.subresourceRange = range;
18002 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18003 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18004 cmdbuf.BeginCommandBuffer();
18005 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18006 &barrier);
18007 barrier.srcAccessMask = 0;
18008 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18009 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18010 barrier.image = destImage.handle();
18011 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18012 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18013 &barrier);
18014 VkImageCopy cregion;
18015 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18016 cregion.srcSubresource.mipLevel = 0;
18017 cregion.srcSubresource.baseArrayLayer = 0;
18018 cregion.srcSubresource.layerCount = 1;
18019 cregion.srcOffset.x = 0;
18020 cregion.srcOffset.y = 0;
18021 cregion.srcOffset.z = 0;
18022 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18023 cregion.dstSubresource.mipLevel = 0;
18024 cregion.dstSubresource.baseArrayLayer = 0;
18025 cregion.dstSubresource.layerCount = 1;
18026 cregion.dstOffset.x = 0;
18027 cregion.dstOffset.y = 0;
18028 cregion.dstOffset.z = 0;
18029 cregion.extent.width = 100;
18030 cregion.extent.height = 100;
18031 cregion.extent.depth = 1;
18032 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
18033 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
18034 cmdbuf.EndCommandBuffer();
18035
18036 VkSubmitInfo submit_info;
18037 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18038 submit_info.pNext = NULL;
18039 submit_info.waitSemaphoreCount = 0;
18040 submit_info.pWaitSemaphores = NULL;
18041 submit_info.pWaitDstStageMask = NULL;
18042 submit_info.commandBufferCount = 1;
18043 submit_info.pCommandBuffers = &cmdbuf.handle();
18044 submit_info.signalSemaphoreCount = 0;
18045 submit_info.pSignalSemaphores = NULL;
18046
18047 m_errorMonitor->ExpectSuccess();
18048 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18049 m_errorMonitor->VerifyNotFound();
18050
18051 vkQueueWaitIdle(m_device->m_queue);
18052 vkDestroyFence(m_device->device(), fence, nullptr);
18053 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18054 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18055}
18056
18057// This is a positive test. No errors should be generated.
18058TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18059 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18060
18061 m_errorMonitor->ExpectSuccess();
18062 ASSERT_NO_FATAL_FAILURE(InitState());
18063
18064 VkEvent event;
18065 VkEventCreateInfo event_create_info{};
18066 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18067 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18068
18069 VkCommandPool command_pool;
18070 VkCommandPoolCreateInfo pool_create_info{};
18071 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18072 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18073 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18074 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18075
18076 VkCommandBuffer command_buffer;
18077 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18078 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18079 command_buffer_allocate_info.commandPool = command_pool;
18080 command_buffer_allocate_info.commandBufferCount = 1;
18081 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18082 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18083
18084 VkQueue queue = VK_NULL_HANDLE;
18085 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18086
18087 {
18088 VkCommandBufferBeginInfo begin_info{};
18089 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18090 vkBeginCommandBuffer(command_buffer, &begin_info);
18091
18092 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
18093 nullptr, 0, nullptr);
18094 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18095 vkEndCommandBuffer(command_buffer);
18096 }
18097 {
18098 VkSubmitInfo submit_info{};
18099 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18100 submit_info.commandBufferCount = 1;
18101 submit_info.pCommandBuffers = &command_buffer;
18102 submit_info.signalSemaphoreCount = 0;
18103 submit_info.pSignalSemaphores = nullptr;
18104 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18105 }
18106 { vkSetEvent(m_device->device(), event); }
18107
18108 vkQueueWaitIdle(queue);
18109
18110 vkDestroyEvent(m_device->device(), event, nullptr);
18111 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18112 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18113
18114 m_errorMonitor->VerifyNotFound();
18115}
18116// This is a positive test. No errors should be generated.
18117TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18118 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18119
18120 ASSERT_NO_FATAL_FAILURE(InitState());
18121 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18122 return;
18123
18124 m_errorMonitor->ExpectSuccess();
18125
18126 VkQueryPool query_pool;
18127 VkQueryPoolCreateInfo query_pool_create_info{};
18128 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18129 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18130 query_pool_create_info.queryCount = 1;
18131 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18132
18133 VkCommandPool command_pool;
18134 VkCommandPoolCreateInfo pool_create_info{};
18135 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18136 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18137 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18138 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18139
18140 VkCommandBuffer command_buffer;
18141 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18142 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18143 command_buffer_allocate_info.commandPool = command_pool;
18144 command_buffer_allocate_info.commandBufferCount = 1;
18145 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18146 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18147
18148 VkCommandBuffer secondary_command_buffer;
18149 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18150 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18151
18152 VkQueue queue = VK_NULL_HANDLE;
18153 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18154
18155 uint32_t qfi = 0;
18156 VkBufferCreateInfo buff_create_info = {};
18157 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18158 buff_create_info.size = 1024;
18159 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18160 buff_create_info.queueFamilyIndexCount = 1;
18161 buff_create_info.pQueueFamilyIndices = &qfi;
18162
18163 VkResult err;
18164 VkBuffer buffer;
18165 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18166 ASSERT_VK_SUCCESS(err);
18167 VkMemoryAllocateInfo mem_alloc = {};
18168 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18169 mem_alloc.pNext = NULL;
18170 mem_alloc.allocationSize = 1024;
18171 mem_alloc.memoryTypeIndex = 0;
18172
18173 VkMemoryRequirements memReqs;
18174 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18175 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18176 if (!pass) {
18177 vkDestroyBuffer(m_device->device(), buffer, NULL);
18178 return;
18179 }
18180
18181 VkDeviceMemory mem;
18182 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18183 ASSERT_VK_SUCCESS(err);
18184 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18185 ASSERT_VK_SUCCESS(err);
18186
18187 VkCommandBufferInheritanceInfo hinfo = {};
18188 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18189 hinfo.renderPass = VK_NULL_HANDLE;
18190 hinfo.subpass = 0;
18191 hinfo.framebuffer = VK_NULL_HANDLE;
18192 hinfo.occlusionQueryEnable = VK_FALSE;
18193 hinfo.queryFlags = 0;
18194 hinfo.pipelineStatistics = 0;
18195
18196 {
18197 VkCommandBufferBeginInfo begin_info{};
18198 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18199 begin_info.pInheritanceInfo = &hinfo;
18200 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18201
18202 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18203 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18204
18205 vkEndCommandBuffer(secondary_command_buffer);
18206
18207 begin_info.pInheritanceInfo = nullptr;
18208 vkBeginCommandBuffer(command_buffer, &begin_info);
18209
18210 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18211 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18212
18213 vkEndCommandBuffer(command_buffer);
18214 }
18215 {
18216 VkSubmitInfo submit_info{};
18217 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18218 submit_info.commandBufferCount = 1;
18219 submit_info.pCommandBuffers = &command_buffer;
18220 submit_info.signalSemaphoreCount = 0;
18221 submit_info.pSignalSemaphores = nullptr;
18222 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18223 }
18224
18225 vkQueueWaitIdle(queue);
18226
18227 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18228 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18229 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18230 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18231 vkDestroyBuffer(m_device->device(), buffer, NULL);
18232 vkFreeMemory(m_device->device(), mem, NULL);
18233
18234 m_errorMonitor->VerifyNotFound();
18235}
18236
18237// This is a positive test. No errors should be generated.
18238TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18239 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18240
18241 ASSERT_NO_FATAL_FAILURE(InitState());
18242 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18243 return;
18244
18245 m_errorMonitor->ExpectSuccess();
18246
18247 VkQueryPool query_pool;
18248 VkQueryPoolCreateInfo query_pool_create_info{};
18249 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18250 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18251 query_pool_create_info.queryCount = 1;
18252 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18253
18254 VkCommandPool command_pool;
18255 VkCommandPoolCreateInfo pool_create_info{};
18256 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18257 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18258 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18259 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18260
18261 VkCommandBuffer command_buffer[2];
18262 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18263 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18264 command_buffer_allocate_info.commandPool = command_pool;
18265 command_buffer_allocate_info.commandBufferCount = 2;
18266 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18267 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18268
18269 VkQueue queue = VK_NULL_HANDLE;
18270 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18271
18272 uint32_t qfi = 0;
18273 VkBufferCreateInfo buff_create_info = {};
18274 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18275 buff_create_info.size = 1024;
18276 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18277 buff_create_info.queueFamilyIndexCount = 1;
18278 buff_create_info.pQueueFamilyIndices = &qfi;
18279
18280 VkResult err;
18281 VkBuffer buffer;
18282 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18283 ASSERT_VK_SUCCESS(err);
18284 VkMemoryAllocateInfo mem_alloc = {};
18285 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18286 mem_alloc.pNext = NULL;
18287 mem_alloc.allocationSize = 1024;
18288 mem_alloc.memoryTypeIndex = 0;
18289
18290 VkMemoryRequirements memReqs;
18291 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18292 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18293 if (!pass) {
18294 vkDestroyBuffer(m_device->device(), buffer, NULL);
18295 return;
18296 }
18297
18298 VkDeviceMemory mem;
18299 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18300 ASSERT_VK_SUCCESS(err);
18301 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18302 ASSERT_VK_SUCCESS(err);
18303
18304 {
18305 VkCommandBufferBeginInfo begin_info{};
18306 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18307 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18308
18309 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18310 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18311
18312 vkEndCommandBuffer(command_buffer[0]);
18313
18314 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18315
18316 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18317
18318 vkEndCommandBuffer(command_buffer[1]);
18319 }
18320 {
18321 VkSubmitInfo submit_info{};
18322 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18323 submit_info.commandBufferCount = 2;
18324 submit_info.pCommandBuffers = command_buffer;
18325 submit_info.signalSemaphoreCount = 0;
18326 submit_info.pSignalSemaphores = nullptr;
18327 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18328 }
18329
18330 vkQueueWaitIdle(queue);
18331
18332 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18333 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18334 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18335 vkDestroyBuffer(m_device->device(), buffer, NULL);
18336 vkFreeMemory(m_device->device(), mem, NULL);
18337
18338 m_errorMonitor->VerifyNotFound();
18339}
18340
Tony Barbourc46924f2016-11-04 11:49:52 -060018341TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018342 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18343
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018344 ASSERT_NO_FATAL_FAILURE(InitState());
18345 VkEvent event;
18346 VkEventCreateInfo event_create_info{};
18347 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18348 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18349
18350 VkCommandPool command_pool;
18351 VkCommandPoolCreateInfo pool_create_info{};
18352 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18353 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18354 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18355 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18356
18357 VkCommandBuffer command_buffer;
18358 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18359 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18360 command_buffer_allocate_info.commandPool = command_pool;
18361 command_buffer_allocate_info.commandBufferCount = 1;
18362 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18363 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18364
18365 VkQueue queue = VK_NULL_HANDLE;
18366 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18367
18368 {
18369 VkCommandBufferBeginInfo begin_info{};
18370 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18371 vkBeginCommandBuffer(command_buffer, &begin_info);
18372
18373 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018374 vkEndCommandBuffer(command_buffer);
18375 }
18376 {
18377 VkSubmitInfo submit_info{};
18378 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18379 submit_info.commandBufferCount = 1;
18380 submit_info.pCommandBuffers = &command_buffer;
18381 submit_info.signalSemaphoreCount = 0;
18382 submit_info.pSignalSemaphores = nullptr;
18383 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18384 }
18385 {
18386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18387 "command buffer.");
18388 vkSetEvent(m_device->device(), event);
18389 m_errorMonitor->VerifyFound();
18390 }
18391
18392 vkQueueWaitIdle(queue);
18393
18394 vkDestroyEvent(m_device->device(), event, nullptr);
18395 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18396 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18397}
18398
18399// This is a positive test. No errors should be generated.
18400TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18401 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18402 "run through a Submit & WaitForFences cycle 3 times. This "
18403 "previously revealed a bug so running this positive test "
18404 "to prevent a regression.");
18405 m_errorMonitor->ExpectSuccess();
18406
18407 ASSERT_NO_FATAL_FAILURE(InitState());
18408 VkQueue queue = VK_NULL_HANDLE;
18409 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18410
18411 static const uint32_t NUM_OBJECTS = 2;
18412 static const uint32_t NUM_FRAMES = 3;
18413 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18414 VkFence fences[NUM_OBJECTS] = {};
18415
18416 VkCommandPool cmd_pool;
18417 VkCommandPoolCreateInfo cmd_pool_ci = {};
18418 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18419 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18420 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18421 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18422 ASSERT_VK_SUCCESS(err);
18423
18424 VkCommandBufferAllocateInfo cmd_buf_info = {};
18425 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18426 cmd_buf_info.commandPool = cmd_pool;
18427 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18428 cmd_buf_info.commandBufferCount = 1;
18429
18430 VkFenceCreateInfo fence_ci = {};
18431 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18432 fence_ci.pNext = nullptr;
18433 fence_ci.flags = 0;
18434
18435 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18436 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18437 ASSERT_VK_SUCCESS(err);
18438 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18439 ASSERT_VK_SUCCESS(err);
18440 }
18441
18442 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18443 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18444 // Create empty cmd buffer
18445 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18446 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18447
18448 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18449 ASSERT_VK_SUCCESS(err);
18450 err = vkEndCommandBuffer(cmd_buffers[obj]);
18451 ASSERT_VK_SUCCESS(err);
18452
18453 VkSubmitInfo submit_info = {};
18454 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18455 submit_info.commandBufferCount = 1;
18456 submit_info.pCommandBuffers = &cmd_buffers[obj];
18457 // Submit cmd buffer and wait for fence
18458 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18459 ASSERT_VK_SUCCESS(err);
18460 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18461 ASSERT_VK_SUCCESS(err);
18462 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18463 ASSERT_VK_SUCCESS(err);
18464 }
18465 }
18466 m_errorMonitor->VerifyNotFound();
18467 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18468 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18469 vkDestroyFence(m_device->device(), fences[i], nullptr);
18470 }
18471}
18472// This is a positive test. No errors should be generated.
18473TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18474
18475 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18476 "submitted on separate queues followed by a QueueWaitIdle.");
18477
18478 ASSERT_NO_FATAL_FAILURE(InitState());
18479 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18480 return;
18481
18482 m_errorMonitor->ExpectSuccess();
18483
18484 VkSemaphore semaphore;
18485 VkSemaphoreCreateInfo semaphore_create_info{};
18486 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18487 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18488
18489 VkCommandPool command_pool;
18490 VkCommandPoolCreateInfo pool_create_info{};
18491 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18492 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18493 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18494 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18495
18496 VkCommandBuffer command_buffer[2];
18497 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18498 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18499 command_buffer_allocate_info.commandPool = command_pool;
18500 command_buffer_allocate_info.commandBufferCount = 2;
18501 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18502 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18503
18504 VkQueue queue = VK_NULL_HANDLE;
18505 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18506
18507 {
18508 VkCommandBufferBeginInfo begin_info{};
18509 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18510 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18511
18512 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18513 nullptr, 0, nullptr, 0, nullptr);
18514
18515 VkViewport viewport{};
18516 viewport.maxDepth = 1.0f;
18517 viewport.minDepth = 0.0f;
18518 viewport.width = 512;
18519 viewport.height = 512;
18520 viewport.x = 0;
18521 viewport.y = 0;
18522 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18523 vkEndCommandBuffer(command_buffer[0]);
18524 }
18525 {
18526 VkCommandBufferBeginInfo begin_info{};
18527 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18528 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18529
18530 VkViewport viewport{};
18531 viewport.maxDepth = 1.0f;
18532 viewport.minDepth = 0.0f;
18533 viewport.width = 512;
18534 viewport.height = 512;
18535 viewport.x = 0;
18536 viewport.y = 0;
18537 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18538 vkEndCommandBuffer(command_buffer[1]);
18539 }
18540 {
18541 VkSubmitInfo submit_info{};
18542 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18543 submit_info.commandBufferCount = 1;
18544 submit_info.pCommandBuffers = &command_buffer[0];
18545 submit_info.signalSemaphoreCount = 1;
18546 submit_info.pSignalSemaphores = &semaphore;
18547 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18548 }
18549 {
18550 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18551 VkSubmitInfo submit_info{};
18552 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18553 submit_info.commandBufferCount = 1;
18554 submit_info.pCommandBuffers = &command_buffer[1];
18555 submit_info.waitSemaphoreCount = 1;
18556 submit_info.pWaitSemaphores = &semaphore;
18557 submit_info.pWaitDstStageMask = flags;
18558 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18559 }
18560
18561 vkQueueWaitIdle(m_device->m_queue);
18562
18563 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18564 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18565 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18566
18567 m_errorMonitor->VerifyNotFound();
18568}
18569
18570// This is a positive test. No errors should be generated.
18571TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18572
18573 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18574 "submitted on separate queues, the second having a fence"
18575 "followed by a QueueWaitIdle.");
18576
18577 ASSERT_NO_FATAL_FAILURE(InitState());
18578 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18579 return;
18580
18581 m_errorMonitor->ExpectSuccess();
18582
18583 VkFence fence;
18584 VkFenceCreateInfo fence_create_info{};
18585 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18586 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18587
18588 VkSemaphore semaphore;
18589 VkSemaphoreCreateInfo semaphore_create_info{};
18590 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18591 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18592
18593 VkCommandPool command_pool;
18594 VkCommandPoolCreateInfo pool_create_info{};
18595 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18596 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18597 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18598 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18599
18600 VkCommandBuffer command_buffer[2];
18601 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18602 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18603 command_buffer_allocate_info.commandPool = command_pool;
18604 command_buffer_allocate_info.commandBufferCount = 2;
18605 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18606 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18607
18608 VkQueue queue = VK_NULL_HANDLE;
18609 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18610
18611 {
18612 VkCommandBufferBeginInfo begin_info{};
18613 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18614 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18615
18616 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18617 nullptr, 0, nullptr, 0, nullptr);
18618
18619 VkViewport viewport{};
18620 viewport.maxDepth = 1.0f;
18621 viewport.minDepth = 0.0f;
18622 viewport.width = 512;
18623 viewport.height = 512;
18624 viewport.x = 0;
18625 viewport.y = 0;
18626 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18627 vkEndCommandBuffer(command_buffer[0]);
18628 }
18629 {
18630 VkCommandBufferBeginInfo begin_info{};
18631 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18632 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18633
18634 VkViewport viewport{};
18635 viewport.maxDepth = 1.0f;
18636 viewport.minDepth = 0.0f;
18637 viewport.width = 512;
18638 viewport.height = 512;
18639 viewport.x = 0;
18640 viewport.y = 0;
18641 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18642 vkEndCommandBuffer(command_buffer[1]);
18643 }
18644 {
18645 VkSubmitInfo submit_info{};
18646 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18647 submit_info.commandBufferCount = 1;
18648 submit_info.pCommandBuffers = &command_buffer[0];
18649 submit_info.signalSemaphoreCount = 1;
18650 submit_info.pSignalSemaphores = &semaphore;
18651 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18652 }
18653 {
18654 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18655 VkSubmitInfo submit_info{};
18656 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18657 submit_info.commandBufferCount = 1;
18658 submit_info.pCommandBuffers = &command_buffer[1];
18659 submit_info.waitSemaphoreCount = 1;
18660 submit_info.pWaitSemaphores = &semaphore;
18661 submit_info.pWaitDstStageMask = flags;
18662 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18663 }
18664
18665 vkQueueWaitIdle(m_device->m_queue);
18666
18667 vkDestroyFence(m_device->device(), fence, nullptr);
18668 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18669 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18670 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18671
18672 m_errorMonitor->VerifyNotFound();
18673}
18674
18675// This is a positive test. No errors should be generated.
18676TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18677
18678 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18679 "submitted on separate queues, the second having a fence"
18680 "followed by two consecutive WaitForFences calls on the same fence.");
18681
18682 ASSERT_NO_FATAL_FAILURE(InitState());
18683 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18684 return;
18685
18686 m_errorMonitor->ExpectSuccess();
18687
18688 VkFence fence;
18689 VkFenceCreateInfo fence_create_info{};
18690 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18691 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18692
18693 VkSemaphore semaphore;
18694 VkSemaphoreCreateInfo semaphore_create_info{};
18695 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18696 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18697
18698 VkCommandPool command_pool;
18699 VkCommandPoolCreateInfo pool_create_info{};
18700 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18701 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18702 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18703 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18704
18705 VkCommandBuffer command_buffer[2];
18706 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18707 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18708 command_buffer_allocate_info.commandPool = command_pool;
18709 command_buffer_allocate_info.commandBufferCount = 2;
18710 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18711 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18712
18713 VkQueue queue = VK_NULL_HANDLE;
18714 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18715
18716 {
18717 VkCommandBufferBeginInfo begin_info{};
18718 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18719 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18720
18721 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18722 nullptr, 0, nullptr, 0, nullptr);
18723
18724 VkViewport viewport{};
18725 viewport.maxDepth = 1.0f;
18726 viewport.minDepth = 0.0f;
18727 viewport.width = 512;
18728 viewport.height = 512;
18729 viewport.x = 0;
18730 viewport.y = 0;
18731 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18732 vkEndCommandBuffer(command_buffer[0]);
18733 }
18734 {
18735 VkCommandBufferBeginInfo begin_info{};
18736 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18737 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18738
18739 VkViewport viewport{};
18740 viewport.maxDepth = 1.0f;
18741 viewport.minDepth = 0.0f;
18742 viewport.width = 512;
18743 viewport.height = 512;
18744 viewport.x = 0;
18745 viewport.y = 0;
18746 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18747 vkEndCommandBuffer(command_buffer[1]);
18748 }
18749 {
18750 VkSubmitInfo submit_info{};
18751 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18752 submit_info.commandBufferCount = 1;
18753 submit_info.pCommandBuffers = &command_buffer[0];
18754 submit_info.signalSemaphoreCount = 1;
18755 submit_info.pSignalSemaphores = &semaphore;
18756 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18757 }
18758 {
18759 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18760 VkSubmitInfo submit_info{};
18761 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18762 submit_info.commandBufferCount = 1;
18763 submit_info.pCommandBuffers = &command_buffer[1];
18764 submit_info.waitSemaphoreCount = 1;
18765 submit_info.pWaitSemaphores = &semaphore;
18766 submit_info.pWaitDstStageMask = flags;
18767 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18768 }
18769
18770 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18771 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18772
18773 vkDestroyFence(m_device->device(), fence, nullptr);
18774 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18775 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18776 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18777
18778 m_errorMonitor->VerifyNotFound();
18779}
18780
18781TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18782
18783 ASSERT_NO_FATAL_FAILURE(InitState());
18784 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18785 printf("Test requires two queues, skipping\n");
18786 return;
18787 }
18788
18789 VkResult err;
18790
18791 m_errorMonitor->ExpectSuccess();
18792
18793 VkQueue q0 = m_device->m_queue;
18794 VkQueue q1 = nullptr;
18795 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18796 ASSERT_NE(q1, nullptr);
18797
18798 // An (empty) command buffer. We must have work in the first submission --
18799 // the layer treats unfenced work differently from fenced work.
18800 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18801 VkCommandPool pool;
18802 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18803 ASSERT_VK_SUCCESS(err);
18804 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18805 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18806 VkCommandBuffer cb;
18807 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18808 ASSERT_VK_SUCCESS(err);
18809 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18810 err = vkBeginCommandBuffer(cb, &cbbi);
18811 ASSERT_VK_SUCCESS(err);
18812 err = vkEndCommandBuffer(cb);
18813 ASSERT_VK_SUCCESS(err);
18814
18815 // A semaphore
18816 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18817 VkSemaphore s;
18818 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18819 ASSERT_VK_SUCCESS(err);
18820
18821 // First submission, to q0
18822 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18823
18824 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18825 ASSERT_VK_SUCCESS(err);
18826
18827 // Second submission, to q1, waiting on s
18828 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18829 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18830
18831 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18832 ASSERT_VK_SUCCESS(err);
18833
18834 // Wait for q0 idle
18835 err = vkQueueWaitIdle(q0);
18836 ASSERT_VK_SUCCESS(err);
18837
18838 // Command buffer should have been completed (it was on q0); reset the pool.
18839 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18840
18841 m_errorMonitor->VerifyNotFound();
18842
18843 // Force device completely idle and clean up resources
18844 vkDeviceWaitIdle(m_device->device());
18845 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18846 vkDestroySemaphore(m_device->device(), s, nullptr);
18847}
18848
18849// This is a positive test. No errors should be generated.
18850TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18851
18852 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18853 "submitted on separate queues, the second having a fence, "
18854 "followed by a WaitForFences call.");
18855
18856 ASSERT_NO_FATAL_FAILURE(InitState());
18857 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18858 return;
18859
18860 m_errorMonitor->ExpectSuccess();
18861
18862 ASSERT_NO_FATAL_FAILURE(InitState());
18863 VkFence fence;
18864 VkFenceCreateInfo fence_create_info{};
18865 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18866 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18867
18868 VkSemaphore semaphore;
18869 VkSemaphoreCreateInfo semaphore_create_info{};
18870 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18871 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18872
18873 VkCommandPool command_pool;
18874 VkCommandPoolCreateInfo pool_create_info{};
18875 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18876 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18877 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18878 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18879
18880 VkCommandBuffer command_buffer[2];
18881 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18882 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18883 command_buffer_allocate_info.commandPool = command_pool;
18884 command_buffer_allocate_info.commandBufferCount = 2;
18885 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18886 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18887
18888 VkQueue queue = VK_NULL_HANDLE;
18889 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18890
18891 {
18892 VkCommandBufferBeginInfo begin_info{};
18893 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18894 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18895
18896 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18897 nullptr, 0, nullptr, 0, nullptr);
18898
18899 VkViewport viewport{};
18900 viewport.maxDepth = 1.0f;
18901 viewport.minDepth = 0.0f;
18902 viewport.width = 512;
18903 viewport.height = 512;
18904 viewport.x = 0;
18905 viewport.y = 0;
18906 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18907 vkEndCommandBuffer(command_buffer[0]);
18908 }
18909 {
18910 VkCommandBufferBeginInfo begin_info{};
18911 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18912 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18913
18914 VkViewport viewport{};
18915 viewport.maxDepth = 1.0f;
18916 viewport.minDepth = 0.0f;
18917 viewport.width = 512;
18918 viewport.height = 512;
18919 viewport.x = 0;
18920 viewport.y = 0;
18921 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18922 vkEndCommandBuffer(command_buffer[1]);
18923 }
18924 {
18925 VkSubmitInfo submit_info{};
18926 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18927 submit_info.commandBufferCount = 1;
18928 submit_info.pCommandBuffers = &command_buffer[0];
18929 submit_info.signalSemaphoreCount = 1;
18930 submit_info.pSignalSemaphores = &semaphore;
18931 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18932 }
18933 {
18934 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18935 VkSubmitInfo submit_info{};
18936 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18937 submit_info.commandBufferCount = 1;
18938 submit_info.pCommandBuffers = &command_buffer[1];
18939 submit_info.waitSemaphoreCount = 1;
18940 submit_info.pWaitSemaphores = &semaphore;
18941 submit_info.pWaitDstStageMask = flags;
18942 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18943 }
18944
18945 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18946
18947 vkDestroyFence(m_device->device(), fence, nullptr);
18948 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18949 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18950 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18951
18952 m_errorMonitor->VerifyNotFound();
18953}
18954
18955// This is a positive test. No errors should be generated.
18956TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18957
18958 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18959 "on the same queue, sharing a signal/wait semaphore, the "
18960 "second having a fence, "
18961 "followed by a WaitForFences call.");
18962
18963 m_errorMonitor->ExpectSuccess();
18964
18965 ASSERT_NO_FATAL_FAILURE(InitState());
18966 VkFence fence;
18967 VkFenceCreateInfo fence_create_info{};
18968 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18969 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18970
18971 VkSemaphore semaphore;
18972 VkSemaphoreCreateInfo semaphore_create_info{};
18973 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18974 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18975
18976 VkCommandPool command_pool;
18977 VkCommandPoolCreateInfo pool_create_info{};
18978 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18979 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18980 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18981 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18982
18983 VkCommandBuffer command_buffer[2];
18984 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18985 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18986 command_buffer_allocate_info.commandPool = command_pool;
18987 command_buffer_allocate_info.commandBufferCount = 2;
18988 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18989 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18990
18991 {
18992 VkCommandBufferBeginInfo begin_info{};
18993 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18994 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18995
18996 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18997 nullptr, 0, nullptr, 0, nullptr);
18998
18999 VkViewport viewport{};
19000 viewport.maxDepth = 1.0f;
19001 viewport.minDepth = 0.0f;
19002 viewport.width = 512;
19003 viewport.height = 512;
19004 viewport.x = 0;
19005 viewport.y = 0;
19006 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19007 vkEndCommandBuffer(command_buffer[0]);
19008 }
19009 {
19010 VkCommandBufferBeginInfo begin_info{};
19011 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19012 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19013
19014 VkViewport viewport{};
19015 viewport.maxDepth = 1.0f;
19016 viewport.minDepth = 0.0f;
19017 viewport.width = 512;
19018 viewport.height = 512;
19019 viewport.x = 0;
19020 viewport.y = 0;
19021 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19022 vkEndCommandBuffer(command_buffer[1]);
19023 }
19024 {
19025 VkSubmitInfo submit_info{};
19026 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19027 submit_info.commandBufferCount = 1;
19028 submit_info.pCommandBuffers = &command_buffer[0];
19029 submit_info.signalSemaphoreCount = 1;
19030 submit_info.pSignalSemaphores = &semaphore;
19031 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19032 }
19033 {
19034 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19035 VkSubmitInfo submit_info{};
19036 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19037 submit_info.commandBufferCount = 1;
19038 submit_info.pCommandBuffers = &command_buffer[1];
19039 submit_info.waitSemaphoreCount = 1;
19040 submit_info.pWaitSemaphores = &semaphore;
19041 submit_info.pWaitDstStageMask = flags;
19042 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19043 }
19044
19045 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19046
19047 vkDestroyFence(m_device->device(), fence, nullptr);
19048 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19049 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19050 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19051
19052 m_errorMonitor->VerifyNotFound();
19053}
19054
19055// This is a positive test. No errors should be generated.
19056TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
19057
19058 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19059 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19060 "SubmitInfos but with a fence, followed by a WaitForFences call.");
19061
19062 m_errorMonitor->ExpectSuccess();
19063
19064 ASSERT_NO_FATAL_FAILURE(InitState());
19065 VkFence fence;
19066 VkFenceCreateInfo fence_create_info{};
19067 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19068 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19069
19070 VkCommandPool command_pool;
19071 VkCommandPoolCreateInfo pool_create_info{};
19072 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19073 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19074 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19075 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19076
19077 VkCommandBuffer command_buffer[2];
19078 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19079 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19080 command_buffer_allocate_info.commandPool = command_pool;
19081 command_buffer_allocate_info.commandBufferCount = 2;
19082 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19083 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19084
19085 {
19086 VkCommandBufferBeginInfo begin_info{};
19087 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19088 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19089
19090 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19091 nullptr, 0, nullptr, 0, nullptr);
19092
19093 VkViewport viewport{};
19094 viewport.maxDepth = 1.0f;
19095 viewport.minDepth = 0.0f;
19096 viewport.width = 512;
19097 viewport.height = 512;
19098 viewport.x = 0;
19099 viewport.y = 0;
19100 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19101 vkEndCommandBuffer(command_buffer[0]);
19102 }
19103 {
19104 VkCommandBufferBeginInfo begin_info{};
19105 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19106 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19107
19108 VkViewport viewport{};
19109 viewport.maxDepth = 1.0f;
19110 viewport.minDepth = 0.0f;
19111 viewport.width = 512;
19112 viewport.height = 512;
19113 viewport.x = 0;
19114 viewport.y = 0;
19115 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19116 vkEndCommandBuffer(command_buffer[1]);
19117 }
19118 {
19119 VkSubmitInfo submit_info{};
19120 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19121 submit_info.commandBufferCount = 1;
19122 submit_info.pCommandBuffers = &command_buffer[0];
19123 submit_info.signalSemaphoreCount = 0;
19124 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19125 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19126 }
19127 {
19128 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19129 VkSubmitInfo submit_info{};
19130 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19131 submit_info.commandBufferCount = 1;
19132 submit_info.pCommandBuffers = &command_buffer[1];
19133 submit_info.waitSemaphoreCount = 0;
19134 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19135 submit_info.pWaitDstStageMask = flags;
19136 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19137 }
19138
19139 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19140
19141 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19142 ASSERT_VK_SUCCESS(err);
19143
19144 vkDestroyFence(m_device->device(), fence, nullptr);
19145 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19146 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19147
19148 m_errorMonitor->VerifyNotFound();
19149}
19150
19151// This is a positive test. No errors should be generated.
19152TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19153
19154 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19155 "on the same queue, the second having a fence, followed "
19156 "by a WaitForFences call.");
19157
19158 m_errorMonitor->ExpectSuccess();
19159
19160 ASSERT_NO_FATAL_FAILURE(InitState());
19161 VkFence fence;
19162 VkFenceCreateInfo fence_create_info{};
19163 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19164 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19165
19166 VkCommandPool command_pool;
19167 VkCommandPoolCreateInfo pool_create_info{};
19168 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19169 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19170 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19171 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19172
19173 VkCommandBuffer command_buffer[2];
19174 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19175 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19176 command_buffer_allocate_info.commandPool = command_pool;
19177 command_buffer_allocate_info.commandBufferCount = 2;
19178 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19179 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19180
19181 {
19182 VkCommandBufferBeginInfo begin_info{};
19183 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19184 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19185
19186 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19187 nullptr, 0, nullptr, 0, nullptr);
19188
19189 VkViewport viewport{};
19190 viewport.maxDepth = 1.0f;
19191 viewport.minDepth = 0.0f;
19192 viewport.width = 512;
19193 viewport.height = 512;
19194 viewport.x = 0;
19195 viewport.y = 0;
19196 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19197 vkEndCommandBuffer(command_buffer[0]);
19198 }
19199 {
19200 VkCommandBufferBeginInfo begin_info{};
19201 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19202 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19203
19204 VkViewport viewport{};
19205 viewport.maxDepth = 1.0f;
19206 viewport.minDepth = 0.0f;
19207 viewport.width = 512;
19208 viewport.height = 512;
19209 viewport.x = 0;
19210 viewport.y = 0;
19211 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19212 vkEndCommandBuffer(command_buffer[1]);
19213 }
19214 {
19215 VkSubmitInfo submit_info{};
19216 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19217 submit_info.commandBufferCount = 1;
19218 submit_info.pCommandBuffers = &command_buffer[0];
19219 submit_info.signalSemaphoreCount = 0;
19220 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19221 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19222 }
19223 {
19224 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19225 VkSubmitInfo submit_info{};
19226 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19227 submit_info.commandBufferCount = 1;
19228 submit_info.pCommandBuffers = &command_buffer[1];
19229 submit_info.waitSemaphoreCount = 0;
19230 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19231 submit_info.pWaitDstStageMask = flags;
19232 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19233 }
19234
19235 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19236
19237 vkDestroyFence(m_device->device(), fence, nullptr);
19238 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19239 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19240
19241 m_errorMonitor->VerifyNotFound();
19242}
19243
19244// This is a positive test. No errors should be generated.
19245TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19246
19247 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19248 "QueueSubmit call followed by a WaitForFences call.");
19249 ASSERT_NO_FATAL_FAILURE(InitState());
19250
19251 m_errorMonitor->ExpectSuccess();
19252
19253 VkFence fence;
19254 VkFenceCreateInfo fence_create_info{};
19255 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19256 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19257
19258 VkSemaphore semaphore;
19259 VkSemaphoreCreateInfo semaphore_create_info{};
19260 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19261 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19262
19263 VkCommandPool command_pool;
19264 VkCommandPoolCreateInfo pool_create_info{};
19265 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19266 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19267 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19268 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19269
19270 VkCommandBuffer command_buffer[2];
19271 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19272 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19273 command_buffer_allocate_info.commandPool = command_pool;
19274 command_buffer_allocate_info.commandBufferCount = 2;
19275 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19276 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19277
19278 {
19279 VkCommandBufferBeginInfo begin_info{};
19280 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19281 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19282
19283 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19284 nullptr, 0, nullptr, 0, nullptr);
19285
19286 VkViewport viewport{};
19287 viewport.maxDepth = 1.0f;
19288 viewport.minDepth = 0.0f;
19289 viewport.width = 512;
19290 viewport.height = 512;
19291 viewport.x = 0;
19292 viewport.y = 0;
19293 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19294 vkEndCommandBuffer(command_buffer[0]);
19295 }
19296 {
19297 VkCommandBufferBeginInfo begin_info{};
19298 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19299 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19300
19301 VkViewport viewport{};
19302 viewport.maxDepth = 1.0f;
19303 viewport.minDepth = 0.0f;
19304 viewport.width = 512;
19305 viewport.height = 512;
19306 viewport.x = 0;
19307 viewport.y = 0;
19308 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19309 vkEndCommandBuffer(command_buffer[1]);
19310 }
19311 {
19312 VkSubmitInfo submit_info[2];
19313 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19314
19315 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19316 submit_info[0].pNext = NULL;
19317 submit_info[0].commandBufferCount = 1;
19318 submit_info[0].pCommandBuffers = &command_buffer[0];
19319 submit_info[0].signalSemaphoreCount = 1;
19320 submit_info[0].pSignalSemaphores = &semaphore;
19321 submit_info[0].waitSemaphoreCount = 0;
19322 submit_info[0].pWaitSemaphores = NULL;
19323 submit_info[0].pWaitDstStageMask = 0;
19324
19325 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19326 submit_info[1].pNext = NULL;
19327 submit_info[1].commandBufferCount = 1;
19328 submit_info[1].pCommandBuffers = &command_buffer[1];
19329 submit_info[1].waitSemaphoreCount = 1;
19330 submit_info[1].pWaitSemaphores = &semaphore;
19331 submit_info[1].pWaitDstStageMask = flags;
19332 submit_info[1].signalSemaphoreCount = 0;
19333 submit_info[1].pSignalSemaphores = NULL;
19334 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19335 }
19336
19337 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19338
19339 vkDestroyFence(m_device->device(), fence, nullptr);
19340 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19341 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19342 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19343
19344 m_errorMonitor->VerifyNotFound();
19345}
19346
19347TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19348 m_errorMonitor->ExpectSuccess();
19349
19350 ASSERT_NO_FATAL_FAILURE(InitState());
19351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19352
Tony Barbour552f6c02016-12-21 14:34:07 -070019353 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019354
19355 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19356 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19357 m_errorMonitor->VerifyNotFound();
19358 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19359 m_errorMonitor->VerifyNotFound();
19360 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19361 m_errorMonitor->VerifyNotFound();
19362
19363 m_commandBuffer->EndCommandBuffer();
19364 m_errorMonitor->VerifyNotFound();
19365}
19366
19367TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19368 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19369 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19370 "has a valid layout, and a second subpass then uses a "
19371 "valid *READ_ONLY* layout.");
19372 m_errorMonitor->ExpectSuccess();
19373 ASSERT_NO_FATAL_FAILURE(InitState());
19374
19375 VkAttachmentReference attach[2] = {};
19376 attach[0].attachment = 0;
19377 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19378 attach[1].attachment = 0;
19379 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19380 VkSubpassDescription subpasses[2] = {};
19381 // First subpass clears DS attach on load
19382 subpasses[0].pDepthStencilAttachment = &attach[0];
19383 // 2nd subpass reads in DS as input attachment
19384 subpasses[1].inputAttachmentCount = 1;
19385 subpasses[1].pInputAttachments = &attach[1];
19386 VkAttachmentDescription attach_desc = {};
19387 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19388 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19389 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19390 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19391 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19392 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19393 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19394 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19395 VkRenderPassCreateInfo rpci = {};
19396 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19397 rpci.attachmentCount = 1;
19398 rpci.pAttachments = &attach_desc;
19399 rpci.subpassCount = 2;
19400 rpci.pSubpasses = subpasses;
19401
19402 // Now create RenderPass and verify no errors
19403 VkRenderPass rp;
19404 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19405 m_errorMonitor->VerifyNotFound();
19406
19407 vkDestroyRenderPass(m_device->device(), rp, NULL);
19408}
19409
19410TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19411 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19412 "as vertex attributes");
19413 m_errorMonitor->ExpectSuccess();
19414
19415 ASSERT_NO_FATAL_FAILURE(InitState());
19416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19417
19418 VkVertexInputBindingDescription input_binding;
19419 memset(&input_binding, 0, sizeof(input_binding));
19420
19421 VkVertexInputAttributeDescription input_attribs[2];
19422 memset(input_attribs, 0, sizeof(input_attribs));
19423
19424 for (int i = 0; i < 2; i++) {
19425 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19426 input_attribs[i].location = i;
19427 }
19428
19429 char const *vsSource = "#version 450\n"
19430 "\n"
19431 "layout(location=0) in mat2x4 x;\n"
19432 "out gl_PerVertex {\n"
19433 " vec4 gl_Position;\n"
19434 "};\n"
19435 "void main(){\n"
19436 " gl_Position = x[0] + x[1];\n"
19437 "}\n";
19438 char const *fsSource = "#version 450\n"
19439 "\n"
19440 "layout(location=0) out vec4 color;\n"
19441 "void main(){\n"
19442 " color = vec4(1);\n"
19443 "}\n";
19444
19445 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19446 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19447
19448 VkPipelineObj pipe(m_device);
19449 pipe.AddColorAttachment();
19450 pipe.AddShader(&vs);
19451 pipe.AddShader(&fs);
19452
19453 pipe.AddVertexInputBindings(&input_binding, 1);
19454 pipe.AddVertexInputAttribs(input_attribs, 2);
19455
19456 VkDescriptorSetObj descriptorSet(m_device);
19457 descriptorSet.AppendDummy();
19458 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19459
19460 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19461
19462 /* expect success */
19463 m_errorMonitor->VerifyNotFound();
19464}
19465
19466TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19467 m_errorMonitor->ExpectSuccess();
19468
19469 ASSERT_NO_FATAL_FAILURE(InitState());
19470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19471
19472 VkVertexInputBindingDescription input_binding;
19473 memset(&input_binding, 0, sizeof(input_binding));
19474
19475 VkVertexInputAttributeDescription input_attribs[2];
19476 memset(input_attribs, 0, sizeof(input_attribs));
19477
19478 for (int i = 0; i < 2; i++) {
19479 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19480 input_attribs[i].location = i;
19481 }
19482
19483 char const *vsSource = "#version 450\n"
19484 "\n"
19485 "layout(location=0) in vec4 x[2];\n"
19486 "out gl_PerVertex {\n"
19487 " vec4 gl_Position;\n"
19488 "};\n"
19489 "void main(){\n"
19490 " gl_Position = x[0] + x[1];\n"
19491 "}\n";
19492 char const *fsSource = "#version 450\n"
19493 "\n"
19494 "layout(location=0) out vec4 color;\n"
19495 "void main(){\n"
19496 " color = vec4(1);\n"
19497 "}\n";
19498
19499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19501
19502 VkPipelineObj pipe(m_device);
19503 pipe.AddColorAttachment();
19504 pipe.AddShader(&vs);
19505 pipe.AddShader(&fs);
19506
19507 pipe.AddVertexInputBindings(&input_binding, 1);
19508 pipe.AddVertexInputAttribs(input_attribs, 2);
19509
19510 VkDescriptorSetObj descriptorSet(m_device);
19511 descriptorSet.AppendDummy();
19512 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19513
19514 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19515
19516 m_errorMonitor->VerifyNotFound();
19517}
19518
19519TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19520 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19521 "through multiple vertex shader inputs, each consuming a different "
19522 "subset of the components.");
19523 m_errorMonitor->ExpectSuccess();
19524
19525 ASSERT_NO_FATAL_FAILURE(InitState());
19526 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19527
19528 VkVertexInputBindingDescription input_binding;
19529 memset(&input_binding, 0, sizeof(input_binding));
19530
19531 VkVertexInputAttributeDescription input_attribs[3];
19532 memset(input_attribs, 0, sizeof(input_attribs));
19533
19534 for (int i = 0; i < 3; i++) {
19535 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19536 input_attribs[i].location = i;
19537 }
19538
19539 char const *vsSource = "#version 450\n"
19540 "\n"
19541 "layout(location=0) in vec4 x;\n"
19542 "layout(location=1) in vec3 y1;\n"
19543 "layout(location=1, component=3) in float y2;\n"
19544 "layout(location=2) in vec4 z;\n"
19545 "out gl_PerVertex {\n"
19546 " vec4 gl_Position;\n"
19547 "};\n"
19548 "void main(){\n"
19549 " gl_Position = x + vec4(y1, y2) + z;\n"
19550 "}\n";
19551 char const *fsSource = "#version 450\n"
19552 "\n"
19553 "layout(location=0) out vec4 color;\n"
19554 "void main(){\n"
19555 " color = vec4(1);\n"
19556 "}\n";
19557
19558 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19559 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19560
19561 VkPipelineObj pipe(m_device);
19562 pipe.AddColorAttachment();
19563 pipe.AddShader(&vs);
19564 pipe.AddShader(&fs);
19565
19566 pipe.AddVertexInputBindings(&input_binding, 1);
19567 pipe.AddVertexInputAttribs(input_attribs, 3);
19568
19569 VkDescriptorSetObj descriptorSet(m_device);
19570 descriptorSet.AppendDummy();
19571 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19572
19573 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19574
19575 m_errorMonitor->VerifyNotFound();
19576}
19577
19578TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19579 m_errorMonitor->ExpectSuccess();
19580
19581 ASSERT_NO_FATAL_FAILURE(InitState());
19582 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19583
19584 char const *vsSource = "#version 450\n"
19585 "out gl_PerVertex {\n"
19586 " vec4 gl_Position;\n"
19587 "};\n"
19588 "void main(){\n"
19589 " gl_Position = vec4(0);\n"
19590 "}\n";
19591 char const *fsSource = "#version 450\n"
19592 "\n"
19593 "layout(location=0) out vec4 color;\n"
19594 "void main(){\n"
19595 " color = vec4(1);\n"
19596 "}\n";
19597
19598 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19599 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19600
19601 VkPipelineObj pipe(m_device);
19602 pipe.AddColorAttachment();
19603 pipe.AddShader(&vs);
19604 pipe.AddShader(&fs);
19605
19606 VkDescriptorSetObj descriptorSet(m_device);
19607 descriptorSet.AppendDummy();
19608 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19609
19610 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19611
19612 m_errorMonitor->VerifyNotFound();
19613}
19614
19615TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19616 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19617 "set out in 14.1.3: fundamental type must match, and producer side must "
19618 "have at least as many components");
19619 m_errorMonitor->ExpectSuccess();
19620
19621 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19622
19623 ASSERT_NO_FATAL_FAILURE(InitState());
19624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19625
19626 char const *vsSource = "#version 450\n"
19627 "out gl_PerVertex {\n"
19628 " vec4 gl_Position;\n"
19629 "};\n"
19630 "layout(location=0) out vec3 x;\n"
19631 "layout(location=1) out ivec3 y;\n"
19632 "layout(location=2) out vec3 z;\n"
19633 "void main(){\n"
19634 " gl_Position = vec4(0);\n"
19635 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19636 "}\n";
19637 char const *fsSource = "#version 450\n"
19638 "\n"
19639 "layout(location=0) out vec4 color;\n"
19640 "layout(location=0) in float x;\n"
19641 "layout(location=1) flat in int y;\n"
19642 "layout(location=2) in vec2 z;\n"
19643 "void main(){\n"
19644 " color = vec4(1 + x + y + z.x);\n"
19645 "}\n";
19646
19647 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19648 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19649
19650 VkPipelineObj pipe(m_device);
19651 pipe.AddColorAttachment();
19652 pipe.AddShader(&vs);
19653 pipe.AddShader(&fs);
19654
19655 VkDescriptorSetObj descriptorSet(m_device);
19656 descriptorSet.AppendDummy();
19657 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19658
19659 VkResult err = VK_SUCCESS;
19660 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19661 ASSERT_VK_SUCCESS(err);
19662
19663 m_errorMonitor->VerifyNotFound();
19664}
19665
19666TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19667 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19668 "passed between the TCS and TES stages");
19669 m_errorMonitor->ExpectSuccess();
19670
19671 ASSERT_NO_FATAL_FAILURE(InitState());
19672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19673
19674 if (!m_device->phy().features().tessellationShader) {
19675 printf("Device does not support tessellation shaders; skipped.\n");
19676 return;
19677 }
19678
19679 char const *vsSource = "#version 450\n"
19680 "void main(){}\n";
19681 char const *tcsSource = "#version 450\n"
19682 "layout(location=0) out int x[];\n"
19683 "layout(vertices=3) out;\n"
19684 "void main(){\n"
19685 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19686 " gl_TessLevelInner[0] = 1;\n"
19687 " x[gl_InvocationID] = gl_InvocationID;\n"
19688 "}\n";
19689 char const *tesSource = "#version 450\n"
19690 "layout(triangles, equal_spacing, cw) in;\n"
19691 "layout(location=0) in int x[];\n"
19692 "out gl_PerVertex { vec4 gl_Position; };\n"
19693 "void main(){\n"
19694 " gl_Position.xyz = gl_TessCoord;\n"
19695 " gl_Position.w = x[0] + x[1] + x[2];\n"
19696 "}\n";
19697 char const *fsSource = "#version 450\n"
19698 "layout(location=0) out vec4 color;\n"
19699 "void main(){\n"
19700 " color = vec4(1);\n"
19701 "}\n";
19702
19703 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19704 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19705 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19706 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19707
19708 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19709 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19710
19711 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19712
19713 VkPipelineObj pipe(m_device);
19714 pipe.SetInputAssembly(&iasci);
19715 pipe.SetTessellation(&tsci);
19716 pipe.AddColorAttachment();
19717 pipe.AddShader(&vs);
19718 pipe.AddShader(&tcs);
19719 pipe.AddShader(&tes);
19720 pipe.AddShader(&fs);
19721
19722 VkDescriptorSetObj descriptorSet(m_device);
19723 descriptorSet.AppendDummy();
19724 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19725
19726 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19727
19728 m_errorMonitor->VerifyNotFound();
19729}
19730
19731TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19732 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19733 "interface block passed into the geometry shader. This "
19734 "is interesting because the 'extra' array level is not "
19735 "present on the member type, but on the block instance.");
19736 m_errorMonitor->ExpectSuccess();
19737
19738 ASSERT_NO_FATAL_FAILURE(InitState());
19739 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19740
19741 if (!m_device->phy().features().geometryShader) {
19742 printf("Device does not support geometry shaders; skipped.\n");
19743 return;
19744 }
19745
19746 char const *vsSource = "#version 450\n"
19747 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19748 "void main(){\n"
19749 " vs_out.x = vec4(1);\n"
19750 "}\n";
19751 char const *gsSource = "#version 450\n"
19752 "layout(triangles) in;\n"
19753 "layout(triangle_strip, max_vertices=3) out;\n"
19754 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19755 "out gl_PerVertex { vec4 gl_Position; };\n"
19756 "void main() {\n"
19757 " gl_Position = gs_in[0].x;\n"
19758 " EmitVertex();\n"
19759 "}\n";
19760 char const *fsSource = "#version 450\n"
19761 "layout(location=0) out vec4 color;\n"
19762 "void main(){\n"
19763 " color = vec4(1);\n"
19764 "}\n";
19765
19766 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19767 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19768 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19769
19770 VkPipelineObj pipe(m_device);
19771 pipe.AddColorAttachment();
19772 pipe.AddShader(&vs);
19773 pipe.AddShader(&gs);
19774 pipe.AddShader(&fs);
19775
19776 VkDescriptorSetObj descriptorSet(m_device);
19777 descriptorSet.AppendDummy();
19778 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19779
19780 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19781
19782 m_errorMonitor->VerifyNotFound();
19783}
19784
19785TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19786 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19787 "attributes. This is interesting because they consume multiple "
19788 "locations.");
19789 m_errorMonitor->ExpectSuccess();
19790
19791 ASSERT_NO_FATAL_FAILURE(InitState());
19792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19793
19794 if (!m_device->phy().features().shaderFloat64) {
19795 printf("Device does not support 64bit vertex attributes; skipped.\n");
19796 return;
19797 }
19798
19799 VkVertexInputBindingDescription input_bindings[1];
19800 memset(input_bindings, 0, sizeof(input_bindings));
19801
19802 VkVertexInputAttributeDescription input_attribs[4];
19803 memset(input_attribs, 0, sizeof(input_attribs));
19804 input_attribs[0].location = 0;
19805 input_attribs[0].offset = 0;
19806 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19807 input_attribs[1].location = 2;
19808 input_attribs[1].offset = 32;
19809 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19810 input_attribs[2].location = 4;
19811 input_attribs[2].offset = 64;
19812 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19813 input_attribs[3].location = 6;
19814 input_attribs[3].offset = 96;
19815 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19816
19817 char const *vsSource = "#version 450\n"
19818 "\n"
19819 "layout(location=0) in dmat4 x;\n"
19820 "out gl_PerVertex {\n"
19821 " vec4 gl_Position;\n"
19822 "};\n"
19823 "void main(){\n"
19824 " gl_Position = vec4(x[0][0]);\n"
19825 "}\n";
19826 char const *fsSource = "#version 450\n"
19827 "\n"
19828 "layout(location=0) out vec4 color;\n"
19829 "void main(){\n"
19830 " color = vec4(1);\n"
19831 "}\n";
19832
19833 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19834 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19835
19836 VkPipelineObj pipe(m_device);
19837 pipe.AddColorAttachment();
19838 pipe.AddShader(&vs);
19839 pipe.AddShader(&fs);
19840
19841 pipe.AddVertexInputBindings(input_bindings, 1);
19842 pipe.AddVertexInputAttribs(input_attribs, 4);
19843
19844 VkDescriptorSetObj descriptorSet(m_device);
19845 descriptorSet.AppendDummy();
19846 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19847
19848 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19849
19850 m_errorMonitor->VerifyNotFound();
19851}
19852
19853TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19854 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19855 m_errorMonitor->ExpectSuccess();
19856
19857 ASSERT_NO_FATAL_FAILURE(InitState());
19858
19859 char const *vsSource = "#version 450\n"
19860 "\n"
19861 "out gl_PerVertex {\n"
19862 " vec4 gl_Position;\n"
19863 "};\n"
19864 "void main(){\n"
19865 " gl_Position = vec4(1);\n"
19866 "}\n";
19867 char const *fsSource = "#version 450\n"
19868 "\n"
19869 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19870 "layout(location=0) out vec4 color;\n"
19871 "void main() {\n"
19872 " color = subpassLoad(x);\n"
19873 "}\n";
19874
19875 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19876 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19877
19878 VkPipelineObj pipe(m_device);
19879 pipe.AddShader(&vs);
19880 pipe.AddShader(&fs);
19881 pipe.AddColorAttachment();
19882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19883
19884 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19885 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19886 VkDescriptorSetLayout dsl;
19887 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19888 ASSERT_VK_SUCCESS(err);
19889
19890 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19891 VkPipelineLayout pl;
19892 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19893 ASSERT_VK_SUCCESS(err);
19894
19895 VkAttachmentDescription descs[2] = {
19896 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19897 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19898 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19899 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19900 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19901 };
19902 VkAttachmentReference color = {
19903 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19904 };
19905 VkAttachmentReference input = {
19906 1, VK_IMAGE_LAYOUT_GENERAL,
19907 };
19908
19909 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19910
19911 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19912 VkRenderPass rp;
19913 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19914 ASSERT_VK_SUCCESS(err);
19915
19916 // should be OK. would go wrong here if it's going to...
19917 pipe.CreateVKPipeline(pl, rp);
19918
19919 m_errorMonitor->VerifyNotFound();
19920
19921 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19922 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19923 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19924}
19925
19926TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19927 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19928 "descriptor-backed resource which is not provided, but the shader does not "
19929 "statically use it. This is interesting because it requires compute pipelines "
19930 "to have a proper descriptor use walk, which they didn't for some time.");
19931 m_errorMonitor->ExpectSuccess();
19932
19933 ASSERT_NO_FATAL_FAILURE(InitState());
19934
19935 char const *csSource = "#version 450\n"
19936 "\n"
19937 "layout(local_size_x=1) in;\n"
19938 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19939 "void main(){\n"
19940 " // x is not used.\n"
19941 "}\n";
19942
19943 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19944
19945 VkDescriptorSetObj descriptorSet(m_device);
19946 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19947
19948 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19949 nullptr,
19950 0,
19951 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19952 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19953 descriptorSet.GetPipelineLayout(),
19954 VK_NULL_HANDLE,
19955 -1 };
19956
19957 VkPipeline pipe;
19958 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19959
19960 m_errorMonitor->VerifyNotFound();
19961
19962 if (err == VK_SUCCESS) {
19963 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19964 }
19965}
19966
19967TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19968 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19969 "sampler portion of a combined image + sampler");
19970 m_errorMonitor->ExpectSuccess();
19971
19972 ASSERT_NO_FATAL_FAILURE(InitState());
19973
19974 VkDescriptorSetLayoutBinding bindings[] = {
19975 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19976 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19977 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19978 };
19979 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19980 VkDescriptorSetLayout dsl;
19981 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19982 ASSERT_VK_SUCCESS(err);
19983
19984 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19985 VkPipelineLayout pl;
19986 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19987 ASSERT_VK_SUCCESS(err);
19988
19989 char const *csSource = "#version 450\n"
19990 "\n"
19991 "layout(local_size_x=1) in;\n"
19992 "layout(set=0, binding=0) uniform sampler s;\n"
19993 "layout(set=0, binding=1) uniform texture2D t;\n"
19994 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19995 "void main() {\n"
19996 " x = texture(sampler2D(t, s), vec2(0));\n"
19997 "}\n";
19998 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19999
20000 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20001 nullptr,
20002 0,
20003 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20004 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20005 pl,
20006 VK_NULL_HANDLE,
20007 -1 };
20008
20009 VkPipeline pipe;
20010 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20011
20012 m_errorMonitor->VerifyNotFound();
20013
20014 if (err == VK_SUCCESS) {
20015 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20016 }
20017
20018 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20019 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20020}
20021
20022TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
20023 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20024 "image portion of a combined image + sampler");
20025 m_errorMonitor->ExpectSuccess();
20026
20027 ASSERT_NO_FATAL_FAILURE(InitState());
20028
20029 VkDescriptorSetLayoutBinding bindings[] = {
20030 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20031 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20032 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20033 };
20034 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20035 VkDescriptorSetLayout dsl;
20036 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20037 ASSERT_VK_SUCCESS(err);
20038
20039 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20040 VkPipelineLayout pl;
20041 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20042 ASSERT_VK_SUCCESS(err);
20043
20044 char const *csSource = "#version 450\n"
20045 "\n"
20046 "layout(local_size_x=1) in;\n"
20047 "layout(set=0, binding=0) uniform texture2D t;\n"
20048 "layout(set=0, binding=1) uniform sampler s;\n"
20049 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20050 "void main() {\n"
20051 " x = texture(sampler2D(t, s), vec2(0));\n"
20052 "}\n";
20053 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20054
20055 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20056 nullptr,
20057 0,
20058 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20059 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20060 pl,
20061 VK_NULL_HANDLE,
20062 -1 };
20063
20064 VkPipeline pipe;
20065 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20066
20067 m_errorMonitor->VerifyNotFound();
20068
20069 if (err == VK_SUCCESS) {
20070 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20071 }
20072
20073 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20074 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20075}
20076
20077TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
20078 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
20079 "both the sampler and the image of a combined image+sampler "
20080 "but via separate variables");
20081 m_errorMonitor->ExpectSuccess();
20082
20083 ASSERT_NO_FATAL_FAILURE(InitState());
20084
20085 VkDescriptorSetLayoutBinding bindings[] = {
20086 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20087 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20088 };
20089 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
20090 VkDescriptorSetLayout dsl;
20091 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20092 ASSERT_VK_SUCCESS(err);
20093
20094 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20095 VkPipelineLayout pl;
20096 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20097 ASSERT_VK_SUCCESS(err);
20098
20099 char const *csSource = "#version 450\n"
20100 "\n"
20101 "layout(local_size_x=1) in;\n"
20102 "layout(set=0, binding=0) uniform texture2D t;\n"
20103 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20104 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20105 "void main() {\n"
20106 " x = texture(sampler2D(t, s), vec2(0));\n"
20107 "}\n";
20108 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20109
20110 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20111 nullptr,
20112 0,
20113 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20114 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20115 pl,
20116 VK_NULL_HANDLE,
20117 -1 };
20118
20119 VkPipeline pipe;
20120 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20121
20122 m_errorMonitor->VerifyNotFound();
20123
20124 if (err == VK_SUCCESS) {
20125 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20126 }
20127
20128 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20129 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20130}
20131
20132TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20133 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20134
20135 ASSERT_NO_FATAL_FAILURE(InitState());
20136
20137 // Positive test to check parameter_validation and unique_objects support
20138 // for NV_dedicated_allocation
20139 uint32_t extension_count = 0;
20140 bool supports_nv_dedicated_allocation = false;
20141 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20142 ASSERT_VK_SUCCESS(err);
20143
20144 if (extension_count > 0) {
20145 std::vector<VkExtensionProperties> available_extensions(extension_count);
20146
20147 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20148 ASSERT_VK_SUCCESS(err);
20149
20150 for (const auto &extension_props : available_extensions) {
20151 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20152 supports_nv_dedicated_allocation = true;
20153 }
20154 }
20155 }
20156
20157 if (supports_nv_dedicated_allocation) {
20158 m_errorMonitor->ExpectSuccess();
20159
20160 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20161 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20162 dedicated_buffer_create_info.pNext = nullptr;
20163 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20164
20165 uint32_t queue_family_index = 0;
20166 VkBufferCreateInfo buffer_create_info = {};
20167 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20168 buffer_create_info.pNext = &dedicated_buffer_create_info;
20169 buffer_create_info.size = 1024;
20170 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20171 buffer_create_info.queueFamilyIndexCount = 1;
20172 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20173
20174 VkBuffer buffer;
20175 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20176 ASSERT_VK_SUCCESS(err);
20177
20178 VkMemoryRequirements memory_reqs;
20179 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20180
20181 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20182 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20183 dedicated_memory_info.pNext = nullptr;
20184 dedicated_memory_info.buffer = buffer;
20185 dedicated_memory_info.image = VK_NULL_HANDLE;
20186
20187 VkMemoryAllocateInfo memory_info = {};
20188 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20189 memory_info.pNext = &dedicated_memory_info;
20190 memory_info.allocationSize = memory_reqs.size;
20191
20192 bool pass;
20193 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20194 ASSERT_TRUE(pass);
20195
20196 VkDeviceMemory buffer_memory;
20197 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20198 ASSERT_VK_SUCCESS(err);
20199
20200 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20201 ASSERT_VK_SUCCESS(err);
20202
20203 vkDestroyBuffer(m_device->device(), buffer, NULL);
20204 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20205
20206 m_errorMonitor->VerifyNotFound();
20207 }
20208}
20209
20210TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20211 VkResult err;
20212
20213 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20214
20215 ASSERT_NO_FATAL_FAILURE(InitState());
20216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20217
20218 std::vector<const char *> device_extension_names;
20219 auto features = m_device->phy().features();
20220 // Artificially disable support for non-solid fill modes
20221 features.fillModeNonSolid = false;
20222 // The sacrificial device object
20223 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20224
20225 VkRenderpassObj render_pass(&test_device);
20226
20227 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20228 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20229 pipeline_layout_ci.setLayoutCount = 0;
20230 pipeline_layout_ci.pSetLayouts = NULL;
20231
20232 VkPipelineLayout pipeline_layout;
20233 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20234 ASSERT_VK_SUCCESS(err);
20235
20236 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20237 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20238 rs_ci.pNext = nullptr;
20239 rs_ci.lineWidth = 1.0f;
20240 rs_ci.rasterizerDiscardEnable = true;
20241
20242 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20243 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20244
20245 // Set polygonMode=FILL. No error is expected
20246 m_errorMonitor->ExpectSuccess();
20247 {
20248 VkPipelineObj pipe(&test_device);
20249 pipe.AddShader(&vs);
20250 pipe.AddShader(&fs);
20251 pipe.AddColorAttachment();
20252 // Set polygonMode to a good value
20253 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20254 pipe.SetRasterization(&rs_ci);
20255 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20256 }
20257 m_errorMonitor->VerifyNotFound();
20258
20259 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20260}
20261
20262TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20263 VkResult err;
20264 ASSERT_NO_FATAL_FAILURE(InitState());
20265 ASSERT_NO_FATAL_FAILURE(InitViewport());
20266 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20267
20268 VkPipelineLayout pipeline_layout;
20269 VkPushConstantRange pc_range = {};
20270 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20271 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20272 pipeline_layout_ci.pushConstantRangeCount = 1;
20273 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20274
20275 //
20276 // Check for invalid push constant ranges in pipeline layouts.
20277 //
20278 struct PipelineLayoutTestCase {
20279 VkPushConstantRange const range;
20280 char const *msg;
20281 };
20282
20283 // Check for overlapping ranges
20284 const uint32_t ranges_per_test = 5;
20285 struct OverlappingRangeTestCase {
20286 VkPushConstantRange const ranges[ranges_per_test];
20287 char const *msg;
20288 };
20289
20290 // Run some positive tests to make sure overlap checking in the layer is OK
20291 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20292 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20293 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20294 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20295 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20296 "" },
20297 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20298 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20299 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20300 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20301 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20302 "" } } };
20303 for (const auto &iter : overlapping_range_tests_pos) {
20304 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20305 m_errorMonitor->ExpectSuccess();
20306 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20307 m_errorMonitor->VerifyNotFound();
20308 if (VK_SUCCESS == err) {
20309 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20310 }
20311 }
20312
20313 //
20314 // CmdPushConstants tests
20315 //
20316 const uint8_t dummy_values[100] = {};
20317
Tony Barbour552f6c02016-12-21 14:34:07 -070020318 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020319
20320 // positive overlapping range tests with cmd
20321 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20322 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20323 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20324 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20325 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20326 } };
20327
20328 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20329 const VkPushConstantRange pc_range4[] = {
20330 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20331 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20332 };
20333
20334 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20335 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20336 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20337 ASSERT_VK_SUCCESS(err);
20338 for (const auto &iter : cmd_overlap_tests_pos) {
20339 m_errorMonitor->ExpectSuccess();
20340 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20341 iter.range.size, dummy_values);
20342 m_errorMonitor->VerifyNotFound();
20343 }
20344 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20345
Tony Barbour552f6c02016-12-21 14:34:07 -070020346 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020347}
20348
20349
20350
20351
20352
20353
20354
20355#if 0 // A few devices have issues with this test so disabling for now
20356TEST_F(VkPositiveLayerTest, LongFenceChain)
20357{
20358 m_errorMonitor->ExpectSuccess();
20359
20360 ASSERT_NO_FATAL_FAILURE(InitState());
20361 VkResult err;
20362
20363 std::vector<VkFence> fences;
20364
20365 const int chainLength = 32768;
20366
20367 for (int i = 0; i < chainLength; i++) {
20368 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20369 VkFence fence;
20370 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20371 ASSERT_VK_SUCCESS(err);
20372
20373 fences.push_back(fence);
20374
20375 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20376 0, nullptr, 0, nullptr };
20377 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20378 ASSERT_VK_SUCCESS(err);
20379
20380 }
20381
20382 // BOOM, stack overflow.
20383 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20384
20385 for (auto fence : fences)
20386 vkDestroyFence(m_device->device(), fence, nullptr);
20387
20388 m_errorMonitor->VerifyNotFound();
20389}
20390#endif
20391
20392
Cody Northrop1242dfd2016-07-13 17:24:59 -060020393#if defined(ANDROID) && defined(VALIDATION_APK)
20394static bool initialized = false;
20395static bool active = false;
20396
20397// Convert Intents to argv
20398// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020399std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020400 std::vector<std::string> args;
20401 JavaVM &vm = *app.activity->vm;
20402 JNIEnv *p_env;
20403 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20404 return args;
20405
20406 JNIEnv &env = *p_env;
20407 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020408 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020409 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020410 jmethodID get_string_extra_method =
20411 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020412 jvalue get_string_extra_args;
20413 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020414 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020415
20416 std::string args_str;
20417 if (extra_str) {
20418 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20419 args_str = extra_utf;
20420 env.ReleaseStringUTFChars(extra_str, extra_utf);
20421 env.DeleteLocalRef(extra_str);
20422 }
20423
20424 env.DeleteLocalRef(get_string_extra_args.l);
20425 env.DeleteLocalRef(intent);
20426 vm.DetachCurrentThread();
20427
20428 // split args_str
20429 std::stringstream ss(args_str);
20430 std::string arg;
20431 while (std::getline(ss, arg, ' ')) {
20432 if (!arg.empty())
20433 args.push_back(arg);
20434 }
20435
20436 return args;
20437}
20438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020439static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020441static void processCommand(struct android_app *app, int32_t cmd) {
20442 switch (cmd) {
20443 case APP_CMD_INIT_WINDOW: {
20444 if (app->window) {
20445 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020446 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020447 break;
20448 }
20449 case APP_CMD_GAINED_FOCUS: {
20450 active = true;
20451 break;
20452 }
20453 case APP_CMD_LOST_FOCUS: {
20454 active = false;
20455 break;
20456 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020457 }
20458}
20459
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020460void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020461 app_dummy();
20462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020463 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020464
20465 int vulkanSupport = InitVulkan();
20466 if (vulkanSupport == 0) {
20467 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20468 return;
20469 }
20470
20471 app->onAppCmd = processCommand;
20472 app->onInputEvent = processInput;
20473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020474 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020475 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020476 struct android_poll_source *source;
20477 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020478 if (source) {
20479 source->process(app, source);
20480 }
20481
20482 if (app->destroyRequested != 0) {
20483 VkTestFramework::Finish();
20484 return;
20485 }
20486 }
20487
20488 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020489 // Use the following key to send arguments to gtest, i.e.
20490 // --es args "--gtest_filter=-VkLayerTest.foo"
20491 const char key[] = "args";
20492 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020493
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020494 std::string filter = "";
20495 if (args.size() > 0) {
20496 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20497 filter += args[0];
20498 } else {
20499 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20500 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020502 int argc = 2;
20503 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20504 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020506 // Route output to files until we can override the gtest output
20507 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20508 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020510 ::testing::InitGoogleTest(&argc, argv);
20511 VkTestFramework::InitArgs(&argc, argv);
20512 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020514 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020515
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020516 if (result != 0) {
20517 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20518 } else {
20519 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20520 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020522 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020524 fclose(stdout);
20525 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020527 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020529 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020530 }
20531 }
20532}
20533#endif
20534
Tony Barbour300a6082015-04-07 13:44:53 -060020535int main(int argc, char **argv) {
20536 int result;
20537
Cody Northrop8e54a402016-03-08 22:25:52 -070020538#ifdef ANDROID
20539 int vulkanSupport = InitVulkan();
20540 if (vulkanSupport == 0)
20541 return 1;
20542#endif
20543
Tony Barbour300a6082015-04-07 13:44:53 -060020544 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020545 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020546
20547 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20548
20549 result = RUN_ALL_TESTS();
20550
Tony Barbour6918cd52015-04-09 12:58:51 -060020551 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020552 return result;
20553}