blob: 4dd37a8db2d319927a1f519818b46dd720ecd6a4 [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);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005327 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5328 VkRect2D scissor = {{0, 0}, {16, 16}};
5329 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5330 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005331 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005332 m_commandBuffer->EndRenderPass();
5333 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005334 // Destroy sampler invalidates the cmd buffer, causing error on submit
5335 vkDestroySampler(m_device->device(), sampler, NULL);
5336 // Attempt to submit cmd buffer
5337 VkSubmitInfo submit_info = {};
5338 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5339 submit_info.commandBufferCount = 1;
5340 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5341 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5342 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005343
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005344 // Now re-update descriptor with valid sampler and delete image
5345 img_info.sampler = sampler2;
5346 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005348 m_commandBuffer->BeginCommandBuffer();
5349 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005350 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5351 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5352 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005353 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5354 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005355 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005356 m_commandBuffer->EndRenderPass();
5357 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005358 // Destroy image invalidates the cmd buffer, causing error on submit
5359 vkDestroyImage(m_device->device(), image, NULL);
5360 // Attempt to submit cmd buffer
5361 submit_info = {};
5362 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5363 submit_info.commandBufferCount = 1;
5364 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5365 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5366 m_errorMonitor->VerifyFound();
5367 // Now update descriptor to be valid, but then free descriptor
5368 img_info.imageView = view2;
5369 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005371 m_commandBuffer->BeginCommandBuffer();
5372 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005373 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5374 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5375 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005376 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5377 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005378 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005379 m_commandBuffer->EndRenderPass();
5380 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005381 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005383 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005384 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005385 // Attempt to submit cmd buffer
5386 submit_info = {};
5387 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5388 submit_info.commandBufferCount = 1;
5389 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5390 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5391 m_errorMonitor->VerifyFound();
5392 // Cleanup
5393 vkFreeMemory(m_device->device(), image_memory, NULL);
5394 vkDestroySampler(m_device->device(), sampler2, NULL);
5395 vkDestroyImage(m_device->device(), image2, NULL);
5396 vkDestroyImageView(m_device->device(), view, NULL);
5397 vkDestroyImageView(m_device->device(), view2, NULL);
5398 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5399 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5400 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5401}
5402
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005403TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5404 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5405 ASSERT_NO_FATAL_FAILURE(InitState());
5406 ASSERT_NO_FATAL_FAILURE(InitViewport());
5407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5408
5409 VkDescriptorPoolSize ds_type_count = {};
5410 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5411 ds_type_count.descriptorCount = 1;
5412
5413 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5414 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5415 ds_pool_ci.pNext = NULL;
5416 ds_pool_ci.maxSets = 1;
5417 ds_pool_ci.poolSizeCount = 1;
5418 ds_pool_ci.pPoolSizes = &ds_type_count;
5419
5420 VkDescriptorPool ds_pool;
5421 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5422 ASSERT_VK_SUCCESS(err);
5423
5424 VkDescriptorSetLayoutBinding dsl_binding = {};
5425 dsl_binding.binding = 0;
5426 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5427 dsl_binding.descriptorCount = 1;
5428 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5429 dsl_binding.pImmutableSamplers = NULL;
5430
5431 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5432 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5433 ds_layout_ci.pNext = NULL;
5434 ds_layout_ci.bindingCount = 1;
5435 ds_layout_ci.pBindings = &dsl_binding;
5436 VkDescriptorSetLayout ds_layout;
5437 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5438 ASSERT_VK_SUCCESS(err);
5439
5440 VkDescriptorSet descriptor_set;
5441 VkDescriptorSetAllocateInfo alloc_info = {};
5442 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5443 alloc_info.descriptorSetCount = 1;
5444 alloc_info.descriptorPool = ds_pool;
5445 alloc_info.pSetLayouts = &ds_layout;
5446 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5447 ASSERT_VK_SUCCESS(err);
5448
5449 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5450 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5451 pipeline_layout_ci.pNext = NULL;
5452 pipeline_layout_ci.setLayoutCount = 1;
5453 pipeline_layout_ci.pSetLayouts = &ds_layout;
5454
5455 VkPipelineLayout pipeline_layout;
5456 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5457 ASSERT_VK_SUCCESS(err);
5458
5459 // Create image to update the descriptor with
5460 VkImageObj image(m_device);
5461 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5462 ASSERT_TRUE(image.initialized());
5463
5464 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5465 // Create Sampler
5466 VkSamplerCreateInfo sampler_ci = {};
5467 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5468 sampler_ci.pNext = NULL;
5469 sampler_ci.magFilter = VK_FILTER_NEAREST;
5470 sampler_ci.minFilter = VK_FILTER_NEAREST;
5471 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5472 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5473 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5474 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5475 sampler_ci.mipLodBias = 1.0;
5476 sampler_ci.anisotropyEnable = VK_FALSE;
5477 sampler_ci.maxAnisotropy = 1;
5478 sampler_ci.compareEnable = VK_FALSE;
5479 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5480 sampler_ci.minLod = 1.0;
5481 sampler_ci.maxLod = 1.0;
5482 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5483 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5484 VkSampler sampler;
5485 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5486 ASSERT_VK_SUCCESS(err);
5487 // Update descriptor with image and sampler
5488 VkDescriptorImageInfo img_info = {};
5489 img_info.sampler = sampler;
5490 img_info.imageView = view;
5491 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5492
5493 VkWriteDescriptorSet descriptor_write;
5494 memset(&descriptor_write, 0, sizeof(descriptor_write));
5495 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5496 descriptor_write.dstSet = descriptor_set;
5497 descriptor_write.dstBinding = 0;
5498 descriptor_write.descriptorCount = 1;
5499 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5500 descriptor_write.pImageInfo = &img_info;
5501
5502 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5503
5504 // Create PSO to be used for draw-time errors below
5505 char const *vsSource = "#version 450\n"
5506 "\n"
5507 "out gl_PerVertex { \n"
5508 " vec4 gl_Position;\n"
5509 "};\n"
5510 "void main(){\n"
5511 " gl_Position = vec4(1);\n"
5512 "}\n";
5513 char const *fsSource = "#version 450\n"
5514 "\n"
5515 "layout(set=0, binding=0) uniform sampler2D s;\n"
5516 "layout(location=0) out vec4 x;\n"
5517 "void main(){\n"
5518 " x = texture(s, vec2(1));\n"
5519 "}\n";
5520 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5521 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5522 VkPipelineObj pipe(m_device);
5523 pipe.AddShader(&vs);
5524 pipe.AddShader(&fs);
5525 pipe.AddColorAttachment();
5526 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5527
Tony Barbour552f6c02016-12-21 14:34:07 -07005528 m_commandBuffer->BeginCommandBuffer();
5529 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005530 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5531 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5532 &descriptor_set, 0, NULL);
5533 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005534 m_commandBuffer->EndRenderPass();
5535 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005536 // Submit cmd buffer to put pool in-flight
5537 VkSubmitInfo submit_info = {};
5538 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5539 submit_info.commandBufferCount = 1;
5540 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5541 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5542 // Destroy pool while in-flight, causing error
5543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5544 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5545 m_errorMonitor->VerifyFound();
5546 vkQueueWaitIdle(m_device->m_queue);
5547 // Cleanup
5548 vkDestroySampler(m_device->device(), sampler, NULL);
5549 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5550 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5551 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5552}
5553
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005554TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5555 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5556 ASSERT_NO_FATAL_FAILURE(InitState());
5557 ASSERT_NO_FATAL_FAILURE(InitViewport());
5558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5559
5560 VkDescriptorPoolSize ds_type_count = {};
5561 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5562 ds_type_count.descriptorCount = 1;
5563
5564 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5565 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5566 ds_pool_ci.pNext = NULL;
5567 ds_pool_ci.maxSets = 1;
5568 ds_pool_ci.poolSizeCount = 1;
5569 ds_pool_ci.pPoolSizes = &ds_type_count;
5570
5571 VkDescriptorPool ds_pool;
5572 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5573 ASSERT_VK_SUCCESS(err);
5574
5575 VkDescriptorSetLayoutBinding dsl_binding = {};
5576 dsl_binding.binding = 0;
5577 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5578 dsl_binding.descriptorCount = 1;
5579 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5580 dsl_binding.pImmutableSamplers = NULL;
5581
5582 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5583 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5584 ds_layout_ci.pNext = NULL;
5585 ds_layout_ci.bindingCount = 1;
5586 ds_layout_ci.pBindings = &dsl_binding;
5587 VkDescriptorSetLayout ds_layout;
5588 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5589 ASSERT_VK_SUCCESS(err);
5590
5591 VkDescriptorSet descriptorSet;
5592 VkDescriptorSetAllocateInfo alloc_info = {};
5593 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5594 alloc_info.descriptorSetCount = 1;
5595 alloc_info.descriptorPool = ds_pool;
5596 alloc_info.pSetLayouts = &ds_layout;
5597 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5598 ASSERT_VK_SUCCESS(err);
5599
5600 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5601 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5602 pipeline_layout_ci.pNext = NULL;
5603 pipeline_layout_ci.setLayoutCount = 1;
5604 pipeline_layout_ci.pSetLayouts = &ds_layout;
5605
5606 VkPipelineLayout pipeline_layout;
5607 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5608 ASSERT_VK_SUCCESS(err);
5609
5610 // Create images to update the descriptor with
5611 VkImage image;
5612 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5613 const int32_t tex_width = 32;
5614 const int32_t tex_height = 32;
5615 VkImageCreateInfo image_create_info = {};
5616 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5617 image_create_info.pNext = NULL;
5618 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5619 image_create_info.format = tex_format;
5620 image_create_info.extent.width = tex_width;
5621 image_create_info.extent.height = tex_height;
5622 image_create_info.extent.depth = 1;
5623 image_create_info.mipLevels = 1;
5624 image_create_info.arrayLayers = 1;
5625 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5626 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5627 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5628 image_create_info.flags = 0;
5629 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5630 ASSERT_VK_SUCCESS(err);
5631 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5632 VkMemoryRequirements memory_reqs;
5633 VkDeviceMemory image_memory;
5634 bool pass;
5635 VkMemoryAllocateInfo memory_info = {};
5636 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5637 memory_info.pNext = NULL;
5638 memory_info.allocationSize = 0;
5639 memory_info.memoryTypeIndex = 0;
5640 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5641 // Allocate enough memory for image
5642 memory_info.allocationSize = memory_reqs.size;
5643 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5644 ASSERT_TRUE(pass);
5645 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5646 ASSERT_VK_SUCCESS(err);
5647 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5648 ASSERT_VK_SUCCESS(err);
5649
5650 VkImageViewCreateInfo image_view_create_info = {};
5651 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5652 image_view_create_info.image = image;
5653 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5654 image_view_create_info.format = tex_format;
5655 image_view_create_info.subresourceRange.layerCount = 1;
5656 image_view_create_info.subresourceRange.baseMipLevel = 0;
5657 image_view_create_info.subresourceRange.levelCount = 1;
5658 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5659
5660 VkImageView view;
5661 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5662 ASSERT_VK_SUCCESS(err);
5663 // Create Samplers
5664 VkSamplerCreateInfo sampler_ci = {};
5665 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5666 sampler_ci.pNext = NULL;
5667 sampler_ci.magFilter = VK_FILTER_NEAREST;
5668 sampler_ci.minFilter = VK_FILTER_NEAREST;
5669 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5670 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5671 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5672 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5673 sampler_ci.mipLodBias = 1.0;
5674 sampler_ci.anisotropyEnable = VK_FALSE;
5675 sampler_ci.maxAnisotropy = 1;
5676 sampler_ci.compareEnable = VK_FALSE;
5677 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5678 sampler_ci.minLod = 1.0;
5679 sampler_ci.maxLod = 1.0;
5680 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5681 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5682 VkSampler sampler;
5683 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5684 ASSERT_VK_SUCCESS(err);
5685 // Update descriptor with image and sampler
5686 VkDescriptorImageInfo img_info = {};
5687 img_info.sampler = sampler;
5688 img_info.imageView = view;
5689 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5690
5691 VkWriteDescriptorSet descriptor_write;
5692 memset(&descriptor_write, 0, sizeof(descriptor_write));
5693 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5694 descriptor_write.dstSet = descriptorSet;
5695 descriptor_write.dstBinding = 0;
5696 descriptor_write.descriptorCount = 1;
5697 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5698 descriptor_write.pImageInfo = &img_info;
5699 // Break memory binding and attempt update
5700 vkFreeMemory(m_device->device(), image_memory, nullptr);
5701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005702 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5704 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5705 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5706 m_errorMonitor->VerifyFound();
5707 // Cleanup
5708 vkDestroyImage(m_device->device(), image, NULL);
5709 vkDestroySampler(m_device->device(), sampler, NULL);
5710 vkDestroyImageView(m_device->device(), view, NULL);
5711 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5712 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5713 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5714}
5715
Karl Schultz6addd812016-02-02 17:17:23 -07005716TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005717 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5718 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005719 // Create a valid cmd buffer
5720 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005721 uint64_t fake_pipeline_handle = 0xbaad6001;
5722 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005723 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5725
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005727 m_commandBuffer->BeginCommandBuffer();
5728 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005729 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005730 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005731
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005732 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005733 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 -06005734 Draw(1, 0, 0, 0);
5735 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005736
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005737 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005738 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 +12005739 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005740 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5741 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005742}
5743
Karl Schultz6addd812016-02-02 17:17:23 -07005744TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005745 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005746 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005749
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005750 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005751 ASSERT_NO_FATAL_FAILURE(InitViewport());
5752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005753 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005754 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5755 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005756
5757 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005758 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5759 ds_pool_ci.pNext = NULL;
5760 ds_pool_ci.maxSets = 1;
5761 ds_pool_ci.poolSizeCount = 1;
5762 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005763
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005764 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005765 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005766 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005767
Tony Barboureb254902015-07-15 12:50:33 -06005768 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005769 dsl_binding.binding = 0;
5770 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5771 dsl_binding.descriptorCount = 1;
5772 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5773 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005774
Tony Barboureb254902015-07-15 12:50:33 -06005775 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005776 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5777 ds_layout_ci.pNext = NULL;
5778 ds_layout_ci.bindingCount = 1;
5779 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005780 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005781 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005782 ASSERT_VK_SUCCESS(err);
5783
5784 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005785 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005786 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005787 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005788 alloc_info.descriptorPool = ds_pool;
5789 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005790 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005791 ASSERT_VK_SUCCESS(err);
5792
Tony Barboureb254902015-07-15 12:50:33 -06005793 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005794 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5795 pipeline_layout_ci.pNext = NULL;
5796 pipeline_layout_ci.setLayoutCount = 1;
5797 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005798
5799 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005800 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005801 ASSERT_VK_SUCCESS(err);
5802
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005803 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005804 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005805 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005806 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005807
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005808 VkPipelineObj pipe(m_device);
5809 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005810 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005811 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005812 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005813
Tony Barbour552f6c02016-12-21 14:34:07 -07005814 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005815 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5816 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5817 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005818
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005819 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005820
Chia-I Wuf7458c52015-10-26 21:10:41 +08005821 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5822 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5823 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005824}
5825
Karl Schultz6addd812016-02-02 17:17:23 -07005826TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005827 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005828 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005829
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005831
5832 ASSERT_NO_FATAL_FAILURE(InitState());
5833 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005834 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5835 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005836
5837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5839 ds_pool_ci.pNext = NULL;
5840 ds_pool_ci.maxSets = 1;
5841 ds_pool_ci.poolSizeCount = 1;
5842 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005843
5844 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005845 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005846 ASSERT_VK_SUCCESS(err);
5847
5848 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005849 dsl_binding.binding = 0;
5850 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5851 dsl_binding.descriptorCount = 1;
5852 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5853 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005854
5855 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005856 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5857 ds_layout_ci.pNext = NULL;
5858 ds_layout_ci.bindingCount = 1;
5859 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005860 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005862 ASSERT_VK_SUCCESS(err);
5863
5864 VkDescriptorSet descriptorSet;
5865 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005867 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005868 alloc_info.descriptorPool = ds_pool;
5869 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005871 ASSERT_VK_SUCCESS(err);
5872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005873 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005874 VkWriteDescriptorSet descriptor_write;
5875 memset(&descriptor_write, 0, sizeof(descriptor_write));
5876 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5877 descriptor_write.dstSet = descriptorSet;
5878 descriptor_write.dstBinding = 0;
5879 descriptor_write.descriptorCount = 1;
5880 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5881 descriptor_write.pTexelBufferView = &view;
5882
5883 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5884
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005885 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005886
5887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5889}
5890
Mark Youngd339ba32016-05-30 13:28:35 -06005891TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005892 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 -06005893
5894 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005896 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005897
5898 ASSERT_NO_FATAL_FAILURE(InitState());
5899
5900 // Create a buffer with no bound memory and then attempt to create
5901 // a buffer view.
5902 VkBufferCreateInfo buff_ci = {};
5903 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005904 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005905 buff_ci.size = 256;
5906 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5907 VkBuffer buffer;
5908 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5909 ASSERT_VK_SUCCESS(err);
5910
5911 VkBufferViewCreateInfo buff_view_ci = {};
5912 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5913 buff_view_ci.buffer = buffer;
5914 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5915 buff_view_ci.range = VK_WHOLE_SIZE;
5916 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005917 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005918
5919 m_errorMonitor->VerifyFound();
5920 vkDestroyBuffer(m_device->device(), buffer, NULL);
5921 // If last error is success, it still created the view, so delete it.
5922 if (err == VK_SUCCESS) {
5923 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5924 }
5925}
5926
Karl Schultz6addd812016-02-02 17:17:23 -07005927TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5928 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5929 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005930 // 1. No dynamicOffset supplied
5931 // 2. Too many dynamicOffsets supplied
5932 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005933 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5935 "0 dynamicOffsets are left in "
5936 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005937
5938 ASSERT_NO_FATAL_FAILURE(InitState());
5939 ASSERT_NO_FATAL_FAILURE(InitViewport());
5940 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5941
5942 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005943 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5944 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005945
5946 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005947 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5948 ds_pool_ci.pNext = NULL;
5949 ds_pool_ci.maxSets = 1;
5950 ds_pool_ci.poolSizeCount = 1;
5951 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005952
5953 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005954 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005955 ASSERT_VK_SUCCESS(err);
5956
5957 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005958 dsl_binding.binding = 0;
5959 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5960 dsl_binding.descriptorCount = 1;
5961 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5962 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005963
5964 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005965 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5966 ds_layout_ci.pNext = NULL;
5967 ds_layout_ci.bindingCount = 1;
5968 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005969 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005970 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005971 ASSERT_VK_SUCCESS(err);
5972
5973 VkDescriptorSet descriptorSet;
5974 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005975 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005976 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005977 alloc_info.descriptorPool = ds_pool;
5978 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005979 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005980 ASSERT_VK_SUCCESS(err);
5981
5982 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005983 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5984 pipeline_layout_ci.pNext = NULL;
5985 pipeline_layout_ci.setLayoutCount = 1;
5986 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005987
5988 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005989 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005990 ASSERT_VK_SUCCESS(err);
5991
5992 // Create a buffer to update the descriptor with
5993 uint32_t qfi = 0;
5994 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005995 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5996 buffCI.size = 1024;
5997 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5998 buffCI.queueFamilyIndexCount = 1;
5999 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006000
6001 VkBuffer dyub;
6002 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6003 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006004 // Allocate memory and bind to buffer so we can make it to the appropriate
6005 // error
6006 VkMemoryAllocateInfo mem_alloc = {};
6007 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6008 mem_alloc.pNext = NULL;
6009 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006010 mem_alloc.memoryTypeIndex = 0;
6011
6012 VkMemoryRequirements memReqs;
6013 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006014 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006015 if (!pass) {
6016 vkDestroyBuffer(m_device->device(), dyub, NULL);
6017 return;
6018 }
6019
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006020 VkDeviceMemory mem;
6021 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6022 ASSERT_VK_SUCCESS(err);
6023 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6024 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006025 // Correctly update descriptor to avoid "NOT_UPDATED" error
6026 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006027 buffInfo.buffer = dyub;
6028 buffInfo.offset = 0;
6029 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006030
6031 VkWriteDescriptorSet descriptor_write;
6032 memset(&descriptor_write, 0, sizeof(descriptor_write));
6033 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6034 descriptor_write.dstSet = descriptorSet;
6035 descriptor_write.dstBinding = 0;
6036 descriptor_write.descriptorCount = 1;
6037 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6038 descriptor_write.pBufferInfo = &buffInfo;
6039
6040 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6041
Tony Barbour552f6c02016-12-21 14:34:07 -07006042 m_commandBuffer->BeginCommandBuffer();
6043 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006044 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6045 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006046 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006047 uint32_t pDynOff[2] = {512, 756};
6048 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6050 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6051 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6052 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006053 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006054 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6056 "offset 0 and range 1024 that "
6057 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006058 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006059 char const *vsSource = "#version 450\n"
6060 "\n"
6061 "out gl_PerVertex { \n"
6062 " vec4 gl_Position;\n"
6063 "};\n"
6064 "void main(){\n"
6065 " gl_Position = vec4(1);\n"
6066 "}\n";
6067 char const *fsSource = "#version 450\n"
6068 "\n"
6069 "layout(location=0) out vec4 x;\n"
6070 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6071 "void main(){\n"
6072 " x = vec4(bar.y);\n"
6073 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006074 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6075 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6076 VkPipelineObj pipe(m_device);
6077 pipe.AddShader(&vs);
6078 pipe.AddShader(&fs);
6079 pipe.AddColorAttachment();
6080 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6081
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006082 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6083 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6084 VkRect2D scissor = {{0, 0}, {16, 16}};
6085 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006087 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006088 // This update should succeed, but offset size of 512 will overstep buffer
6089 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006090 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6091 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006092 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006093 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006094
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006095 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006096 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006097
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006098 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006099 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006100 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6101}
6102
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006103TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6104 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6105 "that doesn't have memory bound");
6106 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006108 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6110 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006111
6112 ASSERT_NO_FATAL_FAILURE(InitState());
6113 ASSERT_NO_FATAL_FAILURE(InitViewport());
6114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6115
6116 VkDescriptorPoolSize ds_type_count = {};
6117 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6118 ds_type_count.descriptorCount = 1;
6119
6120 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6121 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6122 ds_pool_ci.pNext = NULL;
6123 ds_pool_ci.maxSets = 1;
6124 ds_pool_ci.poolSizeCount = 1;
6125 ds_pool_ci.pPoolSizes = &ds_type_count;
6126
6127 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006128 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006129 ASSERT_VK_SUCCESS(err);
6130
6131 VkDescriptorSetLayoutBinding dsl_binding = {};
6132 dsl_binding.binding = 0;
6133 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6134 dsl_binding.descriptorCount = 1;
6135 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6136 dsl_binding.pImmutableSamplers = NULL;
6137
6138 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6139 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6140 ds_layout_ci.pNext = NULL;
6141 ds_layout_ci.bindingCount = 1;
6142 ds_layout_ci.pBindings = &dsl_binding;
6143 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006144 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006145 ASSERT_VK_SUCCESS(err);
6146
6147 VkDescriptorSet descriptorSet;
6148 VkDescriptorSetAllocateInfo alloc_info = {};
6149 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6150 alloc_info.descriptorSetCount = 1;
6151 alloc_info.descriptorPool = ds_pool;
6152 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006153 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006154 ASSERT_VK_SUCCESS(err);
6155
6156 // Create a buffer to update the descriptor with
6157 uint32_t qfi = 0;
6158 VkBufferCreateInfo buffCI = {};
6159 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6160 buffCI.size = 1024;
6161 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6162 buffCI.queueFamilyIndexCount = 1;
6163 buffCI.pQueueFamilyIndices = &qfi;
6164
6165 VkBuffer dyub;
6166 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6167 ASSERT_VK_SUCCESS(err);
6168
6169 // Attempt to update descriptor without binding memory to it
6170 VkDescriptorBufferInfo buffInfo = {};
6171 buffInfo.buffer = dyub;
6172 buffInfo.offset = 0;
6173 buffInfo.range = 1024;
6174
6175 VkWriteDescriptorSet descriptor_write;
6176 memset(&descriptor_write, 0, sizeof(descriptor_write));
6177 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6178 descriptor_write.dstSet = descriptorSet;
6179 descriptor_write.dstBinding = 0;
6180 descriptor_write.descriptorCount = 1;
6181 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6182 descriptor_write.pBufferInfo = &buffInfo;
6183
6184 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6185 m_errorMonitor->VerifyFound();
6186
6187 vkDestroyBuffer(m_device->device(), dyub, NULL);
6188 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6189 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6190}
6191
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006192TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006193 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006194 ASSERT_NO_FATAL_FAILURE(InitState());
6195 ASSERT_NO_FATAL_FAILURE(InitViewport());
6196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6197
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006198 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006199 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006200 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6201 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6202 pipeline_layout_ci.pushConstantRangeCount = 1;
6203 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6204
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006205 //
6206 // Check for invalid push constant ranges in pipeline layouts.
6207 //
6208 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006209 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006210 char const *msg;
6211 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006212
Karl Schultzc81037d2016-05-12 08:11:23 -06006213 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6214 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6215 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6216 "vkCreatePipelineLayout() call has push constants index 0 with "
6217 "size 0."},
6218 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6219 "vkCreatePipelineLayout() call has push constants index 0 with "
6220 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006221 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006222 "vkCreatePipelineLayout() call has push constants index 0 with "
6223 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006224 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006225 "vkCreatePipelineLayout() call has push constants index 0 with "
6226 "size 0."},
6227 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6228 "vkCreatePipelineLayout() call has push constants index 0 with "
6229 "offset 1. Offset must"},
6230 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6231 "vkCreatePipelineLayout() call has push constants index 0 "
6232 "with offset "},
6233 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6234 "vkCreatePipelineLayout() call has push constants "
6235 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006236 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006237 "vkCreatePipelineLayout() call has push constants index 0 "
6238 "with offset "},
6239 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6240 "vkCreatePipelineLayout() call has push "
6241 "constants index 0 with offset "},
6242 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6243 "vkCreatePipelineLayout() call has push "
6244 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006245 }};
6246
6247 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006248 for (const auto &iter : range_tests) {
6249 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6251 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006252 m_errorMonitor->VerifyFound();
6253 if (VK_SUCCESS == err) {
6254 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6255 }
6256 }
6257
6258 // Check for invalid stage flag
6259 pc_range.offset = 0;
6260 pc_range.size = 16;
6261 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006262 m_errorMonitor->SetDesiredFailureMsg(
6263 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6264 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006265 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006266 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006267 if (VK_SUCCESS == err) {
6268 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6269 }
6270
6271 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006272 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006273 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006274 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006275 char const *msg;
6276 };
6277
Karl Schultzc81037d2016-05-12 08:11:23 -06006278 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006279 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6280 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6281 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6282 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6283 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006284 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006285 {
6286 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6287 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6288 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6289 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6290 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006291 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006292 },
6293 {
6294 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6295 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6296 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6297 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6298 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006299 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006300 },
6301 {
6302 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6303 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6304 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6305 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6306 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006307 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006308 },
6309 {
6310 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6311 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6312 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6313 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6314 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006315 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006316 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006317
Karl Schultzc81037d2016-05-12 08:11:23 -06006318 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006319 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006320 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6322 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006323 m_errorMonitor->VerifyFound();
6324 if (VK_SUCCESS == err) {
6325 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6326 }
6327 }
6328
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006329 //
6330 // CmdPushConstants tests
6331 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006332 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006333
6334 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006335 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6336 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006337 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006338 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6339 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006340 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006341 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6342 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006343 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006344 "vkCmdPushConstants() call has push constants with offset 1. "
6345 "Offset must be a multiple of 4."},
6346 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6347 "vkCmdPushConstants() call has push constants with offset 1. "
6348 "Offset must be a multiple of 4."},
6349 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6350 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6351 "0x1 not within flag-matching ranges in pipeline layout"},
6352 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6353 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6354 "0x1 not within flag-matching ranges in pipeline layout"},
6355 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6356 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6357 "0x1 not within flag-matching ranges in pipeline layout"},
6358 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6359 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6360 "0x1 not within flag-matching ranges in pipeline layout"},
6361 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6362 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6363 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006364 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006365 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6366 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006367 }};
6368
Tony Barbour552f6c02016-12-21 14:34:07 -07006369 m_commandBuffer->BeginCommandBuffer();
6370 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006371
6372 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006373 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006374 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006375 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006376 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006377 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006378 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006379 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006380 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6382 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006383 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006384 m_errorMonitor->VerifyFound();
6385 }
6386
6387 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006389 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006390 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006391 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006392
Karl Schultzc81037d2016-05-12 08:11:23 -06006393 // overlapping range tests with cmd
6394 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6395 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6396 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6397 "0x1 not within flag-matching ranges in pipeline layout"},
6398 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6399 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6400 "0x1 not within flag-matching ranges in pipeline layout"},
6401 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6402 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6403 "0x1 not within flag-matching ranges in pipeline layout"},
6404 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006405 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006406 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006407 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6408 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006409 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006410 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006411 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006412 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006413 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006414 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6416 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006417 iter.range.size, dummy_values);
6418 m_errorMonitor->VerifyFound();
6419 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006420 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6421
Tony Barbour552f6c02016-12-21 14:34:07 -07006422 m_commandBuffer->EndRenderPass();
6423 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006424}
6425
Karl Schultz6addd812016-02-02 17:17:23 -07006426TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006427 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006428 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006429
6430 ASSERT_NO_FATAL_FAILURE(InitState());
6431 ASSERT_NO_FATAL_FAILURE(InitViewport());
6432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6433
Mike Stroyanb8a61002016-06-20 16:00:28 -06006434 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6435 VkImageTiling tiling;
6436 VkFormatProperties format_properties;
6437 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006439 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006441 tiling = VK_IMAGE_TILING_OPTIMAL;
6442 } else {
6443 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6444 "skipped.\n");
6445 return;
6446 }
6447
Tobin Ehlis559c6382015-11-05 09:52:49 -07006448 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6449 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006450 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6451 ds_type_count[0].descriptorCount = 10;
6452 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6453 ds_type_count[1].descriptorCount = 2;
6454 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6455 ds_type_count[2].descriptorCount = 2;
6456 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6457 ds_type_count[3].descriptorCount = 5;
6458 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6459 // type
6460 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6461 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6462 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006463
6464 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006465 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6466 ds_pool_ci.pNext = NULL;
6467 ds_pool_ci.maxSets = 5;
6468 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6469 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006470
6471 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006472 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006473 ASSERT_VK_SUCCESS(err);
6474
6475 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6476 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006477 dsl_binding[0].binding = 0;
6478 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6479 dsl_binding[0].descriptorCount = 5;
6480 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6481 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006482
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006483 // Create layout identical to set0 layout but w/ different stageFlags
6484 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006485 dsl_fs_stage_only.binding = 0;
6486 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6487 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006488 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6489 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006490 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006491 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006492 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6493 ds_layout_ci.pNext = NULL;
6494 ds_layout_ci.bindingCount = 1;
6495 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006496 static const uint32_t NUM_LAYOUTS = 4;
6497 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006498 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006499 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6500 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006501 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006502 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006503 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006504 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006505 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006506 dsl_binding[0].binding = 0;
6507 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006508 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006509 dsl_binding[1].binding = 1;
6510 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6511 dsl_binding[1].descriptorCount = 2;
6512 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6513 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006514 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006515 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006516 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006517 ASSERT_VK_SUCCESS(err);
6518 dsl_binding[0].binding = 0;
6519 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006520 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006521 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006522 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006523 ASSERT_VK_SUCCESS(err);
6524 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006525 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006526 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006527 ASSERT_VK_SUCCESS(err);
6528
6529 static const uint32_t NUM_SETS = 4;
6530 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6531 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006532 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006533 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006534 alloc_info.descriptorPool = ds_pool;
6535 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006536 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006537 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006538 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006539 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006540 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006541 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006542 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006543
6544 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006545 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6546 pipeline_layout_ci.pNext = NULL;
6547 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6548 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006549
6550 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006551 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006553 // Create pipelineLayout with only one setLayout
6554 pipeline_layout_ci.setLayoutCount = 1;
6555 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006556 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006557 ASSERT_VK_SUCCESS(err);
6558 // Create pipelineLayout with 2 descriptor setLayout at index 0
6559 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6560 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006561 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006562 ASSERT_VK_SUCCESS(err);
6563 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6564 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6565 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006566 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006567 ASSERT_VK_SUCCESS(err);
6568 // Create pipelineLayout with UB type, but stageFlags for FS only
6569 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6570 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006571 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006572 ASSERT_VK_SUCCESS(err);
6573 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6574 VkDescriptorSetLayout pl_bad_s0[2] = {};
6575 pl_bad_s0[0] = ds_layout_fs_only;
6576 pl_bad_s0[1] = ds_layout[1];
6577 pipeline_layout_ci.setLayoutCount = 2;
6578 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6579 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006580 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006581 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006582
6583 // Create a buffer to update the descriptor with
6584 uint32_t qfi = 0;
6585 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006586 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6587 buffCI.size = 1024;
6588 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6589 buffCI.queueFamilyIndexCount = 1;
6590 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006591
6592 VkBuffer dyub;
6593 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6594 ASSERT_VK_SUCCESS(err);
6595 // Correctly update descriptor to avoid "NOT_UPDATED" error
6596 static const uint32_t NUM_BUFFS = 5;
6597 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006598 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006599 buffInfo[i].buffer = dyub;
6600 buffInfo[i].offset = 0;
6601 buffInfo[i].range = 1024;
6602 }
Karl Schultz6addd812016-02-02 17:17:23 -07006603 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006604 const int32_t tex_width = 32;
6605 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006606 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006607 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6608 image_create_info.pNext = NULL;
6609 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6610 image_create_info.format = tex_format;
6611 image_create_info.extent.width = tex_width;
6612 image_create_info.extent.height = tex_height;
6613 image_create_info.extent.depth = 1;
6614 image_create_info.mipLevels = 1;
6615 image_create_info.arrayLayers = 1;
6616 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006617 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006618 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006619 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006620 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6621 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006622
Karl Schultz6addd812016-02-02 17:17:23 -07006623 VkMemoryRequirements memReqs;
6624 VkDeviceMemory imageMem;
6625 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006626 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006627 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6628 memAlloc.pNext = NULL;
6629 memAlloc.allocationSize = 0;
6630 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006631 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6632 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006633 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006634 ASSERT_TRUE(pass);
6635 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6636 ASSERT_VK_SUCCESS(err);
6637 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6638 ASSERT_VK_SUCCESS(err);
6639
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006640 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006641 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6642 image_view_create_info.image = image;
6643 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6644 image_view_create_info.format = tex_format;
6645 image_view_create_info.subresourceRange.layerCount = 1;
6646 image_view_create_info.subresourceRange.baseMipLevel = 0;
6647 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006648 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006649
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006650 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006651 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006652 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006653 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006654 imageInfo[0].imageView = view;
6655 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6656 imageInfo[1].imageView = view;
6657 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006658 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006659 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006660 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006661 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006662
6663 static const uint32_t NUM_SET_UPDATES = 3;
6664 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6665 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6666 descriptor_write[0].dstSet = descriptorSet[0];
6667 descriptor_write[0].dstBinding = 0;
6668 descriptor_write[0].descriptorCount = 5;
6669 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6670 descriptor_write[0].pBufferInfo = buffInfo;
6671 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6672 descriptor_write[1].dstSet = descriptorSet[1];
6673 descriptor_write[1].dstBinding = 0;
6674 descriptor_write[1].descriptorCount = 2;
6675 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6676 descriptor_write[1].pImageInfo = imageInfo;
6677 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6678 descriptor_write[2].dstSet = descriptorSet[1];
6679 descriptor_write[2].dstBinding = 1;
6680 descriptor_write[2].descriptorCount = 2;
6681 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006682 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006683
6684 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006685
Tobin Ehlis88452832015-12-03 09:40:56 -07006686 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006687 char const *vsSource = "#version 450\n"
6688 "\n"
6689 "out gl_PerVertex {\n"
6690 " vec4 gl_Position;\n"
6691 "};\n"
6692 "void main(){\n"
6693 " gl_Position = vec4(1);\n"
6694 "}\n";
6695 char const *fsSource = "#version 450\n"
6696 "\n"
6697 "layout(location=0) out vec4 x;\n"
6698 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6699 "void main(){\n"
6700 " x = vec4(bar.y);\n"
6701 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006702 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6703 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006704 VkPipelineObj pipe(m_device);
6705 pipe.AddShader(&vs);
6706 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006707 pipe.AddColorAttachment();
6708 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006709
Tony Barbour552f6c02016-12-21 14:34:07 -07006710 m_commandBuffer->BeginCommandBuffer();
6711 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006712
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006713 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006714 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6715 // of PSO
6716 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6717 // cmd_pipeline.c
6718 // due to the fact that cmd_alloc_dset_data() has not been called in
6719 // cmd_bind_graphics_pipeline()
6720 // TODO : Want to cause various binding incompatibility issues here to test
6721 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006722 // First cause various verify_layout_compatibility() fails
6723 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006724 // verify_set_layout_compatibility fail cases:
6725 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006727 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6728 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006729 m_errorMonitor->VerifyFound();
6730
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006731 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6733 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6734 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006735 m_errorMonitor->VerifyFound();
6736
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006737 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006738 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6739 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6741 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6742 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006743 m_errorMonitor->VerifyFound();
6744
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006745 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6746 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6748 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6749 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006750 m_errorMonitor->VerifyFound();
6751
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006752 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6753 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6755 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6756 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6757 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006758 m_errorMonitor->VerifyFound();
6759
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006760 // Cause INFO messages due to disturbing previously bound Sets
6761 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006762 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6763 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006764 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6766 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6767 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006768 m_errorMonitor->VerifyFound();
6769
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006770 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6771 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006772 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6774 "any subsequent sets were disturbed ");
6775 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6776 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006777 m_errorMonitor->VerifyFound();
6778
Tobin Ehlis10fad692016-07-07 12:00:36 -06006779 // Now that we're done actively using the pipelineLayout that gfx pipeline
6780 // was created with, we should be able to delete it. Do that now to verify
6781 // that validation obeys pipelineLayout lifetime
6782 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6783
Tobin Ehlis88452832015-12-03 09:40:56 -07006784 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006785 // 1. Error due to not binding required set (we actually use same code as
6786 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006787 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6788 &descriptorSet[0], 0, NULL);
6789 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6790 &descriptorSet[1], 0, NULL);
6791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Rene Lindsay9f228e42017-01-16 13:57:45 -07006792
6793 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6794 VkRect2D scissor = {{0, 0}, {16, 16}};
6795 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6796 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6797
Tobin Ehlis88452832015-12-03 09:40:56 -07006798 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006799 m_errorMonitor->VerifyFound();
6800
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006801 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006802 // 2. Error due to bound set not being compatible with PSO's
6803 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006804 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6805 &descriptorSet[0], 0, NULL);
6806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006807 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006808 m_errorMonitor->VerifyFound();
6809
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006810 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006811 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006812 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6813 }
6814 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006815 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006816 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6817 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006818 vkFreeMemory(m_device->device(), imageMem, NULL);
6819 vkDestroyImage(m_device->device(), image, NULL);
6820 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006821}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006822
Karl Schultz6addd812016-02-02 17:17:23 -07006823TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006824
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6826 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006827
6828 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006829 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006830 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006831 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006832
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006833 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006834}
6835
Karl Schultz6addd812016-02-02 17:17:23 -07006836TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6837 VkResult err;
6838 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006839
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006841
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006842 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006843
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006844 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006845 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006846 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006847 cmd.commandPool = m_commandPool;
6848 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006849 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006850
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006851 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006852 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006853
6854 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006855 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006856 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006857 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006858 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006859 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 -07006860 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006861
6862 // The error should be caught by validation of the BeginCommandBuffer call
6863 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6864
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006865 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006866 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006867}
6868
Karl Schultz6addd812016-02-02 17:17:23 -07006869TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006870 // Cause error due to Begin while recording CB
6871 // Then cause 2 errors for attempting to reset CB w/o having
6872 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6873 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006875
6876 ASSERT_NO_FATAL_FAILURE(InitState());
6877
6878 // Calls AllocateCommandBuffers
6879 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6880
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006881 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07006882 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006883 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6884 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006885 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6886 cmd_buf_info.pNext = NULL;
6887 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006888 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006889
6890 // Begin CB to transition to recording state
6891 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6892 // Can't re-begin. This should trigger error
6893 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006894 m_errorMonitor->VerifyFound();
6895
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006897 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6898 // Reset attempt will trigger error due to incorrect CommandPool state
6899 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006900 m_errorMonitor->VerifyFound();
6901
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006903 // Transition CB to RECORDED state
6904 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6905 // Now attempting to Begin will implicitly reset, which triggers error
6906 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006907 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006908}
6909
Karl Schultz6addd812016-02-02 17:17:23 -07006910TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006911 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006912 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006913
Mike Weiblencce7ec72016-10-17 19:33:05 -06006914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006915
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006916 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006918
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006919 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006920 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6921 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006922
6923 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006924 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6925 ds_pool_ci.pNext = NULL;
6926 ds_pool_ci.maxSets = 1;
6927 ds_pool_ci.poolSizeCount = 1;
6928 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006929
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006930 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006931 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006932 ASSERT_VK_SUCCESS(err);
6933
Tony Barboureb254902015-07-15 12:50:33 -06006934 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006935 dsl_binding.binding = 0;
6936 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6937 dsl_binding.descriptorCount = 1;
6938 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6939 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006940
Tony Barboureb254902015-07-15 12:50:33 -06006941 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006942 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6943 ds_layout_ci.pNext = NULL;
6944 ds_layout_ci.bindingCount = 1;
6945 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006946
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006947 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006948 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006949 ASSERT_VK_SUCCESS(err);
6950
6951 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006952 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006953 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006954 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006955 alloc_info.descriptorPool = ds_pool;
6956 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006957 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006958 ASSERT_VK_SUCCESS(err);
6959
Tony Barboureb254902015-07-15 12:50:33 -06006960 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006961 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6962 pipeline_layout_ci.setLayoutCount = 1;
6963 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006964
6965 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006966 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006967 ASSERT_VK_SUCCESS(err);
6968
Tobin Ehlise68360f2015-10-01 11:15:13 -06006969 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006970 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006971
6972 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006973 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6974 vp_state_ci.scissorCount = 1;
6975 vp_state_ci.pScissors = &sc;
6976 vp_state_ci.viewportCount = 1;
6977 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006978
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006979 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6980 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6981 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6982 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6983 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6984 rs_state_ci.depthClampEnable = VK_FALSE;
6985 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6986 rs_state_ci.depthBiasEnable = VK_FALSE;
6987
Tony Barboureb254902015-07-15 12:50:33 -06006988 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006989 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6990 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006991 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006992 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6993 gp_ci.layout = pipeline_layout;
6994 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006995
6996 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006997 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6998 pc_ci.initialDataSize = 0;
6999 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007000
7001 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007002 VkPipelineCache pipelineCache;
7003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007004 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007005 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007006 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007007
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007008 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007009
Chia-I Wuf7458c52015-10-26 21:10:41 +08007010 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7011 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7012 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7013 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007014}
Tobin Ehlis912df022015-09-17 08:46:18 -06007015/*// TODO : This test should be good, but needs Tess support in compiler to run
7016TEST_F(VkLayerTest, InvalidPatchControlPoints)
7017{
7018 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007019 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007020
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007022 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7023primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007024
Tobin Ehlis912df022015-09-17 08:46:18 -06007025 ASSERT_NO_FATAL_FAILURE(InitState());
7026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007027
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007028 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007029 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007030 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007031
7032 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7033 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7034 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007035 ds_pool_ci.poolSizeCount = 1;
7036 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007037
7038 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007039 err = vkCreateDescriptorPool(m_device->device(),
7040VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007041 ASSERT_VK_SUCCESS(err);
7042
7043 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007044 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007045 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007046 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007047 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7048 dsl_binding.pImmutableSamplers = NULL;
7049
7050 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007051 ds_layout_ci.sType =
7052VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007053 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007054 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007055 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007056
7057 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007058 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7059&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007060 ASSERT_VK_SUCCESS(err);
7061
7062 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007063 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7064VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007065 ASSERT_VK_SUCCESS(err);
7066
7067 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007068 pipeline_layout_ci.sType =
7069VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007070 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007071 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007072 pipeline_layout_ci.pSetLayouts = &ds_layout;
7073
7074 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007075 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7076&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007077 ASSERT_VK_SUCCESS(err);
7078
7079 VkPipelineShaderStageCreateInfo shaderStages[3];
7080 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7081
Karl Schultz6addd812016-02-02 17:17:23 -07007082 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7083this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007084 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007085 VkShaderObj
7086tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7087this);
7088 VkShaderObj
7089te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7090this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007091
Karl Schultz6addd812016-02-02 17:17:23 -07007092 shaderStages[0].sType =
7093VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007094 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007095 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007096 shaderStages[1].sType =
7097VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007098 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007099 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007100 shaderStages[2].sType =
7101VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007102 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007103 shaderStages[2].shader = te.handle();
7104
7105 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007106 iaCI.sType =
7107VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007108 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007109
7110 VkPipelineTessellationStateCreateInfo tsCI = {};
7111 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7112 tsCI.patchControlPoints = 0; // This will cause an error
7113
7114 VkGraphicsPipelineCreateInfo gp_ci = {};
7115 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7116 gp_ci.pNext = NULL;
7117 gp_ci.stageCount = 3;
7118 gp_ci.pStages = shaderStages;
7119 gp_ci.pVertexInputState = NULL;
7120 gp_ci.pInputAssemblyState = &iaCI;
7121 gp_ci.pTessellationState = &tsCI;
7122 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007123 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007124 gp_ci.pMultisampleState = NULL;
7125 gp_ci.pDepthStencilState = NULL;
7126 gp_ci.pColorBlendState = NULL;
7127 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7128 gp_ci.layout = pipeline_layout;
7129 gp_ci.renderPass = renderPass();
7130
7131 VkPipelineCacheCreateInfo pc_ci = {};
7132 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7133 pc_ci.pNext = NULL;
7134 pc_ci.initialSize = 0;
7135 pc_ci.initialData = 0;
7136 pc_ci.maxSize = 0;
7137
7138 VkPipeline pipeline;
7139 VkPipelineCache pipelineCache;
7140
Karl Schultz6addd812016-02-02 17:17:23 -07007141 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7142&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007143 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007144 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7145&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007146
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007147 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007148
Chia-I Wuf7458c52015-10-26 21:10:41 +08007149 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7152 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007153}
7154*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007155
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007156TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007157 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007158
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007159 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007160
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161 ASSERT_NO_FATAL_FAILURE(InitState());
7162 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007163
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007164 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007165 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7166 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007167
7168 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007169 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7170 ds_pool_ci.maxSets = 1;
7171 ds_pool_ci.poolSizeCount = 1;
7172 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007173
7174 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176 ASSERT_VK_SUCCESS(err);
7177
7178 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007179 dsl_binding.binding = 0;
7180 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7181 dsl_binding.descriptorCount = 1;
7182 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007183
7184 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007185 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7186 ds_layout_ci.bindingCount = 1;
7187 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007188
7189 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007190 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007191 ASSERT_VK_SUCCESS(err);
7192
7193 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007194 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007195 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007196 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007197 alloc_info.descriptorPool = ds_pool;
7198 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007199 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007200 ASSERT_VK_SUCCESS(err);
7201
7202 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007203 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7204 pipeline_layout_ci.setLayoutCount = 1;
7205 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007206
7207 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007208 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007209 ASSERT_VK_SUCCESS(err);
7210
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007211 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007212 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007213 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007214 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007215 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007216 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007217
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007218 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7219 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7220 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7221 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7222 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7223 rs_state_ci.depthClampEnable = VK_FALSE;
7224 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7225 rs_state_ci.depthBiasEnable = VK_FALSE;
7226
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007227 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7228 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7229 vi_ci.pNext = nullptr;
7230 vi_ci.vertexBindingDescriptionCount = 0;
7231 vi_ci.pVertexBindingDescriptions = nullptr;
7232 vi_ci.vertexAttributeDescriptionCount = 0;
7233 vi_ci.pVertexAttributeDescriptions = nullptr;
7234
7235 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7236 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7237 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7238
7239 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7240 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7241 pipe_ms_state_ci.pNext = NULL;
7242 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7243 pipe_ms_state_ci.sampleShadingEnable = 0;
7244 pipe_ms_state_ci.minSampleShading = 1.0;
7245 pipe_ms_state_ci.pSampleMask = NULL;
7246
Cody Northropeb3a6c12015-10-05 14:44:45 -06007247 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007248 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007249
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007250 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007251 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007252 shaderStages[0] = vs.GetStageCreateInfo();
7253 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007254
7255 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007256 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7257 gp_ci.stageCount = 2;
7258 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007259 gp_ci.pVertexInputState = &vi_ci;
7260 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007261 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007262 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007263 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007264 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7265 gp_ci.layout = pipeline_layout;
7266 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007267
7268 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007269 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270
7271 VkPipeline pipeline;
7272 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007273 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007274 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007275
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007276 if (!m_device->phy().features().multiViewport) {
7277 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7278
7279 // Check case where multiViewport is disabled and viewport count is not 1
7280 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7283 vp_state_ci.scissorCount = 0;
7284 vp_state_ci.viewportCount = 0;
7285 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7286 m_errorMonitor->VerifyFound();
7287 } else {
7288 if (m_device->props.limits.maxViewports == 1) {
7289 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7290 } else {
7291 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7292
7293 // Check is that viewportcount and scissorcount match
7294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7295 vp_state_ci.scissorCount = 1;
7296 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7297 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7298 m_errorMonitor->VerifyFound();
7299
7300
7301 // Check case where multiViewport is enabled and viewport count is greater than max
7302 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7305 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7306 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7307 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7308 m_errorMonitor->VerifyFound();
7309 }
7310 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007311
Chia-I Wuf7458c52015-10-26 21:10:41 +08007312 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7313 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7314 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7315 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007316}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007317
7318// 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
7319// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007320TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007321 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007322
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007323 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7324
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007326
Tobin Ehlise68360f2015-10-01 11:15:13 -06007327 ASSERT_NO_FATAL_FAILURE(InitState());
7328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007329
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007330 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007331 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7332 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007333
7334 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007335 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7336 ds_pool_ci.maxSets = 1;
7337 ds_pool_ci.poolSizeCount = 1;
7338 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007339
7340 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007341 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007342 ASSERT_VK_SUCCESS(err);
7343
7344 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007345 dsl_binding.binding = 0;
7346 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7347 dsl_binding.descriptorCount = 1;
7348 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007349
7350 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007351 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7352 ds_layout_ci.bindingCount = 1;
7353 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007354
7355 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007356 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007357 ASSERT_VK_SUCCESS(err);
7358
7359 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007360 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007361 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007362 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007363 alloc_info.descriptorPool = ds_pool;
7364 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007365 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007366 ASSERT_VK_SUCCESS(err);
7367
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007368 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7369 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7370 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7371
7372 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7373 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7374 vi_ci.pNext = nullptr;
7375 vi_ci.vertexBindingDescriptionCount = 0;
7376 vi_ci.pVertexBindingDescriptions = nullptr;
7377 vi_ci.vertexAttributeDescriptionCount = 0;
7378 vi_ci.pVertexAttributeDescriptions = nullptr;
7379
7380 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7381 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7382 pipe_ms_state_ci.pNext = NULL;
7383 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7384 pipe_ms_state_ci.sampleShadingEnable = 0;
7385 pipe_ms_state_ci.minSampleShading = 1.0;
7386 pipe_ms_state_ci.pSampleMask = NULL;
7387
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007389 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7390 pipeline_layout_ci.setLayoutCount = 1;
7391 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007392
7393 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007394 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007395 ASSERT_VK_SUCCESS(err);
7396
7397 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7398 // Set scissor as dynamic to avoid second error
7399 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007400 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7401 dyn_state_ci.dynamicStateCount = 1;
7402 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007403
Cody Northropeb3a6c12015-10-05 14:44:45 -06007404 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007405 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007406
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007407 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007408 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7409 // 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 +08007410 shaderStages[0] = vs.GetStageCreateInfo();
7411 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007412
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007413 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7414 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7415 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7416 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7417 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7418 rs_state_ci.depthClampEnable = VK_FALSE;
7419 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7420 rs_state_ci.depthBiasEnable = VK_FALSE;
7421
Tobin Ehlise68360f2015-10-01 11:15:13 -06007422 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007423 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7424 gp_ci.stageCount = 2;
7425 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007426 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007427 // Not setting VP state w/o dynamic vp state should cause validation error
7428 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007429 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007430 gp_ci.pVertexInputState = &vi_ci;
7431 gp_ci.pInputAssemblyState = &ia_ci;
7432 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007433 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7434 gp_ci.layout = pipeline_layout;
7435 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007436
7437 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007438 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007439
7440 VkPipeline pipeline;
7441 VkPipelineCache pipelineCache;
7442
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007443 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007444 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007445 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007446
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007447 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007448
Chia-I Wuf7458c52015-10-26 21:10:41 +08007449 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7450 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7451 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7452 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007453}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007454
7455// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7456// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007457TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7458 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007459
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007461
Tobin Ehlise68360f2015-10-01 11:15:13 -06007462 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007463
7464 if (!m_device->phy().features().multiViewport) {
7465 printf("Device does not support multiple viewports/scissors; skipped.\n");
7466 return;
7467 }
7468
Tobin Ehlise68360f2015-10-01 11:15:13 -06007469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007470
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007471 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007472 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7473 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007474
7475 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007476 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7477 ds_pool_ci.maxSets = 1;
7478 ds_pool_ci.poolSizeCount = 1;
7479 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480
7481 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007482 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007483 ASSERT_VK_SUCCESS(err);
7484
7485 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007486 dsl_binding.binding = 0;
7487 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7488 dsl_binding.descriptorCount = 1;
7489 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007490
7491 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007492 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7493 ds_layout_ci.bindingCount = 1;
7494 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007495
7496 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007497 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007498 ASSERT_VK_SUCCESS(err);
7499
7500 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007501 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007502 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007503 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007504 alloc_info.descriptorPool = ds_pool;
7505 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007506 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007507 ASSERT_VK_SUCCESS(err);
7508
7509 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007510 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7511 pipeline_layout_ci.setLayoutCount = 1;
7512 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007513
7514 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007515 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007516 ASSERT_VK_SUCCESS(err);
7517
7518 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007519 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7520 vp_state_ci.viewportCount = 1;
7521 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7522 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007523 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007524
7525 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7526 // Set scissor as dynamic to avoid that error
7527 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007528 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7529 dyn_state_ci.dynamicStateCount = 1;
7530 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007531
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007532 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7533 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7534 pipe_ms_state_ci.pNext = NULL;
7535 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7536 pipe_ms_state_ci.sampleShadingEnable = 0;
7537 pipe_ms_state_ci.minSampleShading = 1.0;
7538 pipe_ms_state_ci.pSampleMask = NULL;
7539
Cody Northropeb3a6c12015-10-05 14:44:45 -06007540 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007541 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007542
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007543 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007544 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7545 // 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 +08007546 shaderStages[0] = vs.GetStageCreateInfo();
7547 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007548
Cody Northropf6622dc2015-10-06 10:33:21 -06007549 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7550 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7551 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007552 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007553 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007554 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007555 vi_ci.pVertexAttributeDescriptions = nullptr;
7556
7557 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7558 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7559 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7560
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007561 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007562 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007563 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007564 rs_ci.pNext = nullptr;
7565
Mark Youngc89c6312016-03-31 16:03:20 -06007566 VkPipelineColorBlendAttachmentState att = {};
7567 att.blendEnable = VK_FALSE;
7568 att.colorWriteMask = 0xf;
7569
Cody Northropf6622dc2015-10-06 10:33:21 -06007570 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7571 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7572 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007573 cb_ci.attachmentCount = 1;
7574 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007575
Tobin Ehlise68360f2015-10-01 11:15:13 -06007576 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007577 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7578 gp_ci.stageCount = 2;
7579 gp_ci.pStages = shaderStages;
7580 gp_ci.pVertexInputState = &vi_ci;
7581 gp_ci.pInputAssemblyState = &ia_ci;
7582 gp_ci.pViewportState = &vp_state_ci;
7583 gp_ci.pRasterizationState = &rs_ci;
7584 gp_ci.pColorBlendState = &cb_ci;
7585 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007586 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007587 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7588 gp_ci.layout = pipeline_layout;
7589 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007590
7591 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007592 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007593
7594 VkPipeline pipeline;
7595 VkPipelineCache pipelineCache;
7596
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007597 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007598 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007599 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007600
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007601 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007602
Tobin Ehlisd332f282015-10-02 11:00:56 -06007603 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007604 // First need to successfully create the PSO from above by setting
7605 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007606 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 -07007607
7608 VkViewport vp = {}; // Just need dummy vp to point to
7609 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007610 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007611 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007612 m_commandBuffer->BeginCommandBuffer();
7613 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007614 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007615 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007616 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007617 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007618 Draw(1, 0, 0, 0);
7619
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007620 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007621
7622 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7623 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7624 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007626 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007627}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007628
7629// 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 -07007630// viewportCount
7631TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7632 VkResult err;
7633
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007635
7636 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007637
7638 if (!m_device->phy().features().multiViewport) {
7639 printf("Device does not support multiple viewports/scissors; skipped.\n");
7640 return;
7641 }
7642
Karl Schultz6addd812016-02-02 17:17:23 -07007643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7644
7645 VkDescriptorPoolSize ds_type_count = {};
7646 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7647 ds_type_count.descriptorCount = 1;
7648
7649 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7650 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7651 ds_pool_ci.maxSets = 1;
7652 ds_pool_ci.poolSizeCount = 1;
7653 ds_pool_ci.pPoolSizes = &ds_type_count;
7654
7655 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007656 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007657 ASSERT_VK_SUCCESS(err);
7658
7659 VkDescriptorSetLayoutBinding dsl_binding = {};
7660 dsl_binding.binding = 0;
7661 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7662 dsl_binding.descriptorCount = 1;
7663 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7664
7665 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7666 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7667 ds_layout_ci.bindingCount = 1;
7668 ds_layout_ci.pBindings = &dsl_binding;
7669
7670 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007671 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007672 ASSERT_VK_SUCCESS(err);
7673
7674 VkDescriptorSet descriptorSet;
7675 VkDescriptorSetAllocateInfo alloc_info = {};
7676 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7677 alloc_info.descriptorSetCount = 1;
7678 alloc_info.descriptorPool = ds_pool;
7679 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007680 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007681 ASSERT_VK_SUCCESS(err);
7682
7683 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7684 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7685 pipeline_layout_ci.setLayoutCount = 1;
7686 pipeline_layout_ci.pSetLayouts = &ds_layout;
7687
7688 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007689 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007690 ASSERT_VK_SUCCESS(err);
7691
7692 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7693 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7694 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007695 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007696 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007697 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007698
7699 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7700 // Set scissor as dynamic to avoid that error
7701 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7702 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7703 dyn_state_ci.dynamicStateCount = 1;
7704 dyn_state_ci.pDynamicStates = &vp_state;
7705
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007706 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7707 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7708 pipe_ms_state_ci.pNext = NULL;
7709 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7710 pipe_ms_state_ci.sampleShadingEnable = 0;
7711 pipe_ms_state_ci.minSampleShading = 1.0;
7712 pipe_ms_state_ci.pSampleMask = NULL;
7713
Karl Schultz6addd812016-02-02 17:17:23 -07007714 VkPipelineShaderStageCreateInfo shaderStages[2];
7715 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007717 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007718 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7719 // 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 -07007720 shaderStages[0] = vs.GetStageCreateInfo();
7721 shaderStages[1] = fs.GetStageCreateInfo();
7722
7723 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7724 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7725 vi_ci.pNext = nullptr;
7726 vi_ci.vertexBindingDescriptionCount = 0;
7727 vi_ci.pVertexBindingDescriptions = nullptr;
7728 vi_ci.vertexAttributeDescriptionCount = 0;
7729 vi_ci.pVertexAttributeDescriptions = nullptr;
7730
7731 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7732 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7733 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7734
7735 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7736 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007737 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007738 rs_ci.pNext = nullptr;
7739
Mark Youngc89c6312016-03-31 16:03:20 -06007740 VkPipelineColorBlendAttachmentState att = {};
7741 att.blendEnable = VK_FALSE;
7742 att.colorWriteMask = 0xf;
7743
Karl Schultz6addd812016-02-02 17:17:23 -07007744 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7745 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7746 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007747 cb_ci.attachmentCount = 1;
7748 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007749
7750 VkGraphicsPipelineCreateInfo gp_ci = {};
7751 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7752 gp_ci.stageCount = 2;
7753 gp_ci.pStages = shaderStages;
7754 gp_ci.pVertexInputState = &vi_ci;
7755 gp_ci.pInputAssemblyState = &ia_ci;
7756 gp_ci.pViewportState = &vp_state_ci;
7757 gp_ci.pRasterizationState = &rs_ci;
7758 gp_ci.pColorBlendState = &cb_ci;
7759 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007760 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007761 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7762 gp_ci.layout = pipeline_layout;
7763 gp_ci.renderPass = renderPass();
7764
7765 VkPipelineCacheCreateInfo pc_ci = {};
7766 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7767
7768 VkPipeline pipeline;
7769 VkPipelineCache pipelineCache;
7770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007771 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007772 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007773 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007775 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007776
7777 // Now hit second fail case where we set scissor w/ different count than PSO
7778 // First need to successfully create the PSO from above by setting
7779 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007780 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 -06007781
Tobin Ehlisd332f282015-10-02 11:00:56 -06007782 VkRect2D sc = {}; // Just need dummy vp to point to
7783 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007784 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007785 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007786 m_commandBuffer->BeginCommandBuffer();
7787 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007788 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007789 VkViewport viewports[1] = {};
7790 viewports[0].width = 8;
7791 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007792 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007793 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007794 Draw(1, 0, 0, 0);
7795
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007796 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007797
Chia-I Wuf7458c52015-10-26 21:10:41 +08007798 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7799 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7800 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7801 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007802 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007803}
7804
Mark Young7394fdd2016-03-31 14:56:43 -06007805TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7806 VkResult err;
7807
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007809
7810 ASSERT_NO_FATAL_FAILURE(InitState());
7811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7812
7813 VkDescriptorPoolSize ds_type_count = {};
7814 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7815 ds_type_count.descriptorCount = 1;
7816
7817 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7818 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7819 ds_pool_ci.maxSets = 1;
7820 ds_pool_ci.poolSizeCount = 1;
7821 ds_pool_ci.pPoolSizes = &ds_type_count;
7822
7823 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007824 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007825 ASSERT_VK_SUCCESS(err);
7826
7827 VkDescriptorSetLayoutBinding dsl_binding = {};
7828 dsl_binding.binding = 0;
7829 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7830 dsl_binding.descriptorCount = 1;
7831 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7832
7833 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7834 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7835 ds_layout_ci.bindingCount = 1;
7836 ds_layout_ci.pBindings = &dsl_binding;
7837
7838 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007839 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007840 ASSERT_VK_SUCCESS(err);
7841
7842 VkDescriptorSet descriptorSet;
7843 VkDescriptorSetAllocateInfo alloc_info = {};
7844 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7845 alloc_info.descriptorSetCount = 1;
7846 alloc_info.descriptorPool = ds_pool;
7847 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007848 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007849 ASSERT_VK_SUCCESS(err);
7850
7851 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7852 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7853 pipeline_layout_ci.setLayoutCount = 1;
7854 pipeline_layout_ci.pSetLayouts = &ds_layout;
7855
7856 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007857 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007858 ASSERT_VK_SUCCESS(err);
7859
7860 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7861 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7862 vp_state_ci.scissorCount = 1;
7863 vp_state_ci.pScissors = NULL;
7864 vp_state_ci.viewportCount = 1;
7865 vp_state_ci.pViewports = NULL;
7866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007867 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007868 // Set scissor as dynamic to avoid that error
7869 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7870 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7871 dyn_state_ci.dynamicStateCount = 2;
7872 dyn_state_ci.pDynamicStates = dynamic_states;
7873
7874 VkPipelineShaderStageCreateInfo shaderStages[2];
7875 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7876
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007877 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7878 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007879 this); // TODO - We shouldn't need a fragment shader
7880 // but add it to be able to run on more devices
7881 shaderStages[0] = vs.GetStageCreateInfo();
7882 shaderStages[1] = fs.GetStageCreateInfo();
7883
7884 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7885 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7886 vi_ci.pNext = nullptr;
7887 vi_ci.vertexBindingDescriptionCount = 0;
7888 vi_ci.pVertexBindingDescriptions = nullptr;
7889 vi_ci.vertexAttributeDescriptionCount = 0;
7890 vi_ci.pVertexAttributeDescriptions = nullptr;
7891
7892 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7893 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7894 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7895
7896 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7897 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7898 rs_ci.pNext = nullptr;
7899
Mark Young47107952016-05-02 15:59:55 -06007900 // Check too low (line width of -1.0f).
7901 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007902
7903 VkPipelineColorBlendAttachmentState att = {};
7904 att.blendEnable = VK_FALSE;
7905 att.colorWriteMask = 0xf;
7906
7907 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7908 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7909 cb_ci.pNext = nullptr;
7910 cb_ci.attachmentCount = 1;
7911 cb_ci.pAttachments = &att;
7912
7913 VkGraphicsPipelineCreateInfo gp_ci = {};
7914 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7915 gp_ci.stageCount = 2;
7916 gp_ci.pStages = shaderStages;
7917 gp_ci.pVertexInputState = &vi_ci;
7918 gp_ci.pInputAssemblyState = &ia_ci;
7919 gp_ci.pViewportState = &vp_state_ci;
7920 gp_ci.pRasterizationState = &rs_ci;
7921 gp_ci.pColorBlendState = &cb_ci;
7922 gp_ci.pDynamicState = &dyn_state_ci;
7923 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7924 gp_ci.layout = pipeline_layout;
7925 gp_ci.renderPass = renderPass();
7926
7927 VkPipelineCacheCreateInfo pc_ci = {};
7928 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7929
7930 VkPipeline pipeline;
7931 VkPipelineCache pipelineCache;
7932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007933 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007934 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007935 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007936
7937 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007938 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007939
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007941
7942 // Check too high (line width of 65536.0f).
7943 rs_ci.lineWidth = 65536.0f;
7944
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007945 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007946 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007947 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007948
7949 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007950 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007953
7954 dyn_state_ci.dynamicStateCount = 3;
7955
7956 rs_ci.lineWidth = 1.0f;
7957
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007958 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007959 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07007961 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007962 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007963
7964 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007965 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007966 m_errorMonitor->VerifyFound();
7967
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007969
7970 // Check too high with dynamic setting.
7971 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7972 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07007973 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06007974
7975 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7976 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7977 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7978 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007979 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007980}
7981
Karl Schultz6addd812016-02-02 17:17:23 -07007982TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007983 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07007985 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007986
7987 ASSERT_NO_FATAL_FAILURE(InitState());
7988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007989
Tony Barbour552f6c02016-12-21 14:34:07 -07007990 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007991 // Don't care about RenderPass handle b/c error should be flagged before
7992 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007993 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007994
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007995 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007996}
7997
Karl Schultz6addd812016-02-02 17:17:23 -07007998TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007999 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8001 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008002
8003 ASSERT_NO_FATAL_FAILURE(InitState());
8004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008005
Tony Barbour552f6c02016-12-21 14:34:07 -07008006 m_commandBuffer->BeginCommandBuffer();
8007 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008008 // Just create a dummy Renderpass that's non-NULL so we can get to the
8009 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008010 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008011
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008012 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008013}
8014
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008015TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
8016 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
8017 "the number of renderPass attachments that use loadOp"
8018 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8019
8020 ASSERT_NO_FATAL_FAILURE(InitState());
8021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8022
8023 // Create a renderPass with a single attachment that uses loadOp CLEAR
8024 VkAttachmentReference attach = {};
8025 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8026 VkSubpassDescription subpass = {};
8027 subpass.inputAttachmentCount = 1;
8028 subpass.pInputAttachments = &attach;
8029 VkRenderPassCreateInfo rpci = {};
8030 rpci.subpassCount = 1;
8031 rpci.pSubpasses = &subpass;
8032 rpci.attachmentCount = 1;
8033 VkAttachmentDescription attach_desc = {};
8034 attach_desc.format = VK_FORMAT_UNDEFINED;
8035 // Set loadOp to CLEAR
8036 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8037 rpci.pAttachments = &attach_desc;
8038 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8039 VkRenderPass rp;
8040 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8041
8042 VkCommandBufferInheritanceInfo hinfo = {};
8043 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8044 hinfo.renderPass = VK_NULL_HANDLE;
8045 hinfo.subpass = 0;
8046 hinfo.framebuffer = VK_NULL_HANDLE;
8047 hinfo.occlusionQueryEnable = VK_FALSE;
8048 hinfo.queryFlags = 0;
8049 hinfo.pipelineStatistics = 0;
8050 VkCommandBufferBeginInfo info = {};
8051 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8052 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8053 info.pInheritanceInfo = &hinfo;
8054
8055 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8056 VkRenderPassBeginInfo rp_begin = {};
8057 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8058 rp_begin.pNext = NULL;
8059 rp_begin.renderPass = renderPass();
8060 rp_begin.framebuffer = framebuffer();
8061 rp_begin.clearValueCount = 0; // Should be 1
8062
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008064
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008065 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008066
8067 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008068
8069 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008070}
8071
Slawomir Cygan0808f392016-11-28 17:53:23 +01008072TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
8073 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
8074 "the number of renderPass attachments that use loadOp"
8075 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8076
8077 ASSERT_NO_FATAL_FAILURE(InitState());
8078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8079
8080 // Create a renderPass with a single attachment that uses loadOp CLEAR
8081 VkAttachmentReference attach = {};
8082 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8083 VkSubpassDescription subpass = {};
8084 subpass.inputAttachmentCount = 1;
8085 subpass.pInputAttachments = &attach;
8086 VkRenderPassCreateInfo rpci = {};
8087 rpci.subpassCount = 1;
8088 rpci.pSubpasses = &subpass;
8089 rpci.attachmentCount = 1;
8090 VkAttachmentDescription attach_desc = {};
8091 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8092 // Set loadOp to CLEAR
8093 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8094 rpci.pAttachments = &attach_desc;
8095 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8096 VkRenderPass rp;
8097 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8098
8099 VkCommandBufferBeginInfo info = {};
8100 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8101 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8102
8103 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8104 VkRenderPassBeginInfo rp_begin = {};
8105 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8106 rp_begin.pNext = NULL;
8107 rp_begin.renderPass = renderPass();
8108 rp_begin.framebuffer = framebuffer();
8109 rp_begin.clearValueCount = 2; // Should be 1
8110
8111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8112 " 2 but only first 1 entries in pClearValues array are used");
8113
8114 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8115
8116 m_errorMonitor->VerifyFound();
8117
8118 vkDestroyRenderPass(m_device->device(), rp, NULL);
8119}
8120
8121
Cody Northrop3bb4d962016-05-09 16:15:57 -06008122TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8123
8124 TEST_DESCRIPTION("End a command buffer with an active render pass");
8125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8127 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008128
8129 ASSERT_NO_FATAL_FAILURE(InitState());
8130 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8131
Tony Barbour552f6c02016-12-21 14:34:07 -07008132 m_commandBuffer->BeginCommandBuffer();
8133 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8134 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008135
8136 m_errorMonitor->VerifyFound();
8137
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008138 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8139 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008140}
8141
Karl Schultz6addd812016-02-02 17:17:23 -07008142TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008143 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8145 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008146
8147 ASSERT_NO_FATAL_FAILURE(InitState());
8148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008149
Tony Barbour552f6c02016-12-21 14:34:07 -07008150 m_commandBuffer->BeginCommandBuffer();
8151 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008152
8153 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008154 vk_testing::Buffer dstBuffer;
8155 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008156
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008157 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008158
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008159 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008160}
8161
Karl Schultz6addd812016-02-02 17:17:23 -07008162TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008163 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8165 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008166
8167 ASSERT_NO_FATAL_FAILURE(InitState());
8168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008169
Tony Barbour552f6c02016-12-21 14:34:07 -07008170 m_commandBuffer->BeginCommandBuffer();
8171 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008172
8173 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008174 vk_testing::Buffer dstBuffer;
8175 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008176
Karl Schultz6addd812016-02-02 17:17:23 -07008177 VkDeviceSize dstOffset = 0;
8178 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008179 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008180
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008181 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008182
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008183 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008184}
8185
Karl Schultz6addd812016-02-02 17:17:23 -07008186TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008187 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8189 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008190
8191 ASSERT_NO_FATAL_FAILURE(InitState());
8192 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008193
Tony Barbour552f6c02016-12-21 14:34:07 -07008194 m_commandBuffer->BeginCommandBuffer();
8195 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008196
Michael Lentine0a369f62016-02-03 16:51:46 -06008197 VkClearColorValue clear_color;
8198 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008199 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8200 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8201 const int32_t tex_width = 32;
8202 const int32_t tex_height = 32;
8203 VkImageCreateInfo image_create_info = {};
8204 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8205 image_create_info.pNext = NULL;
8206 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8207 image_create_info.format = tex_format;
8208 image_create_info.extent.width = tex_width;
8209 image_create_info.extent.height = tex_height;
8210 image_create_info.extent.depth = 1;
8211 image_create_info.mipLevels = 1;
8212 image_create_info.arrayLayers = 1;
8213 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8214 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8215 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008216
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008217 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008218 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008219
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008220 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008222 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008223
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008224 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008225}
8226
Karl Schultz6addd812016-02-02 17:17:23 -07008227TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008228 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8230 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008231
8232 ASSERT_NO_FATAL_FAILURE(InitState());
8233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008234
Tony Barbour552f6c02016-12-21 14:34:07 -07008235 m_commandBuffer->BeginCommandBuffer();
8236 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008237
8238 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008239 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008240 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8241 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8242 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8243 image_create_info.extent.width = 64;
8244 image_create_info.extent.height = 64;
8245 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8246 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008247
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008248 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008249 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008250
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008251 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008252
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008253 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
8254 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008255
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008256 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008257}
8258
Karl Schultz6addd812016-02-02 17:17:23 -07008259TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008260 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008261 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008262
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8264 "must be issued inside an active "
8265 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008266
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008267 ASSERT_NO_FATAL_FAILURE(InitState());
8268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008269
8270 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008271 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008272 ASSERT_VK_SUCCESS(err);
8273
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008274 VkClearAttachment color_attachment;
8275 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8276 color_attachment.clearValue.color.float32[0] = 0;
8277 color_attachment.clearValue.color.float32[1] = 0;
8278 color_attachment.clearValue.color.float32[2] = 0;
8279 color_attachment.clearValue.color.float32[3] = 0;
8280 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008281 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008282 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008284 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008285}
8286
Chris Forbes3b97e932016-09-07 11:29:24 +12008287TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8288 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8289 "called too many times in a renderpass instance");
8290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8292 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008293
8294 ASSERT_NO_FATAL_FAILURE(InitState());
8295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8296
Tony Barbour552f6c02016-12-21 14:34:07 -07008297 m_commandBuffer->BeginCommandBuffer();
8298 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008299
8300 // error here.
8301 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8302 m_errorMonitor->VerifyFound();
8303
Tony Barbour552f6c02016-12-21 14:34:07 -07008304 m_commandBuffer->EndRenderPass();
8305 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008306}
8307
Chris Forbes6d624702016-09-07 13:57:05 +12008308TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8309 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8310 "called before the final subpass has been reached");
8311
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8313 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008314
8315 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8317 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008319 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008320
8321 VkRenderPass rp;
8322 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8323 ASSERT_VK_SUCCESS(err);
8324
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008325 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008326
8327 VkFramebuffer fb;
8328 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8329 ASSERT_VK_SUCCESS(err);
8330
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008331 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008333 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 +12008334
8335 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8336
8337 // Error here.
8338 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8339 m_errorMonitor->VerifyFound();
8340
8341 // Clean up.
8342 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8343 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8344}
8345
Karl Schultz9e66a292016-04-21 15:57:51 -06008346TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8347 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8349 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008350
8351 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008352 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008353
8354 VkBufferMemoryBarrier buf_barrier = {};
8355 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8356 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8357 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8358 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8359 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8360 buf_barrier.buffer = VK_NULL_HANDLE;
8361 buf_barrier.offset = 0;
8362 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8364 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008365
8366 m_errorMonitor->VerifyFound();
8367}
8368
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008369TEST_F(VkLayerTest, InvalidBarriers) {
8370 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8371
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008373
8374 ASSERT_NO_FATAL_FAILURE(InitState());
8375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8376
8377 VkMemoryBarrier mem_barrier = {};
8378 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8379 mem_barrier.pNext = NULL;
8380 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8381 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008382 m_commandBuffer->BeginCommandBuffer();
8383 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008384 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008385 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008386 &mem_barrier, 0, nullptr, 0, nullptr);
8387 m_errorMonitor->VerifyFound();
8388
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008390 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008391 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 -06008392 ASSERT_TRUE(image.initialized());
8393 VkImageMemoryBarrier img_barrier = {};
8394 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8395 img_barrier.pNext = NULL;
8396 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8397 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8398 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8399 // New layout can't be UNDEFINED
8400 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8401 img_barrier.image = image.handle();
8402 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8403 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8404 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8405 img_barrier.subresourceRange.baseArrayLayer = 0;
8406 img_barrier.subresourceRange.baseMipLevel = 0;
8407 img_barrier.subresourceRange.layerCount = 1;
8408 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008409 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8410 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008411 m_errorMonitor->VerifyFound();
8412 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8413
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8415 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008416 // baseArrayLayer + layerCount must be <= image's arrayLayers
8417 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008418 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8419 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008420 m_errorMonitor->VerifyFound();
8421 img_barrier.subresourceRange.baseArrayLayer = 0;
8422
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008424 // baseMipLevel + levelCount must be <= image's mipLevels
8425 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008426 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8427 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008428 m_errorMonitor->VerifyFound();
8429 img_barrier.subresourceRange.baseMipLevel = 0;
8430
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008431 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 -06008432 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008433 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8434 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008435 VkBufferMemoryBarrier buf_barrier = {};
8436 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8437 buf_barrier.pNext = NULL;
8438 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8439 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8440 buf_barrier.buffer = buffer.handle();
8441 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8442 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8443 buf_barrier.offset = 0;
8444 buf_barrier.size = VK_WHOLE_SIZE;
8445 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008446 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8447 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008448 m_errorMonitor->VerifyFound();
8449 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8450
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008452 buf_barrier.offset = 257;
8453 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8455 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008456 m_errorMonitor->VerifyFound();
8457 buf_barrier.offset = 0;
8458
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008460 buf_barrier.size = 257;
8461 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008462 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8463 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008464 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008465
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008466 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008467 m_errorMonitor->SetDesiredFailureMsg(
8468 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8469 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8470 m_errorMonitor->SetDesiredFailureMsg(
8471 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8472 "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 -06008473 VkDepthStencilObj ds_image(m_device);
8474 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8475 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008476 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8477 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008478 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008479 // Use of COLOR aspect on DS image is error
8480 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8482 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008483 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008484 // Now test depth-only
8485 VkFormatProperties format_props;
8486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8488 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8490 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8492 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008493 VkDepthStencilObj d_image(m_device);
8494 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8495 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008496 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008497 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008498 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008499 // Use of COLOR aspect on depth image is error
8500 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008501 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8502 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008503 m_errorMonitor->VerifyFound();
8504 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008505 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8506 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008507 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8509 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008510 VkDepthStencilObj s_image(m_device);
8511 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8512 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008514 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008515 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008516 // Use of COLOR aspect on depth image is error
8517 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8519 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008520 m_errorMonitor->VerifyFound();
8521 }
8522 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8524 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8526 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008527 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008528 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 -06008529 ASSERT_TRUE(c_image.initialized());
8530 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8531 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8532 img_barrier.image = c_image.handle();
8533 // Set aspect to depth (non-color)
8534 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008535 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8536 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008537 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008538
8539 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8540
8541 // Create command pool with incompatible queueflags
8542 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8543 uint32_t queue_family_index = UINT32_MAX;
8544 for (uint32_t i = 0; i < queue_props.size(); i++) {
8545 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8546 queue_family_index = i;
8547 break;
8548 }
8549 }
8550 if (queue_family_index == UINT32_MAX) {
8551 printf("No non-compute queue found; skipped.\n");
8552 return;
8553 }
8554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8555
8556 VkCommandPool command_pool;
8557 VkCommandPoolCreateInfo pool_create_info{};
8558 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8559 pool_create_info.queueFamilyIndex = queue_family_index;
8560 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8561 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8562
8563 // Allocate a command buffer
8564 VkCommandBuffer bad_command_buffer;
8565 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8566 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8567 command_buffer_allocate_info.commandPool = command_pool;
8568 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8569 command_buffer_allocate_info.commandBufferCount = 1;
8570 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8571
8572 VkCommandBufferBeginInfo cbbi = {};
8573 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8574 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8575 buf_barrier.offset = 0;
8576 buf_barrier.size = VK_WHOLE_SIZE;
8577 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8578 &buf_barrier, 0, nullptr);
8579 m_errorMonitor->VerifyFound();
8580
8581 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8582 vkEndCommandBuffer(bad_command_buffer);
8583 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8584 printf("The non-compute queue does not support graphics; skipped.\n");
8585 return;
8586 }
8587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8588 VkEvent event;
8589 VkEventCreateInfo event_create_info{};
8590 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8591 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8592 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8593 nullptr, 0, nullptr);
8594 m_errorMonitor->VerifyFound();
8595
8596 vkEndCommandBuffer(bad_command_buffer);
8597 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008598}
8599
Tony Barbour18ba25c2016-09-29 13:42:40 -06008600TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8601 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8602
8603 m_errorMonitor->SetDesiredFailureMsg(
8604 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8605 "must have required access bit");
8606 ASSERT_NO_FATAL_FAILURE(InitState());
8607 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008608 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 -06008609 ASSERT_TRUE(image.initialized());
8610
8611 VkImageMemoryBarrier barrier = {};
8612 VkImageSubresourceRange range;
8613 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8614 barrier.srcAccessMask = 0;
8615 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8616 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8617 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8618 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8619 barrier.image = image.handle();
8620 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8621 range.baseMipLevel = 0;
8622 range.levelCount = 1;
8623 range.baseArrayLayer = 0;
8624 range.layerCount = 1;
8625 barrier.subresourceRange = range;
8626 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8627 cmdbuf.BeginCommandBuffer();
8628 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8629 &barrier);
8630 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8631 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8632 barrier.srcAccessMask = 0;
8633 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8634 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8635 &barrier);
8636
8637 m_errorMonitor->VerifyFound();
8638}
8639
Karl Schultz6addd812016-02-02 17:17:23 -07008640TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008641 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008642 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008643
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008645
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008646 ASSERT_NO_FATAL_FAILURE(InitState());
8647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008648 uint32_t qfi = 0;
8649 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008650 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8651 buffCI.size = 1024;
8652 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8653 buffCI.queueFamilyIndexCount = 1;
8654 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008655
8656 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008657 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008658 ASSERT_VK_SUCCESS(err);
8659
Tony Barbour552f6c02016-12-21 14:34:07 -07008660 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008661 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008662 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8663 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008664 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008665 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008666
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008667 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008668
Chia-I Wuf7458c52015-10-26 21:10:41 +08008669 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008670}
8671
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008672TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8673 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8675 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8676 "of the indices specified when the device was created, via the "
8677 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008678
8679 ASSERT_NO_FATAL_FAILURE(InitState());
8680 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8681 VkBufferCreateInfo buffCI = {};
8682 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8683 buffCI.size = 1024;
8684 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8685 buffCI.queueFamilyIndexCount = 1;
8686 // Introduce failure by specifying invalid queue_family_index
8687 uint32_t qfi = 777;
8688 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008689 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008690
8691 VkBuffer ib;
8692 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8693
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008694 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008695 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008696}
8697
Karl Schultz6addd812016-02-02 17:17:23 -07008698TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008699TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008700 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008701
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008702 ASSERT_NO_FATAL_FAILURE(InitState());
8703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008704
Chris Forbesf29a84f2016-10-06 18:39:28 +13008705 // An empty primary command buffer
8706 VkCommandBufferObj cb(m_device, m_commandPool);
8707 cb.BeginCommandBuffer();
8708 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008709
Chris Forbesf29a84f2016-10-06 18:39:28 +13008710 m_commandBuffer->BeginCommandBuffer();
8711 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8712 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008713
Chris Forbesf29a84f2016-10-06 18:39:28 +13008714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8715 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008716 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008717}
8718
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008719TEST_F(VkLayerTest, DSUsageBitsErrors) {
8720 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8721 "that do not have correct usage bits sets.");
8722 VkResult err;
8723
8724 ASSERT_NO_FATAL_FAILURE(InitState());
8725 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8726 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8727 ds_type_count[i].type = VkDescriptorType(i);
8728 ds_type_count[i].descriptorCount = 1;
8729 }
8730 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8731 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8732 ds_pool_ci.pNext = NULL;
8733 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8734 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8735 ds_pool_ci.pPoolSizes = ds_type_count;
8736
8737 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008738 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008739 ASSERT_VK_SUCCESS(err);
8740
8741 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008742 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008743 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8744 dsl_binding[i].binding = 0;
8745 dsl_binding[i].descriptorType = VkDescriptorType(i);
8746 dsl_binding[i].descriptorCount = 1;
8747 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8748 dsl_binding[i].pImmutableSamplers = NULL;
8749 }
8750
8751 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8752 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8753 ds_layout_ci.pNext = NULL;
8754 ds_layout_ci.bindingCount = 1;
8755 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8756 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8757 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008758 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008759 ASSERT_VK_SUCCESS(err);
8760 }
8761 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8762 VkDescriptorSetAllocateInfo alloc_info = {};
8763 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8764 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8765 alloc_info.descriptorPool = ds_pool;
8766 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008767 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008768 ASSERT_VK_SUCCESS(err);
8769
8770 // Create a buffer & bufferView to be used for invalid updates
8771 VkBufferCreateInfo buff_ci = {};
8772 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8773 // This usage is not valid for any descriptor type
8774 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8775 buff_ci.size = 256;
8776 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8777 VkBuffer buffer;
8778 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8779 ASSERT_VK_SUCCESS(err);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008780 VkMemoryRequirements mem_reqs;
8781 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8782 VkMemoryAllocateInfo mem_alloc_info = {};
8783 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8784 mem_alloc_info.pNext = NULL;
8785 mem_alloc_info.memoryTypeIndex = 0;
8786 mem_alloc_info.allocationSize = mem_reqs.size;
8787 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8788 if (!pass) {
8789 vkDestroyBuffer(m_device->device(), buffer, NULL);
8790 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8791 return;
8792 }
8793 VkDeviceMemory mem;
8794 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
8795 ASSERT_VK_SUCCESS(err);
8796 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8797 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008798
8799 VkBufferViewCreateInfo buff_view_ci = {};
8800 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8801 buff_view_ci.buffer = buffer;
8802 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8803 buff_view_ci.range = VK_WHOLE_SIZE;
8804 VkBufferView buff_view;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008805 // 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 -06008806 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008807 ASSERT_VK_SUCCESS(err);
8808
8809 // Create an image to be used for invalid updates
8810 VkImageCreateInfo image_ci = {};
8811 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8812 image_ci.imageType = VK_IMAGE_TYPE_2D;
8813 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8814 image_ci.extent.width = 64;
8815 image_ci.extent.height = 64;
8816 image_ci.extent.depth = 1;
8817 image_ci.mipLevels = 1;
8818 image_ci.arrayLayers = 1;
8819 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8820 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8821 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8822 // This usage is not valid for any descriptor type
8823 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8824 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8825 VkImage image;
8826 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8827 ASSERT_VK_SUCCESS(err);
8828 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008829 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008830
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008831 VkMemoryAllocateInfo mem_alloc = {};
8832 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8833 mem_alloc.pNext = NULL;
8834 mem_alloc.allocationSize = 0;
8835 mem_alloc.memoryTypeIndex = 0;
8836 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8837 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008838 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008839 ASSERT_TRUE(pass);
8840 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8841 ASSERT_VK_SUCCESS(err);
8842 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8843 ASSERT_VK_SUCCESS(err);
8844 // Now create view for image
8845 VkImageViewCreateInfo image_view_ci = {};
8846 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8847 image_view_ci.image = image;
8848 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8849 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8850 image_view_ci.subresourceRange.layerCount = 1;
8851 image_view_ci.subresourceRange.baseArrayLayer = 0;
8852 image_view_ci.subresourceRange.levelCount = 1;
8853 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8854 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008855 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008856 ASSERT_VK_SUCCESS(err);
8857
8858 VkDescriptorBufferInfo buff_info = {};
8859 buff_info.buffer = buffer;
8860 VkDescriptorImageInfo img_info = {};
8861 img_info.imageView = image_view;
8862 VkWriteDescriptorSet descriptor_write = {};
8863 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8864 descriptor_write.dstBinding = 0;
8865 descriptor_write.descriptorCount = 1;
8866 descriptor_write.pTexelBufferView = &buff_view;
8867 descriptor_write.pBufferInfo = &buff_info;
8868 descriptor_write.pImageInfo = &img_info;
8869
8870 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008871 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
8872 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
8873 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
8874 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
8875 VALIDATION_ERROR_00943, // STORAGE_IMAGE
8876 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
8877 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
8878 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
8879 VALIDATION_ERROR_00947, // STORAGE_BUFFER
8880 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
8881 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
8882 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
8883 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008884 // Start loop at 1 as SAMPLER desc type has no usage bit error
8885 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8886 descriptor_write.descriptorType = VkDescriptorType(i);
8887 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008890 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008891
8892 m_errorMonitor->VerifyFound();
8893 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8894 }
8895 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8896 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008897 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008898 vkDestroyImageView(m_device->device(), image_view, NULL);
8899 vkDestroyBuffer(m_device->device(), buffer, NULL);
8900 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008901 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008902 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8903}
8904
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008905TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008906 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8907 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8908 "1. offset value greater than buffer size\n"
8909 "2. range value of 0\n"
8910 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008911 VkResult err;
8912
8913 ASSERT_NO_FATAL_FAILURE(InitState());
8914 VkDescriptorPoolSize ds_type_count = {};
8915 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8916 ds_type_count.descriptorCount = 1;
8917
8918 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8919 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8920 ds_pool_ci.pNext = NULL;
8921 ds_pool_ci.maxSets = 1;
8922 ds_pool_ci.poolSizeCount = 1;
8923 ds_pool_ci.pPoolSizes = &ds_type_count;
8924
8925 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008926 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008927 ASSERT_VK_SUCCESS(err);
8928
8929 // Create layout with single uniform buffer descriptor
8930 VkDescriptorSetLayoutBinding dsl_binding = {};
8931 dsl_binding.binding = 0;
8932 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8933 dsl_binding.descriptorCount = 1;
8934 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8935 dsl_binding.pImmutableSamplers = NULL;
8936
8937 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8938 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8939 ds_layout_ci.pNext = NULL;
8940 ds_layout_ci.bindingCount = 1;
8941 ds_layout_ci.pBindings = &dsl_binding;
8942 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008944 ASSERT_VK_SUCCESS(err);
8945
8946 VkDescriptorSet descriptor_set = {};
8947 VkDescriptorSetAllocateInfo alloc_info = {};
8948 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8949 alloc_info.descriptorSetCount = 1;
8950 alloc_info.descriptorPool = ds_pool;
8951 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008953 ASSERT_VK_SUCCESS(err);
8954
8955 // Create a buffer to be used for invalid updates
8956 VkBufferCreateInfo buff_ci = {};
8957 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8958 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8959 buff_ci.size = 256;
8960 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8961 VkBuffer buffer;
8962 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8963 ASSERT_VK_SUCCESS(err);
8964 // Have to bind memory to buffer before descriptor update
8965 VkMemoryAllocateInfo mem_alloc = {};
8966 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8967 mem_alloc.pNext = NULL;
8968 mem_alloc.allocationSize = 256;
8969 mem_alloc.memoryTypeIndex = 0;
8970
8971 VkMemoryRequirements mem_reqs;
8972 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008973 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008974 if (!pass) {
8975 vkDestroyBuffer(m_device->device(), buffer, NULL);
8976 return;
8977 }
8978
8979 VkDeviceMemory mem;
8980 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8981 ASSERT_VK_SUCCESS(err);
8982 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8983 ASSERT_VK_SUCCESS(err);
8984
8985 VkDescriptorBufferInfo buff_info = {};
8986 buff_info.buffer = buffer;
8987 // First make offset 1 larger than buffer size
8988 buff_info.offset = 257;
8989 buff_info.range = VK_WHOLE_SIZE;
8990 VkWriteDescriptorSet descriptor_write = {};
8991 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8992 descriptor_write.dstBinding = 0;
8993 descriptor_write.descriptorCount = 1;
8994 descriptor_write.pTexelBufferView = nullptr;
8995 descriptor_write.pBufferInfo = &buff_info;
8996 descriptor_write.pImageInfo = nullptr;
8997
8998 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8999 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009001
9002 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9003
9004 m_errorMonitor->VerifyFound();
9005 // Now cause error due to range of 0
9006 buff_info.offset = 0;
9007 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009009
9010 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9011
9012 m_errorMonitor->VerifyFound();
9013 // Now cause error due to range exceeding buffer size - offset
9014 buff_info.offset = 128;
9015 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009017
9018 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9019
9020 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009021 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009022 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9023 vkDestroyBuffer(m_device->device(), buffer, NULL);
9024 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9025 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9026}
9027
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009028TEST_F(VkLayerTest, DSAspectBitsErrors) {
9029 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9030 // are set, but could expand this test to hit more cases.
9031 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
9032 "that do not have correct aspect bits sets.");
9033 VkResult err;
9034
9035 ASSERT_NO_FATAL_FAILURE(InitState());
9036 VkDescriptorPoolSize ds_type_count = {};
9037 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9038 ds_type_count.descriptorCount = 1;
9039
9040 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9041 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9042 ds_pool_ci.pNext = NULL;
9043 ds_pool_ci.maxSets = 5;
9044 ds_pool_ci.poolSizeCount = 1;
9045 ds_pool_ci.pPoolSizes = &ds_type_count;
9046
9047 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009048 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009049 ASSERT_VK_SUCCESS(err);
9050
9051 VkDescriptorSetLayoutBinding dsl_binding = {};
9052 dsl_binding.binding = 0;
9053 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9054 dsl_binding.descriptorCount = 1;
9055 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9056 dsl_binding.pImmutableSamplers = NULL;
9057
9058 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9059 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9060 ds_layout_ci.pNext = NULL;
9061 ds_layout_ci.bindingCount = 1;
9062 ds_layout_ci.pBindings = &dsl_binding;
9063 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009064 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009065 ASSERT_VK_SUCCESS(err);
9066
9067 VkDescriptorSet descriptor_set = {};
9068 VkDescriptorSetAllocateInfo alloc_info = {};
9069 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9070 alloc_info.descriptorSetCount = 1;
9071 alloc_info.descriptorPool = ds_pool;
9072 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009073 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009074 ASSERT_VK_SUCCESS(err);
9075
9076 // Create an image to be used for invalid updates
9077 VkImageCreateInfo image_ci = {};
9078 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9079 image_ci.imageType = VK_IMAGE_TYPE_2D;
9080 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9081 image_ci.extent.width = 64;
9082 image_ci.extent.height = 64;
9083 image_ci.extent.depth = 1;
9084 image_ci.mipLevels = 1;
9085 image_ci.arrayLayers = 1;
9086 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9087 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9088 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9089 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9090 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9091 VkImage image;
9092 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9093 ASSERT_VK_SUCCESS(err);
9094 // Bind memory to image
9095 VkMemoryRequirements mem_reqs;
9096 VkDeviceMemory image_mem;
9097 bool pass;
9098 VkMemoryAllocateInfo mem_alloc = {};
9099 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9100 mem_alloc.pNext = NULL;
9101 mem_alloc.allocationSize = 0;
9102 mem_alloc.memoryTypeIndex = 0;
9103 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9104 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009105 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009106 ASSERT_TRUE(pass);
9107 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9108 ASSERT_VK_SUCCESS(err);
9109 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9110 ASSERT_VK_SUCCESS(err);
9111 // Now create view for image
9112 VkImageViewCreateInfo image_view_ci = {};
9113 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9114 image_view_ci.image = image;
9115 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9116 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9117 image_view_ci.subresourceRange.layerCount = 1;
9118 image_view_ci.subresourceRange.baseArrayLayer = 0;
9119 image_view_ci.subresourceRange.levelCount = 1;
9120 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009121 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009122
9123 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009124 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009125 ASSERT_VK_SUCCESS(err);
9126
9127 VkDescriptorImageInfo img_info = {};
9128 img_info.imageView = image_view;
9129 VkWriteDescriptorSet descriptor_write = {};
9130 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9131 descriptor_write.dstBinding = 0;
9132 descriptor_write.descriptorCount = 1;
9133 descriptor_write.pTexelBufferView = NULL;
9134 descriptor_write.pBufferInfo = NULL;
9135 descriptor_write.pImageInfo = &img_info;
9136 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9137 descriptor_write.dstSet = descriptor_set;
9138 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9139 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009141
9142 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9143
9144 m_errorMonitor->VerifyFound();
9145 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9146 vkDestroyImage(m_device->device(), image, NULL);
9147 vkFreeMemory(m_device->device(), image_mem, NULL);
9148 vkDestroyImageView(m_device->device(), image_view, NULL);
9149 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9150 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9151}
9152
Karl Schultz6addd812016-02-02 17:17:23 -07009153TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009154 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009155 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9158 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9159 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009160
Tobin Ehlis3b780662015-05-28 12:11:26 -06009161 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009162 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009163 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009164 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9165 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009166
9167 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009168 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9169 ds_pool_ci.pNext = NULL;
9170 ds_pool_ci.maxSets = 1;
9171 ds_pool_ci.poolSizeCount = 1;
9172 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009173
Tobin Ehlis3b780662015-05-28 12:11:26 -06009174 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009175 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009176 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009177 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009178 dsl_binding.binding = 0;
9179 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9180 dsl_binding.descriptorCount = 1;
9181 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9182 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009183
Tony Barboureb254902015-07-15 12:50:33 -06009184 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009185 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9186 ds_layout_ci.pNext = NULL;
9187 ds_layout_ci.bindingCount = 1;
9188 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009189
Tobin Ehlis3b780662015-05-28 12:11:26 -06009190 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009192 ASSERT_VK_SUCCESS(err);
9193
9194 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009195 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009196 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009197 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009198 alloc_info.descriptorPool = ds_pool;
9199 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009200 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009201 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009202
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009203 VkSamplerCreateInfo sampler_ci = {};
9204 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9205 sampler_ci.pNext = NULL;
9206 sampler_ci.magFilter = VK_FILTER_NEAREST;
9207 sampler_ci.minFilter = VK_FILTER_NEAREST;
9208 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9209 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9210 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9211 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9212 sampler_ci.mipLodBias = 1.0;
9213 sampler_ci.anisotropyEnable = VK_FALSE;
9214 sampler_ci.maxAnisotropy = 1;
9215 sampler_ci.compareEnable = VK_FALSE;
9216 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9217 sampler_ci.minLod = 1.0;
9218 sampler_ci.maxLod = 1.0;
9219 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9220 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9221 VkSampler sampler;
9222 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9223 ASSERT_VK_SUCCESS(err);
9224
9225 VkDescriptorImageInfo info = {};
9226 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009227
9228 VkWriteDescriptorSet descriptor_write;
9229 memset(&descriptor_write, 0, sizeof(descriptor_write));
9230 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009231 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009232 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009233 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009234 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009235 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009236
9237 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9238
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009239 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009240
Chia-I Wuf7458c52015-10-26 21:10:41 +08009241 vkDestroySampler(m_device->device(), sampler, NULL);
9242 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9243 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009244}
9245
Karl Schultz6addd812016-02-02 17:17:23 -07009246TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009247 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009248 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009249
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009251
Tobin Ehlis3b780662015-05-28 12:11:26 -06009252 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009253 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009254 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009255 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9256 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009257
9258 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009259 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9260 ds_pool_ci.pNext = NULL;
9261 ds_pool_ci.maxSets = 1;
9262 ds_pool_ci.poolSizeCount = 1;
9263 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009264
Tobin Ehlis3b780662015-05-28 12:11:26 -06009265 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009266 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009267 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009268
Tony Barboureb254902015-07-15 12:50:33 -06009269 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009270 dsl_binding.binding = 0;
9271 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9272 dsl_binding.descriptorCount = 1;
9273 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9274 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009275
9276 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009277 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9278 ds_layout_ci.pNext = NULL;
9279 ds_layout_ci.bindingCount = 1;
9280 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009281
Tobin Ehlis3b780662015-05-28 12:11:26 -06009282 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009283 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009284 ASSERT_VK_SUCCESS(err);
9285
9286 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009287 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009288 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009289 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009290 alloc_info.descriptorPool = ds_pool;
9291 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009292 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009293 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009294
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009295 // Correctly update descriptor to avoid "NOT_UPDATED" error
9296 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009297 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009298 buff_info.offset = 0;
9299 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009300
9301 VkWriteDescriptorSet descriptor_write;
9302 memset(&descriptor_write, 0, sizeof(descriptor_write));
9303 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009304 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009305 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009306 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009307 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9308 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009309
9310 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9311
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009312 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009313
Chia-I Wuf7458c52015-10-26 21:10:41 +08009314 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9315 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009316}
9317
Karl Schultz6addd812016-02-02 17:17:23 -07009318TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009319 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009320 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009321
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009323
Tobin Ehlis3b780662015-05-28 12:11:26 -06009324 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009325 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009326 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009327 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9328 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009329
9330 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009331 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9332 ds_pool_ci.pNext = NULL;
9333 ds_pool_ci.maxSets = 1;
9334 ds_pool_ci.poolSizeCount = 1;
9335 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009336
Tobin Ehlis3b780662015-05-28 12:11:26 -06009337 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009338 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009339 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009340
Tony Barboureb254902015-07-15 12:50:33 -06009341 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009342 dsl_binding.binding = 0;
9343 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9344 dsl_binding.descriptorCount = 1;
9345 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9346 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009347
9348 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009349 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9350 ds_layout_ci.pNext = NULL;
9351 ds_layout_ci.bindingCount = 1;
9352 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009353 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009355 ASSERT_VK_SUCCESS(err);
9356
9357 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009358 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009360 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009361 alloc_info.descriptorPool = ds_pool;
9362 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009364 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009365
Tony Barboureb254902015-07-15 12:50:33 -06009366 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009367 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9368 sampler_ci.pNext = NULL;
9369 sampler_ci.magFilter = VK_FILTER_NEAREST;
9370 sampler_ci.minFilter = VK_FILTER_NEAREST;
9371 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9372 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9373 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9374 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9375 sampler_ci.mipLodBias = 1.0;
9376 sampler_ci.anisotropyEnable = VK_FALSE;
9377 sampler_ci.maxAnisotropy = 1;
9378 sampler_ci.compareEnable = VK_FALSE;
9379 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9380 sampler_ci.minLod = 1.0;
9381 sampler_ci.maxLod = 1.0;
9382 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9383 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009384
Tobin Ehlis3b780662015-05-28 12:11:26 -06009385 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009386 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009387 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009388
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009389 VkDescriptorImageInfo info = {};
9390 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009391
9392 VkWriteDescriptorSet descriptor_write;
9393 memset(&descriptor_write, 0, sizeof(descriptor_write));
9394 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009395 descriptor_write.dstSet = descriptorSet;
9396 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009397 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009398 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009399 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009400 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009401
9402 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9403
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009404 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009405
Chia-I Wuf7458c52015-10-26 21:10:41 +08009406 vkDestroySampler(m_device->device(), sampler, NULL);
9407 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9408 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009409}
9410
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009411TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9412 // Create layout w/ empty binding and attempt to update it
9413 VkResult err;
9414
9415 ASSERT_NO_FATAL_FAILURE(InitState());
9416
9417 VkDescriptorPoolSize ds_type_count = {};
9418 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9419 ds_type_count.descriptorCount = 1;
9420
9421 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9422 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9423 ds_pool_ci.pNext = NULL;
9424 ds_pool_ci.maxSets = 1;
9425 ds_pool_ci.poolSizeCount = 1;
9426 ds_pool_ci.pPoolSizes = &ds_type_count;
9427
9428 VkDescriptorPool ds_pool;
9429 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9430 ASSERT_VK_SUCCESS(err);
9431
9432 VkDescriptorSetLayoutBinding dsl_binding = {};
9433 dsl_binding.binding = 0;
9434 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9435 dsl_binding.descriptorCount = 0;
9436 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9437 dsl_binding.pImmutableSamplers = NULL;
9438
9439 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9440 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9441 ds_layout_ci.pNext = NULL;
9442 ds_layout_ci.bindingCount = 1;
9443 ds_layout_ci.pBindings = &dsl_binding;
9444 VkDescriptorSetLayout ds_layout;
9445 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9446 ASSERT_VK_SUCCESS(err);
9447
9448 VkDescriptorSet descriptor_set;
9449 VkDescriptorSetAllocateInfo alloc_info = {};
9450 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9451 alloc_info.descriptorSetCount = 1;
9452 alloc_info.descriptorPool = ds_pool;
9453 alloc_info.pSetLayouts = &ds_layout;
9454 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9455 ASSERT_VK_SUCCESS(err);
9456
9457 VkSamplerCreateInfo sampler_ci = {};
9458 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9459 sampler_ci.magFilter = VK_FILTER_NEAREST;
9460 sampler_ci.minFilter = VK_FILTER_NEAREST;
9461 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9462 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9463 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9464 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9465 sampler_ci.mipLodBias = 1.0;
9466 sampler_ci.maxAnisotropy = 1;
9467 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9468 sampler_ci.minLod = 1.0;
9469 sampler_ci.maxLod = 1.0;
9470 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9471
9472 VkSampler sampler;
9473 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9474 ASSERT_VK_SUCCESS(err);
9475
9476 VkDescriptorImageInfo info = {};
9477 info.sampler = sampler;
9478
9479 VkWriteDescriptorSet descriptor_write;
9480 memset(&descriptor_write, 0, sizeof(descriptor_write));
9481 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9482 descriptor_write.dstSet = descriptor_set;
9483 descriptor_write.dstBinding = 0;
9484 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9485 // This is the wrong type, but empty binding error will be flagged first
9486 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9487 descriptor_write.pImageInfo = &info;
9488
9489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9490 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9491 m_errorMonitor->VerifyFound();
9492
9493 vkDestroySampler(m_device->device(), sampler, NULL);
9494 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9495 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9496}
9497
Karl Schultz6addd812016-02-02 17:17:23 -07009498TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9499 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9500 // types
9501 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009502
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009503 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 -06009504
Tobin Ehlis3b780662015-05-28 12:11:26 -06009505 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009506
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009507 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009508 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9509 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009510
9511 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009512 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9513 ds_pool_ci.pNext = NULL;
9514 ds_pool_ci.maxSets = 1;
9515 ds_pool_ci.poolSizeCount = 1;
9516 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009517
Tobin Ehlis3b780662015-05-28 12:11:26 -06009518 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009519 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009520 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009521 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009522 dsl_binding.binding = 0;
9523 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9524 dsl_binding.descriptorCount = 1;
9525 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9526 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009527
Tony Barboureb254902015-07-15 12:50:33 -06009528 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009529 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9530 ds_layout_ci.pNext = NULL;
9531 ds_layout_ci.bindingCount = 1;
9532 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009533
Tobin Ehlis3b780662015-05-28 12:11:26 -06009534 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009535 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009536 ASSERT_VK_SUCCESS(err);
9537
9538 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009539 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009540 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009541 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009542 alloc_info.descriptorPool = ds_pool;
9543 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009544 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009545 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009546
Tony Barboureb254902015-07-15 12:50:33 -06009547 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009548 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9549 sampler_ci.pNext = NULL;
9550 sampler_ci.magFilter = VK_FILTER_NEAREST;
9551 sampler_ci.minFilter = VK_FILTER_NEAREST;
9552 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9553 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9554 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9555 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9556 sampler_ci.mipLodBias = 1.0;
9557 sampler_ci.anisotropyEnable = VK_FALSE;
9558 sampler_ci.maxAnisotropy = 1;
9559 sampler_ci.compareEnable = VK_FALSE;
9560 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9561 sampler_ci.minLod = 1.0;
9562 sampler_ci.maxLod = 1.0;
9563 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9564 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009565 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009566 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009567 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009568
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009569 VkDescriptorImageInfo info = {};
9570 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009571
9572 VkWriteDescriptorSet descriptor_write;
9573 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009574 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009575 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009576 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009577 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009578 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009579 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009580
9581 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9582
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009583 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009584
Chia-I Wuf7458c52015-10-26 21:10:41 +08009585 vkDestroySampler(m_device->device(), sampler, NULL);
9586 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9587 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009588}
9589
Karl Schultz6addd812016-02-02 17:17:23 -07009590TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009591 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009592 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009593
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009595
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009596 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009597 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9598 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009599 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009600 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9601 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009602
9603 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009604 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9605 ds_pool_ci.pNext = NULL;
9606 ds_pool_ci.maxSets = 1;
9607 ds_pool_ci.poolSizeCount = 1;
9608 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009609
9610 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009611 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009612 ASSERT_VK_SUCCESS(err);
9613
9614 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009615 dsl_binding.binding = 0;
9616 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9617 dsl_binding.descriptorCount = 1;
9618 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9619 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009620
9621 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009622 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9623 ds_layout_ci.pNext = NULL;
9624 ds_layout_ci.bindingCount = 1;
9625 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009626 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009627 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009628 ASSERT_VK_SUCCESS(err);
9629
9630 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009631 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009632 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009633 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009634 alloc_info.descriptorPool = ds_pool;
9635 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009636 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009637 ASSERT_VK_SUCCESS(err);
9638
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009639 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009640
9641 VkDescriptorImageInfo descriptor_info;
9642 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9643 descriptor_info.sampler = sampler;
9644
9645 VkWriteDescriptorSet descriptor_write;
9646 memset(&descriptor_write, 0, sizeof(descriptor_write));
9647 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009648 descriptor_write.dstSet = descriptorSet;
9649 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009650 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009651 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9652 descriptor_write.pImageInfo = &descriptor_info;
9653
9654 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9655
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009656 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009657
Chia-I Wuf7458c52015-10-26 21:10:41 +08009658 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9659 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009660}
9661
Karl Schultz6addd812016-02-02 17:17:23 -07009662TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9663 // Create a single combined Image/Sampler descriptor and send it an invalid
9664 // imageView
9665 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009666
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009668
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009669 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009670 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009671 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9672 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009673
9674 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009675 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9676 ds_pool_ci.pNext = NULL;
9677 ds_pool_ci.maxSets = 1;
9678 ds_pool_ci.poolSizeCount = 1;
9679 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009680
9681 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009682 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009683 ASSERT_VK_SUCCESS(err);
9684
9685 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009686 dsl_binding.binding = 0;
9687 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9688 dsl_binding.descriptorCount = 1;
9689 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9690 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009691
9692 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009693 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9694 ds_layout_ci.pNext = NULL;
9695 ds_layout_ci.bindingCount = 1;
9696 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009697 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009698 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009699 ASSERT_VK_SUCCESS(err);
9700
9701 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009702 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009703 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009704 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009705 alloc_info.descriptorPool = ds_pool;
9706 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009707 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009708 ASSERT_VK_SUCCESS(err);
9709
9710 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009711 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9712 sampler_ci.pNext = NULL;
9713 sampler_ci.magFilter = VK_FILTER_NEAREST;
9714 sampler_ci.minFilter = VK_FILTER_NEAREST;
9715 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9716 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9717 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9718 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9719 sampler_ci.mipLodBias = 1.0;
9720 sampler_ci.anisotropyEnable = VK_FALSE;
9721 sampler_ci.maxAnisotropy = 1;
9722 sampler_ci.compareEnable = VK_FALSE;
9723 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9724 sampler_ci.minLod = 1.0;
9725 sampler_ci.maxLod = 1.0;
9726 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9727 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009728
9729 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009730 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009731 ASSERT_VK_SUCCESS(err);
9732
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009734
9735 VkDescriptorImageInfo descriptor_info;
9736 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9737 descriptor_info.sampler = sampler;
9738 descriptor_info.imageView = view;
9739
9740 VkWriteDescriptorSet descriptor_write;
9741 memset(&descriptor_write, 0, sizeof(descriptor_write));
9742 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009743 descriptor_write.dstSet = descriptorSet;
9744 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009745 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009746 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9747 descriptor_write.pImageInfo = &descriptor_info;
9748
9749 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9750
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009751 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009752
Chia-I Wuf7458c52015-10-26 21:10:41 +08009753 vkDestroySampler(m_device->device(), sampler, NULL);
9754 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9755 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009756}
9757
Karl Schultz6addd812016-02-02 17:17:23 -07009758TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9759 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9760 // into the other
9761 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9764 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9765 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009766
Tobin Ehlis04356f92015-10-27 16:35:27 -06009767 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009768 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009769 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009770 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9771 ds_type_count[0].descriptorCount = 1;
9772 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9773 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009774
9775 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009776 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9777 ds_pool_ci.pNext = NULL;
9778 ds_pool_ci.maxSets = 1;
9779 ds_pool_ci.poolSizeCount = 2;
9780 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009781
9782 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009783 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009784 ASSERT_VK_SUCCESS(err);
9785 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009786 dsl_binding[0].binding = 0;
9787 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9788 dsl_binding[0].descriptorCount = 1;
9789 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9790 dsl_binding[0].pImmutableSamplers = NULL;
9791 dsl_binding[1].binding = 1;
9792 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9793 dsl_binding[1].descriptorCount = 1;
9794 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9795 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009796
9797 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009798 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9799 ds_layout_ci.pNext = NULL;
9800 ds_layout_ci.bindingCount = 2;
9801 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009802
9803 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009804 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009805 ASSERT_VK_SUCCESS(err);
9806
9807 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009808 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009809 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009810 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009811 alloc_info.descriptorPool = ds_pool;
9812 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009813 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009814 ASSERT_VK_SUCCESS(err);
9815
9816 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009817 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9818 sampler_ci.pNext = NULL;
9819 sampler_ci.magFilter = VK_FILTER_NEAREST;
9820 sampler_ci.minFilter = VK_FILTER_NEAREST;
9821 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9822 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9823 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9824 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9825 sampler_ci.mipLodBias = 1.0;
9826 sampler_ci.anisotropyEnable = VK_FALSE;
9827 sampler_ci.maxAnisotropy = 1;
9828 sampler_ci.compareEnable = VK_FALSE;
9829 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9830 sampler_ci.minLod = 1.0;
9831 sampler_ci.maxLod = 1.0;
9832 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9833 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009834
9835 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009836 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009837 ASSERT_VK_SUCCESS(err);
9838
9839 VkDescriptorImageInfo info = {};
9840 info.sampler = sampler;
9841
9842 VkWriteDescriptorSet descriptor_write;
9843 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9844 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009845 descriptor_write.dstSet = descriptorSet;
9846 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009847 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009848 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9849 descriptor_write.pImageInfo = &info;
9850 // This write update should succeed
9851 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9852 // Now perform a copy update that fails due to type mismatch
9853 VkCopyDescriptorSet copy_ds_update;
9854 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9855 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9856 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009857 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009858 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009859 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009860 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009861 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9862
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009863 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009864 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009865 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 -06009866 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9867 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9868 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009869 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009870 copy_ds_update.dstSet = descriptorSet;
9871 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009872 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009873 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9874
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009875 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009876
Tobin Ehlis04356f92015-10-27 16:35:27 -06009877 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9879 "update array offset of 0 and update of "
9880 "5 descriptors oversteps total number "
9881 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009882
Tobin Ehlis04356f92015-10-27 16:35:27 -06009883 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9884 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9885 copy_ds_update.srcSet = descriptorSet;
9886 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009887 copy_ds_update.dstSet = descriptorSet;
9888 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009889 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009890 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9891
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009892 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009893
Chia-I Wuf7458c52015-10-26 21:10:41 +08009894 vkDestroySampler(m_device->device(), sampler, NULL);
9895 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9896 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009897}
9898
Karl Schultz6addd812016-02-02 17:17:23 -07009899TEST_F(VkLayerTest, NumSamplesMismatch) {
9900 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9901 // sampleCount
9902 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009905
Tobin Ehlis3b780662015-05-28 12:11:26 -06009906 ASSERT_NO_FATAL_FAILURE(InitState());
9907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009908 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009909 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009910 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009911
9912 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009913 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9914 ds_pool_ci.pNext = NULL;
9915 ds_pool_ci.maxSets = 1;
9916 ds_pool_ci.poolSizeCount = 1;
9917 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009918
Tobin Ehlis3b780662015-05-28 12:11:26 -06009919 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009920 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009921 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009922
Tony Barboureb254902015-07-15 12:50:33 -06009923 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009924 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009925 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009926 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009927 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9928 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009929
Tony Barboureb254902015-07-15 12:50:33 -06009930 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9931 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9932 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009933 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009934 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009935
Tobin Ehlis3b780662015-05-28 12:11:26 -06009936 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009937 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009938 ASSERT_VK_SUCCESS(err);
9939
9940 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009941 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009942 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009943 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009944 alloc_info.descriptorPool = ds_pool;
9945 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009946 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009947 ASSERT_VK_SUCCESS(err);
9948
Tony Barboureb254902015-07-15 12:50:33 -06009949 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009951 pipe_ms_state_ci.pNext = NULL;
9952 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9953 pipe_ms_state_ci.sampleShadingEnable = 0;
9954 pipe_ms_state_ci.minSampleShading = 1.0;
9955 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009956
Tony Barboureb254902015-07-15 12:50:33 -06009957 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009958 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9959 pipeline_layout_ci.pNext = NULL;
9960 pipeline_layout_ci.setLayoutCount = 1;
9961 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009962
9963 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009964 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009965 ASSERT_VK_SUCCESS(err);
9966
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009967 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9968 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9969 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009970 VkPipelineObj pipe(m_device);
9971 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009972 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009973 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009974 pipe.SetMSAA(&pipe_ms_state_ci);
9975 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009976
Tony Barbour552f6c02016-12-21 14:34:07 -07009977 m_commandBuffer->BeginCommandBuffer();
9978 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009979 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009980
Rene Lindsay3bdc7a42017-01-06 13:20:15 -07009981 VkViewport viewport = {0, 0, 16, 16, 0, 1};
9982 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
9983 VkRect2D scissor = {{0, 0}, {16, 16}};
9984 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
9985
Mark Young29927482016-05-04 14:38:51 -06009986 // Render triangle (the error should trigger on the attempt to draw).
9987 Draw(3, 1, 0, 0);
9988
9989 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -07009990 m_commandBuffer->EndRenderPass();
9991 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -06009992
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009993 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009994
Chia-I Wuf7458c52015-10-26 21:10:41 +08009995 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9996 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9997 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009998}
Mark Young29927482016-05-04 14:38:51 -06009999
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010000TEST_F(VkLayerTest, RenderPassIncompatible) {
10001 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
10002 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -060010003 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010004 VkResult err;
10005
10006 ASSERT_NO_FATAL_FAILURE(InitState());
10007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10008
10009 VkDescriptorSetLayoutBinding dsl_binding = {};
10010 dsl_binding.binding = 0;
10011 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10012 dsl_binding.descriptorCount = 1;
10013 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10014 dsl_binding.pImmutableSamplers = NULL;
10015
10016 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10017 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10018 ds_layout_ci.pNext = NULL;
10019 ds_layout_ci.bindingCount = 1;
10020 ds_layout_ci.pBindings = &dsl_binding;
10021
10022 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010023 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010024 ASSERT_VK_SUCCESS(err);
10025
10026 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10027 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10028 pipeline_layout_ci.pNext = NULL;
10029 pipeline_layout_ci.setLayoutCount = 1;
10030 pipeline_layout_ci.pSetLayouts = &ds_layout;
10031
10032 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010033 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010034 ASSERT_VK_SUCCESS(err);
10035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010036 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10037 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10038 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010039 // Create a renderpass that will be incompatible with default renderpass
10040 VkAttachmentReference attach = {};
10041 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10042 VkAttachmentReference color_att = {};
10043 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10044 VkSubpassDescription subpass = {};
10045 subpass.inputAttachmentCount = 1;
10046 subpass.pInputAttachments = &attach;
10047 subpass.colorAttachmentCount = 1;
10048 subpass.pColorAttachments = &color_att;
10049 VkRenderPassCreateInfo rpci = {};
10050 rpci.subpassCount = 1;
10051 rpci.pSubpasses = &subpass;
10052 rpci.attachmentCount = 1;
10053 VkAttachmentDescription attach_desc = {};
10054 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010055 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10056 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010057 rpci.pAttachments = &attach_desc;
10058 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10059 VkRenderPass rp;
10060 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10061 VkPipelineObj pipe(m_device);
10062 pipe.AddShader(&vs);
10063 pipe.AddShader(&fs);
10064 pipe.AddColorAttachment();
10065 VkViewport view_port = {};
10066 m_viewports.push_back(view_port);
10067 pipe.SetViewport(m_viewports);
10068 VkRect2D rect = {};
10069 m_scissors.push_back(rect);
10070 pipe.SetScissor(m_scissors);
10071 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10072
10073 VkCommandBufferInheritanceInfo cbii = {};
10074 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10075 cbii.renderPass = rp;
10076 cbii.subpass = 0;
10077 VkCommandBufferBeginInfo cbbi = {};
10078 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10079 cbbi.pInheritanceInfo = &cbii;
10080 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10081 VkRenderPassBeginInfo rpbi = {};
10082 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10083 rpbi.framebuffer = m_framebuffer;
10084 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10086 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010089 // Render triangle (the error should trigger on the attempt to draw).
10090 Draw(3, 1, 0, 0);
10091
10092 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010093 m_commandBuffer->EndRenderPass();
10094 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010095
10096 m_errorMonitor->VerifyFound();
10097
10098 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10099 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10100 vkDestroyRenderPass(m_device->device(), rp, NULL);
10101}
10102
Mark Youngc89c6312016-03-31 16:03:20 -060010103TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10104 // Create Pipeline where the number of blend attachments doesn't match the
10105 // number of color attachments. In this case, we don't add any color
10106 // blend attachments even though we have a color attachment.
10107 VkResult err;
10108
10109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010110 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010111
10112 ASSERT_NO_FATAL_FAILURE(InitState());
10113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10114 VkDescriptorPoolSize ds_type_count = {};
10115 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10116 ds_type_count.descriptorCount = 1;
10117
10118 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10119 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10120 ds_pool_ci.pNext = NULL;
10121 ds_pool_ci.maxSets = 1;
10122 ds_pool_ci.poolSizeCount = 1;
10123 ds_pool_ci.pPoolSizes = &ds_type_count;
10124
10125 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010126 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010127 ASSERT_VK_SUCCESS(err);
10128
10129 VkDescriptorSetLayoutBinding dsl_binding = {};
10130 dsl_binding.binding = 0;
10131 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10132 dsl_binding.descriptorCount = 1;
10133 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10134 dsl_binding.pImmutableSamplers = NULL;
10135
10136 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10137 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10138 ds_layout_ci.pNext = NULL;
10139 ds_layout_ci.bindingCount = 1;
10140 ds_layout_ci.pBindings = &dsl_binding;
10141
10142 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010143 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010144 ASSERT_VK_SUCCESS(err);
10145
10146 VkDescriptorSet descriptorSet;
10147 VkDescriptorSetAllocateInfo alloc_info = {};
10148 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10149 alloc_info.descriptorSetCount = 1;
10150 alloc_info.descriptorPool = ds_pool;
10151 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010152 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010153 ASSERT_VK_SUCCESS(err);
10154
10155 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010157 pipe_ms_state_ci.pNext = NULL;
10158 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10159 pipe_ms_state_ci.sampleShadingEnable = 0;
10160 pipe_ms_state_ci.minSampleShading = 1.0;
10161 pipe_ms_state_ci.pSampleMask = NULL;
10162
10163 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10164 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10165 pipeline_layout_ci.pNext = NULL;
10166 pipeline_layout_ci.setLayoutCount = 1;
10167 pipeline_layout_ci.pSetLayouts = &ds_layout;
10168
10169 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010170 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010171 ASSERT_VK_SUCCESS(err);
10172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010173 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10174 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10175 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010176 VkPipelineObj pipe(m_device);
10177 pipe.AddShader(&vs);
10178 pipe.AddShader(&fs);
10179 pipe.SetMSAA(&pipe_ms_state_ci);
10180 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10181
Tony Barbour552f6c02016-12-21 14:34:07 -070010182 m_commandBuffer->BeginCommandBuffer();
10183 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010184 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010185
Rene Lindsay6d5c4fe2017-01-13 09:41:19 -070010186 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10187 VkRect2D scissor = {{0, 0}, {16, 16}};
10188 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10189 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10190
Mark Young29927482016-05-04 14:38:51 -060010191 // Render triangle (the error should trigger on the attempt to draw).
10192 Draw(3, 1, 0, 0);
10193
10194 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010195 m_commandBuffer->EndRenderPass();
10196 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010197
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010198 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010199
10200 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10201 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10202 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10203}
Mark Young29927482016-05-04 14:38:51 -060010204
Mark Muellerd4914412016-06-13 17:52:06 -060010205TEST_F(VkLayerTest, MissingClearAttachment) {
10206 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10207 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010208 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010210
10211 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10212 m_errorMonitor->VerifyFound();
10213}
10214
Karl Schultz6addd812016-02-02 17:17:23 -070010215TEST_F(VkLayerTest, ClearCmdNoDraw) {
10216 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
10217 // to issuing a Draw
10218 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060010221 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010222
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010223 ASSERT_NO_FATAL_FAILURE(InitState());
10224 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010225
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010226 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010227 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10228 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010229
10230 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010231 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10232 ds_pool_ci.pNext = NULL;
10233 ds_pool_ci.maxSets = 1;
10234 ds_pool_ci.poolSizeCount = 1;
10235 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010236
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010237 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010238 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010239 ASSERT_VK_SUCCESS(err);
10240
Tony Barboureb254902015-07-15 12:50:33 -060010241 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010242 dsl_binding.binding = 0;
10243 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10244 dsl_binding.descriptorCount = 1;
10245 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10246 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010247
Tony Barboureb254902015-07-15 12:50:33 -060010248 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010249 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10250 ds_layout_ci.pNext = NULL;
10251 ds_layout_ci.bindingCount = 1;
10252 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010253
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010254 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010255 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010256 ASSERT_VK_SUCCESS(err);
10257
10258 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010259 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010260 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010261 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010262 alloc_info.descriptorPool = ds_pool;
10263 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010264 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010265 ASSERT_VK_SUCCESS(err);
10266
Tony Barboureb254902015-07-15 12:50:33 -060010267 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010268 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010269 pipe_ms_state_ci.pNext = NULL;
10270 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10271 pipe_ms_state_ci.sampleShadingEnable = 0;
10272 pipe_ms_state_ci.minSampleShading = 1.0;
10273 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010274
Tony Barboureb254902015-07-15 12:50:33 -060010275 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010276 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10277 pipeline_layout_ci.pNext = NULL;
10278 pipeline_layout_ci.setLayoutCount = 1;
10279 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010280
10281 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010282 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010283 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010285 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010286 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010287 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010288 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010289
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010290 VkPipelineObj pipe(m_device);
10291 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010292 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010293 pipe.SetMSAA(&pipe_ms_state_ci);
10294 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010295
Tony Barbour552f6c02016-12-21 14:34:07 -070010296 m_commandBuffer->BeginCommandBuffer();
10297 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010298
Karl Schultz6addd812016-02-02 17:17:23 -070010299 // Main thing we care about for this test is that the VkImage obj we're
10300 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010301 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010302 VkClearAttachment color_attachment;
10303 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10304 color_attachment.clearValue.color.float32[0] = 1.0;
10305 color_attachment.clearValue.color.float32[1] = 1.0;
10306 color_attachment.clearValue.color.float32[2] = 1.0;
10307 color_attachment.clearValue.color.float32[3] = 1.0;
10308 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010309 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010311 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010312
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010313 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010314
Chia-I Wuf7458c52015-10-26 21:10:41 +080010315 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10316 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10317 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010318}
10319
Karl Schultz6addd812016-02-02 17:17:23 -070010320TEST_F(VkLayerTest, VtxBufferBadIndex) {
10321 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10324 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010325
Tobin Ehlis502480b2015-06-24 15:53:07 -060010326 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010327 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010329
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010330 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010331 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10332 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010333
10334 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010335 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10336 ds_pool_ci.pNext = NULL;
10337 ds_pool_ci.maxSets = 1;
10338 ds_pool_ci.poolSizeCount = 1;
10339 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010340
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010341 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010342 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010343 ASSERT_VK_SUCCESS(err);
10344
Tony Barboureb254902015-07-15 12:50:33 -060010345 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010346 dsl_binding.binding = 0;
10347 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10348 dsl_binding.descriptorCount = 1;
10349 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10350 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010351
Tony Barboureb254902015-07-15 12:50:33 -060010352 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010353 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10354 ds_layout_ci.pNext = NULL;
10355 ds_layout_ci.bindingCount = 1;
10356 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010357
Tobin Ehlis502480b2015-06-24 15:53:07 -060010358 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010359 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010360 ASSERT_VK_SUCCESS(err);
10361
10362 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010363 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010364 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010365 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010366 alloc_info.descriptorPool = ds_pool;
10367 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010368 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010369 ASSERT_VK_SUCCESS(err);
10370
Tony Barboureb254902015-07-15 12:50:33 -060010371 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010372 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010373 pipe_ms_state_ci.pNext = NULL;
10374 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10375 pipe_ms_state_ci.sampleShadingEnable = 0;
10376 pipe_ms_state_ci.minSampleShading = 1.0;
10377 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010378
Tony Barboureb254902015-07-15 12:50:33 -060010379 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010380 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10381 pipeline_layout_ci.pNext = NULL;
10382 pipeline_layout_ci.setLayoutCount = 1;
10383 pipeline_layout_ci.pSetLayouts = &ds_layout;
10384 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010385
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010386 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010387 ASSERT_VK_SUCCESS(err);
10388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010389 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10390 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10391 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010392 VkPipelineObj pipe(m_device);
10393 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010394 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010395 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010396 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010397 pipe.SetViewport(m_viewports);
10398 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010399 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010400
Tony Barbour552f6c02016-12-21 14:34:07 -070010401 m_commandBuffer->BeginCommandBuffer();
10402 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010403 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010404 // Don't care about actual data, just need to get to draw to flag error
10405 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010406 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010407 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010408 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010409
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010410 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010411
Chia-I Wuf7458c52015-10-26 21:10:41 +080010412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010415}
Mark Muellerdfe37552016-07-07 14:47:42 -060010416
Mark Mueller2ee294f2016-08-04 12:59:48 -060010417TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10418 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10419 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010420 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010421
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010422 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10423 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010425 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10426 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010427
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010428 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010431 // The following test fails with recent NVidia drivers.
10432 // By the time core_validation is reached, the NVidia
10433 // driver has sanitized the invalid condition and core_validation
10434 // is not introduced to the failure condition. This is not the case
10435 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010436 // uint32_t count = static_cast<uint32_t>(~0);
10437 // VkPhysicalDevice physical_device;
10438 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10439 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010442 float queue_priority = 0.0;
10443
10444 VkDeviceQueueCreateInfo queue_create_info = {};
10445 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10446 queue_create_info.queueCount = 1;
10447 queue_create_info.pQueuePriorities = &queue_priority;
10448 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10449
10450 VkPhysicalDeviceFeatures features = m_device->phy().features();
10451 VkDevice testDevice;
10452 VkDeviceCreateInfo device_create_info = {};
10453 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10454 device_create_info.queueCreateInfoCount = 1;
10455 device_create_info.pQueueCreateInfos = &queue_create_info;
10456 device_create_info.pEnabledFeatures = &features;
10457 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10458 m_errorMonitor->VerifyFound();
10459
10460 queue_create_info.queueFamilyIndex = 1;
10461
10462 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10463 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10464 for (unsigned i = 0; i < feature_count; i++) {
10465 if (VK_FALSE == feature_array[i]) {
10466 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010468 device_create_info.pEnabledFeatures = &features;
10469 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10470 m_errorMonitor->VerifyFound();
10471 break;
10472 }
10473 }
10474}
10475
Tobin Ehlis16edf082016-11-21 12:33:49 -070010476TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10477 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10478
10479 ASSERT_NO_FATAL_FAILURE(InitState());
10480
10481 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10482 std::vector<VkDeviceQueueCreateInfo> queue_info;
10483 queue_info.reserve(queue_props.size());
10484 std::vector<std::vector<float>> queue_priorities;
10485 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10486 VkDeviceQueueCreateInfo qi{};
10487 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10488 qi.queueFamilyIndex = i;
10489 qi.queueCount = queue_props[i].queueCount;
10490 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10491 qi.pQueuePriorities = queue_priorities[i].data();
10492 queue_info.push_back(qi);
10493 }
10494
10495 std::vector<const char *> device_extension_names;
10496
10497 VkDevice local_device;
10498 VkDeviceCreateInfo device_create_info = {};
10499 auto features = m_device->phy().features();
10500 // Intentionally disable pipeline stats
10501 features.pipelineStatisticsQuery = VK_FALSE;
10502 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10503 device_create_info.pNext = NULL;
10504 device_create_info.queueCreateInfoCount = queue_info.size();
10505 device_create_info.pQueueCreateInfos = queue_info.data();
10506 device_create_info.enabledLayerCount = 0;
10507 device_create_info.ppEnabledLayerNames = NULL;
10508 device_create_info.pEnabledFeatures = &features;
10509 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10510 ASSERT_VK_SUCCESS(err);
10511
10512 VkQueryPoolCreateInfo qpci{};
10513 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10514 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10515 qpci.queryCount = 1;
10516 VkQueryPool query_pool;
10517
10518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10519 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10520 m_errorMonitor->VerifyFound();
10521
10522 vkDestroyDevice(local_device, nullptr);
10523}
10524
Mark Mueller2ee294f2016-08-04 12:59:48 -060010525TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10526 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10527 "End a command buffer with a query still in progress.");
10528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010529 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10530 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10531 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010533 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010536
10537 ASSERT_NO_FATAL_FAILURE(InitState());
10538
10539 VkEvent event;
10540 VkEventCreateInfo event_create_info{};
10541 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10542 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10543
Mark Mueller2ee294f2016-08-04 12:59:48 -060010544 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010545 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010546
Tony Barbour552f6c02016-12-21 14:34:07 -070010547 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010548
10549 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010550 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 -060010551 ASSERT_TRUE(image.initialized());
10552 VkImageMemoryBarrier img_barrier = {};
10553 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10554 img_barrier.pNext = NULL;
10555 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10556 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10557 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10558 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10559 img_barrier.image = image.handle();
10560 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010561
10562 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10563 // that layer validation catches the case when it is not.
10564 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010565 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10566 img_barrier.subresourceRange.baseArrayLayer = 0;
10567 img_barrier.subresourceRange.baseMipLevel = 0;
10568 img_barrier.subresourceRange.layerCount = 1;
10569 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010570 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10571 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010572 m_errorMonitor->VerifyFound();
10573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010575
10576 VkQueryPool query_pool;
10577 VkQueryPoolCreateInfo query_pool_create_info = {};
10578 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10579 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10580 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010581 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010582
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010583 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010584 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10585
10586 vkEndCommandBuffer(m_commandBuffer->handle());
10587 m_errorMonitor->VerifyFound();
10588
10589 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10590 vkDestroyEvent(m_device->device(), event, nullptr);
10591}
10592
Mark Muellerdfe37552016-07-07 14:47:42 -060010593TEST_F(VkLayerTest, VertexBufferInvalid) {
10594 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10595 "delete a buffer twice, use an invalid offset for each "
10596 "buffer type, and attempt to bind a null buffer");
10597
10598 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10599 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010600 const char *invalid_offset_message = "vkBindBufferMemory(): "
10601 "memoryOffset is 0x";
10602 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10603 "storage memoryOffset "
10604 "is 0x";
10605 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10606 "texel memoryOffset "
10607 "is 0x";
10608 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10609 "uniform memoryOffset "
10610 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010611
10612 ASSERT_NO_FATAL_FAILURE(InitState());
10613 ASSERT_NO_FATAL_FAILURE(InitViewport());
10614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10615
10616 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010617 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010618 pipe_ms_state_ci.pNext = NULL;
10619 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10620 pipe_ms_state_ci.sampleShadingEnable = 0;
10621 pipe_ms_state_ci.minSampleShading = 1.0;
10622 pipe_ms_state_ci.pSampleMask = nullptr;
10623
10624 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10625 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10626 VkPipelineLayout pipeline_layout;
10627
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010628 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010629 ASSERT_VK_SUCCESS(err);
10630
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010631 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10632 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010633 VkPipelineObj pipe(m_device);
10634 pipe.AddShader(&vs);
10635 pipe.AddShader(&fs);
10636 pipe.AddColorAttachment();
10637 pipe.SetMSAA(&pipe_ms_state_ci);
10638 pipe.SetViewport(m_viewports);
10639 pipe.SetScissor(m_scissors);
10640 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10641
Tony Barbour552f6c02016-12-21 14:34:07 -070010642 m_commandBuffer->BeginCommandBuffer();
10643 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010644 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010645
10646 {
10647 // Create and bind a vertex buffer in a reduced scope, which will cause
10648 // it to be deleted upon leaving this scope
10649 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010650 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010651 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10652 draw_verticies.AddVertexInputToPipe(pipe);
10653 }
10654
10655 Draw(1, 0, 0, 0);
10656
Tony Barbour552f6c02016-12-21 14:34:07 -070010657 m_commandBuffer->EndRenderPass();
10658 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010661 QueueCommandBuffer(false);
10662 m_errorMonitor->VerifyFound();
10663
10664 {
10665 // Create and bind a vertex buffer in a reduced scope, and delete it
10666 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010667 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010669 buffer_test.TestDoubleDestroy();
10670 }
10671 m_errorMonitor->VerifyFound();
10672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010673 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010674 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10676 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10677 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010678 m_errorMonitor->VerifyFound();
10679 }
10680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010681 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10682 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010683 // Create and bind a memory buffer with an invalid offset again,
10684 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10686 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10687 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010688 m_errorMonitor->VerifyFound();
10689 }
10690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010691 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010692 // Create and bind a memory buffer with an invalid offset again, but
10693 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10695 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10696 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010697 m_errorMonitor->VerifyFound();
10698 }
10699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010700 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010701 // Create and bind a memory buffer with an invalid offset again, but
10702 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10704 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10705 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010706 m_errorMonitor->VerifyFound();
10707 }
10708
10709 {
10710 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010712 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10713 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010714 m_errorMonitor->VerifyFound();
10715 }
10716
10717 {
10718 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010720 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10721 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010722 }
10723 m_errorMonitor->VerifyFound();
10724
10725 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10726}
10727
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010728// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10729TEST_F(VkLayerTest, InvalidImageLayout) {
10730 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010731 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10732 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010733 // 3 in ValidateCmdBufImageLayouts
10734 // * -1 Attempt to submit cmd buf w/ deleted image
10735 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10736 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010737
10738 ASSERT_NO_FATAL_FAILURE(InitState());
10739 // Create src & dst images to use for copy operations
10740 VkImage src_image;
10741 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010742 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010743
10744 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10745 const int32_t tex_width = 32;
10746 const int32_t tex_height = 32;
10747
10748 VkImageCreateInfo image_create_info = {};
10749 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10750 image_create_info.pNext = NULL;
10751 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10752 image_create_info.format = tex_format;
10753 image_create_info.extent.width = tex_width;
10754 image_create_info.extent.height = tex_height;
10755 image_create_info.extent.depth = 1;
10756 image_create_info.mipLevels = 1;
10757 image_create_info.arrayLayers = 4;
10758 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10759 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10760 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010761 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010762 image_create_info.flags = 0;
10763
10764 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10765 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010766 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010767 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10768 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010769 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10770 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10771 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10772 ASSERT_VK_SUCCESS(err);
10773
10774 // Allocate memory
10775 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010776 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010777 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010778 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10779 mem_alloc.pNext = NULL;
10780 mem_alloc.allocationSize = 0;
10781 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010782
10783 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010784 mem_alloc.allocationSize = img_mem_reqs.size;
10785 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010786 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010787 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010788 ASSERT_VK_SUCCESS(err);
10789
10790 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010791 mem_alloc.allocationSize = img_mem_reqs.size;
10792 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010793 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010794 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010795 ASSERT_VK_SUCCESS(err);
10796
10797 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010798 mem_alloc.allocationSize = img_mem_reqs.size;
10799 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010800 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010801 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010802 ASSERT_VK_SUCCESS(err);
10803
10804 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10805 ASSERT_VK_SUCCESS(err);
10806 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10807 ASSERT_VK_SUCCESS(err);
10808 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10809 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010810
Tony Barbour552f6c02016-12-21 14:34:07 -070010811 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010812 VkImageCopy copy_region;
10813 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10814 copy_region.srcSubresource.mipLevel = 0;
10815 copy_region.srcSubresource.baseArrayLayer = 0;
10816 copy_region.srcSubresource.layerCount = 1;
10817 copy_region.srcOffset.x = 0;
10818 copy_region.srcOffset.y = 0;
10819 copy_region.srcOffset.z = 0;
10820 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10821 copy_region.dstSubresource.mipLevel = 0;
10822 copy_region.dstSubresource.baseArrayLayer = 0;
10823 copy_region.dstSubresource.layerCount = 1;
10824 copy_region.dstOffset.x = 0;
10825 copy_region.dstOffset.y = 0;
10826 copy_region.dstOffset.z = 0;
10827 copy_region.extent.width = 1;
10828 copy_region.extent.height = 1;
10829 copy_region.extent.depth = 1;
10830
10831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10832 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10833 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 -060010834 m_errorMonitor->VerifyFound();
10835 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10837 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10838 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010839 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 -060010840 m_errorMonitor->VerifyFound();
10841 // Final src error is due to bad layout type
10842 m_errorMonitor->SetDesiredFailureMsg(
10843 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10844 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010845 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 -060010846 m_errorMonitor->VerifyFound();
10847 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10849 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010850 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 -060010851 m_errorMonitor->VerifyFound();
10852 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10854 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10855 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010856 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 -060010857 m_errorMonitor->VerifyFound();
10858 m_errorMonitor->SetDesiredFailureMsg(
10859 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10860 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010861 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 -060010862 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010863
Cort3b021012016-12-07 12:00:57 -080010864 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10865 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10866 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10867 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10868 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10869 transfer_dst_image_barrier[0].srcAccessMask = 0;
10870 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10871 transfer_dst_image_barrier[0].image = dst_image;
10872 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10873 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10874 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10875 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10876 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10877 transfer_dst_image_barrier[0].image = depth_image;
10878 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10879 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10880 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10881
10882 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010883 VkClearColorValue color_clear_value = {};
10884 VkImageSubresourceRange clear_range;
10885 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10886 clear_range.baseMipLevel = 0;
10887 clear_range.baseArrayLayer = 0;
10888 clear_range.layerCount = 1;
10889 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010890
Cort3b021012016-12-07 12:00:57 -080010891 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10892 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010895 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010896 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010897 // Fail due to provided layout not matching actual current layout for color clear.
10898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010899 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010900 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010901
Cort530cf382016-12-08 09:59:47 -080010902 VkClearDepthStencilValue depth_clear_value = {};
10903 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010904
10905 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10906 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010909 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010910 m_errorMonitor->VerifyFound();
10911 // Fail due to provided layout not matching actual current layout for depth clear.
10912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010913 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010914 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010915
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010916 // Now cause error due to bad image layout transition in PipelineBarrier
10917 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010918 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010919 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010920 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010921 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010922 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10923 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010924 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Alex Smithc4659e42017-01-10 09:51:22 +000010925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout of aspect 1 from "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010926 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10927 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10928 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10929 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010930 m_errorMonitor->VerifyFound();
10931
10932 // Finally some layout errors at RenderPass create time
10933 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10934 VkAttachmentReference attach = {};
10935 // perf warning for GENERAL layout w/ non-DS input attachment
10936 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10937 VkSubpassDescription subpass = {};
10938 subpass.inputAttachmentCount = 1;
10939 subpass.pInputAttachments = &attach;
10940 VkRenderPassCreateInfo rpci = {};
10941 rpci.subpassCount = 1;
10942 rpci.pSubpasses = &subpass;
10943 rpci.attachmentCount = 1;
10944 VkAttachmentDescription attach_desc = {};
10945 attach_desc.format = VK_FORMAT_UNDEFINED;
10946 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010947 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010948 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10950 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010951 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10952 m_errorMonitor->VerifyFound();
10953 // error w/ non-general layout
10954 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10955
10956 m_errorMonitor->SetDesiredFailureMsg(
10957 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10958 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10959 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10960 m_errorMonitor->VerifyFound();
10961 subpass.inputAttachmentCount = 0;
10962 subpass.colorAttachmentCount = 1;
10963 subpass.pColorAttachments = &attach;
10964 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10965 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10967 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010968 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10969 m_errorMonitor->VerifyFound();
10970 // error w/ non-color opt or GENERAL layout for color attachment
10971 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10972 m_errorMonitor->SetDesiredFailureMsg(
10973 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10974 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10975 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10976 m_errorMonitor->VerifyFound();
10977 subpass.colorAttachmentCount = 0;
10978 subpass.pDepthStencilAttachment = &attach;
10979 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10980 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10982 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010983 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10984 m_errorMonitor->VerifyFound();
10985 // error w/ non-ds opt or GENERAL layout for color attachment
10986 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10988 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10989 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010990 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10991 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010992 // For this error we need a valid renderpass so create default one
10993 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10994 attach.attachment = 0;
10995 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10996 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10997 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10998 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10999 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11000 // Can't do a CLEAR load on READ_ONLY initialLayout
11001 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11002 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11003 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
11005 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11006 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011007 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11008 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011009
Cort3b021012016-12-07 12:00:57 -080011010 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11011 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11012 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011013 vkDestroyImage(m_device->device(), src_image, NULL);
11014 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011015 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011016}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011017
Tobin Ehlise0936662016-10-11 08:10:51 -060011018TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11019 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11020 VkResult err;
11021
11022 ASSERT_NO_FATAL_FAILURE(InitState());
11023
11024 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11025 VkImageTiling tiling;
11026 VkFormatProperties format_properties;
11027 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11028 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11029 tiling = VK_IMAGE_TILING_LINEAR;
11030 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11031 tiling = VK_IMAGE_TILING_OPTIMAL;
11032 } else {
11033 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11034 "skipped.\n");
11035 return;
11036 }
11037
11038 VkDescriptorPoolSize ds_type = {};
11039 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11040 ds_type.descriptorCount = 1;
11041
11042 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11043 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11044 ds_pool_ci.maxSets = 1;
11045 ds_pool_ci.poolSizeCount = 1;
11046 ds_pool_ci.pPoolSizes = &ds_type;
11047 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11048
11049 VkDescriptorPool ds_pool;
11050 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11051 ASSERT_VK_SUCCESS(err);
11052
11053 VkDescriptorSetLayoutBinding dsl_binding = {};
11054 dsl_binding.binding = 0;
11055 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11056 dsl_binding.descriptorCount = 1;
11057 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11058 dsl_binding.pImmutableSamplers = NULL;
11059
11060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11062 ds_layout_ci.pNext = NULL;
11063 ds_layout_ci.bindingCount = 1;
11064 ds_layout_ci.pBindings = &dsl_binding;
11065
11066 VkDescriptorSetLayout ds_layout;
11067 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11068 ASSERT_VK_SUCCESS(err);
11069
11070 VkDescriptorSetAllocateInfo alloc_info = {};
11071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11072 alloc_info.descriptorSetCount = 1;
11073 alloc_info.descriptorPool = ds_pool;
11074 alloc_info.pSetLayouts = &ds_layout;
11075 VkDescriptorSet descriptor_set;
11076 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11077 ASSERT_VK_SUCCESS(err);
11078
11079 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11080 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11081 pipeline_layout_ci.pNext = NULL;
11082 pipeline_layout_ci.setLayoutCount = 1;
11083 pipeline_layout_ci.pSetLayouts = &ds_layout;
11084 VkPipelineLayout pipeline_layout;
11085 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11086 ASSERT_VK_SUCCESS(err);
11087
11088 VkImageObj image(m_device);
11089 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11090 ASSERT_TRUE(image.initialized());
11091 VkImageView view = image.targetView(tex_format);
11092
11093 VkDescriptorImageInfo image_info = {};
11094 image_info.imageView = view;
11095 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11096
11097 VkWriteDescriptorSet descriptor_write = {};
11098 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11099 descriptor_write.dstSet = descriptor_set;
11100 descriptor_write.dstBinding = 0;
11101 descriptor_write.descriptorCount = 1;
11102 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11103 descriptor_write.pImageInfo = &image_info;
11104
11105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11106 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11107 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11108 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11109 m_errorMonitor->VerifyFound();
11110
11111 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11112 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11113 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11114 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11115}
11116
Mark Mueller93b938f2016-08-18 10:27:40 -060011117TEST_F(VkLayerTest, SimultaneousUse) {
11118 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11119 "in primary and secondary command buffers.");
11120
11121 ASSERT_NO_FATAL_FAILURE(InitState());
11122 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11123
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011124 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011125 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11126 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011127
11128 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011129 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011130 command_buffer_allocate_info.commandPool = m_commandPool;
11131 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11132 command_buffer_allocate_info.commandBufferCount = 1;
11133
11134 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011135 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011136 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11137 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011138 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011139 command_buffer_inheritance_info.renderPass = m_renderPass;
11140 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011141
Mark Mueller93b938f2016-08-18 10:27:40 -060011142 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011143 command_buffer_begin_info.flags =
11144 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011145 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11146
11147 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11148 vkEndCommandBuffer(secondary_command_buffer);
11149
Mark Mueller93b938f2016-08-18 10:27:40 -060011150 VkSubmitInfo submit_info = {};
11151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11152 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011153 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011154
Mark Mueller4042b652016-09-05 22:52:21 -060011155 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011156 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11158 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011159 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011160 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011161 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11162 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011163
11164 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060011165 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11166
Mark Mueller4042b652016-09-05 22:52:21 -060011167 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011168 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011169 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11172 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011173 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011174 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11175 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011176
11177 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011178}
11179
Mark Mueller917f6bc2016-08-30 10:57:19 -060011180TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11181 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11182 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011183 "Delete objects that are inuse. Call VkQueueSubmit "
11184 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011185
11186 ASSERT_NO_FATAL_FAILURE(InitState());
11187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011189 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011191
Tony Barbour552f6c02016-12-21 14:34:07 -070011192 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011193
11194 VkEvent event;
11195 VkEventCreateInfo event_create_info = {};
11196 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11197 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011199
Tony Barbour552f6c02016-12-21 14:34:07 -070011200 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011201 vkDestroyEvent(m_device->device(), event, nullptr);
11202
11203 VkSubmitInfo submit_info = {};
11204 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11205 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011206 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011208 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11209 m_errorMonitor->VerifyFound();
11210
11211 m_errorMonitor->SetDesiredFailureMsg(0, "");
11212 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11213
11214 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11215
Mark Mueller917f6bc2016-08-30 10:57:19 -060011216 VkSemaphoreCreateInfo semaphore_create_info = {};
11217 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11218 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011219 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011220 VkFenceCreateInfo fence_create_info = {};
11221 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11222 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011223 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011224
11225 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011226 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011227 descriptor_pool_type_count.descriptorCount = 1;
11228
11229 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11230 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11231 descriptor_pool_create_info.maxSets = 1;
11232 descriptor_pool_create_info.poolSizeCount = 1;
11233 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011234 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011235
11236 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011237 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011238
11239 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011240 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011241 descriptorset_layout_binding.descriptorCount = 1;
11242 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11243
11244 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011245 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011246 descriptorset_layout_create_info.bindingCount = 1;
11247 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11248
11249 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011250 ASSERT_VK_SUCCESS(
11251 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011252
11253 VkDescriptorSet descriptorset;
11254 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011255 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011256 descriptorset_allocate_info.descriptorSetCount = 1;
11257 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11258 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011259 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011260
Mark Mueller4042b652016-09-05 22:52:21 -060011261 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11262
11263 VkDescriptorBufferInfo buffer_info = {};
11264 buffer_info.buffer = buffer_test.GetBuffer();
11265 buffer_info.offset = 0;
11266 buffer_info.range = 1024;
11267
11268 VkWriteDescriptorSet write_descriptor_set = {};
11269 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11270 write_descriptor_set.dstSet = descriptorset;
11271 write_descriptor_set.descriptorCount = 1;
11272 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11273 write_descriptor_set.pBufferInfo = &buffer_info;
11274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011275 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011277 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11278 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011279
11280 VkPipelineObj pipe(m_device);
11281 pipe.AddColorAttachment();
11282 pipe.AddShader(&vs);
11283 pipe.AddShader(&fs);
11284
11285 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011286 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011287 pipeline_layout_create_info.setLayoutCount = 1;
11288 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11289
11290 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011291 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011292
11293 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11294
Tony Barbour552f6c02016-12-21 14:34:07 -070011295 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011296 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011298 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11299 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11300 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011301
Tony Barbour552f6c02016-12-21 14:34:07 -070011302 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011303
Mark Mueller917f6bc2016-08-30 10:57:19 -060011304 submit_info.signalSemaphoreCount = 1;
11305 submit_info.pSignalSemaphores = &semaphore;
11306 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011307
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011309 vkDestroyEvent(m_device->device(), event, nullptr);
11310 m_errorMonitor->VerifyFound();
11311
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011313 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11314 m_errorMonitor->VerifyFound();
11315
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011317 vkDestroyFence(m_device->device(), fence, nullptr);
11318 m_errorMonitor->VerifyFound();
11319
Tobin Ehlis122207b2016-09-01 08:50:06 -070011320 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011321 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11322 vkDestroyFence(m_device->device(), fence, nullptr);
11323 vkDestroyEvent(m_device->device(), event, nullptr);
11324 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011325 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011326 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11327}
11328
Tobin Ehlis2adda372016-09-01 08:51:06 -070011329TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11330 TEST_DESCRIPTION("Delete in-use query pool.");
11331
11332 ASSERT_NO_FATAL_FAILURE(InitState());
11333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11334
11335 VkQueryPool query_pool;
11336 VkQueryPoolCreateInfo query_pool_ci{};
11337 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11338 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11339 query_pool_ci.queryCount = 1;
11340 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011341 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011342 // Reset query pool to create binding with cmd buffer
11343 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11344
Tony Barbour552f6c02016-12-21 14:34:07 -070011345 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011346
11347 VkSubmitInfo submit_info = {};
11348 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11349 submit_info.commandBufferCount = 1;
11350 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11351 // Submit cmd buffer and then destroy query pool while in-flight
11352 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11353
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011355 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11356 m_errorMonitor->VerifyFound();
11357
11358 vkQueueWaitIdle(m_device->m_queue);
11359 // Now that cmd buffer done we can safely destroy query_pool
11360 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11361}
11362
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011363TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11364 TEST_DESCRIPTION("Delete in-use pipeline.");
11365
11366 ASSERT_NO_FATAL_FAILURE(InitState());
11367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11368
11369 // Empty pipeline layout used for binding PSO
11370 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11371 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11372 pipeline_layout_ci.setLayoutCount = 0;
11373 pipeline_layout_ci.pSetLayouts = NULL;
11374
11375 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011376 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011377 ASSERT_VK_SUCCESS(err);
11378
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011380 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011381 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11382 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011383 // Store pipeline handle so we can actually delete it before test finishes
11384 VkPipeline delete_this_pipeline;
11385 { // Scope pipeline so it will be auto-deleted
11386 VkPipelineObj pipe(m_device);
11387 pipe.AddShader(&vs);
11388 pipe.AddShader(&fs);
11389 pipe.AddColorAttachment();
11390 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11391 delete_this_pipeline = pipe.handle();
11392
Tony Barbour552f6c02016-12-21 14:34:07 -070011393 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011394 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011395 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011396
Tony Barbour552f6c02016-12-21 14:34:07 -070011397 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011398
11399 VkSubmitInfo submit_info = {};
11400 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11401 submit_info.commandBufferCount = 1;
11402 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11403 // Submit cmd buffer and then pipeline destroyed while in-flight
11404 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11405 } // Pipeline deletion triggered here
11406 m_errorMonitor->VerifyFound();
11407 // Make sure queue finished and then actually delete pipeline
11408 vkQueueWaitIdle(m_device->m_queue);
11409 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11410 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11411}
11412
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011413TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11414 TEST_DESCRIPTION("Delete in-use imageView.");
11415
11416 ASSERT_NO_FATAL_FAILURE(InitState());
11417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11418
11419 VkDescriptorPoolSize ds_type_count;
11420 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11421 ds_type_count.descriptorCount = 1;
11422
11423 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11424 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11425 ds_pool_ci.maxSets = 1;
11426 ds_pool_ci.poolSizeCount = 1;
11427 ds_pool_ci.pPoolSizes = &ds_type_count;
11428
11429 VkDescriptorPool ds_pool;
11430 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11431 ASSERT_VK_SUCCESS(err);
11432
11433 VkSamplerCreateInfo sampler_ci = {};
11434 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11435 sampler_ci.pNext = NULL;
11436 sampler_ci.magFilter = VK_FILTER_NEAREST;
11437 sampler_ci.minFilter = VK_FILTER_NEAREST;
11438 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11439 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11440 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11441 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11442 sampler_ci.mipLodBias = 1.0;
11443 sampler_ci.anisotropyEnable = VK_FALSE;
11444 sampler_ci.maxAnisotropy = 1;
11445 sampler_ci.compareEnable = VK_FALSE;
11446 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11447 sampler_ci.minLod = 1.0;
11448 sampler_ci.maxLod = 1.0;
11449 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11450 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11451 VkSampler sampler;
11452
11453 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11454 ASSERT_VK_SUCCESS(err);
11455
11456 VkDescriptorSetLayoutBinding layout_binding;
11457 layout_binding.binding = 0;
11458 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11459 layout_binding.descriptorCount = 1;
11460 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11461 layout_binding.pImmutableSamplers = NULL;
11462
11463 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11464 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11465 ds_layout_ci.bindingCount = 1;
11466 ds_layout_ci.pBindings = &layout_binding;
11467 VkDescriptorSetLayout ds_layout;
11468 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11469 ASSERT_VK_SUCCESS(err);
11470
11471 VkDescriptorSetAllocateInfo alloc_info = {};
11472 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11473 alloc_info.descriptorSetCount = 1;
11474 alloc_info.descriptorPool = ds_pool;
11475 alloc_info.pSetLayouts = &ds_layout;
11476 VkDescriptorSet descriptor_set;
11477 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11478 ASSERT_VK_SUCCESS(err);
11479
11480 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11481 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11482 pipeline_layout_ci.pNext = NULL;
11483 pipeline_layout_ci.setLayoutCount = 1;
11484 pipeline_layout_ci.pSetLayouts = &ds_layout;
11485
11486 VkPipelineLayout pipeline_layout;
11487 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11488 ASSERT_VK_SUCCESS(err);
11489
11490 VkImageObj image(m_device);
11491 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11492 ASSERT_TRUE(image.initialized());
11493
11494 VkImageView view;
11495 VkImageViewCreateInfo ivci = {};
11496 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11497 ivci.image = image.handle();
11498 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11499 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11500 ivci.subresourceRange.layerCount = 1;
11501 ivci.subresourceRange.baseMipLevel = 0;
11502 ivci.subresourceRange.levelCount = 1;
11503 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11504
11505 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11506 ASSERT_VK_SUCCESS(err);
11507
11508 VkDescriptorImageInfo image_info{};
11509 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11510 image_info.imageView = view;
11511 image_info.sampler = sampler;
11512
11513 VkWriteDescriptorSet descriptor_write = {};
11514 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11515 descriptor_write.dstSet = descriptor_set;
11516 descriptor_write.dstBinding = 0;
11517 descriptor_write.descriptorCount = 1;
11518 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11519 descriptor_write.pImageInfo = &image_info;
11520
11521 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11522
11523 // Create PSO to use the sampler
11524 char const *vsSource = "#version 450\n"
11525 "\n"
11526 "out gl_PerVertex { \n"
11527 " vec4 gl_Position;\n"
11528 "};\n"
11529 "void main(){\n"
11530 " gl_Position = vec4(1);\n"
11531 "}\n";
11532 char const *fsSource = "#version 450\n"
11533 "\n"
11534 "layout(set=0, binding=0) uniform sampler2D s;\n"
11535 "layout(location=0) out vec4 x;\n"
11536 "void main(){\n"
11537 " x = texture(s, vec2(1));\n"
11538 "}\n";
11539 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11540 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11541 VkPipelineObj pipe(m_device);
11542 pipe.AddShader(&vs);
11543 pipe.AddShader(&fs);
11544 pipe.AddColorAttachment();
11545 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11546
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011548
Tony Barbour552f6c02016-12-21 14:34:07 -070011549 m_commandBuffer->BeginCommandBuffer();
11550 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011551 // Bind pipeline to cmd buffer
11552 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11553 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11554 &descriptor_set, 0, nullptr);
11555 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011556 m_commandBuffer->EndRenderPass();
11557 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011558 // Submit cmd buffer then destroy sampler
11559 VkSubmitInfo submit_info = {};
11560 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11561 submit_info.commandBufferCount = 1;
11562 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11563 // Submit cmd buffer and then destroy imageView while in-flight
11564 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11565
11566 vkDestroyImageView(m_device->device(), view, nullptr);
11567 m_errorMonitor->VerifyFound();
11568 vkQueueWaitIdle(m_device->m_queue);
11569 // Now we can actually destroy imageView
11570 vkDestroyImageView(m_device->device(), view, NULL);
11571 vkDestroySampler(m_device->device(), sampler, nullptr);
11572 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11573 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11574 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11575}
11576
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011577TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11578 TEST_DESCRIPTION("Delete in-use bufferView.");
11579
11580 ASSERT_NO_FATAL_FAILURE(InitState());
11581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11582
11583 VkDescriptorPoolSize ds_type_count;
11584 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11585 ds_type_count.descriptorCount = 1;
11586
11587 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11588 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11589 ds_pool_ci.maxSets = 1;
11590 ds_pool_ci.poolSizeCount = 1;
11591 ds_pool_ci.pPoolSizes = &ds_type_count;
11592
11593 VkDescriptorPool ds_pool;
11594 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11595 ASSERT_VK_SUCCESS(err);
11596
11597 VkDescriptorSetLayoutBinding layout_binding;
11598 layout_binding.binding = 0;
11599 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11600 layout_binding.descriptorCount = 1;
11601 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11602 layout_binding.pImmutableSamplers = NULL;
11603
11604 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11605 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11606 ds_layout_ci.bindingCount = 1;
11607 ds_layout_ci.pBindings = &layout_binding;
11608 VkDescriptorSetLayout ds_layout;
11609 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11610 ASSERT_VK_SUCCESS(err);
11611
11612 VkDescriptorSetAllocateInfo alloc_info = {};
11613 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11614 alloc_info.descriptorSetCount = 1;
11615 alloc_info.descriptorPool = ds_pool;
11616 alloc_info.pSetLayouts = &ds_layout;
11617 VkDescriptorSet descriptor_set;
11618 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11619 ASSERT_VK_SUCCESS(err);
11620
11621 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11622 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11623 pipeline_layout_ci.pNext = NULL;
11624 pipeline_layout_ci.setLayoutCount = 1;
11625 pipeline_layout_ci.pSetLayouts = &ds_layout;
11626
11627 VkPipelineLayout pipeline_layout;
11628 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11629 ASSERT_VK_SUCCESS(err);
11630
11631 VkBuffer buffer;
11632 uint32_t queue_family_index = 0;
11633 VkBufferCreateInfo buffer_create_info = {};
11634 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11635 buffer_create_info.size = 1024;
11636 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11637 buffer_create_info.queueFamilyIndexCount = 1;
11638 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11639
11640 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11641 ASSERT_VK_SUCCESS(err);
11642
11643 VkMemoryRequirements memory_reqs;
11644 VkDeviceMemory buffer_memory;
11645
11646 VkMemoryAllocateInfo memory_info = {};
11647 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11648 memory_info.allocationSize = 0;
11649 memory_info.memoryTypeIndex = 0;
11650
11651 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11652 memory_info.allocationSize = memory_reqs.size;
11653 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11654 ASSERT_TRUE(pass);
11655
11656 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11657 ASSERT_VK_SUCCESS(err);
11658 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11659 ASSERT_VK_SUCCESS(err);
11660
11661 VkBufferView view;
11662 VkBufferViewCreateInfo bvci = {};
11663 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11664 bvci.buffer = buffer;
11665 bvci.format = VK_FORMAT_R8_UNORM;
11666 bvci.range = VK_WHOLE_SIZE;
11667
11668 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11669 ASSERT_VK_SUCCESS(err);
11670
11671 VkWriteDescriptorSet descriptor_write = {};
11672 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11673 descriptor_write.dstSet = descriptor_set;
11674 descriptor_write.dstBinding = 0;
11675 descriptor_write.descriptorCount = 1;
11676 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11677 descriptor_write.pTexelBufferView = &view;
11678
11679 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11680
11681 char const *vsSource = "#version 450\n"
11682 "\n"
11683 "out gl_PerVertex { \n"
11684 " vec4 gl_Position;\n"
11685 "};\n"
11686 "void main(){\n"
11687 " gl_Position = vec4(1);\n"
11688 "}\n";
11689 char const *fsSource = "#version 450\n"
11690 "\n"
11691 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11692 "layout(location=0) out vec4 x;\n"
11693 "void main(){\n"
11694 " x = imageLoad(s, 0);\n"
11695 "}\n";
11696 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11697 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11698 VkPipelineObj pipe(m_device);
11699 pipe.AddShader(&vs);
11700 pipe.AddShader(&fs);
11701 pipe.AddColorAttachment();
11702 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11703
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011705
Tony Barbour552f6c02016-12-21 14:34:07 -070011706 m_commandBuffer->BeginCommandBuffer();
11707 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011708 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11709 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11710 VkRect2D scissor = {{0, 0}, {16, 16}};
11711 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11712 // Bind pipeline to cmd buffer
11713 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11714 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11715 &descriptor_set, 0, nullptr);
11716 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011717 m_commandBuffer->EndRenderPass();
11718 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011719
11720 VkSubmitInfo submit_info = {};
11721 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11722 submit_info.commandBufferCount = 1;
11723 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11724 // Submit cmd buffer and then destroy bufferView while in-flight
11725 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11726
11727 vkDestroyBufferView(m_device->device(), view, nullptr);
11728 m_errorMonitor->VerifyFound();
11729 vkQueueWaitIdle(m_device->m_queue);
11730 // Now we can actually destroy bufferView
11731 vkDestroyBufferView(m_device->device(), view, NULL);
11732 vkDestroyBuffer(m_device->device(), buffer, NULL);
11733 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11734 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11735 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11736 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11737}
11738
Tobin Ehlis209532e2016-09-07 13:52:18 -060011739TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11740 TEST_DESCRIPTION("Delete in-use sampler.");
11741
11742 ASSERT_NO_FATAL_FAILURE(InitState());
11743 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11744
11745 VkDescriptorPoolSize ds_type_count;
11746 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11747 ds_type_count.descriptorCount = 1;
11748
11749 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11750 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11751 ds_pool_ci.maxSets = 1;
11752 ds_pool_ci.poolSizeCount = 1;
11753 ds_pool_ci.pPoolSizes = &ds_type_count;
11754
11755 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011756 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011757 ASSERT_VK_SUCCESS(err);
11758
11759 VkSamplerCreateInfo sampler_ci = {};
11760 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11761 sampler_ci.pNext = NULL;
11762 sampler_ci.magFilter = VK_FILTER_NEAREST;
11763 sampler_ci.minFilter = VK_FILTER_NEAREST;
11764 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11765 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11766 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11767 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11768 sampler_ci.mipLodBias = 1.0;
11769 sampler_ci.anisotropyEnable = VK_FALSE;
11770 sampler_ci.maxAnisotropy = 1;
11771 sampler_ci.compareEnable = VK_FALSE;
11772 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11773 sampler_ci.minLod = 1.0;
11774 sampler_ci.maxLod = 1.0;
11775 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11776 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11777 VkSampler sampler;
11778
11779 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11780 ASSERT_VK_SUCCESS(err);
11781
11782 VkDescriptorSetLayoutBinding layout_binding;
11783 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011784 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011785 layout_binding.descriptorCount = 1;
11786 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11787 layout_binding.pImmutableSamplers = NULL;
11788
11789 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11790 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11791 ds_layout_ci.bindingCount = 1;
11792 ds_layout_ci.pBindings = &layout_binding;
11793 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011795 ASSERT_VK_SUCCESS(err);
11796
11797 VkDescriptorSetAllocateInfo alloc_info = {};
11798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11799 alloc_info.descriptorSetCount = 1;
11800 alloc_info.descriptorPool = ds_pool;
11801 alloc_info.pSetLayouts = &ds_layout;
11802 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011803 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011804 ASSERT_VK_SUCCESS(err);
11805
11806 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11807 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11808 pipeline_layout_ci.pNext = NULL;
11809 pipeline_layout_ci.setLayoutCount = 1;
11810 pipeline_layout_ci.pSetLayouts = &ds_layout;
11811
11812 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011813 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011814 ASSERT_VK_SUCCESS(err);
11815
11816 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011817 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 -060011818 ASSERT_TRUE(image.initialized());
11819
11820 VkImageView view;
11821 VkImageViewCreateInfo ivci = {};
11822 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11823 ivci.image = image.handle();
11824 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11825 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11826 ivci.subresourceRange.layerCount = 1;
11827 ivci.subresourceRange.baseMipLevel = 0;
11828 ivci.subresourceRange.levelCount = 1;
11829 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11830
11831 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11832 ASSERT_VK_SUCCESS(err);
11833
11834 VkDescriptorImageInfo image_info{};
11835 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11836 image_info.imageView = view;
11837 image_info.sampler = sampler;
11838
11839 VkWriteDescriptorSet descriptor_write = {};
11840 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11841 descriptor_write.dstSet = descriptor_set;
11842 descriptor_write.dstBinding = 0;
11843 descriptor_write.descriptorCount = 1;
11844 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11845 descriptor_write.pImageInfo = &image_info;
11846
11847 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11848
11849 // Create PSO to use the sampler
11850 char const *vsSource = "#version 450\n"
11851 "\n"
11852 "out gl_PerVertex { \n"
11853 " vec4 gl_Position;\n"
11854 "};\n"
11855 "void main(){\n"
11856 " gl_Position = vec4(1);\n"
11857 "}\n";
11858 char const *fsSource = "#version 450\n"
11859 "\n"
11860 "layout(set=0, binding=0) uniform sampler2D s;\n"
11861 "layout(location=0) out vec4 x;\n"
11862 "void main(){\n"
11863 " x = texture(s, vec2(1));\n"
11864 "}\n";
11865 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11866 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11867 VkPipelineObj pipe(m_device);
11868 pipe.AddShader(&vs);
11869 pipe.AddShader(&fs);
11870 pipe.AddColorAttachment();
11871 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11872
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011874
Tony Barbour552f6c02016-12-21 14:34:07 -070011875 m_commandBuffer->BeginCommandBuffer();
11876 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011877 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011878 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11879 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11880 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070011881
11882 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11883 VkRect2D scissor = {{0, 0}, {16, 16}};
11884 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11885 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11886
Tobin Ehlis209532e2016-09-07 13:52:18 -060011887 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011888 m_commandBuffer->EndRenderPass();
11889 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060011890 // Submit cmd buffer then destroy sampler
11891 VkSubmitInfo submit_info = {};
11892 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11893 submit_info.commandBufferCount = 1;
11894 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11895 // Submit cmd buffer and then destroy sampler while in-flight
11896 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11897
Rene Lindsay4da11732017-01-13 14:42:10 -070011898 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060011899 m_errorMonitor->VerifyFound();
11900 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070011901
Tobin Ehlis209532e2016-09-07 13:52:18 -060011902 // Now we can actually destroy sampler
Rene Lindsay4da11732017-01-13 14:42:10 -070011903 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060011904 vkDestroyImageView(m_device->device(), view, NULL);
11905 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11907 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11908}
11909
Mark Mueller1cd9f412016-08-25 13:23:52 -060011910TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011911 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011912 "signaled but not waited on by the queue. Wait on a "
11913 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011914
11915 ASSERT_NO_FATAL_FAILURE(InitState());
11916 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11917
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011918 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11919 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11920 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011921
Tony Barbour552f6c02016-12-21 14:34:07 -070011922 m_commandBuffer->BeginCommandBuffer();
11923 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060011924
11925 VkSemaphoreCreateInfo semaphore_create_info = {};
11926 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11927 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011928 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011929 VkSubmitInfo submit_info = {};
11930 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11931 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011932 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011933 submit_info.signalSemaphoreCount = 1;
11934 submit_info.pSignalSemaphores = &semaphore;
11935 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11936 m_errorMonitor->SetDesiredFailureMsg(0, "");
11937 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011938 m_commandBuffer->BeginCommandBuffer();
11939 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011941 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11942 m_errorMonitor->VerifyFound();
11943
Mark Mueller1cd9f412016-08-25 13:23:52 -060011944 VkFenceCreateInfo fence_create_info = {};
11945 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11946 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011947 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011950 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11951 m_errorMonitor->VerifyFound();
11952
Mark Mueller4042b652016-09-05 22:52:21 -060011953 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011954 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011955 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11956}
11957
Tobin Ehlis4af23302016-07-19 10:50:30 -060011958TEST_F(VkLayerTest, FramebufferIncompatible) {
11959 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11960 "that does not match the framebuffer for the active "
11961 "renderpass.");
11962 ASSERT_NO_FATAL_FAILURE(InitState());
11963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11964
11965 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011966 VkAttachmentDescription attachment = {0,
11967 VK_FORMAT_B8G8R8A8_UNORM,
11968 VK_SAMPLE_COUNT_1_BIT,
11969 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11970 VK_ATTACHMENT_STORE_OP_STORE,
11971 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11972 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11973 VK_IMAGE_LAYOUT_UNDEFINED,
11974 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011976 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011978 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011980 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011981
11982 VkRenderPass rp;
11983 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11984 ASSERT_VK_SUCCESS(err);
11985
11986 // A compatible framebuffer.
11987 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011988 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 -060011989 ASSERT_TRUE(image.initialized());
11990
11991 VkImageViewCreateInfo ivci = {
11992 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11993 nullptr,
11994 0,
11995 image.handle(),
11996 VK_IMAGE_VIEW_TYPE_2D,
11997 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011998 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11999 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012000 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12001 };
12002 VkImageView view;
12003 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12004 ASSERT_VK_SUCCESS(err);
12005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012006 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012007 VkFramebuffer fb;
12008 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12009 ASSERT_VK_SUCCESS(err);
12010
12011 VkCommandBufferAllocateInfo cbai = {};
12012 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12013 cbai.commandPool = m_commandPool;
12014 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12015 cbai.commandBufferCount = 1;
12016
12017 VkCommandBuffer sec_cb;
12018 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12019 ASSERT_VK_SUCCESS(err);
12020 VkCommandBufferBeginInfo cbbi = {};
12021 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012022 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012023 cbii.renderPass = renderPass();
12024 cbii.framebuffer = fb;
12025 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12026 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012027 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 -060012028 cbbi.pInheritanceInfo = &cbii;
12029 vkBeginCommandBuffer(sec_cb, &cbbi);
12030 vkEndCommandBuffer(sec_cb);
12031
Chris Forbes3400bc52016-09-13 18:10:34 +120012032 VkCommandBufferBeginInfo cbbi2 = {
12033 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12034 0, nullptr
12035 };
12036 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12037 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012040 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012041 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12042 m_errorMonitor->VerifyFound();
12043 // Cleanup
12044 vkDestroyImageView(m_device->device(), view, NULL);
12045 vkDestroyRenderPass(m_device->device(), rp, NULL);
12046 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12047}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012048
12049TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
12050 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
12051 "invalid value. If logicOp is not available, attempt to "
12052 "use it and verify that we see the correct error.");
12053 ASSERT_NO_FATAL_FAILURE(InitState());
12054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12055
12056 auto features = m_device->phy().features();
12057 // Set the expected error depending on whether or not logicOp available
12058 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
12060 "enabled, logicOpEnable must be "
12061 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012062 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012064 }
12065 // Create a pipeline using logicOp
12066 VkResult err;
12067
12068 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12069 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12070
12071 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012072 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012073 ASSERT_VK_SUCCESS(err);
12074
12075 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12076 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12077 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012078 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012079 vp_state_ci.pViewports = &vp;
12080 vp_state_ci.scissorCount = 1;
12081 VkRect2D scissors = {}; // Dummy scissors to point to
12082 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012083
12084 VkPipelineShaderStageCreateInfo shaderStages[2];
12085 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12086
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012087 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12088 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012089 shaderStages[0] = vs.GetStageCreateInfo();
12090 shaderStages[1] = fs.GetStageCreateInfo();
12091
12092 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12093 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12094
12095 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12096 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12097 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12098
12099 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12100 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012101 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012102
12103 VkPipelineColorBlendAttachmentState att = {};
12104 att.blendEnable = VK_FALSE;
12105 att.colorWriteMask = 0xf;
12106
12107 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12108 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12109 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12110 cb_ci.logicOpEnable = VK_TRUE;
12111 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
12112 cb_ci.attachmentCount = 1;
12113 cb_ci.pAttachments = &att;
12114
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012115 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12116 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12117 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12118
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012119 VkGraphicsPipelineCreateInfo gp_ci = {};
12120 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12121 gp_ci.stageCount = 2;
12122 gp_ci.pStages = shaderStages;
12123 gp_ci.pVertexInputState = &vi_ci;
12124 gp_ci.pInputAssemblyState = &ia_ci;
12125 gp_ci.pViewportState = &vp_state_ci;
12126 gp_ci.pRasterizationState = &rs_ci;
12127 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012128 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012129 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12130 gp_ci.layout = pipeline_layout;
12131 gp_ci.renderPass = renderPass();
12132
12133 VkPipelineCacheCreateInfo pc_ci = {};
12134 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12135
12136 VkPipeline pipeline;
12137 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012138 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012139 ASSERT_VK_SUCCESS(err);
12140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012141 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012142 m_errorMonitor->VerifyFound();
12143 if (VK_SUCCESS == err) {
12144 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12145 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012146 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12147 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12148}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012149#endif // DRAW_STATE_TESTS
12150
Tobin Ehlis0788f522015-05-26 16:11:58 -060012151#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012152#if GTEST_IS_THREADSAFE
12153struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012154 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012155 VkEvent event;
12156 bool bailout;
12157};
12158
Karl Schultz6addd812016-02-02 17:17:23 -070012159extern "C" void *AddToCommandBuffer(void *arg) {
12160 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012161
Mike Stroyana6d14942016-07-13 15:10:05 -060012162 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012163 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012164 if (data->bailout) {
12165 break;
12166 }
12167 }
12168 return NULL;
12169}
12170
Karl Schultz6addd812016-02-02 17:17:23 -070012171TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012172 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012175
Mike Stroyanaccf7692015-05-12 16:00:45 -060012176 ASSERT_NO_FATAL_FAILURE(InitState());
12177 ASSERT_NO_FATAL_FAILURE(InitViewport());
12178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12179
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012180 // Calls AllocateCommandBuffers
12181 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012182
12183 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012184 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012185
12186 VkEventCreateInfo event_info;
12187 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012188 VkResult err;
12189
12190 memset(&event_info, 0, sizeof(event_info));
12191 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12192
Chia-I Wuf7458c52015-10-26 21:10:41 +080012193 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012194 ASSERT_VK_SUCCESS(err);
12195
Mike Stroyanaccf7692015-05-12 16:00:45 -060012196 err = vkResetEvent(device(), event);
12197 ASSERT_VK_SUCCESS(err);
12198
12199 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012200 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012201 data.event = event;
12202 data.bailout = false;
12203 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012204
12205 // First do some correct operations using multiple threads.
12206 // Add many entries to command buffer from another thread.
12207 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12208 // Make non-conflicting calls from this thread at the same time.
12209 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012210 uint32_t count;
12211 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012212 }
12213 test_platform_thread_join(thread, NULL);
12214
12215 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012216 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012217 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012218 // Add many entries to command buffer from this thread at the same time.
12219 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012220
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012221 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012222 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012223
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012224 m_errorMonitor->SetBailout(NULL);
12225
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012226 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012227
Chia-I Wuf7458c52015-10-26 21:10:41 +080012228 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012229}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012230#endif // GTEST_IS_THREADSAFE
12231#endif // THREADING_TESTS
12232
Chris Forbes9f7ff632015-05-25 11:13:08 +120012233#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012234TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012235 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12236 "with an impossible code size");
12237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012239
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012240 ASSERT_NO_FATAL_FAILURE(InitState());
12241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12242
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012243 VkShaderModule module;
12244 VkShaderModuleCreateInfo moduleCreateInfo;
12245 struct icd_spv_header spv;
12246
12247 spv.magic = ICD_SPV_MAGIC;
12248 spv.version = ICD_SPV_VERSION;
12249 spv.gen_magic = 0;
12250
12251 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12252 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012253 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012254 moduleCreateInfo.codeSize = 4;
12255 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012256 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012257
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012258 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012259}
12260
Karl Schultz6addd812016-02-02 17:17:23 -070012261TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012262 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12263 "with a bad magic number");
12264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012266
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012267 ASSERT_NO_FATAL_FAILURE(InitState());
12268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12269
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012270 VkShaderModule module;
12271 VkShaderModuleCreateInfo moduleCreateInfo;
12272 struct icd_spv_header spv;
12273
12274 spv.magic = ~ICD_SPV_MAGIC;
12275 spv.version = ICD_SPV_VERSION;
12276 spv.gen_magic = 0;
12277
12278 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12279 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012280 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012281 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12282 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012283 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012284
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012285 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012286}
12287
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012288#if 0
12289// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012290TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012292 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012293
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012294 ASSERT_NO_FATAL_FAILURE(InitState());
12295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12296
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012297 VkShaderModule module;
12298 VkShaderModuleCreateInfo moduleCreateInfo;
12299 struct icd_spv_header spv;
12300
12301 spv.magic = ICD_SPV_MAGIC;
12302 spv.version = ~ICD_SPV_VERSION;
12303 spv.gen_magic = 0;
12304
12305 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12306 moduleCreateInfo.pNext = NULL;
12307
Karl Schultz6addd812016-02-02 17:17:23 -070012308 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012309 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12310 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012311 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012312
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012313 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012314}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012315#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012316
Karl Schultz6addd812016-02-02 17:17:23 -070012317TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012318 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12319 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012321
Chris Forbes9f7ff632015-05-25 11:13:08 +120012322 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012325 char const *vsSource = "#version 450\n"
12326 "\n"
12327 "layout(location=0) out float x;\n"
12328 "out gl_PerVertex {\n"
12329 " vec4 gl_Position;\n"
12330 "};\n"
12331 "void main(){\n"
12332 " gl_Position = vec4(1);\n"
12333 " x = 0;\n"
12334 "}\n";
12335 char const *fsSource = "#version 450\n"
12336 "\n"
12337 "layout(location=0) out vec4 color;\n"
12338 "void main(){\n"
12339 " color = vec4(1);\n"
12340 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012341
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012342 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12343 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012344
12345 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012346 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012347 pipe.AddShader(&vs);
12348 pipe.AddShader(&fs);
12349
Chris Forbes9f7ff632015-05-25 11:13:08 +120012350 VkDescriptorSetObj descriptorSet(m_device);
12351 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012352 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012353
Tony Barbour5781e8f2015-08-04 16:23:11 -060012354 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012355
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012356 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012357}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012358
Mark Mueller098c9cb2016-09-08 09:01:57 -060012359TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12360 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12361
12362 ASSERT_NO_FATAL_FAILURE(InitState());
12363 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12364
12365 const char *bad_specialization_message =
12366 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12367
12368 char const *vsSource =
12369 "#version 450\n"
12370 "\n"
12371 "out gl_PerVertex {\n"
12372 " vec4 gl_Position;\n"
12373 "};\n"
12374 "void main(){\n"
12375 " gl_Position = vec4(1);\n"
12376 "}\n";
12377
12378 char const *fsSource =
12379 "#version 450\n"
12380 "\n"
12381 "layout (constant_id = 0) const float r = 0.0f;\n"
12382 "layout(location = 0) out vec4 uFragColor;\n"
12383 "void main(){\n"
12384 " uFragColor = vec4(r,1,0,1);\n"
12385 "}\n";
12386
12387 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12388 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12389
12390 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12391 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12392
12393 VkPipelineLayout pipeline_layout;
12394 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12395
12396 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12397 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12398 vp_state_create_info.viewportCount = 1;
12399 VkViewport viewport = {};
12400 vp_state_create_info.pViewports = &viewport;
12401 vp_state_create_info.scissorCount = 1;
12402 VkRect2D scissors = {};
12403 vp_state_create_info.pScissors = &scissors;
12404
12405 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12406
12407 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12408 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12409 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12410 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12411
12412 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12413 vs.GetStageCreateInfo(),
12414 fs.GetStageCreateInfo()
12415 };
12416
12417 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12418 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12419
12420 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12421 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12422 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12423
12424 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12425 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12426 rasterization_state_create_info.pNext = nullptr;
12427 rasterization_state_create_info.lineWidth = 1.0f;
12428 rasterization_state_create_info.rasterizerDiscardEnable = true;
12429
12430 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12431 color_blend_attachment_state.blendEnable = VK_FALSE;
12432 color_blend_attachment_state.colorWriteMask = 0xf;
12433
12434 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12435 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12436 color_blend_state_create_info.attachmentCount = 1;
12437 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12438
12439 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12440 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12441 graphicspipe_create_info.stageCount = 2;
12442 graphicspipe_create_info.pStages = shader_stage_create_info;
12443 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12444 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12445 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12446 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12447 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12448 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12449 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12450 graphicspipe_create_info.layout = pipeline_layout;
12451 graphicspipe_create_info.renderPass = renderPass();
12452
12453 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12454 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12455
12456 VkPipelineCache pipelineCache;
12457 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12458
12459 // This structure maps constant ids to data locations.
12460 const VkSpecializationMapEntry entry =
12461 // id, offset, size
12462 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12463
12464 uint32_t data = 1;
12465
12466 // Set up the info describing spec map and data
12467 const VkSpecializationInfo specialization_info = {
12468 1,
12469 &entry,
12470 1 * sizeof(float),
12471 &data,
12472 };
12473 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12474
12475 VkPipeline pipeline;
12476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12477 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12478 m_errorMonitor->VerifyFound();
12479
12480 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12481 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12482}
12483
12484TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12485 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12486
12487 ASSERT_NO_FATAL_FAILURE(InitState());
12488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12489
12490 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12491
12492 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12493 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12494 descriptor_pool_type_count[0].descriptorCount = 1;
12495 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12496 descriptor_pool_type_count[1].descriptorCount = 1;
12497
12498 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12499 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12500 descriptor_pool_create_info.maxSets = 1;
12501 descriptor_pool_create_info.poolSizeCount = 2;
12502 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12503 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12504
12505 VkDescriptorPool descriptorset_pool;
12506 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12507
12508 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12509 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12510 descriptorset_layout_binding.descriptorCount = 1;
12511 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12512
12513 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12514 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12515 descriptorset_layout_create_info.bindingCount = 1;
12516 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12517
12518 VkDescriptorSetLayout descriptorset_layout;
12519 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12520
12521 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12522 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12523 descriptorset_allocate_info.descriptorSetCount = 1;
12524 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12525 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12526 VkDescriptorSet descriptorset;
12527 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12528
12529 // Challenge core_validation with a non uniform buffer type.
12530 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12531
Mark Mueller098c9cb2016-09-08 09:01:57 -060012532 char const *vsSource =
12533 "#version 450\n"
12534 "\n"
12535 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12536 " mat4 mvp;\n"
12537 "} ubuf;\n"
12538 "out gl_PerVertex {\n"
12539 " vec4 gl_Position;\n"
12540 "};\n"
12541 "void main(){\n"
12542 " gl_Position = ubuf.mvp * vec4(1);\n"
12543 "}\n";
12544
12545 char const *fsSource =
12546 "#version 450\n"
12547 "\n"
12548 "layout(location = 0) out vec4 uFragColor;\n"
12549 "void main(){\n"
12550 " uFragColor = vec4(0,1,0,1);\n"
12551 "}\n";
12552
12553 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12554 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12555
12556 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12557 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12558 pipeline_layout_create_info.setLayoutCount = 1;
12559 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12560
12561 VkPipelineLayout pipeline_layout;
12562 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12563
12564 VkPipelineObj pipe(m_device);
12565 pipe.AddColorAttachment();
12566 pipe.AddShader(&vs);
12567 pipe.AddShader(&fs);
12568
12569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12570 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12571 m_errorMonitor->VerifyFound();
12572
12573 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12574 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12575 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12576}
12577
12578TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12579 TEST_DESCRIPTION(
12580 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12581
12582 ASSERT_NO_FATAL_FAILURE(InitState());
12583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12584
12585 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12586
12587 VkDescriptorPoolSize descriptor_pool_type_count = {};
12588 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12589 descriptor_pool_type_count.descriptorCount = 1;
12590
12591 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12592 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12593 descriptor_pool_create_info.maxSets = 1;
12594 descriptor_pool_create_info.poolSizeCount = 1;
12595 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12596 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12597
12598 VkDescriptorPool descriptorset_pool;
12599 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12600
12601 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12602 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12603 descriptorset_layout_binding.descriptorCount = 1;
12604 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12605 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12606
12607 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12608 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12609 descriptorset_layout_create_info.bindingCount = 1;
12610 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12611
12612 VkDescriptorSetLayout descriptorset_layout;
12613 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12614 nullptr, &descriptorset_layout));
12615
12616 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12617 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12618 descriptorset_allocate_info.descriptorSetCount = 1;
12619 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12620 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12621 VkDescriptorSet descriptorset;
12622 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12623
12624 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12625
Mark Mueller098c9cb2016-09-08 09:01:57 -060012626 char const *vsSource =
12627 "#version 450\n"
12628 "\n"
12629 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12630 " mat4 mvp;\n"
12631 "} ubuf;\n"
12632 "out gl_PerVertex {\n"
12633 " vec4 gl_Position;\n"
12634 "};\n"
12635 "void main(){\n"
12636 " gl_Position = ubuf.mvp * vec4(1);\n"
12637 "}\n";
12638
12639 char const *fsSource =
12640 "#version 450\n"
12641 "\n"
12642 "layout(location = 0) out vec4 uFragColor;\n"
12643 "void main(){\n"
12644 " uFragColor = vec4(0,1,0,1);\n"
12645 "}\n";
12646
12647 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12648 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12649
12650 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12651 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12652 pipeline_layout_create_info.setLayoutCount = 1;
12653 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12654
12655 VkPipelineLayout pipeline_layout;
12656 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12657
12658 VkPipelineObj pipe(m_device);
12659 pipe.AddColorAttachment();
12660 pipe.AddShader(&vs);
12661 pipe.AddShader(&fs);
12662
12663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12664 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12665 m_errorMonitor->VerifyFound();
12666
12667 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12668 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12669 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12670}
12671
12672TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12673 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12674 "accessible from the current shader stage.");
12675
12676 ASSERT_NO_FATAL_FAILURE(InitState());
12677 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12678
12679 const char *push_constant_not_accessible_message =
12680 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12681
12682 char const *vsSource =
12683 "#version 450\n"
12684 "\n"
12685 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12686 "out gl_PerVertex {\n"
12687 " vec4 gl_Position;\n"
12688 "};\n"
12689 "void main(){\n"
12690 " gl_Position = vec4(consts.x);\n"
12691 "}\n";
12692
12693 char const *fsSource =
12694 "#version 450\n"
12695 "\n"
12696 "layout(location = 0) out vec4 uFragColor;\n"
12697 "void main(){\n"
12698 " uFragColor = vec4(0,1,0,1);\n"
12699 "}\n";
12700
12701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12703
12704 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12705 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12706
12707 // Set up a push constant range
12708 VkPushConstantRange push_constant_ranges = {};
12709 // Set to the wrong stage to challenge core_validation
12710 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12711 push_constant_ranges.size = 4;
12712
12713 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12714 pipeline_layout_create_info.pushConstantRangeCount = 1;
12715
12716 VkPipelineLayout pipeline_layout;
12717 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12718
12719 VkPipelineObj pipe(m_device);
12720 pipe.AddColorAttachment();
12721 pipe.AddShader(&vs);
12722 pipe.AddShader(&fs);
12723
12724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12725 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12726 m_errorMonitor->VerifyFound();
12727
12728 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12729}
12730
12731TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12732 TEST_DESCRIPTION(
12733 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12734
12735 ASSERT_NO_FATAL_FAILURE(InitState());
12736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12737
12738 const char *feature_not_enabled_message =
12739 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12740
12741 // Some awkward steps are required to test with custom device features.
12742 std::vector<const char *> device_extension_names;
12743 auto features = m_device->phy().features();
12744 // Disable support for 64 bit floats
12745 features.shaderFloat64 = false;
12746 // The sacrificial device object
12747 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12748
12749 char const *vsSource = "#version 450\n"
12750 "\n"
12751 "out gl_PerVertex {\n"
12752 " vec4 gl_Position;\n"
12753 "};\n"
12754 "void main(){\n"
12755 " gl_Position = vec4(1);\n"
12756 "}\n";
12757 char const *fsSource = "#version 450\n"
12758 "\n"
12759 "layout(location=0) out vec4 color;\n"
12760 "void main(){\n"
12761 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12762 " color = vec4(green);\n"
12763 "}\n";
12764
12765 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12766 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12767
12768 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012769
12770 VkPipelineObj pipe(&test_device);
12771 pipe.AddColorAttachment();
12772 pipe.AddShader(&vs);
12773 pipe.AddShader(&fs);
12774
12775 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12776 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12777 VkPipelineLayout pipeline_layout;
12778 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12779
12780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12781 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12782 m_errorMonitor->VerifyFound();
12783
12784 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12785}
12786
12787TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12788 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12789
12790 ASSERT_NO_FATAL_FAILURE(InitState());
12791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12792
12793 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12794
12795 char const *vsSource = "#version 450\n"
12796 "\n"
12797 "out gl_PerVertex {\n"
12798 " vec4 gl_Position;\n"
12799 "};\n"
12800 "layout(xfb_buffer = 1) out;"
12801 "void main(){\n"
12802 " gl_Position = vec4(1);\n"
12803 "}\n";
12804 char const *fsSource = "#version 450\n"
12805 "\n"
12806 "layout(location=0) out vec4 color;\n"
12807 "void main(){\n"
12808 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12809 " color = vec4(green);\n"
12810 "}\n";
12811
12812 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12813 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12814
12815 VkPipelineObj pipe(m_device);
12816 pipe.AddColorAttachment();
12817 pipe.AddShader(&vs);
12818 pipe.AddShader(&fs);
12819
12820 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12821 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12822 VkPipelineLayout pipeline_layout;
12823 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12824
12825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12826 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12827 m_errorMonitor->VerifyFound();
12828
12829 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12830}
12831
Karl Schultz6addd812016-02-02 17:17:23 -070012832TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012833 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12834 "which is not present in the outputs of the previous stage");
12835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012837
Chris Forbes59cb88d2015-05-25 11:13:13 +120012838 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012839 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012840
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012841 char const *vsSource = "#version 450\n"
12842 "\n"
12843 "out gl_PerVertex {\n"
12844 " vec4 gl_Position;\n"
12845 "};\n"
12846 "void main(){\n"
12847 " gl_Position = vec4(1);\n"
12848 "}\n";
12849 char const *fsSource = "#version 450\n"
12850 "\n"
12851 "layout(location=0) in float x;\n"
12852 "layout(location=0) out vec4 color;\n"
12853 "void main(){\n"
12854 " color = vec4(x);\n"
12855 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012856
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012857 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12858 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012859
12860 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012861 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012862 pipe.AddShader(&vs);
12863 pipe.AddShader(&fs);
12864
Chris Forbes59cb88d2015-05-25 11:13:13 +120012865 VkDescriptorSetObj descriptorSet(m_device);
12866 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012867 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012868
Tony Barbour5781e8f2015-08-04 16:23:11 -060012869 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012870
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012871 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012872}
12873
Karl Schultz6addd812016-02-02 17:17:23 -070012874TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012875 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12876 "within an interace block, which is not present in the outputs "
12877 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012879
12880 ASSERT_NO_FATAL_FAILURE(InitState());
12881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012883 char const *vsSource = "#version 450\n"
12884 "\n"
12885 "out gl_PerVertex {\n"
12886 " vec4 gl_Position;\n"
12887 "};\n"
12888 "void main(){\n"
12889 " gl_Position = vec4(1);\n"
12890 "}\n";
12891 char const *fsSource = "#version 450\n"
12892 "\n"
12893 "in block { layout(location=0) float x; } ins;\n"
12894 "layout(location=0) out vec4 color;\n"
12895 "void main(){\n"
12896 " color = vec4(ins.x);\n"
12897 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012898
12899 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12900 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12901
12902 VkPipelineObj pipe(m_device);
12903 pipe.AddColorAttachment();
12904 pipe.AddShader(&vs);
12905 pipe.AddShader(&fs);
12906
12907 VkDescriptorSetObj descriptorSet(m_device);
12908 descriptorSet.AppendDummy();
12909 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12910
12911 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12912
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012913 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012914}
12915
Karl Schultz6addd812016-02-02 17:17:23 -070012916TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012917 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012918 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12920 "output arr[2] of float32' vs 'ptr to "
Rene Lindsay479c2fa2017-01-10 11:43:26 -070012921 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012922
12923 ASSERT_NO_FATAL_FAILURE(InitState());
12924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12925
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012926 char const *vsSource = "#version 450\n"
12927 "\n"
12928 "layout(location=0) out float x[2];\n"
12929 "out gl_PerVertex {\n"
12930 " vec4 gl_Position;\n"
12931 "};\n"
12932 "void main(){\n"
12933 " x[0] = 0; x[1] = 0;\n"
12934 " gl_Position = vec4(1);\n"
12935 "}\n";
12936 char const *fsSource = "#version 450\n"
12937 "\n"
Rene Lindsay479c2fa2017-01-10 11:43:26 -070012938 "layout(location=0) in float x[1];\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012939 "layout(location=0) out vec4 color;\n"
12940 "void main(){\n"
Rene Lindsay479c2fa2017-01-10 11:43:26 -070012941 " color = vec4(x[0]);\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012942 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012943
12944 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12945 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12946
12947 VkPipelineObj pipe(m_device);
12948 pipe.AddColorAttachment();
12949 pipe.AddShader(&vs);
12950 pipe.AddShader(&fs);
12951
12952 VkDescriptorSetObj descriptorSet(m_device);
12953 descriptorSet.AppendDummy();
12954 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12955
12956 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12957
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012958 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012959}
12960
Karl Schultz6addd812016-02-02 17:17:23 -070012961TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012962 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012963 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012965
Chris Forbesb56af562015-05-25 11:13:17 +120012966 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012968
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012969 char const *vsSource = "#version 450\n"
12970 "\n"
12971 "layout(location=0) out int x;\n"
12972 "out gl_PerVertex {\n"
12973 " vec4 gl_Position;\n"
12974 "};\n"
12975 "void main(){\n"
12976 " x = 0;\n"
12977 " gl_Position = vec4(1);\n"
12978 "}\n";
12979 char const *fsSource = "#version 450\n"
12980 "\n"
12981 "layout(location=0) in float x;\n" /* VS writes int */
12982 "layout(location=0) out vec4 color;\n"
12983 "void main(){\n"
12984 " color = vec4(x);\n"
12985 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012986
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012987 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12988 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012989
12990 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012991 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012992 pipe.AddShader(&vs);
12993 pipe.AddShader(&fs);
12994
Chris Forbesb56af562015-05-25 11:13:17 +120012995 VkDescriptorSetObj descriptorSet(m_device);
12996 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012997 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012998
Tony Barbour5781e8f2015-08-04 16:23:11 -060012999 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013000
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013001 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013002}
13003
Karl Schultz6addd812016-02-02 17:17:23 -070013004TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013005 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013006 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120013007 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013009
13010 ASSERT_NO_FATAL_FAILURE(InitState());
13011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013013 char const *vsSource = "#version 450\n"
13014 "\n"
13015 "out block { layout(location=0) int x; } outs;\n"
13016 "out gl_PerVertex {\n"
13017 " vec4 gl_Position;\n"
13018 "};\n"
13019 "void main(){\n"
13020 " outs.x = 0;\n"
13021 " gl_Position = vec4(1);\n"
13022 "}\n";
13023 char const *fsSource = "#version 450\n"
13024 "\n"
13025 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13026 "layout(location=0) out vec4 color;\n"
13027 "void main(){\n"
13028 " color = vec4(ins.x);\n"
13029 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013030
13031 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13032 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13033
13034 VkPipelineObj pipe(m_device);
13035 pipe.AddColorAttachment();
13036 pipe.AddShader(&vs);
13037 pipe.AddShader(&fs);
13038
13039 VkDescriptorSetObj descriptorSet(m_device);
13040 descriptorSet.AppendDummy();
13041 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13042
13043 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13044
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013045 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013046}
13047
13048TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013049 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013050 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120013051 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013052 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 +130013053
13054 ASSERT_NO_FATAL_FAILURE(InitState());
13055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013057 char const *vsSource = "#version 450\n"
13058 "\n"
13059 "out block { layout(location=1) float x; } outs;\n"
13060 "out gl_PerVertex {\n"
13061 " vec4 gl_Position;\n"
13062 "};\n"
13063 "void main(){\n"
13064 " outs.x = 0;\n"
13065 " gl_Position = vec4(1);\n"
13066 "}\n";
13067 char const *fsSource = "#version 450\n"
13068 "\n"
13069 "in block { layout(location=0) float x; } ins;\n"
13070 "layout(location=0) out vec4 color;\n"
13071 "void main(){\n"
13072 " color = vec4(ins.x);\n"
13073 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013074
13075 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13076 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13077
13078 VkPipelineObj pipe(m_device);
13079 pipe.AddColorAttachment();
13080 pipe.AddShader(&vs);
13081 pipe.AddShader(&fs);
13082
13083 VkDescriptorSetObj descriptorSet(m_device);
13084 descriptorSet.AppendDummy();
13085 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13086
13087 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13088
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013089 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013090}
13091
13092TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013093 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013094 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120013095 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013096 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 +130013097
13098 ASSERT_NO_FATAL_FAILURE(InitState());
13099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13100
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013101 char const *vsSource = "#version 450\n"
13102 "\n"
13103 "out block { layout(location=0, component=0) float x; } outs;\n"
13104 "out gl_PerVertex {\n"
13105 " vec4 gl_Position;\n"
13106 "};\n"
13107 "void main(){\n"
13108 " outs.x = 0;\n"
13109 " gl_Position = vec4(1);\n"
13110 "}\n";
13111 char const *fsSource = "#version 450\n"
13112 "\n"
13113 "in block { layout(location=0, component=1) float x; } ins;\n"
13114 "layout(location=0) out vec4 color;\n"
13115 "void main(){\n"
13116 " color = vec4(ins.x);\n"
13117 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013118
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 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13132
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013133 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013134}
13135
Chris Forbes1f3b0152016-11-30 12:48:40 +130013136TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13137 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13138
13139 ASSERT_NO_FATAL_FAILURE(InitState());
13140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13141
13142 char const *vsSource = "#version 450\n"
13143 "layout(location=0) out mediump float x;\n"
13144 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13145 char const *fsSource = "#version 450\n"
13146 "layout(location=0) in highp float x;\n"
13147 "layout(location=0) out vec4 color;\n"
13148 "void main() { color = vec4(x); }\n";
13149
13150 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13151 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13152
13153 VkPipelineObj pipe(m_device);
13154 pipe.AddColorAttachment();
13155 pipe.AddShader(&vs);
13156 pipe.AddShader(&fs);
13157
13158 VkDescriptorSetObj descriptorSet(m_device);
13159 descriptorSet.AppendDummy();
13160 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13161
13162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13163
13164 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13165
13166 m_errorMonitor->VerifyFound();
13167}
13168
Chris Forbes870a39e2016-11-30 12:55:56 +130013169TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13170 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13171
13172 ASSERT_NO_FATAL_FAILURE(InitState());
13173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13174
13175 char const *vsSource = "#version 450\n"
13176 "out block { layout(location=0) mediump float x; };\n"
13177 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13178 char const *fsSource = "#version 450\n"
13179 "in block { layout(location=0) highp float x; };\n"
13180 "layout(location=0) out vec4 color;\n"
13181 "void main() { color = vec4(x); }\n";
13182
13183 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13184 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13185
13186 VkPipelineObj pipe(m_device);
13187 pipe.AddColorAttachment();
13188 pipe.AddShader(&vs);
13189 pipe.AddShader(&fs);
13190
13191 VkDescriptorSetObj descriptorSet(m_device);
13192 descriptorSet.AppendDummy();
13193 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13194
13195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13196
13197 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13198
13199 m_errorMonitor->VerifyFound();
13200}
13201
Karl Schultz6addd812016-02-02 17:17:23 -070013202TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013203 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13204 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013206
Chris Forbesde136e02015-05-25 11:13:28 +120013207 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013208 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013209
13210 VkVertexInputBindingDescription input_binding;
13211 memset(&input_binding, 0, sizeof(input_binding));
13212
13213 VkVertexInputAttributeDescription input_attrib;
13214 memset(&input_attrib, 0, sizeof(input_attrib));
13215 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13216
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013217 char const *vsSource = "#version 450\n"
13218 "\n"
13219 "out gl_PerVertex {\n"
13220 " vec4 gl_Position;\n"
13221 "};\n"
13222 "void main(){\n"
13223 " gl_Position = vec4(1);\n"
13224 "}\n";
13225 char const *fsSource = "#version 450\n"
13226 "\n"
13227 "layout(location=0) out vec4 color;\n"
13228 "void main(){\n"
13229 " color = vec4(1);\n"
13230 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013231
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013234
13235 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013236 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013237 pipe.AddShader(&vs);
13238 pipe.AddShader(&fs);
13239
13240 pipe.AddVertexInputBindings(&input_binding, 1);
13241 pipe.AddVertexInputAttribs(&input_attrib, 1);
13242
Chris Forbesde136e02015-05-25 11:13:28 +120013243 VkDescriptorSetObj descriptorSet(m_device);
13244 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013245 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013246
Tony Barbour5781e8f2015-08-04 16:23:11 -060013247 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013248
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013249 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013250}
13251
Karl Schultz6addd812016-02-02 17:17:23 -070013252TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013253 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13254 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013256
13257 ASSERT_NO_FATAL_FAILURE(InitState());
13258 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13259
13260 VkVertexInputBindingDescription input_binding;
13261 memset(&input_binding, 0, sizeof(input_binding));
13262
13263 VkVertexInputAttributeDescription input_attrib;
13264 memset(&input_attrib, 0, sizeof(input_attrib));
13265 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013267 char const *vsSource = "#version 450\n"
13268 "\n"
13269 "layout(location=1) in float x;\n"
13270 "out gl_PerVertex {\n"
13271 " vec4 gl_Position;\n"
13272 "};\n"
13273 "void main(){\n"
13274 " gl_Position = vec4(x);\n"
13275 "}\n";
13276 char const *fsSource = "#version 450\n"
13277 "\n"
13278 "layout(location=0) out vec4 color;\n"
13279 "void main(){\n"
13280 " color = vec4(1);\n"
13281 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013282
13283 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13284 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13285
13286 VkPipelineObj pipe(m_device);
13287 pipe.AddColorAttachment();
13288 pipe.AddShader(&vs);
13289 pipe.AddShader(&fs);
13290
13291 pipe.AddVertexInputBindings(&input_binding, 1);
13292 pipe.AddVertexInputAttribs(&input_attrib, 1);
13293
13294 VkDescriptorSetObj descriptorSet(m_device);
13295 descriptorSet.AppendDummy();
13296 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13297
13298 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13299
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013300 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013301}
13302
Karl Schultz6addd812016-02-02 17:17:23 -070013303TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013304 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013305 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013306 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 -060013307
Chris Forbes62e8e502015-05-25 11:13:29 +120013308 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013311 char const *vsSource = "#version 450\n"
13312 "\n"
13313 "layout(location=0) in vec4 x;\n" /* not provided */
13314 "out gl_PerVertex {\n"
13315 " vec4 gl_Position;\n"
13316 "};\n"
13317 "void main(){\n"
13318 " gl_Position = x;\n"
13319 "}\n";
13320 char const *fsSource = "#version 450\n"
13321 "\n"
13322 "layout(location=0) out vec4 color;\n"
13323 "void main(){\n"
13324 " color = vec4(1);\n"
13325 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013326
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013327 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13328 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013329
13330 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013331 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013332 pipe.AddShader(&vs);
13333 pipe.AddShader(&fs);
13334
Chris Forbes62e8e502015-05-25 11:13:29 +120013335 VkDescriptorSetObj descriptorSet(m_device);
13336 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013337 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013338
Tony Barbour5781e8f2015-08-04 16:23:11 -060013339 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013340
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013341 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013342}
13343
Karl Schultz6addd812016-02-02 17:17:23 -070013344TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013345 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13346 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013347 "vertex shader input that consumes it");
13348 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 -060013349
Chris Forbesc97d98e2015-05-25 11:13:31 +120013350 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013352
13353 VkVertexInputBindingDescription input_binding;
13354 memset(&input_binding, 0, sizeof(input_binding));
13355
13356 VkVertexInputAttributeDescription input_attrib;
13357 memset(&input_attrib, 0, sizeof(input_attrib));
13358 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013360 char const *vsSource = "#version 450\n"
13361 "\n"
13362 "layout(location=0) in int x;\n" /* attrib provided float */
13363 "out gl_PerVertex {\n"
13364 " vec4 gl_Position;\n"
13365 "};\n"
13366 "void main(){\n"
13367 " gl_Position = vec4(x);\n"
13368 "}\n";
13369 char const *fsSource = "#version 450\n"
13370 "\n"
13371 "layout(location=0) out vec4 color;\n"
13372 "void main(){\n"
13373 " color = vec4(1);\n"
13374 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013375
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013376 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13377 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013378
13379 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013380 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013381 pipe.AddShader(&vs);
13382 pipe.AddShader(&fs);
13383
13384 pipe.AddVertexInputBindings(&input_binding, 1);
13385 pipe.AddVertexInputAttribs(&input_attrib, 1);
13386
Chris Forbesc97d98e2015-05-25 11:13:31 +120013387 VkDescriptorSetObj descriptorSet(m_device);
13388 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013389 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013390
Tony Barbour5781e8f2015-08-04 16:23:11 -060013391 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013392
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013393 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013394}
13395
Chris Forbesc68b43c2016-04-06 11:18:47 +120013396TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013397 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13398 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13400 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013401
13402 ASSERT_NO_FATAL_FAILURE(InitState());
13403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013405 char const *vsSource = "#version 450\n"
13406 "\n"
13407 "out gl_PerVertex {\n"
13408 " vec4 gl_Position;\n"
13409 "};\n"
13410 "void main(){\n"
13411 " gl_Position = vec4(1);\n"
13412 "}\n";
13413 char const *fsSource = "#version 450\n"
13414 "\n"
13415 "layout(location=0) out vec4 color;\n"
13416 "void main(){\n"
13417 " color = vec4(1);\n"
13418 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013419
13420 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13421 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13422
13423 VkPipelineObj pipe(m_device);
13424 pipe.AddColorAttachment();
13425 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013426 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013427 pipe.AddShader(&fs);
13428
13429 VkDescriptorSetObj descriptorSet(m_device);
13430 descriptorSet.AppendDummy();
13431 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13432
13433 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13434
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013435 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013436}
13437
Chris Forbes82ff92a2016-09-09 10:50:24 +120013438TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13440 "No entrypoint found named `foo`");
13441
13442 ASSERT_NO_FATAL_FAILURE(InitState());
13443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13444
13445 char const *vsSource = "#version 450\n"
13446 "out gl_PerVertex {\n"
13447 " vec4 gl_Position;\n"
13448 "};\n"
13449 "void main(){\n"
13450 " gl_Position = vec4(0);\n"
13451 "}\n";
13452 char const *fsSource = "#version 450\n"
13453 "\n"
13454 "layout(location=0) out vec4 color;\n"
13455 "void main(){\n"
13456 " color = vec4(1);\n"
13457 "}\n";
13458
13459 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13460 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13461
13462 VkPipelineObj pipe(m_device);
13463 pipe.AddColorAttachment();
13464 pipe.AddShader(&vs);
13465 pipe.AddShader(&fs);
13466
13467 VkDescriptorSetObj descriptorSet(m_device);
13468 descriptorSet.AppendDummy();
13469 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13470
13471 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13472
13473 m_errorMonitor->VerifyFound();
13474}
13475
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013476TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13477 m_errorMonitor->SetDesiredFailureMsg(
13478 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13479 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13480 "uses a depth/stencil attachment");
13481
13482 ASSERT_NO_FATAL_FAILURE(InitState());
13483 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13484
13485 char const *vsSource = "#version 450\n"
13486 "void main(){ gl_Position = vec4(0); }\n";
13487 char const *fsSource = "#version 450\n"
13488 "\n"
13489 "layout(location=0) out vec4 color;\n"
13490 "void main(){\n"
13491 " color = vec4(1);\n"
13492 "}\n";
13493
13494 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13495 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13496
13497 VkPipelineObj pipe(m_device);
13498 pipe.AddColorAttachment();
13499 pipe.AddShader(&vs);
13500 pipe.AddShader(&fs);
13501
13502 VkDescriptorSetObj descriptorSet(m_device);
13503 descriptorSet.AppendDummy();
13504 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13505
13506 VkAttachmentDescription attachments[] = {
13507 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13508 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13509 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13510 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13511 },
13512 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13513 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13514 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13515 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13516 },
13517 };
13518 VkAttachmentReference refs[] = {
13519 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13520 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13521 };
13522 VkSubpassDescription subpass = {
13523 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13524 1, &refs[0], nullptr, &refs[1],
13525 0, nullptr
13526 };
13527 VkRenderPassCreateInfo rpci = {
13528 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13529 0, 2, attachments, 1, &subpass, 0, nullptr
13530 };
13531 VkRenderPass rp;
13532 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13533 ASSERT_VK_SUCCESS(err);
13534
13535 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13536
13537 m_errorMonitor->VerifyFound();
13538
13539 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13540}
13541
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013542TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013543 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13544 "the TCS without the patch decoration, but consumed in the TES "
13545 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13547 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013548
13549 ASSERT_NO_FATAL_FAILURE(InitState());
13550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13551
Chris Forbesc1e852d2016-04-04 19:26:42 +120013552 if (!m_device->phy().features().tessellationShader) {
13553 printf("Device does not support tessellation shaders; skipped.\n");
13554 return;
13555 }
13556
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013557 char const *vsSource = "#version 450\n"
13558 "void main(){}\n";
13559 char const *tcsSource = "#version 450\n"
13560 "layout(location=0) out int x[];\n"
13561 "layout(vertices=3) out;\n"
13562 "void main(){\n"
13563 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13564 " gl_TessLevelInner[0] = 1;\n"
13565 " x[gl_InvocationID] = gl_InvocationID;\n"
13566 "}\n";
13567 char const *tesSource = "#version 450\n"
13568 "layout(triangles, equal_spacing, cw) in;\n"
13569 "layout(location=0) patch in int x;\n"
13570 "out gl_PerVertex { vec4 gl_Position; };\n"
13571 "void main(){\n"
13572 " gl_Position.xyz = gl_TessCoord;\n"
13573 " gl_Position.w = x;\n"
13574 "}\n";
13575 char const *fsSource = "#version 450\n"
13576 "layout(location=0) out vec4 color;\n"
13577 "void main(){\n"
13578 " color = vec4(1);\n"
13579 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013580
13581 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13582 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13583 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13584 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013586 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13587 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013589 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013590
13591 VkPipelineObj pipe(m_device);
13592 pipe.SetInputAssembly(&iasci);
13593 pipe.SetTessellation(&tsci);
13594 pipe.AddColorAttachment();
13595 pipe.AddShader(&vs);
13596 pipe.AddShader(&tcs);
13597 pipe.AddShader(&tes);
13598 pipe.AddShader(&fs);
13599
13600 VkDescriptorSetObj descriptorSet(m_device);
13601 descriptorSet.AppendDummy();
13602 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13603
13604 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13605
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013606 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013607}
13608
Karl Schultz6addd812016-02-02 17:17:23 -070013609TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013610 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13611 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13613 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013614
Chris Forbes280ba2c2015-06-12 11:16:41 +120013615 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013616 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013617
13618 /* Two binding descriptions for binding 0 */
13619 VkVertexInputBindingDescription input_bindings[2];
13620 memset(input_bindings, 0, sizeof(input_bindings));
13621
13622 VkVertexInputAttributeDescription input_attrib;
13623 memset(&input_attrib, 0, sizeof(input_attrib));
13624 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013626 char const *vsSource = "#version 450\n"
13627 "\n"
13628 "layout(location=0) in float x;\n" /* attrib provided float */
13629 "out gl_PerVertex {\n"
13630 " vec4 gl_Position;\n"
13631 "};\n"
13632 "void main(){\n"
13633 " gl_Position = vec4(x);\n"
13634 "}\n";
13635 char const *fsSource = "#version 450\n"
13636 "\n"
13637 "layout(location=0) out vec4 color;\n"
13638 "void main(){\n"
13639 " color = vec4(1);\n"
13640 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013641
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013642 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13643 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013644
13645 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013646 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013647 pipe.AddShader(&vs);
13648 pipe.AddShader(&fs);
13649
13650 pipe.AddVertexInputBindings(input_bindings, 2);
13651 pipe.AddVertexInputAttribs(&input_attrib, 1);
13652
Chris Forbes280ba2c2015-06-12 11:16:41 +120013653 VkDescriptorSetObj descriptorSet(m_device);
13654 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013655 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013656
Tony Barbour5781e8f2015-08-04 16:23:11 -060013657 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013658
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013659 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013660}
Chris Forbes8f68b562015-05-25 11:13:32 +120013661
Karl Schultz6addd812016-02-02 17:17:23 -070013662TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013663 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013664 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013666
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013667 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013668
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013669 char const *vsSource = "#version 450\n"
13670 "\n"
13671 "out gl_PerVertex {\n"
13672 " vec4 gl_Position;\n"
13673 "};\n"
13674 "void main(){\n"
13675 " gl_Position = vec4(1);\n"
13676 "}\n";
13677 char const *fsSource = "#version 450\n"
13678 "\n"
13679 "void main(){\n"
13680 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013681
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013682 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13683 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013684
13685 VkPipelineObj pipe(m_device);
13686 pipe.AddShader(&vs);
13687 pipe.AddShader(&fs);
13688
Chia-I Wu08accc62015-07-07 11:50:03 +080013689 /* set up CB 0, not written */
13690 pipe.AddColorAttachment();
13691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013692
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013693 VkDescriptorSetObj descriptorSet(m_device);
13694 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013695 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013696
Tony Barbour5781e8f2015-08-04 16:23:11 -060013697 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013698
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013699 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013700}
13701
Karl Schultz6addd812016-02-02 17:17:23 -070013702TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013703 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013704 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013706 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013707
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013708 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013709
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013710 char const *vsSource = "#version 450\n"
13711 "\n"
13712 "out gl_PerVertex {\n"
13713 " vec4 gl_Position;\n"
13714 "};\n"
13715 "void main(){\n"
13716 " gl_Position = vec4(1);\n"
13717 "}\n";
13718 char const *fsSource = "#version 450\n"
13719 "\n"
13720 "layout(location=0) out vec4 x;\n"
13721 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13722 "void main(){\n"
13723 " x = vec4(1);\n"
13724 " y = vec4(1);\n"
13725 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013726
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013727 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13728 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013729
13730 VkPipelineObj pipe(m_device);
13731 pipe.AddShader(&vs);
13732 pipe.AddShader(&fs);
13733
Chia-I Wu08accc62015-07-07 11:50:03 +080013734 /* set up CB 0, not written */
13735 pipe.AddColorAttachment();
13736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013737 /* FS writes CB 1, but we don't configure it */
13738
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013739 VkDescriptorSetObj descriptorSet(m_device);
13740 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013741 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013742
Tony Barbour5781e8f2015-08-04 16:23:11 -060013743 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013744
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013745 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013746}
13747
Karl Schultz6addd812016-02-02 17:17:23 -070013748TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013749 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013750 "type of an fragment shader output variable, and the format of the corresponding attachment");
13751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013752
Chris Forbesa36d69e2015-05-25 11:13:44 +120013753 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013755 char const *vsSource = "#version 450\n"
13756 "\n"
13757 "out gl_PerVertex {\n"
13758 " vec4 gl_Position;\n"
13759 "};\n"
13760 "void main(){\n"
13761 " gl_Position = vec4(1);\n"
13762 "}\n";
13763 char const *fsSource = "#version 450\n"
13764 "\n"
13765 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13766 "void main(){\n"
13767 " x = ivec4(1);\n"
13768 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013769
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013770 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13771 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013772
13773 VkPipelineObj pipe(m_device);
13774 pipe.AddShader(&vs);
13775 pipe.AddShader(&fs);
13776
Chia-I Wu08accc62015-07-07 11:50:03 +080013777 /* set up CB 0; type is UNORM by default */
13778 pipe.AddColorAttachment();
13779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013780
Chris Forbesa36d69e2015-05-25 11:13:44 +120013781 VkDescriptorSetObj descriptorSet(m_device);
13782 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013783 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013784
Tony Barbour5781e8f2015-08-04 16:23:11 -060013785 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013786
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013787 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013788}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013789
Karl Schultz6addd812016-02-02 17:17:23 -070013790TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013791 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13792 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013794
Chris Forbes556c76c2015-08-14 12:04:59 +120013795 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013797 char const *vsSource = "#version 450\n"
13798 "\n"
13799 "out gl_PerVertex {\n"
13800 " vec4 gl_Position;\n"
13801 "};\n"
13802 "void main(){\n"
13803 " gl_Position = vec4(1);\n"
13804 "}\n";
13805 char const *fsSource = "#version 450\n"
13806 "\n"
13807 "layout(location=0) out vec4 x;\n"
13808 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13809 "void main(){\n"
13810 " x = vec4(bar.y);\n"
13811 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013812
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013813 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13814 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013815
Chris Forbes556c76c2015-08-14 12:04:59 +120013816 VkPipelineObj pipe(m_device);
13817 pipe.AddShader(&vs);
13818 pipe.AddShader(&fs);
13819
13820 /* set up CB 0; type is UNORM by default */
13821 pipe.AddColorAttachment();
13822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13823
13824 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013825 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013826
13827 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13828
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013829 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013830}
13831
Chris Forbes5c59e902016-02-26 16:56:09 +130013832TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013833 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13834 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013836
13837 ASSERT_NO_FATAL_FAILURE(InitState());
13838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013839 char const *vsSource = "#version 450\n"
13840 "\n"
13841 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13842 "out gl_PerVertex {\n"
13843 " vec4 gl_Position;\n"
13844 "};\n"
13845 "void main(){\n"
13846 " gl_Position = vec4(consts.x);\n"
13847 "}\n";
13848 char const *fsSource = "#version 450\n"
13849 "\n"
13850 "layout(location=0) out vec4 x;\n"
13851 "void main(){\n"
13852 " x = vec4(1);\n"
13853 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013854
13855 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13857
13858 VkPipelineObj pipe(m_device);
13859 pipe.AddShader(&vs);
13860 pipe.AddShader(&fs);
13861
13862 /* set up CB 0; type is UNORM by default */
13863 pipe.AddColorAttachment();
13864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13865
13866 VkDescriptorSetObj descriptorSet(m_device);
13867 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13868
13869 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13870
13871 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013872 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013873}
13874
Chris Forbes3fb17902016-08-22 14:57:55 +120013875TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13876 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13877 "which is not included in the subpass description");
13878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13879 "consumes input attachment index 0 but not provided in subpass");
13880
13881 ASSERT_NO_FATAL_FAILURE(InitState());
13882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013883 char const *vsSource = "#version 450\n"
13884 "\n"
13885 "out gl_PerVertex {\n"
13886 " vec4 gl_Position;\n"
13887 "};\n"
13888 "void main(){\n"
13889 " gl_Position = vec4(1);\n"
13890 "}\n";
13891 char const *fsSource = "#version 450\n"
13892 "\n"
13893 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13894 "layout(location=0) out vec4 color;\n"
13895 "void main() {\n"
13896 " color = subpassLoad(x);\n"
13897 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013898
13899 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13900 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13901
13902 VkPipelineObj pipe(m_device);
13903 pipe.AddShader(&vs);
13904 pipe.AddShader(&fs);
13905 pipe.AddColorAttachment();
13906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013908 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13909 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013910 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013911 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013912 ASSERT_VK_SUCCESS(err);
13913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013914 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013915 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013916 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013917 ASSERT_VK_SUCCESS(err);
13918
13919 // error here.
13920 pipe.CreateVKPipeline(pl, renderPass());
13921
13922 m_errorMonitor->VerifyFound();
13923
13924 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13925 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13926}
13927
Chris Forbes5a9a0472016-08-22 16:02:09 +120013928TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13929 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13930 "with a format having a different fundamental type");
13931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13932 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13933
13934 ASSERT_NO_FATAL_FAILURE(InitState());
13935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013936 char const *vsSource = "#version 450\n"
13937 "\n"
13938 "out gl_PerVertex {\n"
13939 " vec4 gl_Position;\n"
13940 "};\n"
13941 "void main(){\n"
13942 " gl_Position = vec4(1);\n"
13943 "}\n";
13944 char const *fsSource = "#version 450\n"
13945 "\n"
13946 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13947 "layout(location=0) out vec4 color;\n"
13948 "void main() {\n"
13949 " color = subpassLoad(x);\n"
13950 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013951
13952 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13953 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13954
13955 VkPipelineObj pipe(m_device);
13956 pipe.AddShader(&vs);
13957 pipe.AddShader(&fs);
13958 pipe.AddColorAttachment();
13959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013961 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13962 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013963 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013964 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013965 ASSERT_VK_SUCCESS(err);
13966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013967 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013968 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013969 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013970 ASSERT_VK_SUCCESS(err);
13971
13972 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013973 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13974 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13975 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13976 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13977 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 +120013978 };
13979 VkAttachmentReference color = {
13980 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13981 };
13982 VkAttachmentReference input = {
13983 1, VK_IMAGE_LAYOUT_GENERAL,
13984 };
13985
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013986 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013988 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013989 VkRenderPass rp;
13990 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13991 ASSERT_VK_SUCCESS(err);
13992
13993 // error here.
13994 pipe.CreateVKPipeline(pl, rp);
13995
13996 m_errorMonitor->VerifyFound();
13997
13998 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13999 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14000 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14001}
14002
Chris Forbes541f7b02016-08-22 15:30:27 +120014003TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14004 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14005 "which is not included in the subpass description -- array case");
14006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014007 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014008
14009 ASSERT_NO_FATAL_FAILURE(InitState());
14010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014011 char const *vsSource = "#version 450\n"
14012 "\n"
14013 "out gl_PerVertex {\n"
14014 " vec4 gl_Position;\n"
14015 "};\n"
14016 "void main(){\n"
14017 " gl_Position = vec4(1);\n"
14018 "}\n";
14019 char const *fsSource = "#version 450\n"
14020 "\n"
Rene Lindsay07b60af2017-01-10 15:57:55 -070014021 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014022 "layout(location=0) out vec4 color;\n"
14023 "void main() {\n"
Rene Lindsay07b60af2017-01-10 15:57:55 -070014024 " color = subpassLoad(xs[0]);\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014025 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014026
14027 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14028 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14029
14030 VkPipelineObj pipe(m_device);
14031 pipe.AddShader(&vs);
14032 pipe.AddShader(&fs);
14033 pipe.AddColorAttachment();
14034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014036 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14037 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014038 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014039 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014040 ASSERT_VK_SUCCESS(err);
14041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014042 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014043 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014044 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014045 ASSERT_VK_SUCCESS(err);
14046
14047 // error here.
14048 pipe.CreateVKPipeline(pl, renderPass());
14049
14050 m_errorMonitor->VerifyFound();
14051
14052 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14053 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14054}
14055
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014056TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014057 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
14058 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014060
14061 ASSERT_NO_FATAL_FAILURE(InitState());
14062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014063 char const *csSource = "#version 450\n"
14064 "\n"
14065 "layout(local_size_x=1) in;\n"
14066 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14067 "void main(){\n"
14068 " x = vec4(1);\n"
14069 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014070
14071 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14072
14073 VkDescriptorSetObj descriptorSet(m_device);
14074 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014076 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14077 nullptr,
14078 0,
14079 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14080 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14081 descriptorSet.GetPipelineLayout(),
14082 VK_NULL_HANDLE,
14083 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014084
14085 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014086 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014087
14088 m_errorMonitor->VerifyFound();
14089
14090 if (err == VK_SUCCESS) {
14091 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14092 }
14093}
14094
Chris Forbes22a9b092016-07-19 14:34:05 +120014095TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014096 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
14097 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14099 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014100
14101 ASSERT_NO_FATAL_FAILURE(InitState());
14102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014103 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14104 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014105 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014106 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014107 ASSERT_VK_SUCCESS(err);
14108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014109 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014110 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014111 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014112 ASSERT_VK_SUCCESS(err);
14113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014114 char const *csSource = "#version 450\n"
14115 "\n"
14116 "layout(local_size_x=1) in;\n"
14117 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14118 "void main() {\n"
14119 " x.x = 1.0f;\n"
14120 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014121 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014123 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14124 nullptr,
14125 0,
14126 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14127 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14128 pl,
14129 VK_NULL_HANDLE,
14130 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014131
14132 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014133 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014134
14135 m_errorMonitor->VerifyFound();
14136
14137 if (err == VK_SUCCESS) {
14138 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14139 }
14140
14141 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14142 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14143}
14144
Chris Forbes50020592016-07-27 13:52:41 +120014145TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14146 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14147 "does not match the dimensionality declared in the shader");
14148
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014149 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 +120014150
14151 ASSERT_NO_FATAL_FAILURE(InitState());
14152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014154 char const *vsSource = "#version 450\n"
14155 "\n"
14156 "out gl_PerVertex { vec4 gl_Position; };\n"
14157 "void main() { gl_Position = vec4(0); }\n";
14158 char const *fsSource = "#version 450\n"
14159 "\n"
14160 "layout(set=0, binding=0) uniform sampler3D s;\n"
14161 "layout(location=0) out vec4 color;\n"
14162 "void main() {\n"
14163 " color = texture(s, vec3(0));\n"
14164 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014165 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14166 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14167
14168 VkPipelineObj pipe(m_device);
14169 pipe.AddShader(&vs);
14170 pipe.AddShader(&fs);
14171 pipe.AddColorAttachment();
14172
14173 VkTextureObj texture(m_device, nullptr);
14174 VkSamplerObj sampler(m_device);
14175
14176 VkDescriptorSetObj descriptorSet(m_device);
14177 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14178 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14179
14180 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14181 ASSERT_VK_SUCCESS(err);
14182
Tony Barbour552f6c02016-12-21 14:34:07 -070014183 m_commandBuffer->BeginCommandBuffer();
14184 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014185
14186 m_commandBuffer->BindPipeline(pipe);
14187 m_commandBuffer->BindDescriptorSet(descriptorSet);
14188
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014189 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014190 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014191 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014192 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14193
14194 // error produced here.
14195 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14196
14197 m_errorMonitor->VerifyFound();
14198
Tony Barbour552f6c02016-12-21 14:34:07 -070014199 m_commandBuffer->EndRenderPass();
14200 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014201}
14202
Chris Forbes5533bfc2016-07-27 14:12:34 +120014203TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14204 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14205 "are consumed via singlesample images types in the shader, or vice versa.");
14206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014208
14209 ASSERT_NO_FATAL_FAILURE(InitState());
14210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014212 char const *vsSource = "#version 450\n"
14213 "\n"
14214 "out gl_PerVertex { vec4 gl_Position; };\n"
14215 "void main() { gl_Position = vec4(0); }\n";
14216 char const *fsSource = "#version 450\n"
14217 "\n"
14218 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14219 "layout(location=0) out vec4 color;\n"
14220 "void main() {\n"
14221 " color = texelFetch(s, ivec2(0), 0);\n"
14222 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014223 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14224 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14225
14226 VkPipelineObj pipe(m_device);
14227 pipe.AddShader(&vs);
14228 pipe.AddShader(&fs);
14229 pipe.AddColorAttachment();
14230
14231 VkTextureObj texture(m_device, nullptr);
14232 VkSamplerObj sampler(m_device);
14233
14234 VkDescriptorSetObj descriptorSet(m_device);
14235 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14236 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14237
14238 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14239 ASSERT_VK_SUCCESS(err);
14240
Tony Barbour552f6c02016-12-21 14:34:07 -070014241 m_commandBuffer->BeginCommandBuffer();
14242 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014243
14244 m_commandBuffer->BindPipeline(pipe);
14245 m_commandBuffer->BindDescriptorSet(descriptorSet);
14246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014247 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014248 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014249 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014250 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14251
14252 // error produced here.
14253 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14254
14255 m_errorMonitor->VerifyFound();
14256
Tony Barbour552f6c02016-12-21 14:34:07 -070014257 m_commandBuffer->EndRenderPass();
14258 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014259}
14260
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014261#endif // SHADER_CHECKER_TESTS
14262
14263#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014264TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014266
14267 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014268
14269 // Create an image
14270 VkImage image;
14271
Karl Schultz6addd812016-02-02 17:17:23 -070014272 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14273 const int32_t tex_width = 32;
14274 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014275
14276 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014277 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14278 image_create_info.pNext = NULL;
14279 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14280 image_create_info.format = tex_format;
14281 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014282 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014283 image_create_info.extent.depth = 1;
14284 image_create_info.mipLevels = 1;
14285 image_create_info.arrayLayers = 1;
14286 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14287 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14288 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14289 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014290
14291 // Introduce error by sending down a bogus width extent
14292 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014293 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014294
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014295 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014296}
14297
Mark Youngc48c4c12016-04-11 14:26:49 -060014298TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14300 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014301
14302 ASSERT_NO_FATAL_FAILURE(InitState());
14303
14304 // Create an image
14305 VkImage image;
14306
14307 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14308 const int32_t tex_width = 32;
14309 const int32_t tex_height = 32;
14310
14311 VkImageCreateInfo image_create_info = {};
14312 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14313 image_create_info.pNext = NULL;
14314 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14315 image_create_info.format = tex_format;
14316 image_create_info.extent.width = tex_width;
14317 image_create_info.extent.height = tex_height;
14318 image_create_info.extent.depth = 1;
14319 image_create_info.mipLevels = 1;
14320 image_create_info.arrayLayers = 1;
14321 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14322 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14323 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14324 image_create_info.flags = 0;
14325
14326 // Introduce error by sending down a bogus width extent
14327 image_create_info.extent.width = 0;
14328 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14329
14330 m_errorMonitor->VerifyFound();
14331}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014332#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014333
Tobin Ehliscde08892015-09-22 10:11:37 -060014334#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014335
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014336TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14337 TEST_DESCRIPTION("Create a render pass with an attachment description "
14338 "format set to VK_FORMAT_UNDEFINED");
14339
14340 ASSERT_NO_FATAL_FAILURE(InitState());
14341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014344
14345 VkAttachmentReference color_attach = {};
14346 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14347 color_attach.attachment = 0;
14348 VkSubpassDescription subpass = {};
14349 subpass.colorAttachmentCount = 1;
14350 subpass.pColorAttachments = &color_attach;
14351
14352 VkRenderPassCreateInfo rpci = {};
14353 rpci.subpassCount = 1;
14354 rpci.pSubpasses = &subpass;
14355 rpci.attachmentCount = 1;
14356 VkAttachmentDescription attach_desc = {};
14357 attach_desc.format = VK_FORMAT_UNDEFINED;
14358 rpci.pAttachments = &attach_desc;
14359 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14360 VkRenderPass rp;
14361 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14362
14363 m_errorMonitor->VerifyFound();
14364
14365 if (result == VK_SUCCESS) {
14366 vkDestroyRenderPass(m_device->device(), rp, NULL);
14367 }
14368}
14369
Karl Schultz6addd812016-02-02 17:17:23 -070014370TEST_F(VkLayerTest, InvalidImageView) {
14371 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014372
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014374
Tobin Ehliscde08892015-09-22 10:11:37 -060014375 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014376
Mike Stroyana3082432015-09-25 13:39:21 -060014377 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014378 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014379
Karl Schultz6addd812016-02-02 17:17:23 -070014380 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14381 const int32_t tex_width = 32;
14382 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014383
14384 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014385 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14386 image_create_info.pNext = NULL;
14387 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14388 image_create_info.format = tex_format;
14389 image_create_info.extent.width = tex_width;
14390 image_create_info.extent.height = tex_height;
14391 image_create_info.extent.depth = 1;
14392 image_create_info.mipLevels = 1;
14393 image_create_info.arrayLayers = 1;
14394 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14395 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14396 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14397 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014398
Chia-I Wuf7458c52015-10-26 21:10:41 +080014399 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014400 ASSERT_VK_SUCCESS(err);
14401
14402 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014403 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014404 image_view_create_info.image = image;
14405 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14406 image_view_create_info.format = tex_format;
14407 image_view_create_info.subresourceRange.layerCount = 1;
14408 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14409 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014410 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014411
14412 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014413 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014414
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014415 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014416 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014417}
Mike Stroyana3082432015-09-25 13:39:21 -060014418
Mark Youngd339ba32016-05-30 13:28:35 -060014419TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14420 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014422 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014423
14424 ASSERT_NO_FATAL_FAILURE(InitState());
14425
14426 // Create an image and try to create a view with no memory backing the image
14427 VkImage image;
14428
14429 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14430 const int32_t tex_width = 32;
14431 const int32_t tex_height = 32;
14432
14433 VkImageCreateInfo image_create_info = {};
14434 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14435 image_create_info.pNext = NULL;
14436 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14437 image_create_info.format = tex_format;
14438 image_create_info.extent.width = tex_width;
14439 image_create_info.extent.height = tex_height;
14440 image_create_info.extent.depth = 1;
14441 image_create_info.mipLevels = 1;
14442 image_create_info.arrayLayers = 1;
14443 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14444 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14445 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14446 image_create_info.flags = 0;
14447
14448 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14449 ASSERT_VK_SUCCESS(err);
14450
14451 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014452 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014453 image_view_create_info.image = image;
14454 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14455 image_view_create_info.format = tex_format;
14456 image_view_create_info.subresourceRange.layerCount = 1;
14457 image_view_create_info.subresourceRange.baseMipLevel = 0;
14458 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014459 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014460
14461 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014462 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014463
14464 m_errorMonitor->VerifyFound();
14465 vkDestroyImage(m_device->device(), image, NULL);
14466 // If last error is success, it still created the view, so delete it.
14467 if (err == VK_SUCCESS) {
14468 vkDestroyImageView(m_device->device(), view, NULL);
14469 }
Mark Youngd339ba32016-05-30 13:28:35 -060014470}
14471
Karl Schultz6addd812016-02-02 17:17:23 -070014472TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014473 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014475
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014476 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014477
Karl Schultz6addd812016-02-02 17:17:23 -070014478 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014479 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014480 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014481 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014482
14483 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014484 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014485 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014486 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14487 image_view_create_info.format = tex_format;
14488 image_view_create_info.subresourceRange.baseMipLevel = 0;
14489 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014490 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014491 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014492 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014493
14494 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014495 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014496
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014497 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014498}
14499
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014500TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014501 VkResult err;
14502 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014503
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014505
Mike Stroyana3082432015-09-25 13:39:21 -060014506 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014507
14508 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014509 VkImage srcImage;
14510 VkImage dstImage;
14511 VkDeviceMemory srcMem;
14512 VkDeviceMemory destMem;
14513 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014514
14515 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014516 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14517 image_create_info.pNext = NULL;
14518 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14519 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14520 image_create_info.extent.width = 32;
14521 image_create_info.extent.height = 32;
14522 image_create_info.extent.depth = 1;
14523 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014524 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014525 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14526 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14527 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14528 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014530 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014531 ASSERT_VK_SUCCESS(err);
14532
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014533 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014534 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014535 ASSERT_VK_SUCCESS(err);
14536
14537 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014538 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014539 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14540 memAlloc.pNext = NULL;
14541 memAlloc.allocationSize = 0;
14542 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014543
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014544 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014545 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014546 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014547 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014548 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014549 ASSERT_VK_SUCCESS(err);
14550
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014551 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014552 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014553 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014554 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014555 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014556 ASSERT_VK_SUCCESS(err);
14557
14558 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14559 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014560 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014561 ASSERT_VK_SUCCESS(err);
14562
Tony Barbour552f6c02016-12-21 14:34:07 -070014563 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014564 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014565 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014566 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014567 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014568 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014569 copyRegion.srcOffset.x = 0;
14570 copyRegion.srcOffset.y = 0;
14571 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014572 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014573 copyRegion.dstSubresource.mipLevel = 0;
14574 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014575 // Introduce failure by forcing the dst layerCount to differ from src
14576 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014577 copyRegion.dstOffset.x = 0;
14578 copyRegion.dstOffset.y = 0;
14579 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014580 copyRegion.extent.width = 1;
14581 copyRegion.extent.height = 1;
14582 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014583 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070014584 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014585
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014586 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014587
Chia-I Wuf7458c52015-10-26 21:10:41 +080014588 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014589 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014590 vkFreeMemory(m_device->device(), srcMem, NULL);
14591 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014592}
14593
Tony Barbourd6673642016-05-05 14:46:39 -060014594TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14595
14596 TEST_DESCRIPTION("Creating images with unsuported formats ");
14597
14598 ASSERT_NO_FATAL_FAILURE(InitState());
14599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14600 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014601 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 -060014602 VK_IMAGE_TILING_OPTIMAL, 0);
14603 ASSERT_TRUE(image.initialized());
14604
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014605 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014606 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014607 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014608 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14609 image_create_info.format = VK_FORMAT_UNDEFINED;
14610 image_create_info.extent.width = 32;
14611 image_create_info.extent.height = 32;
14612 image_create_info.extent.depth = 1;
14613 image_create_info.mipLevels = 1;
14614 image_create_info.arrayLayers = 1;
14615 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14616 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14617 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14620 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014621
14622 VkImage localImage;
14623 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14624 m_errorMonitor->VerifyFound();
14625
Tony Barbourd6673642016-05-05 14:46:39 -060014626 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014627 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014628 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14629 VkFormat format = static_cast<VkFormat>(f);
14630 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014631 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014632 unsupported = format;
14633 break;
14634 }
14635 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014636
Tony Barbourd6673642016-05-05 14:46:39 -060014637 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014638 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014640
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014641 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014642 m_errorMonitor->VerifyFound();
14643 }
14644}
14645
14646TEST_F(VkLayerTest, ImageLayerViewTests) {
14647 VkResult ret;
14648 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14649
14650 ASSERT_NO_FATAL_FAILURE(InitState());
14651
14652 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014653 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 -060014654 VK_IMAGE_TILING_OPTIMAL, 0);
14655 ASSERT_TRUE(image.initialized());
14656
14657 VkImageView imgView;
14658 VkImageViewCreateInfo imgViewInfo = {};
14659 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14660 imgViewInfo.image = image.handle();
14661 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14662 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14663 imgViewInfo.subresourceRange.layerCount = 1;
14664 imgViewInfo.subresourceRange.baseMipLevel = 0;
14665 imgViewInfo.subresourceRange.levelCount = 1;
14666 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14667
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014669 // View can't have baseMipLevel >= image's mipLevels - Expect
14670 // VIEW_CREATE_ERROR
14671 imgViewInfo.subresourceRange.baseMipLevel = 1;
14672 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14673 m_errorMonitor->VerifyFound();
14674 imgViewInfo.subresourceRange.baseMipLevel = 0;
14675
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060014677 // View can't have baseArrayLayer >= image's arraySize - Expect
14678 // VIEW_CREATE_ERROR
14679 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14680 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14681 m_errorMonitor->VerifyFound();
14682 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14683
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14685 "pCreateInfo->subresourceRange."
14686 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014687 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14688 imgViewInfo.subresourceRange.levelCount = 0;
14689 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14690 m_errorMonitor->VerifyFound();
14691 imgViewInfo.subresourceRange.levelCount = 1;
14692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14694 "pCreateInfo->subresourceRange."
14695 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014696 m_errorMonitor->SetDesiredFailureMsg(
14697 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14698 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014699 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14700 imgViewInfo.subresourceRange.layerCount = 0;
14701 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14702 m_errorMonitor->VerifyFound();
14703 imgViewInfo.subresourceRange.layerCount = 1;
14704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14707 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14708 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014709 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14710 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14711 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14712 m_errorMonitor->VerifyFound();
14713 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14714
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060014716 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14717 // VIEW_CREATE_ERROR
14718 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14719 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14720 m_errorMonitor->VerifyFound();
14721 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14722
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014724 // TODO: Update framework to easily passing mutable flag into ImageObj init
14725 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070014726 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
14727 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14728 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014729 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14730 // VIEW_CREATE_ERROR
14731 VkImageCreateInfo mutImgInfo = image.create_info();
14732 VkImage mutImage;
14733 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014734 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014735 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14736 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14737 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14738 ASSERT_VK_SUCCESS(ret);
14739 imgViewInfo.image = mutImage;
14740 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14741 m_errorMonitor->VerifyFound();
14742 imgViewInfo.image = image.handle();
14743 vkDestroyImage(m_device->handle(), mutImage, NULL);
14744}
14745
14746TEST_F(VkLayerTest, MiscImageLayerTests) {
14747
14748 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14749
14750 ASSERT_NO_FATAL_FAILURE(InitState());
14751
Rene Lindsay135204f2016-12-22 17:11:09 -070014752 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060014753 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070014754 image.init(128, 128, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14755 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060014756 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060014757 vk_testing::Buffer buffer;
14758 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070014759 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060014760 VkBufferImageCopy region = {};
14761 region.bufferRowLength = 128;
14762 region.bufferImageHeight = 128;
14763 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14764 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014765 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014766 region.imageExtent.height = 4;
14767 region.imageExtent.width = 4;
14768 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070014769
14770 VkImageObj image2(m_device);
14771 image2.init(128, 128, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14772 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
14773 ASSERT_TRUE(image2.initialized());
14774 vk_testing::Buffer buffer2;
14775 VkMemoryPropertyFlags reqs2 = 0;
14776 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
14777 VkBufferImageCopy region2 = {};
14778 region2.bufferRowLength = 128;
14779 region2.bufferImageHeight = 128;
14780 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14781 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14782 region2.imageSubresource.layerCount = 1;
14783 region2.imageExtent.height = 4;
14784 region2.imageExtent.width = 4;
14785 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014786 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014787
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014788 // Image must have offset.z of 0 and extent.depth of 1
14789 // Introduce failure by setting imageExtent.depth to 0
14790 region.imageExtent.depth = 0;
14791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14792 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14793 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14794 m_errorMonitor->VerifyFound();
14795
14796 region.imageExtent.depth = 1;
14797
14798 // Image must have offset.z of 0 and extent.depth of 1
14799 // Introduce failure by setting imageOffset.z to 4
14800 region.imageOffset.z = 4;
14801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14802 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14803 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14804 m_errorMonitor->VerifyFound();
14805
14806 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014807 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14808 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070014809 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014811 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14812 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014813 m_errorMonitor->VerifyFound();
14814
14815 // BufferOffset must be a multiple of 4
14816 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070014817 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070014819 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
14820 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014821 m_errorMonitor->VerifyFound();
14822
14823 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14824 region.bufferOffset = 0;
14825 region.imageExtent.height = 128;
14826 region.imageExtent.width = 128;
14827 // Introduce failure by setting bufferRowLength > 0 but less than width
14828 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014830 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14831 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014832 m_errorMonitor->VerifyFound();
14833
14834 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14835 region.bufferRowLength = 128;
14836 // Introduce failure by setting bufferRowHeight > 0 but less than height
14837 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014839 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14840 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014841 m_errorMonitor->VerifyFound();
14842
14843 region.bufferImageHeight = 128;
Dave Houlton34df4cb2016-12-01 16:43:06 -070014844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014845 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014846 // Expect INVALID_FILTER
14847 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014848 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
14849 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014850 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014851 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14852 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014853 VkImageBlit blitRegion = {};
14854 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14855 blitRegion.srcSubresource.baseArrayLayer = 0;
14856 blitRegion.srcSubresource.layerCount = 1;
14857 blitRegion.srcSubresource.mipLevel = 0;
14858 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14859 blitRegion.dstSubresource.baseArrayLayer = 0;
14860 blitRegion.dstSubresource.layerCount = 1;
14861 blitRegion.dstSubresource.mipLevel = 0;
14862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014863 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014864 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014865 m_errorMonitor->VerifyFound();
14866
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014867 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14869 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14870 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014871 m_errorMonitor->VerifyFound();
14872
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014874 VkImageMemoryBarrier img_barrier;
14875 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14876 img_barrier.pNext = NULL;
14877 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14878 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14879 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14880 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14881 img_barrier.image = image.handle();
14882 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14883 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14884 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14885 img_barrier.subresourceRange.baseArrayLayer = 0;
14886 img_barrier.subresourceRange.baseMipLevel = 0;
14887 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14888 img_barrier.subresourceRange.layerCount = 0;
14889 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014890 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14891 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014892 m_errorMonitor->VerifyFound();
14893 img_barrier.subresourceRange.layerCount = 1;
14894}
14895
14896TEST_F(VkLayerTest, ImageFormatLimits) {
14897
14898 TEST_DESCRIPTION("Exceed the limits of image format ");
14899
Cody Northropc31a84f2016-08-22 10:41:47 -060014900 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014902 VkImageCreateInfo image_create_info = {};
14903 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14904 image_create_info.pNext = NULL;
14905 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14906 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14907 image_create_info.extent.width = 32;
14908 image_create_info.extent.height = 32;
14909 image_create_info.extent.depth = 1;
14910 image_create_info.mipLevels = 1;
14911 image_create_info.arrayLayers = 1;
14912 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14913 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14914 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14915 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14916 image_create_info.flags = 0;
14917
14918 VkImage nullImg;
14919 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014920 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14921 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070014922 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014923 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14924 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14925 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070014926 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014927
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014929 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14930 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14931 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14932 m_errorMonitor->VerifyFound();
14933 image_create_info.mipLevels = 1;
14934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014936 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14937 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14938 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14939 m_errorMonitor->VerifyFound();
14940 image_create_info.arrayLayers = 1;
14941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014943 int samples = imgFmtProps.sampleCounts >> 1;
14944 image_create_info.samples = (VkSampleCountFlagBits)samples;
14945 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14946 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14947 m_errorMonitor->VerifyFound();
14948 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14949
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14951 "VK_IMAGE_LAYOUT_UNDEFINED or "
14952 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014953 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14954 // Expect INVALID_LAYOUT
14955 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14956 m_errorMonitor->VerifyFound();
14957 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14958}
14959
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014960TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14961
14962 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014964
14965 ASSERT_NO_FATAL_FAILURE(InitState());
14966
14967 VkImageObj src_image(m_device);
14968 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14969 VkImageObj dst_image(m_device);
14970 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14971
Tony Barbour552f6c02016-12-21 14:34:07 -070014972 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014973 VkImageCopy copy_region;
14974 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14975 copy_region.srcSubresource.mipLevel = 0;
14976 copy_region.srcSubresource.baseArrayLayer = 0;
14977 copy_region.srcSubresource.layerCount = 0;
14978 copy_region.srcOffset.x = 0;
14979 copy_region.srcOffset.y = 0;
14980 copy_region.srcOffset.z = 0;
14981 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14982 copy_region.dstSubresource.mipLevel = 0;
14983 copy_region.dstSubresource.baseArrayLayer = 0;
14984 copy_region.dstSubresource.layerCount = 0;
14985 copy_region.dstOffset.x = 0;
14986 copy_region.dstOffset.y = 0;
14987 copy_region.dstOffset.z = 0;
14988 copy_region.extent.width = 64;
14989 copy_region.extent.height = 64;
14990 copy_region.extent.depth = 1;
14991 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14992 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070014993 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014994
14995 m_errorMonitor->VerifyFound();
14996}
14997
14998TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14999
15000 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015002
15003 ASSERT_NO_FATAL_FAILURE(InitState());
15004
15005 VkImageObj src_image(m_device);
15006 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15007 VkImageObj dst_image(m_device);
15008 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15009
Tony Barbour552f6c02016-12-21 14:34:07 -070015010 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015011 VkImageCopy copy_region;
15012 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15013 copy_region.srcSubresource.mipLevel = 0;
15014 copy_region.srcSubresource.baseArrayLayer = 0;
15015 copy_region.srcSubresource.layerCount = 0;
15016 copy_region.srcOffset.x = 0;
15017 copy_region.srcOffset.y = 0;
15018 copy_region.srcOffset.z = 0;
15019 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15020 copy_region.dstSubresource.mipLevel = 0;
15021 copy_region.dstSubresource.baseArrayLayer = 0;
15022 copy_region.dstSubresource.layerCount = 0;
15023 copy_region.dstOffset.x = 0;
15024 copy_region.dstOffset.y = 0;
15025 copy_region.dstOffset.z = 0;
15026 copy_region.extent.width = 64;
15027 copy_region.extent.height = 64;
15028 copy_region.extent.depth = 1;
15029 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15030 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015031 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015032
15033 m_errorMonitor->VerifyFound();
15034}
15035
Karl Schultz6addd812016-02-02 17:17:23 -070015036TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015037 VkResult err;
15038 bool pass;
15039
15040 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015042
15043 ASSERT_NO_FATAL_FAILURE(InitState());
15044
15045 // Create two images of different types and try to copy between them
15046 VkImage srcImage;
15047 VkImage dstImage;
15048 VkDeviceMemory srcMem;
15049 VkDeviceMemory destMem;
15050 VkMemoryRequirements memReqs;
15051
15052 VkImageCreateInfo image_create_info = {};
15053 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15054 image_create_info.pNext = NULL;
15055 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15056 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15057 image_create_info.extent.width = 32;
15058 image_create_info.extent.height = 32;
15059 image_create_info.extent.depth = 1;
15060 image_create_info.mipLevels = 1;
15061 image_create_info.arrayLayers = 1;
15062 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15063 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15064 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15065 image_create_info.flags = 0;
15066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015067 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015068 ASSERT_VK_SUCCESS(err);
15069
15070 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15071 // Introduce failure by creating second image with a different-sized format.
15072 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015074 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015075 ASSERT_VK_SUCCESS(err);
15076
15077 // Allocate memory
15078 VkMemoryAllocateInfo memAlloc = {};
15079 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15080 memAlloc.pNext = NULL;
15081 memAlloc.allocationSize = 0;
15082 memAlloc.memoryTypeIndex = 0;
15083
15084 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15085 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015086 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015087 ASSERT_TRUE(pass);
15088 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15089 ASSERT_VK_SUCCESS(err);
15090
15091 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15092 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015093 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015094 ASSERT_TRUE(pass);
15095 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15096 ASSERT_VK_SUCCESS(err);
15097
15098 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15099 ASSERT_VK_SUCCESS(err);
15100 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15101 ASSERT_VK_SUCCESS(err);
15102
Tony Barbour552f6c02016-12-21 14:34:07 -070015103 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015104 VkImageCopy copyRegion;
15105 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15106 copyRegion.srcSubresource.mipLevel = 0;
15107 copyRegion.srcSubresource.baseArrayLayer = 0;
15108 copyRegion.srcSubresource.layerCount = 0;
15109 copyRegion.srcOffset.x = 0;
15110 copyRegion.srcOffset.y = 0;
15111 copyRegion.srcOffset.z = 0;
15112 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15113 copyRegion.dstSubresource.mipLevel = 0;
15114 copyRegion.dstSubresource.baseArrayLayer = 0;
15115 copyRegion.dstSubresource.layerCount = 0;
15116 copyRegion.dstOffset.x = 0;
15117 copyRegion.dstOffset.y = 0;
15118 copyRegion.dstOffset.z = 0;
15119 copyRegion.extent.width = 1;
15120 copyRegion.extent.height = 1;
15121 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015122 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015123 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015124
15125 m_errorMonitor->VerifyFound();
15126
15127 vkDestroyImage(m_device->device(), srcImage, NULL);
15128 vkDestroyImage(m_device->device(), dstImage, NULL);
15129 vkFreeMemory(m_device->device(), srcMem, NULL);
15130 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015131}
15132
Karl Schultz6addd812016-02-02 17:17:23 -070015133TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15134 VkResult err;
15135 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015136
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015137 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15139 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015140
Mike Stroyana3082432015-09-25 13:39:21 -060015141 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015142
15143 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015144 VkImage srcImage;
15145 VkImage dstImage;
15146 VkDeviceMemory srcMem;
15147 VkDeviceMemory destMem;
15148 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015149
15150 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015151 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15152 image_create_info.pNext = NULL;
15153 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15154 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15155 image_create_info.extent.width = 32;
15156 image_create_info.extent.height = 32;
15157 image_create_info.extent.depth = 1;
15158 image_create_info.mipLevels = 1;
15159 image_create_info.arrayLayers = 1;
15160 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15161 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15162 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15163 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015165 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015166 ASSERT_VK_SUCCESS(err);
15167
Karl Schultzbdb75952016-04-19 11:36:49 -060015168 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15169
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015170 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015171 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015172 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015173 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015176 ASSERT_VK_SUCCESS(err);
15177
15178 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015179 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015180 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15181 memAlloc.pNext = NULL;
15182 memAlloc.allocationSize = 0;
15183 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015184
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015185 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015186 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015187 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015188 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015189 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015190 ASSERT_VK_SUCCESS(err);
15191
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015192 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015193 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015194 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015195 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015196 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015197 ASSERT_VK_SUCCESS(err);
15198
15199 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15200 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015201 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015202 ASSERT_VK_SUCCESS(err);
15203
Tony Barbour552f6c02016-12-21 14:34:07 -070015204 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015205 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015206 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015207 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015208 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015209 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015210 copyRegion.srcOffset.x = 0;
15211 copyRegion.srcOffset.y = 0;
15212 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015213 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015214 copyRegion.dstSubresource.mipLevel = 0;
15215 copyRegion.dstSubresource.baseArrayLayer = 0;
15216 copyRegion.dstSubresource.layerCount = 0;
15217 copyRegion.dstOffset.x = 0;
15218 copyRegion.dstOffset.y = 0;
15219 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015220 copyRegion.extent.width = 1;
15221 copyRegion.extent.height = 1;
15222 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015223 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015224 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015225
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015226 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015227
Chia-I Wuf7458c52015-10-26 21:10:41 +080015228 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015229 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015230 vkFreeMemory(m_device->device(), srcMem, NULL);
15231 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015232}
15233
Karl Schultz6addd812016-02-02 17:17:23 -070015234TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15235 VkResult err;
15236 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15239 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015240
Mike Stroyana3082432015-09-25 13:39:21 -060015241 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015242
15243 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015244 VkImage srcImage;
15245 VkImage dstImage;
15246 VkDeviceMemory srcMem;
15247 VkDeviceMemory destMem;
15248 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015249
15250 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015251 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15252 image_create_info.pNext = NULL;
15253 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15254 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15255 image_create_info.extent.width = 32;
15256 image_create_info.extent.height = 1;
15257 image_create_info.extent.depth = 1;
15258 image_create_info.mipLevels = 1;
15259 image_create_info.arrayLayers = 1;
15260 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15261 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15262 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15263 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015265 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015266 ASSERT_VK_SUCCESS(err);
15267
Karl Schultz6addd812016-02-02 17:17:23 -070015268 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015270 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015271 ASSERT_VK_SUCCESS(err);
15272
15273 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015274 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015275 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15276 memAlloc.pNext = NULL;
15277 memAlloc.allocationSize = 0;
15278 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015279
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015280 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015281 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015282 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015283 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015284 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015285 ASSERT_VK_SUCCESS(err);
15286
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015287 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015288 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015289 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015290 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015291 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015292 ASSERT_VK_SUCCESS(err);
15293
15294 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15295 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015296 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015297 ASSERT_VK_SUCCESS(err);
15298
Tony Barbour552f6c02016-12-21 14:34:07 -070015299 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015300 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015301 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15302 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015303 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015304 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015305 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015306 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015307 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015308 resolveRegion.srcOffset.x = 0;
15309 resolveRegion.srcOffset.y = 0;
15310 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015311 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015312 resolveRegion.dstSubresource.mipLevel = 0;
15313 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015314 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015315 resolveRegion.dstOffset.x = 0;
15316 resolveRegion.dstOffset.y = 0;
15317 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015318 resolveRegion.extent.width = 1;
15319 resolveRegion.extent.height = 1;
15320 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015321 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015322 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015323
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015324 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015325
Chia-I Wuf7458c52015-10-26 21:10:41 +080015326 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015327 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015328 vkFreeMemory(m_device->device(), srcMem, NULL);
15329 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015330}
15331
Karl Schultz6addd812016-02-02 17:17:23 -070015332TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15333 VkResult err;
15334 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15337 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015338
Mike Stroyana3082432015-09-25 13:39:21 -060015339 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015340
Chris Forbesa7530692016-05-08 12:35:39 +120015341 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015342 VkImage srcImage;
15343 VkImage dstImage;
15344 VkDeviceMemory srcMem;
15345 VkDeviceMemory destMem;
15346 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015347
15348 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015349 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15350 image_create_info.pNext = NULL;
15351 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15352 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15353 image_create_info.extent.width = 32;
15354 image_create_info.extent.height = 1;
15355 image_create_info.extent.depth = 1;
15356 image_create_info.mipLevels = 1;
15357 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015358 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015359 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15360 // Note: Some implementations expect color attachment usage for any
15361 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015362 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015363 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015365 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015366 ASSERT_VK_SUCCESS(err);
15367
Karl Schultz6addd812016-02-02 17:17:23 -070015368 // Note: Some implementations expect color attachment usage for any
15369 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015370 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015372 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015373 ASSERT_VK_SUCCESS(err);
15374
15375 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015376 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015377 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15378 memAlloc.pNext = NULL;
15379 memAlloc.allocationSize = 0;
15380 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015381
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015382 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015383 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015384 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015385 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015386 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015387 ASSERT_VK_SUCCESS(err);
15388
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015389 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015390 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015391 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015392 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015393 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015394 ASSERT_VK_SUCCESS(err);
15395
15396 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15397 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015398 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015399 ASSERT_VK_SUCCESS(err);
15400
Tony Barbour552f6c02016-12-21 14:34:07 -070015401 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015402 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015403 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15404 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015405 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015406 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015407 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015408 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015409 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015410 resolveRegion.srcOffset.x = 0;
15411 resolveRegion.srcOffset.y = 0;
15412 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015413 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015414 resolveRegion.dstSubresource.mipLevel = 0;
15415 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015416 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015417 resolveRegion.dstOffset.x = 0;
15418 resolveRegion.dstOffset.y = 0;
15419 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015420 resolveRegion.extent.width = 1;
15421 resolveRegion.extent.height = 1;
15422 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015423 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015424 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015425
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015426 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015427
Chia-I Wuf7458c52015-10-26 21:10:41 +080015428 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015429 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015430 vkFreeMemory(m_device->device(), srcMem, NULL);
15431 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015432}
15433
Karl Schultz6addd812016-02-02 17:17:23 -070015434TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15435 VkResult err;
15436 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15439 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015440
Mike Stroyana3082432015-09-25 13:39:21 -060015441 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015442
15443 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015444 VkImage srcImage;
15445 VkImage dstImage;
15446 VkDeviceMemory srcMem;
15447 VkDeviceMemory destMem;
15448 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015449
15450 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015451 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15452 image_create_info.pNext = NULL;
15453 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15454 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15455 image_create_info.extent.width = 32;
15456 image_create_info.extent.height = 1;
15457 image_create_info.extent.depth = 1;
15458 image_create_info.mipLevels = 1;
15459 image_create_info.arrayLayers = 1;
15460 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15461 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15462 // Note: Some implementations expect color attachment usage for any
15463 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015464 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015465 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015466
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015467 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015468 ASSERT_VK_SUCCESS(err);
15469
Karl Schultz6addd812016-02-02 17:17:23 -070015470 // Set format to something other than source image
15471 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15472 // Note: Some implementations expect color attachment usage for any
15473 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015474 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015475 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015476
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015477 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015478 ASSERT_VK_SUCCESS(err);
15479
15480 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015481 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015482 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15483 memAlloc.pNext = NULL;
15484 memAlloc.allocationSize = 0;
15485 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015486
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015487 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015488 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015489 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015490 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015491 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015492 ASSERT_VK_SUCCESS(err);
15493
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015494 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015495 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015496 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015497 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015498 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015499 ASSERT_VK_SUCCESS(err);
15500
15501 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15502 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015503 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015504 ASSERT_VK_SUCCESS(err);
15505
Tony Barbour552f6c02016-12-21 14:34:07 -070015506 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015507 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015508 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15509 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015510 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015511 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015512 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015513 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015514 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015515 resolveRegion.srcOffset.x = 0;
15516 resolveRegion.srcOffset.y = 0;
15517 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015518 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015519 resolveRegion.dstSubresource.mipLevel = 0;
15520 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015521 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015522 resolveRegion.dstOffset.x = 0;
15523 resolveRegion.dstOffset.y = 0;
15524 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015525 resolveRegion.extent.width = 1;
15526 resolveRegion.extent.height = 1;
15527 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015528 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015529 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015530
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015531 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015532
Chia-I Wuf7458c52015-10-26 21:10:41 +080015533 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015534 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015535 vkFreeMemory(m_device->device(), srcMem, NULL);
15536 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015537}
15538
Karl Schultz6addd812016-02-02 17:17:23 -070015539TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15540 VkResult err;
15541 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015542
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15544 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015545
Mike Stroyana3082432015-09-25 13:39:21 -060015546 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015547
15548 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015549 VkImage srcImage;
15550 VkImage dstImage;
15551 VkDeviceMemory srcMem;
15552 VkDeviceMemory destMem;
15553 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015554
15555 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015556 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15557 image_create_info.pNext = NULL;
15558 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15559 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15560 image_create_info.extent.width = 32;
15561 image_create_info.extent.height = 1;
15562 image_create_info.extent.depth = 1;
15563 image_create_info.mipLevels = 1;
15564 image_create_info.arrayLayers = 1;
15565 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15566 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15567 // Note: Some implementations expect color attachment usage for any
15568 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015569 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015570 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015571
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015572 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015573 ASSERT_VK_SUCCESS(err);
15574
Karl Schultz6addd812016-02-02 17:17:23 -070015575 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15576 // Note: Some implementations expect color attachment usage for any
15577 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015578 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015579 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015581 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015582 ASSERT_VK_SUCCESS(err);
15583
15584 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015585 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015586 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15587 memAlloc.pNext = NULL;
15588 memAlloc.allocationSize = 0;
15589 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015590
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015591 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015592 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015593 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015594 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015595 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015596 ASSERT_VK_SUCCESS(err);
15597
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015598 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015599 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015600 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015601 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015602 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015603 ASSERT_VK_SUCCESS(err);
15604
15605 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15606 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015607 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015608 ASSERT_VK_SUCCESS(err);
15609
Tony Barbour552f6c02016-12-21 14:34:07 -070015610 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015611 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015612 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15613 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015614 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015615 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015616 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015617 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015618 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015619 resolveRegion.srcOffset.x = 0;
15620 resolveRegion.srcOffset.y = 0;
15621 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015622 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015623 resolveRegion.dstSubresource.mipLevel = 0;
15624 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015625 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015626 resolveRegion.dstOffset.x = 0;
15627 resolveRegion.dstOffset.y = 0;
15628 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015629 resolveRegion.extent.width = 1;
15630 resolveRegion.extent.height = 1;
15631 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015632 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015633 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015634
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015635 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015636
Chia-I Wuf7458c52015-10-26 21:10:41 +080015637 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015638 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015639 vkFreeMemory(m_device->device(), srcMem, NULL);
15640 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015641}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015642
Karl Schultz6addd812016-02-02 17:17:23 -070015643TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015644 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015645 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15646 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015647 // The image format check comes 2nd in validation so we trigger it first,
15648 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015649 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015650
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15652 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015653
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015654 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015655
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015656 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015657 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15658 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015659
15660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15662 ds_pool_ci.pNext = NULL;
15663 ds_pool_ci.maxSets = 1;
15664 ds_pool_ci.poolSizeCount = 1;
15665 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015666
15667 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015668 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015669 ASSERT_VK_SUCCESS(err);
15670
15671 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015672 dsl_binding.binding = 0;
15673 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15674 dsl_binding.descriptorCount = 1;
15675 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15676 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015677
15678 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015679 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15680 ds_layout_ci.pNext = NULL;
15681 ds_layout_ci.bindingCount = 1;
15682 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015683 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015684 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015685 ASSERT_VK_SUCCESS(err);
15686
15687 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015688 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015689 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015690 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015691 alloc_info.descriptorPool = ds_pool;
15692 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015693 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015694 ASSERT_VK_SUCCESS(err);
15695
Karl Schultz6addd812016-02-02 17:17:23 -070015696 VkImage image_bad;
15697 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015698 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015699 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015700 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015701 const int32_t tex_width = 32;
15702 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015703
15704 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15706 image_create_info.pNext = NULL;
15707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15708 image_create_info.format = tex_format_bad;
15709 image_create_info.extent.width = tex_width;
15710 image_create_info.extent.height = tex_height;
15711 image_create_info.extent.depth = 1;
15712 image_create_info.mipLevels = 1;
15713 image_create_info.arrayLayers = 1;
15714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15715 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015716 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015717 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015718
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015719 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015720 ASSERT_VK_SUCCESS(err);
15721 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015722 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15723 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015724 ASSERT_VK_SUCCESS(err);
15725
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015726 // ---Bind image memory---
15727 VkMemoryRequirements img_mem_reqs;
15728 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15729 VkMemoryAllocateInfo image_alloc_info = {};
15730 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15731 image_alloc_info.pNext = NULL;
15732 image_alloc_info.memoryTypeIndex = 0;
15733 image_alloc_info.allocationSize = img_mem_reqs.size;
15734 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &image_alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15735 ASSERT_TRUE(pass);
15736 VkDeviceMemory mem;
15737 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15738 ASSERT_VK_SUCCESS(err);
15739 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15740 ASSERT_VK_SUCCESS(err);
15741 // -----------------------
15742
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015743 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015744 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015745 image_view_create_info.image = image_bad;
15746 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15747 image_view_create_info.format = tex_format_bad;
15748 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15749 image_view_create_info.subresourceRange.baseMipLevel = 0;
15750 image_view_create_info.subresourceRange.layerCount = 1;
15751 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015752 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015753
15754 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015755 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015756
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015757 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015758
Chia-I Wuf7458c52015-10-26 21:10:41 +080015759 vkDestroyImage(m_device->device(), image_bad, NULL);
15760 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015761 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15762 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015763
15764 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015765}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015766
15767TEST_F(VkLayerTest, ClearImageErrors) {
15768 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15769 "ClearDepthStencilImage with a color image.");
15770
15771 ASSERT_NO_FATAL_FAILURE(InitState());
15772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15773
Tony Barbour552f6c02016-12-21 14:34:07 -070015774 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015775
15776 // Color image
15777 VkClearColorValue clear_color;
15778 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15779 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15780 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15781 const int32_t img_width = 32;
15782 const int32_t img_height = 32;
15783 VkImageCreateInfo image_create_info = {};
15784 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15785 image_create_info.pNext = NULL;
15786 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15787 image_create_info.format = color_format;
15788 image_create_info.extent.width = img_width;
15789 image_create_info.extent.height = img_height;
15790 image_create_info.extent.depth = 1;
15791 image_create_info.mipLevels = 1;
15792 image_create_info.arrayLayers = 1;
15793 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15794 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15795 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15796
15797 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015798 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015800 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015801
15802 // Depth/Stencil image
15803 VkClearDepthStencilValue clear_value = {0};
15804 reqs = 0; // don't need HOST_VISIBLE DS image
15805 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15806 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15807 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15808 ds_image_create_info.extent.width = 64;
15809 ds_image_create_info.extent.height = 64;
15810 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015811 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 -060015812
15813 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015814 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015815
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015816 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 -060015817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015819
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015820 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015821 &color_range);
15822
15823 m_errorMonitor->VerifyFound();
15824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15826 "image created without "
15827 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015828
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015829 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015830 &color_range);
15831
15832 m_errorMonitor->VerifyFound();
15833
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015834 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15836 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015838 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015839 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015840
15841 m_errorMonitor->VerifyFound();
15842}
Tobin Ehliscde08892015-09-22 10:11:37 -060015843#endif // IMAGE_TESTS
15844
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015845
15846// WSI Enabled Tests
15847//
Chris Forbes09368e42016-10-13 11:59:22 +130015848#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015849TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15850
15851#if defined(VK_USE_PLATFORM_XCB_KHR)
15852 VkSurfaceKHR surface = VK_NULL_HANDLE;
15853
15854 VkResult err;
15855 bool pass;
15856 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15857 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15858 // uint32_t swapchain_image_count = 0;
15859 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15860 // uint32_t image_index = 0;
15861 // VkPresentInfoKHR present_info = {};
15862
15863 ASSERT_NO_FATAL_FAILURE(InitState());
15864
15865 // Use the create function from one of the VK_KHR_*_surface extension in
15866 // order to create a surface, testing all known errors in the process,
15867 // before successfully creating a surface:
15868 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15870 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15871 pass = (err != VK_SUCCESS);
15872 ASSERT_TRUE(pass);
15873 m_errorMonitor->VerifyFound();
15874
15875 // Next, try to create a surface with the wrong
15876 // VkXcbSurfaceCreateInfoKHR::sType:
15877 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15878 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15880 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15881 pass = (err != VK_SUCCESS);
15882 ASSERT_TRUE(pass);
15883 m_errorMonitor->VerifyFound();
15884
15885 // Create a native window, and then correctly create a surface:
15886 xcb_connection_t *connection;
15887 xcb_screen_t *screen;
15888 xcb_window_t xcb_window;
15889 xcb_intern_atom_reply_t *atom_wm_delete_window;
15890
15891 const xcb_setup_t *setup;
15892 xcb_screen_iterator_t iter;
15893 int scr;
15894 uint32_t value_mask, value_list[32];
15895 int width = 1;
15896 int height = 1;
15897
15898 connection = xcb_connect(NULL, &scr);
15899 ASSERT_TRUE(connection != NULL);
15900 setup = xcb_get_setup(connection);
15901 iter = xcb_setup_roots_iterator(setup);
15902 while (scr-- > 0)
15903 xcb_screen_next(&iter);
15904 screen = iter.data;
15905
15906 xcb_window = xcb_generate_id(connection);
15907
15908 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15909 value_list[0] = screen->black_pixel;
15910 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15911
15912 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15913 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15914
15915 /* Magic code that will send notification when window is destroyed */
15916 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15917 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15918
15919 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15920 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15921 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15922 free(reply);
15923
15924 xcb_map_window(connection, xcb_window);
15925
15926 // Force the x/y coordinates to 100,100 results are identical in consecutive
15927 // runs
15928 const uint32_t coords[] = { 100, 100 };
15929 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15930
15931 // Finally, try to correctly create a surface:
15932 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15933 xcb_create_info.pNext = NULL;
15934 xcb_create_info.flags = 0;
15935 xcb_create_info.connection = connection;
15936 xcb_create_info.window = xcb_window;
15937 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15938 pass = (err == VK_SUCCESS);
15939 ASSERT_TRUE(pass);
15940
15941 // Check if surface supports presentation:
15942
15943 // 1st, do so without having queried the queue families:
15944 VkBool32 supported = false;
15945 // TODO: Get the following error to come out:
15946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15947 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15948 "function");
15949 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15950 pass = (err != VK_SUCCESS);
15951 // ASSERT_TRUE(pass);
15952 // m_errorMonitor->VerifyFound();
15953
15954 // Next, query a queue family index that's too large:
15955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15956 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15957 pass = (err != VK_SUCCESS);
15958 ASSERT_TRUE(pass);
15959 m_errorMonitor->VerifyFound();
15960
15961 // Finally, do so correctly:
15962 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15963 // SUPPORTED
15964 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15965 pass = (err == VK_SUCCESS);
15966 ASSERT_TRUE(pass);
15967
15968 // Before proceeding, try to create a swapchain without having called
15969 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15970 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15971 swapchain_create_info.pNext = NULL;
15972 swapchain_create_info.flags = 0;
15973 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15974 swapchain_create_info.surface = surface;
15975 swapchain_create_info.imageArrayLayers = 1;
15976 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15977 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15979 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15980 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15981 pass = (err != VK_SUCCESS);
15982 ASSERT_TRUE(pass);
15983 m_errorMonitor->VerifyFound();
15984
15985 // Get the surface capabilities:
15986 VkSurfaceCapabilitiesKHR surface_capabilities;
15987
15988 // Do so correctly (only error logged by this entrypoint is if the
15989 // extension isn't enabled):
15990 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15991 pass = (err == VK_SUCCESS);
15992 ASSERT_TRUE(pass);
15993
15994 // Get the surface formats:
15995 uint32_t surface_format_count;
15996
15997 // First, try without a pointer to surface_format_count:
15998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15999 "specified as NULL");
16000 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16001 pass = (err == VK_SUCCESS);
16002 ASSERT_TRUE(pass);
16003 m_errorMonitor->VerifyFound();
16004
16005 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16006 // correctly done a 1st try (to get the count):
16007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16008 surface_format_count = 0;
16009 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16010 pass = (err == VK_SUCCESS);
16011 ASSERT_TRUE(pass);
16012 m_errorMonitor->VerifyFound();
16013
16014 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16015 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16016 pass = (err == VK_SUCCESS);
16017 ASSERT_TRUE(pass);
16018
16019 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16020 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16021
16022 // Next, do a 2nd try with surface_format_count being set too high:
16023 surface_format_count += 5;
16024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16025 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16026 pass = (err == VK_SUCCESS);
16027 ASSERT_TRUE(pass);
16028 m_errorMonitor->VerifyFound();
16029
16030 // Finally, do a correct 1st and 2nd try:
16031 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16032 pass = (err == VK_SUCCESS);
16033 ASSERT_TRUE(pass);
16034 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16035 pass = (err == VK_SUCCESS);
16036 ASSERT_TRUE(pass);
16037
16038 // Get the surface present modes:
16039 uint32_t surface_present_mode_count;
16040
16041 // First, try without a pointer to surface_format_count:
16042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16043 "specified as NULL");
16044
16045 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16046 pass = (err == VK_SUCCESS);
16047 ASSERT_TRUE(pass);
16048 m_errorMonitor->VerifyFound();
16049
16050 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16051 // correctly done a 1st try (to get the count):
16052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16053 surface_present_mode_count = 0;
16054 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16055 (VkPresentModeKHR *)&surface_present_mode_count);
16056 pass = (err == VK_SUCCESS);
16057 ASSERT_TRUE(pass);
16058 m_errorMonitor->VerifyFound();
16059
16060 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16061 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16062 pass = (err == VK_SUCCESS);
16063 ASSERT_TRUE(pass);
16064
16065 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16066 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16067
16068 // Next, do a 2nd try with surface_format_count being set too high:
16069 surface_present_mode_count += 5;
16070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16071 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16072 pass = (err == VK_SUCCESS);
16073 ASSERT_TRUE(pass);
16074 m_errorMonitor->VerifyFound();
16075
16076 // Finally, do a correct 1st and 2nd try:
16077 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16078 pass = (err == VK_SUCCESS);
16079 ASSERT_TRUE(pass);
16080 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16081 pass = (err == VK_SUCCESS);
16082 ASSERT_TRUE(pass);
16083
16084 // Create a swapchain:
16085
16086 // First, try without a pointer to swapchain_create_info:
16087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16088 "specified as NULL");
16089
16090 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16091 pass = (err != VK_SUCCESS);
16092 ASSERT_TRUE(pass);
16093 m_errorMonitor->VerifyFound();
16094
16095 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16096 // sType:
16097 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16099
16100 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16101 pass = (err != VK_SUCCESS);
16102 ASSERT_TRUE(pass);
16103 m_errorMonitor->VerifyFound();
16104
16105 // Next, call with a NULL swapchain pointer:
16106 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16107 swapchain_create_info.pNext = NULL;
16108 swapchain_create_info.flags = 0;
16109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16110 "specified as NULL");
16111
16112 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16113 pass = (err != VK_SUCCESS);
16114 ASSERT_TRUE(pass);
16115 m_errorMonitor->VerifyFound();
16116
16117 // TODO: Enhance swapchain layer so that
16118 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16119
16120 // Next, call with a queue family index that's too large:
16121 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16122 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16123 swapchain_create_info.queueFamilyIndexCount = 2;
16124 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16126 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16127 pass = (err != VK_SUCCESS);
16128 ASSERT_TRUE(pass);
16129 m_errorMonitor->VerifyFound();
16130
16131 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16132 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16133 swapchain_create_info.queueFamilyIndexCount = 1;
16134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16135 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16136 "pCreateInfo->pQueueFamilyIndices).");
16137 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16138 pass = (err != VK_SUCCESS);
16139 ASSERT_TRUE(pass);
16140 m_errorMonitor->VerifyFound();
16141
16142 // Next, call with an invalid imageSharingMode:
16143 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16144 swapchain_create_info.queueFamilyIndexCount = 1;
16145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16146 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16147 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16148 pass = (err != VK_SUCCESS);
16149 ASSERT_TRUE(pass);
16150 m_errorMonitor->VerifyFound();
16151 // Fix for the future:
16152 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16153 // SUPPORTED
16154 swapchain_create_info.queueFamilyIndexCount = 0;
16155 queueFamilyIndex[0] = 0;
16156 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16157
16158 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16159 // Get the images from a swapchain:
16160 // Acquire an image from a swapchain:
16161 // Present an image to a swapchain:
16162 // Destroy the swapchain:
16163
16164 // TODOs:
16165 //
16166 // - Try destroying the device without first destroying the swapchain
16167 //
16168 // - Try destroying the device without first destroying the surface
16169 //
16170 // - Try destroying the surface without first destroying the swapchain
16171
16172 // Destroy the surface:
16173 vkDestroySurfaceKHR(instance(), surface, NULL);
16174
16175 // Tear down the window:
16176 xcb_destroy_window(connection, xcb_window);
16177 xcb_disconnect(connection);
16178
16179#else // VK_USE_PLATFORM_XCB_KHR
16180 return;
16181#endif // VK_USE_PLATFORM_XCB_KHR
16182}
Chris Forbes09368e42016-10-13 11:59:22 +130016183#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016184
16185//
16186// POSITIVE VALIDATION TESTS
16187//
16188// These tests do not expect to encounter ANY validation errors pass only if this is true
16189
Tobin Ehlise0006882016-11-03 10:14:28 -060016190TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16191 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16192 "by a transition in the primary.");
16193 VkResult err;
16194 m_errorMonitor->ExpectSuccess();
16195 ASSERT_NO_FATAL_FAILURE(InitState());
16196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16197 // Allocate a secondary and primary cmd buffer
16198 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16199 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16200 command_buffer_allocate_info.commandPool = m_commandPool;
16201 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16202 command_buffer_allocate_info.commandBufferCount = 1;
16203
16204 VkCommandBuffer secondary_command_buffer;
16205 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16206 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16207 VkCommandBuffer primary_command_buffer;
16208 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16209 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16210 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16211 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16212 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16213 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16214 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16215
16216 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16217 ASSERT_VK_SUCCESS(err);
16218 VkImageObj image(m_device);
16219 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16220 ASSERT_TRUE(image.initialized());
16221 VkImageMemoryBarrier img_barrier = {};
16222 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16223 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16224 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16225 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16226 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16227 img_barrier.image = image.handle();
16228 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16229 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16230 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16231 img_barrier.subresourceRange.baseArrayLayer = 0;
16232 img_barrier.subresourceRange.baseMipLevel = 0;
16233 img_barrier.subresourceRange.layerCount = 1;
16234 img_barrier.subresourceRange.levelCount = 1;
16235 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16236 0, nullptr, 1, &img_barrier);
16237 err = vkEndCommandBuffer(secondary_command_buffer);
16238 ASSERT_VK_SUCCESS(err);
16239
16240 // Now update primary cmd buffer to execute secondary and transitions image
16241 command_buffer_begin_info.pInheritanceInfo = nullptr;
16242 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16243 ASSERT_VK_SUCCESS(err);
16244 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16245 VkImageMemoryBarrier img_barrier2 = {};
16246 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16247 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16248 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16249 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16250 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16251 img_barrier2.image = image.handle();
16252 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16253 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16254 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16255 img_barrier2.subresourceRange.baseArrayLayer = 0;
16256 img_barrier2.subresourceRange.baseMipLevel = 0;
16257 img_barrier2.subresourceRange.layerCount = 1;
16258 img_barrier2.subresourceRange.levelCount = 1;
16259 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16260 nullptr, 1, &img_barrier2);
16261 err = vkEndCommandBuffer(primary_command_buffer);
16262 ASSERT_VK_SUCCESS(err);
16263 VkSubmitInfo submit_info = {};
16264 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16265 submit_info.commandBufferCount = 1;
16266 submit_info.pCommandBuffers = &primary_command_buffer;
16267 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16268 ASSERT_VK_SUCCESS(err);
16269 m_errorMonitor->VerifyNotFound();
16270 err = vkDeviceWaitIdle(m_device->device());
16271 ASSERT_VK_SUCCESS(err);
16272 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16273 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16274}
16275
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016276// This is a positive test. No failures are expected.
16277TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16278 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16279 "is ignoring VkWriteDescriptorSet members that are not "
16280 "related to the descriptor type specified by "
16281 "VkWriteDescriptorSet::descriptorType. Correct "
16282 "validation behavior will result in the test running to "
16283 "completion without validation errors.");
16284
16285 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16286
16287 ASSERT_NO_FATAL_FAILURE(InitState());
16288
16289 // Image Case
16290 {
16291 m_errorMonitor->ExpectSuccess();
16292
16293 VkImage image;
16294 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16295 const int32_t tex_width = 32;
16296 const int32_t tex_height = 32;
16297 VkImageCreateInfo image_create_info = {};
16298 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16299 image_create_info.pNext = NULL;
16300 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16301 image_create_info.format = tex_format;
16302 image_create_info.extent.width = tex_width;
16303 image_create_info.extent.height = tex_height;
16304 image_create_info.extent.depth = 1;
16305 image_create_info.mipLevels = 1;
16306 image_create_info.arrayLayers = 1;
16307 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16308 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16309 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16310 image_create_info.flags = 0;
16311 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16312 ASSERT_VK_SUCCESS(err);
16313
16314 VkMemoryRequirements memory_reqs;
16315 VkDeviceMemory image_memory;
16316 bool pass;
16317 VkMemoryAllocateInfo memory_info = {};
16318 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16319 memory_info.pNext = NULL;
16320 memory_info.allocationSize = 0;
16321 memory_info.memoryTypeIndex = 0;
16322 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16323 memory_info.allocationSize = memory_reqs.size;
16324 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16325 ASSERT_TRUE(pass);
16326 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16327 ASSERT_VK_SUCCESS(err);
16328 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16329 ASSERT_VK_SUCCESS(err);
16330
16331 VkImageViewCreateInfo image_view_create_info = {};
16332 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16333 image_view_create_info.image = image;
16334 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16335 image_view_create_info.format = tex_format;
16336 image_view_create_info.subresourceRange.layerCount = 1;
16337 image_view_create_info.subresourceRange.baseMipLevel = 0;
16338 image_view_create_info.subresourceRange.levelCount = 1;
16339 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16340
16341 VkImageView view;
16342 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16343 ASSERT_VK_SUCCESS(err);
16344
16345 VkDescriptorPoolSize ds_type_count = {};
16346 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16347 ds_type_count.descriptorCount = 1;
16348
16349 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16350 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16351 ds_pool_ci.pNext = NULL;
16352 ds_pool_ci.maxSets = 1;
16353 ds_pool_ci.poolSizeCount = 1;
16354 ds_pool_ci.pPoolSizes = &ds_type_count;
16355
16356 VkDescriptorPool ds_pool;
16357 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16358 ASSERT_VK_SUCCESS(err);
16359
16360 VkDescriptorSetLayoutBinding dsl_binding = {};
16361 dsl_binding.binding = 0;
16362 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16363 dsl_binding.descriptorCount = 1;
16364 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16365 dsl_binding.pImmutableSamplers = NULL;
16366
16367 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16368 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16369 ds_layout_ci.pNext = NULL;
16370 ds_layout_ci.bindingCount = 1;
16371 ds_layout_ci.pBindings = &dsl_binding;
16372 VkDescriptorSetLayout ds_layout;
16373 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16374 ASSERT_VK_SUCCESS(err);
16375
16376 VkDescriptorSet descriptor_set;
16377 VkDescriptorSetAllocateInfo alloc_info = {};
16378 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16379 alloc_info.descriptorSetCount = 1;
16380 alloc_info.descriptorPool = ds_pool;
16381 alloc_info.pSetLayouts = &ds_layout;
16382 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16383 ASSERT_VK_SUCCESS(err);
16384
16385 VkDescriptorImageInfo image_info = {};
16386 image_info.imageView = view;
16387 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16388
16389 VkWriteDescriptorSet descriptor_write;
16390 memset(&descriptor_write, 0, sizeof(descriptor_write));
16391 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16392 descriptor_write.dstSet = descriptor_set;
16393 descriptor_write.dstBinding = 0;
16394 descriptor_write.descriptorCount = 1;
16395 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16396 descriptor_write.pImageInfo = &image_info;
16397
16398 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16399 // be
16400 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16401 // This will most likely produce a crash if the parameter_validation
16402 // layer
16403 // does not correctly ignore pBufferInfo.
16404 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16405 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16406
16407 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16408
16409 m_errorMonitor->VerifyNotFound();
16410
16411 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16412 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16413 vkDestroyImageView(m_device->device(), view, NULL);
16414 vkDestroyImage(m_device->device(), image, NULL);
16415 vkFreeMemory(m_device->device(), image_memory, NULL);
16416 }
16417
16418 // Buffer Case
16419 {
16420 m_errorMonitor->ExpectSuccess();
16421
16422 VkBuffer buffer;
16423 uint32_t queue_family_index = 0;
16424 VkBufferCreateInfo buffer_create_info = {};
16425 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16426 buffer_create_info.size = 1024;
16427 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16428 buffer_create_info.queueFamilyIndexCount = 1;
16429 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16430
16431 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16432 ASSERT_VK_SUCCESS(err);
16433
16434 VkMemoryRequirements memory_reqs;
16435 VkDeviceMemory buffer_memory;
16436 bool pass;
16437 VkMemoryAllocateInfo memory_info = {};
16438 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16439 memory_info.pNext = NULL;
16440 memory_info.allocationSize = 0;
16441 memory_info.memoryTypeIndex = 0;
16442
16443 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16444 memory_info.allocationSize = memory_reqs.size;
16445 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16446 ASSERT_TRUE(pass);
16447
16448 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16449 ASSERT_VK_SUCCESS(err);
16450 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16451 ASSERT_VK_SUCCESS(err);
16452
16453 VkDescriptorPoolSize ds_type_count = {};
16454 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16455 ds_type_count.descriptorCount = 1;
16456
16457 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16458 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16459 ds_pool_ci.pNext = NULL;
16460 ds_pool_ci.maxSets = 1;
16461 ds_pool_ci.poolSizeCount = 1;
16462 ds_pool_ci.pPoolSizes = &ds_type_count;
16463
16464 VkDescriptorPool ds_pool;
16465 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16466 ASSERT_VK_SUCCESS(err);
16467
16468 VkDescriptorSetLayoutBinding dsl_binding = {};
16469 dsl_binding.binding = 0;
16470 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16471 dsl_binding.descriptorCount = 1;
16472 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16473 dsl_binding.pImmutableSamplers = NULL;
16474
16475 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16476 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16477 ds_layout_ci.pNext = NULL;
16478 ds_layout_ci.bindingCount = 1;
16479 ds_layout_ci.pBindings = &dsl_binding;
16480 VkDescriptorSetLayout ds_layout;
16481 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16482 ASSERT_VK_SUCCESS(err);
16483
16484 VkDescriptorSet descriptor_set;
16485 VkDescriptorSetAllocateInfo alloc_info = {};
16486 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16487 alloc_info.descriptorSetCount = 1;
16488 alloc_info.descriptorPool = ds_pool;
16489 alloc_info.pSetLayouts = &ds_layout;
16490 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16491 ASSERT_VK_SUCCESS(err);
16492
16493 VkDescriptorBufferInfo buffer_info = {};
16494 buffer_info.buffer = buffer;
16495 buffer_info.offset = 0;
16496 buffer_info.range = 1024;
16497
16498 VkWriteDescriptorSet descriptor_write;
16499 memset(&descriptor_write, 0, sizeof(descriptor_write));
16500 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16501 descriptor_write.dstSet = descriptor_set;
16502 descriptor_write.dstBinding = 0;
16503 descriptor_write.descriptorCount = 1;
16504 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16505 descriptor_write.pBufferInfo = &buffer_info;
16506
16507 // Set pImageInfo and pTexelBufferView to invalid values, which should
16508 // be
16509 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16510 // This will most likely produce a crash if the parameter_validation
16511 // layer
16512 // does not correctly ignore pImageInfo.
16513 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16514 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16515
16516 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16517
16518 m_errorMonitor->VerifyNotFound();
16519
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016520 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16521 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16522 vkDestroyBuffer(m_device->device(), buffer, NULL);
16523 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16524 }
16525
16526 // Texel Buffer Case
16527 {
16528 m_errorMonitor->ExpectSuccess();
16529
16530 VkBuffer buffer;
16531 uint32_t queue_family_index = 0;
16532 VkBufferCreateInfo buffer_create_info = {};
16533 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16534 buffer_create_info.size = 1024;
16535 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16536 buffer_create_info.queueFamilyIndexCount = 1;
16537 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16538
16539 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16540 ASSERT_VK_SUCCESS(err);
16541
16542 VkMemoryRequirements memory_reqs;
16543 VkDeviceMemory buffer_memory;
16544 bool pass;
16545 VkMemoryAllocateInfo memory_info = {};
16546 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16547 memory_info.pNext = NULL;
16548 memory_info.allocationSize = 0;
16549 memory_info.memoryTypeIndex = 0;
16550
16551 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16552 memory_info.allocationSize = memory_reqs.size;
16553 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16554 ASSERT_TRUE(pass);
16555
16556 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16557 ASSERT_VK_SUCCESS(err);
16558 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16559 ASSERT_VK_SUCCESS(err);
16560
16561 VkBufferViewCreateInfo buff_view_ci = {};
16562 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16563 buff_view_ci.buffer = buffer;
16564 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16565 buff_view_ci.range = VK_WHOLE_SIZE;
16566 VkBufferView buffer_view;
16567 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16568
16569 VkDescriptorPoolSize ds_type_count = {};
16570 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16571 ds_type_count.descriptorCount = 1;
16572
16573 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16574 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16575 ds_pool_ci.pNext = NULL;
16576 ds_pool_ci.maxSets = 1;
16577 ds_pool_ci.poolSizeCount = 1;
16578 ds_pool_ci.pPoolSizes = &ds_type_count;
16579
16580 VkDescriptorPool ds_pool;
16581 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16582 ASSERT_VK_SUCCESS(err);
16583
16584 VkDescriptorSetLayoutBinding dsl_binding = {};
16585 dsl_binding.binding = 0;
16586 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16587 dsl_binding.descriptorCount = 1;
16588 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16589 dsl_binding.pImmutableSamplers = NULL;
16590
16591 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16592 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16593 ds_layout_ci.pNext = NULL;
16594 ds_layout_ci.bindingCount = 1;
16595 ds_layout_ci.pBindings = &dsl_binding;
16596 VkDescriptorSetLayout ds_layout;
16597 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16598 ASSERT_VK_SUCCESS(err);
16599
16600 VkDescriptorSet descriptor_set;
16601 VkDescriptorSetAllocateInfo alloc_info = {};
16602 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16603 alloc_info.descriptorSetCount = 1;
16604 alloc_info.descriptorPool = ds_pool;
16605 alloc_info.pSetLayouts = &ds_layout;
16606 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16607 ASSERT_VK_SUCCESS(err);
16608
16609 VkWriteDescriptorSet descriptor_write;
16610 memset(&descriptor_write, 0, sizeof(descriptor_write));
16611 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16612 descriptor_write.dstSet = descriptor_set;
16613 descriptor_write.dstBinding = 0;
16614 descriptor_write.descriptorCount = 1;
16615 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16616 descriptor_write.pTexelBufferView = &buffer_view;
16617
16618 // Set pImageInfo and pBufferInfo to invalid values, which should be
16619 // ignored for descriptorType ==
16620 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16621 // This will most likely produce a crash if the parameter_validation
16622 // layer
16623 // does not correctly ignore pImageInfo and pBufferInfo.
16624 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16625 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16626
16627 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16628
16629 m_errorMonitor->VerifyNotFound();
16630
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016631 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16632 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16633 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16634 vkDestroyBuffer(m_device->device(), buffer, NULL);
16635 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16636 }
16637}
16638
Tobin Ehlisf7428442016-10-25 07:58:24 -060016639TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16640 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16641
16642 ASSERT_NO_FATAL_FAILURE(InitState());
16643 // Create layout where two binding #s are "1"
16644 static const uint32_t NUM_BINDINGS = 3;
16645 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16646 dsl_binding[0].binding = 1;
16647 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16648 dsl_binding[0].descriptorCount = 1;
16649 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16650 dsl_binding[0].pImmutableSamplers = NULL;
16651 dsl_binding[1].binding = 0;
16652 dsl_binding[1].descriptorCount = 1;
16653 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16654 dsl_binding[1].descriptorCount = 1;
16655 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16656 dsl_binding[1].pImmutableSamplers = NULL;
16657 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16658 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16659 dsl_binding[2].descriptorCount = 1;
16660 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16661 dsl_binding[2].pImmutableSamplers = NULL;
16662
16663 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16664 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16665 ds_layout_ci.pNext = NULL;
16666 ds_layout_ci.bindingCount = NUM_BINDINGS;
16667 ds_layout_ci.pBindings = dsl_binding;
16668 VkDescriptorSetLayout ds_layout;
16669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16670 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16671 m_errorMonitor->VerifyFound();
16672}
16673
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016674TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016675 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16676
16677 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016678
Tony Barbour552f6c02016-12-21 14:34:07 -070016679 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016680
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016681 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16682
16683 {
16684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16685 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16686 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16687 m_errorMonitor->VerifyFound();
16688 }
16689
16690 {
16691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16692 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16693 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16694 m_errorMonitor->VerifyFound();
16695 }
16696
16697 {
16698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16699 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16700 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16701 m_errorMonitor->VerifyFound();
16702 }
16703
16704 {
16705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16706 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16707 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16708 m_errorMonitor->VerifyFound();
16709 }
16710
16711 {
16712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16713 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16714 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16715 m_errorMonitor->VerifyFound();
16716 }
16717
16718 {
16719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16720 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16721 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16722 m_errorMonitor->VerifyFound();
16723 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016724
16725 {
16726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16727 VkRect2D scissor = {{-1, 0}, {16, 16}};
16728 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16729 m_errorMonitor->VerifyFound();
16730 }
16731
16732 {
16733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16734 VkRect2D scissor = {{0, -2}, {16, 16}};
16735 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16736 m_errorMonitor->VerifyFound();
16737 }
16738
16739 {
16740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16741 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16742 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16743 m_errorMonitor->VerifyFound();
16744 }
16745
16746 {
16747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16748 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16749 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16750 m_errorMonitor->VerifyFound();
16751 }
16752
Tony Barbour552f6c02016-12-21 14:34:07 -070016753 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016754}
16755
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016756// This is a positive test. No failures are expected.
16757TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16758 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16759 VkResult err;
16760
16761 ASSERT_NO_FATAL_FAILURE(InitState());
16762 m_errorMonitor->ExpectSuccess();
16763 VkDescriptorPoolSize ds_type_count = {};
16764 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16765 ds_type_count.descriptorCount = 2;
16766
16767 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16768 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16769 ds_pool_ci.pNext = NULL;
16770 ds_pool_ci.maxSets = 1;
16771 ds_pool_ci.poolSizeCount = 1;
16772 ds_pool_ci.pPoolSizes = &ds_type_count;
16773
16774 VkDescriptorPool ds_pool;
16775 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16776 ASSERT_VK_SUCCESS(err);
16777
16778 // Create layout with two uniform buffer descriptors w/ empty binding between them
16779 static const uint32_t NUM_BINDINGS = 3;
16780 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16781 dsl_binding[0].binding = 0;
16782 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16783 dsl_binding[0].descriptorCount = 1;
16784 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16785 dsl_binding[0].pImmutableSamplers = NULL;
16786 dsl_binding[1].binding = 1;
16787 dsl_binding[1].descriptorCount = 0; // empty binding
16788 dsl_binding[2].binding = 2;
16789 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16790 dsl_binding[2].descriptorCount = 1;
16791 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16792 dsl_binding[2].pImmutableSamplers = NULL;
16793
16794 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16795 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16796 ds_layout_ci.pNext = NULL;
16797 ds_layout_ci.bindingCount = NUM_BINDINGS;
16798 ds_layout_ci.pBindings = dsl_binding;
16799 VkDescriptorSetLayout ds_layout;
16800 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16801 ASSERT_VK_SUCCESS(err);
16802
16803 VkDescriptorSet descriptor_set = {};
16804 VkDescriptorSetAllocateInfo alloc_info = {};
16805 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16806 alloc_info.descriptorSetCount = 1;
16807 alloc_info.descriptorPool = ds_pool;
16808 alloc_info.pSetLayouts = &ds_layout;
16809 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16810 ASSERT_VK_SUCCESS(err);
16811
16812 // Create a buffer to be used for update
16813 VkBufferCreateInfo buff_ci = {};
16814 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16815 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16816 buff_ci.size = 256;
16817 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16818 VkBuffer buffer;
16819 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16820 ASSERT_VK_SUCCESS(err);
16821 // Have to bind memory to buffer before descriptor update
16822 VkMemoryAllocateInfo mem_alloc = {};
16823 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16824 mem_alloc.pNext = NULL;
16825 mem_alloc.allocationSize = 512; // one allocation for both buffers
16826 mem_alloc.memoryTypeIndex = 0;
16827
16828 VkMemoryRequirements mem_reqs;
16829 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16830 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16831 if (!pass) {
16832 vkDestroyBuffer(m_device->device(), buffer, NULL);
16833 return;
16834 }
16835
16836 VkDeviceMemory mem;
16837 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16838 ASSERT_VK_SUCCESS(err);
16839 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16840 ASSERT_VK_SUCCESS(err);
16841
16842 // Only update the descriptor at binding 2
16843 VkDescriptorBufferInfo buff_info = {};
16844 buff_info.buffer = buffer;
16845 buff_info.offset = 0;
16846 buff_info.range = VK_WHOLE_SIZE;
16847 VkWriteDescriptorSet descriptor_write = {};
16848 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16849 descriptor_write.dstBinding = 2;
16850 descriptor_write.descriptorCount = 1;
16851 descriptor_write.pTexelBufferView = nullptr;
16852 descriptor_write.pBufferInfo = &buff_info;
16853 descriptor_write.pImageInfo = nullptr;
16854 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16855 descriptor_write.dstSet = descriptor_set;
16856
16857 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16858
16859 m_errorMonitor->VerifyNotFound();
16860 // Cleanup
16861 vkFreeMemory(m_device->device(), mem, NULL);
16862 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16863 vkDestroyBuffer(m_device->device(), buffer, NULL);
16864 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16865}
16866
16867// This is a positive test. No failures are expected.
16868TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16869 VkResult err;
16870 bool pass;
16871
16872 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16873 "the buffer, create an image, and bind the same memory to "
16874 "it");
16875
16876 m_errorMonitor->ExpectSuccess();
16877
16878 ASSERT_NO_FATAL_FAILURE(InitState());
16879
16880 VkBuffer buffer;
16881 VkImage image;
16882 VkDeviceMemory mem;
16883 VkMemoryRequirements mem_reqs;
16884
16885 VkBufferCreateInfo buf_info = {};
16886 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16887 buf_info.pNext = NULL;
16888 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16889 buf_info.size = 256;
16890 buf_info.queueFamilyIndexCount = 0;
16891 buf_info.pQueueFamilyIndices = NULL;
16892 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16893 buf_info.flags = 0;
16894 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16895 ASSERT_VK_SUCCESS(err);
16896
16897 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16898
16899 VkMemoryAllocateInfo alloc_info = {};
16900 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16901 alloc_info.pNext = NULL;
16902 alloc_info.memoryTypeIndex = 0;
16903
16904 // Ensure memory is big enough for both bindings
16905 alloc_info.allocationSize = 0x10000;
16906
16907 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16908 if (!pass) {
16909 vkDestroyBuffer(m_device->device(), buffer, NULL);
16910 return;
16911 }
16912
16913 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16914 ASSERT_VK_SUCCESS(err);
16915
16916 uint8_t *pData;
16917 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16918 ASSERT_VK_SUCCESS(err);
16919
16920 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16921
16922 vkUnmapMemory(m_device->device(), mem);
16923
16924 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16925 ASSERT_VK_SUCCESS(err);
16926
16927 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16928 // memory. In fact, it was never used by the GPU.
16929 // Just be be sure, wait for idle.
16930 vkDestroyBuffer(m_device->device(), buffer, NULL);
16931 vkDeviceWaitIdle(m_device->device());
16932
Tobin Ehlis6a005702016-12-28 15:25:56 -070016933 // Use optimal as some platforms report linear support but then fail image creation
16934 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
16935 VkImageFormatProperties image_format_properties;
16936 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
16937 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
16938 if (image_format_properties.maxExtent.width == 0) {
16939 printf("Image format not supported; skipped.\n");
16940 vkFreeMemory(m_device->device(), mem, NULL);
16941 return;
16942 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016943 VkImageCreateInfo image_create_info = {};
16944 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16945 image_create_info.pNext = NULL;
16946 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16947 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16948 image_create_info.extent.width = 64;
16949 image_create_info.extent.height = 64;
16950 image_create_info.extent.depth = 1;
16951 image_create_info.mipLevels = 1;
16952 image_create_info.arrayLayers = 1;
16953 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070016954 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016955 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16956 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16957 image_create_info.queueFamilyIndexCount = 0;
16958 image_create_info.pQueueFamilyIndices = NULL;
16959 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16960 image_create_info.flags = 0;
16961
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016962 /* Create a mappable image. It will be the texture if linear images are ok
16963 * to be textures or it will be the staging image if they are not.
16964 */
16965 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16966 ASSERT_VK_SUCCESS(err);
16967
16968 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16969
Tobin Ehlis6a005702016-12-28 15:25:56 -070016970 VkMemoryAllocateInfo mem_alloc = {};
16971 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16972 mem_alloc.pNext = NULL;
16973 mem_alloc.allocationSize = 0;
16974 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016975 mem_alloc.allocationSize = mem_reqs.size;
16976
16977 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16978 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070016979 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016980 vkDestroyImage(m_device->device(), image, NULL);
16981 return;
16982 }
16983
16984 // VALIDATION FAILURE:
16985 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16986 ASSERT_VK_SUCCESS(err);
16987
16988 m_errorMonitor->VerifyNotFound();
16989
16990 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016991 vkDestroyImage(m_device->device(), image, NULL);
16992}
16993
Tobin Ehlis953e8392016-11-17 10:54:13 -070016994TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16995 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16996 // We previously had a bug where dynamic offset of inactive bindings was still being used
16997 VkResult err;
16998 m_errorMonitor->ExpectSuccess();
16999
17000 ASSERT_NO_FATAL_FAILURE(InitState());
17001 ASSERT_NO_FATAL_FAILURE(InitViewport());
17002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17003
17004 VkDescriptorPoolSize ds_type_count = {};
17005 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17006 ds_type_count.descriptorCount = 3;
17007
17008 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17009 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17010 ds_pool_ci.pNext = NULL;
17011 ds_pool_ci.maxSets = 1;
17012 ds_pool_ci.poolSizeCount = 1;
17013 ds_pool_ci.pPoolSizes = &ds_type_count;
17014
17015 VkDescriptorPool ds_pool;
17016 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17017 ASSERT_VK_SUCCESS(err);
17018
17019 const uint32_t BINDING_COUNT = 3;
17020 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017021 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017022 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17023 dsl_binding[0].descriptorCount = 1;
17024 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17025 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017026 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017027 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17028 dsl_binding[1].descriptorCount = 1;
17029 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17030 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017031 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017032 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17033 dsl_binding[2].descriptorCount = 1;
17034 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17035 dsl_binding[2].pImmutableSamplers = NULL;
17036
17037 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17038 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17039 ds_layout_ci.pNext = NULL;
17040 ds_layout_ci.bindingCount = BINDING_COUNT;
17041 ds_layout_ci.pBindings = dsl_binding;
17042 VkDescriptorSetLayout ds_layout;
17043 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17044 ASSERT_VK_SUCCESS(err);
17045
17046 VkDescriptorSet descriptor_set;
17047 VkDescriptorSetAllocateInfo alloc_info = {};
17048 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17049 alloc_info.descriptorSetCount = 1;
17050 alloc_info.descriptorPool = ds_pool;
17051 alloc_info.pSetLayouts = &ds_layout;
17052 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17053 ASSERT_VK_SUCCESS(err);
17054
17055 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17056 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17057 pipeline_layout_ci.pNext = NULL;
17058 pipeline_layout_ci.setLayoutCount = 1;
17059 pipeline_layout_ci.pSetLayouts = &ds_layout;
17060
17061 VkPipelineLayout pipeline_layout;
17062 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17063 ASSERT_VK_SUCCESS(err);
17064
17065 // Create two buffers to update the descriptors with
17066 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17067 uint32_t qfi = 0;
17068 VkBufferCreateInfo buffCI = {};
17069 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17070 buffCI.size = 2048;
17071 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17072 buffCI.queueFamilyIndexCount = 1;
17073 buffCI.pQueueFamilyIndices = &qfi;
17074
17075 VkBuffer dyub1;
17076 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17077 ASSERT_VK_SUCCESS(err);
17078 // buffer2
17079 buffCI.size = 1024;
17080 VkBuffer dyub2;
17081 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17082 ASSERT_VK_SUCCESS(err);
17083 // Allocate memory and bind to buffers
17084 VkMemoryAllocateInfo mem_alloc[2] = {};
17085 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17086 mem_alloc[0].pNext = NULL;
17087 mem_alloc[0].memoryTypeIndex = 0;
17088 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17089 mem_alloc[1].pNext = NULL;
17090 mem_alloc[1].memoryTypeIndex = 0;
17091
17092 VkMemoryRequirements mem_reqs1;
17093 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17094 VkMemoryRequirements mem_reqs2;
17095 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17096 mem_alloc[0].allocationSize = mem_reqs1.size;
17097 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17098 mem_alloc[1].allocationSize = mem_reqs2.size;
17099 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17100 if (!pass) {
17101 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17102 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17103 return;
17104 }
17105
17106 VkDeviceMemory mem1;
17107 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17108 ASSERT_VK_SUCCESS(err);
17109 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17110 ASSERT_VK_SUCCESS(err);
17111 VkDeviceMemory mem2;
17112 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17113 ASSERT_VK_SUCCESS(err);
17114 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17115 ASSERT_VK_SUCCESS(err);
17116 // Update descriptors
17117 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17118 buff_info[0].buffer = dyub1;
17119 buff_info[0].offset = 0;
17120 buff_info[0].range = 256;
17121 buff_info[1].buffer = dyub1;
17122 buff_info[1].offset = 256;
17123 buff_info[1].range = 512;
17124 buff_info[2].buffer = dyub2;
17125 buff_info[2].offset = 0;
17126 buff_info[2].range = 512;
17127
17128 VkWriteDescriptorSet descriptor_write;
17129 memset(&descriptor_write, 0, sizeof(descriptor_write));
17130 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17131 descriptor_write.dstSet = descriptor_set;
17132 descriptor_write.dstBinding = 0;
17133 descriptor_write.descriptorCount = BINDING_COUNT;
17134 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17135 descriptor_write.pBufferInfo = buff_info;
17136
17137 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17138
Tony Barbour552f6c02016-12-21 14:34:07 -070017139 m_commandBuffer->BeginCommandBuffer();
17140 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017141
17142 // Create PSO to be used for draw-time errors below
17143 char const *vsSource = "#version 450\n"
17144 "\n"
17145 "out gl_PerVertex { \n"
17146 " vec4 gl_Position;\n"
17147 "};\n"
17148 "void main(){\n"
17149 " gl_Position = vec4(1);\n"
17150 "}\n";
17151 char const *fsSource = "#version 450\n"
17152 "\n"
17153 "layout(location=0) out vec4 x;\n"
17154 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17155 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17156 "void main(){\n"
17157 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17158 "}\n";
17159 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17160 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17161 VkPipelineObj pipe(m_device);
17162 pipe.SetViewport(m_viewports);
17163 pipe.SetScissor(m_scissors);
17164 pipe.AddShader(&vs);
17165 pipe.AddShader(&fs);
17166 pipe.AddColorAttachment();
17167 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17168
17169 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17170 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17171 // we used to have a bug in this case.
17172 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17173 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17174 &descriptor_set, BINDING_COUNT, dyn_off);
17175 Draw(1, 0, 0, 0);
17176 m_errorMonitor->VerifyNotFound();
17177
17178 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17179 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17180 vkFreeMemory(m_device->device(), mem1, NULL);
17181 vkFreeMemory(m_device->device(), mem2, NULL);
17182
17183 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17184 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17185 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17186}
17187
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017188TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17189
17190 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17191 "mapping while using VK_WHOLE_SIZE does not cause access "
17192 "violations");
17193 VkResult err;
17194 uint8_t *pData;
17195 ASSERT_NO_FATAL_FAILURE(InitState());
17196
17197 VkDeviceMemory mem;
17198 VkMemoryRequirements mem_reqs;
17199 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017200 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017201 VkMemoryAllocateInfo alloc_info = {};
17202 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17203 alloc_info.pNext = NULL;
17204 alloc_info.memoryTypeIndex = 0;
17205
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017206 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017207 alloc_info.allocationSize = allocation_size;
17208
17209 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17210 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17211 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17212 if (!pass) {
17213 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17214 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17215 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17216 if (!pass) {
17217 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17218 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17219 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17220 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17221 if (!pass) {
17222 return;
17223 }
17224 }
17225 }
17226
17227 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17228 ASSERT_VK_SUCCESS(err);
17229
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017230 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017231 m_errorMonitor->ExpectSuccess();
17232 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17233 ASSERT_VK_SUCCESS(err);
17234 VkMappedMemoryRange mmr = {};
17235 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17236 mmr.memory = mem;
17237 mmr.offset = 0;
17238 mmr.size = VK_WHOLE_SIZE;
17239 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
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017246 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017247 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017248 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017249 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 = 6 * 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);
17256 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17257 ASSERT_VK_SUCCESS(err);
17258 m_errorMonitor->VerifyNotFound();
17259 vkUnmapMemory(m_device->device(), mem);
17260
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017261 // Map with offset and size
17262 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017263 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017264 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017265 ASSERT_VK_SUCCESS(err);
17266 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17267 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017268 mmr.offset = 4 * atom_size;
17269 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017270 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17271 ASSERT_VK_SUCCESS(err);
17272 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17273 ASSERT_VK_SUCCESS(err);
17274 m_errorMonitor->VerifyNotFound();
17275 vkUnmapMemory(m_device->device(), mem);
17276
17277 // Map without offset and flush WHOLE_SIZE with two separate offsets
17278 m_errorMonitor->ExpectSuccess();
17279 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17280 ASSERT_VK_SUCCESS(err);
17281 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17282 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017283 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017284 mmr.size = VK_WHOLE_SIZE;
17285 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17286 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017287 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017288 mmr.size = VK_WHOLE_SIZE;
17289 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17290 ASSERT_VK_SUCCESS(err);
17291 m_errorMonitor->VerifyNotFound();
17292 vkUnmapMemory(m_device->device(), mem);
17293
17294 vkFreeMemory(m_device->device(), mem, NULL);
17295}
17296
17297// This is a positive test. We used to expect error in this case but spec now allows it
17298TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17299 m_errorMonitor->ExpectSuccess();
17300 vk_testing::Fence testFence;
17301 VkFenceCreateInfo fenceInfo = {};
17302 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17303 fenceInfo.pNext = NULL;
17304
17305 ASSERT_NO_FATAL_FAILURE(InitState());
17306 testFence.init(*m_device, fenceInfo);
17307 VkFence fences[1] = { testFence.handle() };
17308 VkResult result = vkResetFences(m_device->device(), 1, fences);
17309 ASSERT_VK_SUCCESS(result);
17310
17311 m_errorMonitor->VerifyNotFound();
17312}
17313
17314TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17315 m_errorMonitor->ExpectSuccess();
17316
17317 ASSERT_NO_FATAL_FAILURE(InitState());
17318 VkResult err;
17319
17320 // Record (empty!) command buffer that can be submitted multiple times
17321 // simultaneously.
17322 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17323 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17324 m_commandBuffer->BeginCommandBuffer(&cbbi);
17325 m_commandBuffer->EndCommandBuffer();
17326
17327 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17328 VkFence fence;
17329 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17330 ASSERT_VK_SUCCESS(err);
17331
17332 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17333 VkSemaphore s1, s2;
17334 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17335 ASSERT_VK_SUCCESS(err);
17336 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17337 ASSERT_VK_SUCCESS(err);
17338
17339 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17340 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17341 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17342 ASSERT_VK_SUCCESS(err);
17343
17344 // Submit CB again, signaling s2.
17345 si.pSignalSemaphores = &s2;
17346 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17347 ASSERT_VK_SUCCESS(err);
17348
17349 // Wait for fence.
17350 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17351 ASSERT_VK_SUCCESS(err);
17352
17353 // CB is still in flight from second submission, but semaphore s1 is no
17354 // longer in flight. delete it.
17355 vkDestroySemaphore(m_device->device(), s1, nullptr);
17356
17357 m_errorMonitor->VerifyNotFound();
17358
17359 // Force device idle and clean up remaining objects
17360 vkDeviceWaitIdle(m_device->device());
17361 vkDestroySemaphore(m_device->device(), s2, nullptr);
17362 vkDestroyFence(m_device->device(), fence, nullptr);
17363}
17364
17365TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17366 m_errorMonitor->ExpectSuccess();
17367
17368 ASSERT_NO_FATAL_FAILURE(InitState());
17369 VkResult err;
17370
17371 // A fence created signaled
17372 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17373 VkFence f1;
17374 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17375 ASSERT_VK_SUCCESS(err);
17376
17377 // A fence created not
17378 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17379 VkFence f2;
17380 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17381 ASSERT_VK_SUCCESS(err);
17382
17383 // Submit the unsignaled fence
17384 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17385 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17386
17387 // Wait on both fences, with signaled first.
17388 VkFence fences[] = { f1, f2 };
17389 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17390
17391 // Should have both retired!
17392 vkDestroyFence(m_device->device(), f1, nullptr);
17393 vkDestroyFence(m_device->device(), f2, nullptr);
17394
17395 m_errorMonitor->VerifyNotFound();
17396}
17397
17398TEST_F(VkPositiveLayerTest, ValidUsage) {
17399 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17400 "doesn't generate validation errors");
17401
17402 ASSERT_NO_FATAL_FAILURE(InitState());
17403
17404 m_errorMonitor->ExpectSuccess();
17405 // Verify that we can create a view with usage INPUT_ATTACHMENT
17406 VkImageObj image(m_device);
17407 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17408 ASSERT_TRUE(image.initialized());
17409 VkImageView imageView;
17410 VkImageViewCreateInfo ivci = {};
17411 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17412 ivci.image = image.handle();
17413 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17414 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17415 ivci.subresourceRange.layerCount = 1;
17416 ivci.subresourceRange.baseMipLevel = 0;
17417 ivci.subresourceRange.levelCount = 1;
17418 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17419
17420 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17421 m_errorMonitor->VerifyNotFound();
17422 vkDestroyImageView(m_device->device(), imageView, NULL);
17423}
17424
17425// This is a positive test. No failures are expected.
17426TEST_F(VkPositiveLayerTest, BindSparse) {
17427 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17428 "and then free the memory");
17429
17430 ASSERT_NO_FATAL_FAILURE(InitState());
17431
17432 auto index = m_device->graphics_queue_node_index_;
17433 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17434 return;
17435
17436 m_errorMonitor->ExpectSuccess();
17437
17438 VkImage image;
17439 VkImageCreateInfo image_create_info = {};
17440 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17441 image_create_info.pNext = NULL;
17442 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17443 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17444 image_create_info.extent.width = 64;
17445 image_create_info.extent.height = 64;
17446 image_create_info.extent.depth = 1;
17447 image_create_info.mipLevels = 1;
17448 image_create_info.arrayLayers = 1;
17449 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17450 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17451 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17452 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17453 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17454 ASSERT_VK_SUCCESS(err);
17455
17456 VkMemoryRequirements memory_reqs;
17457 VkDeviceMemory memory_one, memory_two;
17458 bool pass;
17459 VkMemoryAllocateInfo memory_info = {};
17460 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17461 memory_info.pNext = NULL;
17462 memory_info.allocationSize = 0;
17463 memory_info.memoryTypeIndex = 0;
17464 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17465 // Find an image big enough to allow sparse mapping of 2 memory regions
17466 // Increase the image size until it is at least twice the
17467 // size of the required alignment, to ensure we can bind both
17468 // allocated memory blocks to the image on aligned offsets.
17469 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17470 vkDestroyImage(m_device->device(), image, nullptr);
17471 image_create_info.extent.width *= 2;
17472 image_create_info.extent.height *= 2;
17473 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17474 ASSERT_VK_SUCCESS(err);
17475 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17476 }
17477 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17478 // at the end of the first
17479 memory_info.allocationSize = memory_reqs.alignment;
17480 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17481 ASSERT_TRUE(pass);
17482 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17483 ASSERT_VK_SUCCESS(err);
17484 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17485 ASSERT_VK_SUCCESS(err);
17486 VkSparseMemoryBind binds[2];
17487 binds[0].flags = 0;
17488 binds[0].memory = memory_one;
17489 binds[0].memoryOffset = 0;
17490 binds[0].resourceOffset = 0;
17491 binds[0].size = memory_info.allocationSize;
17492 binds[1].flags = 0;
17493 binds[1].memory = memory_two;
17494 binds[1].memoryOffset = 0;
17495 binds[1].resourceOffset = memory_info.allocationSize;
17496 binds[1].size = memory_info.allocationSize;
17497
17498 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17499 opaqueBindInfo.image = image;
17500 opaqueBindInfo.bindCount = 2;
17501 opaqueBindInfo.pBinds = binds;
17502
17503 VkFence fence = VK_NULL_HANDLE;
17504 VkBindSparseInfo bindSparseInfo = {};
17505 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17506 bindSparseInfo.imageOpaqueBindCount = 1;
17507 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17508
17509 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17510 vkQueueWaitIdle(m_device->m_queue);
17511 vkDestroyImage(m_device->device(), image, NULL);
17512 vkFreeMemory(m_device->device(), memory_one, NULL);
17513 vkFreeMemory(m_device->device(), memory_two, NULL);
17514 m_errorMonitor->VerifyNotFound();
17515}
17516
17517TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17518 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17519 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17520 "the command buffer has prior knowledge of that "
17521 "attachment's layout.");
17522
17523 m_errorMonitor->ExpectSuccess();
17524
17525 ASSERT_NO_FATAL_FAILURE(InitState());
17526
17527 // A renderpass with one color attachment.
17528 VkAttachmentDescription attachment = { 0,
17529 VK_FORMAT_R8G8B8A8_UNORM,
17530 VK_SAMPLE_COUNT_1_BIT,
17531 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17532 VK_ATTACHMENT_STORE_OP_STORE,
17533 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17534 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17535 VK_IMAGE_LAYOUT_UNDEFINED,
17536 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17537
17538 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17539
17540 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17541
17542 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17543
17544 VkRenderPass rp;
17545 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17546 ASSERT_VK_SUCCESS(err);
17547
17548 // A compatible framebuffer.
17549 VkImageObj image(m_device);
17550 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17551 ASSERT_TRUE(image.initialized());
17552
17553 VkImageViewCreateInfo ivci = {
17554 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17555 nullptr,
17556 0,
17557 image.handle(),
17558 VK_IMAGE_VIEW_TYPE_2D,
17559 VK_FORMAT_R8G8B8A8_UNORM,
17560 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17561 VK_COMPONENT_SWIZZLE_IDENTITY },
17562 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17563 };
17564 VkImageView view;
17565 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17566 ASSERT_VK_SUCCESS(err);
17567
17568 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17569 VkFramebuffer fb;
17570 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17571 ASSERT_VK_SUCCESS(err);
17572
17573 // Record a single command buffer which uses this renderpass twice. The
17574 // bug is triggered at the beginning of the second renderpass, when the
17575 // command buffer already has a layout recorded for the attachment.
17576 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 -070017577 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017578 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17579 vkCmdEndRenderPass(m_commandBuffer->handle());
17580 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17581
17582 m_errorMonitor->VerifyNotFound();
17583
17584 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017585 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017586
17587 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17588 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17589 vkDestroyImageView(m_device->device(), view, nullptr);
17590}
17591
17592TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17593 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17594 "command buffer, bind them together, then destroy "
17595 "command pool and framebuffer and verify there are no "
17596 "errors.");
17597
17598 m_errorMonitor->ExpectSuccess();
17599
17600 ASSERT_NO_FATAL_FAILURE(InitState());
17601
17602 // A renderpass with one color attachment.
17603 VkAttachmentDescription attachment = { 0,
17604 VK_FORMAT_R8G8B8A8_UNORM,
17605 VK_SAMPLE_COUNT_1_BIT,
17606 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17607 VK_ATTACHMENT_STORE_OP_STORE,
17608 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17609 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17610 VK_IMAGE_LAYOUT_UNDEFINED,
17611 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17612
17613 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17614
17615 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17616
17617 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17618
17619 VkRenderPass rp;
17620 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17621 ASSERT_VK_SUCCESS(err);
17622
17623 // A compatible framebuffer.
17624 VkImageObj image(m_device);
17625 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17626 ASSERT_TRUE(image.initialized());
17627
17628 VkImageViewCreateInfo ivci = {
17629 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17630 nullptr,
17631 0,
17632 image.handle(),
17633 VK_IMAGE_VIEW_TYPE_2D,
17634 VK_FORMAT_R8G8B8A8_UNORM,
17635 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17636 VK_COMPONENT_SWIZZLE_IDENTITY },
17637 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17638 };
17639 VkImageView view;
17640 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17641 ASSERT_VK_SUCCESS(err);
17642
17643 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17644 VkFramebuffer fb;
17645 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17646 ASSERT_VK_SUCCESS(err);
17647
17648 // Explicitly create a command buffer to bind the FB to so that we can then
17649 // destroy the command pool in order to implicitly free command buffer
17650 VkCommandPool command_pool;
17651 VkCommandPoolCreateInfo pool_create_info{};
17652 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17653 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17654 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17655 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17656
17657 VkCommandBuffer command_buffer;
17658 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17659 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17660 command_buffer_allocate_info.commandPool = command_pool;
17661 command_buffer_allocate_info.commandBufferCount = 1;
17662 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17663 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17664
17665 // Begin our cmd buffer with renderpass using our framebuffer
17666 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17667 VkCommandBufferBeginInfo begin_info{};
17668 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17669 vkBeginCommandBuffer(command_buffer, &begin_info);
17670
17671 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17672 vkCmdEndRenderPass(command_buffer);
17673 vkEndCommandBuffer(command_buffer);
17674 vkDestroyImageView(m_device->device(), view, nullptr);
17675 // Destroy command pool to implicitly free command buffer
17676 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17677 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17678 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17679 m_errorMonitor->VerifyNotFound();
17680}
17681
17682TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17683 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17684 "transitions for the first subpass");
17685
17686 m_errorMonitor->ExpectSuccess();
17687
17688 ASSERT_NO_FATAL_FAILURE(InitState());
17689
17690 // A renderpass with one color attachment.
17691 VkAttachmentDescription attachment = { 0,
17692 VK_FORMAT_R8G8B8A8_UNORM,
17693 VK_SAMPLE_COUNT_1_BIT,
17694 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17695 VK_ATTACHMENT_STORE_OP_STORE,
17696 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17697 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17698 VK_IMAGE_LAYOUT_UNDEFINED,
17699 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17700
17701 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17702
17703 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17704
17705 VkSubpassDependency dep = { 0,
17706 0,
17707 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17708 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17709 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17710 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17711 VK_DEPENDENCY_BY_REGION_BIT };
17712
17713 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17714
17715 VkResult err;
17716 VkRenderPass rp;
17717 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17718 ASSERT_VK_SUCCESS(err);
17719
17720 // A compatible framebuffer.
17721 VkImageObj image(m_device);
17722 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17723 ASSERT_TRUE(image.initialized());
17724
17725 VkImageViewCreateInfo ivci = {
17726 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17727 nullptr,
17728 0,
17729 image.handle(),
17730 VK_IMAGE_VIEW_TYPE_2D,
17731 VK_FORMAT_R8G8B8A8_UNORM,
17732 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17733 VK_COMPONENT_SWIZZLE_IDENTITY },
17734 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17735 };
17736 VkImageView view;
17737 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17738 ASSERT_VK_SUCCESS(err);
17739
17740 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17741 VkFramebuffer fb;
17742 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17743 ASSERT_VK_SUCCESS(err);
17744
17745 // Record a single command buffer which issues a pipeline barrier w/
17746 // image memory barrier for the attachment. This detects the previously
17747 // missing tracking of the subpass layout by throwing a validation error
17748 // if it doesn't occur.
17749 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 -070017750 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017751 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17752
17753 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17754 nullptr,
17755 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17756 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17757 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17758 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17759 VK_QUEUE_FAMILY_IGNORED,
17760 VK_QUEUE_FAMILY_IGNORED,
17761 image.handle(),
17762 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17763 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17764 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17765 &imb);
17766
17767 vkCmdEndRenderPass(m_commandBuffer->handle());
17768 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017769 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017770
17771 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17772 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17773 vkDestroyImageView(m_device->device(), view, nullptr);
17774}
17775
17776TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17777 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17778 "is used as a depth/stencil framebuffer attachment, the "
17779 "aspectMask is ignored and both depth and stencil image "
17780 "subresources are used.");
17781
17782 VkFormatProperties format_properties;
17783 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17784 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17785 return;
17786 }
17787
17788 m_errorMonitor->ExpectSuccess();
17789
17790 ASSERT_NO_FATAL_FAILURE(InitState());
17791
17792 VkAttachmentDescription attachment = { 0,
17793 VK_FORMAT_D32_SFLOAT_S8_UINT,
17794 VK_SAMPLE_COUNT_1_BIT,
17795 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17796 VK_ATTACHMENT_STORE_OP_STORE,
17797 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17798 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17799 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17800 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17801
17802 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17803
17804 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17805
17806 VkSubpassDependency dep = { 0,
17807 0,
17808 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17809 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17810 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17811 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17812 VK_DEPENDENCY_BY_REGION_BIT};
17813
17814 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17815
17816 VkResult err;
17817 VkRenderPass rp;
17818 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17819 ASSERT_VK_SUCCESS(err);
17820
17821 VkImageObj image(m_device);
17822 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17823 0x26, // usage
17824 VK_IMAGE_TILING_OPTIMAL, 0);
17825 ASSERT_TRUE(image.initialized());
17826 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17827
17828 VkImageViewCreateInfo ivci = {
17829 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17830 nullptr,
17831 0,
17832 image.handle(),
17833 VK_IMAGE_VIEW_TYPE_2D,
17834 VK_FORMAT_D32_SFLOAT_S8_UINT,
17835 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17836 { 0x2, 0, 1, 0, 1 },
17837 };
17838 VkImageView view;
17839 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17840 ASSERT_VK_SUCCESS(err);
17841
17842 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17843 VkFramebuffer fb;
17844 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17845 ASSERT_VK_SUCCESS(err);
17846
17847 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 -070017848 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017849 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17850
17851 VkImageMemoryBarrier imb = {};
17852 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17853 imb.pNext = nullptr;
17854 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17855 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17856 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17857 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17858 imb.srcQueueFamilyIndex = 0;
17859 imb.dstQueueFamilyIndex = 0;
17860 imb.image = image.handle();
17861 imb.subresourceRange.aspectMask = 0x6;
17862 imb.subresourceRange.baseMipLevel = 0;
17863 imb.subresourceRange.levelCount = 0x1;
17864 imb.subresourceRange.baseArrayLayer = 0;
17865 imb.subresourceRange.layerCount = 0x1;
17866
17867 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17868 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17869 &imb);
17870
17871 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017872 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017873 QueueCommandBuffer(false);
17874 m_errorMonitor->VerifyNotFound();
17875
17876 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17877 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17878 vkDestroyImageView(m_device->device(), view, nullptr);
17879}
17880
17881TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17882 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17883 "errors, when an attachment reference is "
17884 "VK_ATTACHMENT_UNUSED");
17885
17886 m_errorMonitor->ExpectSuccess();
17887
17888 ASSERT_NO_FATAL_FAILURE(InitState());
17889
17890 // A renderpass with no attachments
17891 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17892
17893 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17894
17895 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17896
17897 VkRenderPass rp;
17898 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17899 ASSERT_VK_SUCCESS(err);
17900
17901 // A compatible framebuffer.
17902 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17903 VkFramebuffer fb;
17904 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17905 ASSERT_VK_SUCCESS(err);
17906
17907 // Record a command buffer which just begins and ends the renderpass. The
17908 // bug manifests in BeginRenderPass.
17909 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 -070017910 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017911 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17912 vkCmdEndRenderPass(m_commandBuffer->handle());
17913 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017914 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017915
17916 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17917 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17918}
17919
17920// This is a positive test. No errors are expected.
17921TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17922 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17923 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17924 VkResult result = VK_SUCCESS;
17925 VkImageFormatProperties formatProps;
17926 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17927 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17928 &formatProps);
17929 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17930 return;
17931 }
17932
17933 ASSERT_NO_FATAL_FAILURE(InitState());
17934 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17935 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17936 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17937 VkAttachmentDescription att = {};
17938 VkAttachmentReference ref = {};
17939 att.format = depth_stencil_fmt;
17940 att.samples = VK_SAMPLE_COUNT_1_BIT;
17941 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17942 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17943 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17944 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17945 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17946 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17947
17948 VkClearValue clear;
17949 clear.depthStencil.depth = 1.0;
17950 clear.depthStencil.stencil = 0;
17951 ref.attachment = 0;
17952 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17953
17954 VkSubpassDescription subpass = {};
17955 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17956 subpass.flags = 0;
17957 subpass.inputAttachmentCount = 0;
17958 subpass.pInputAttachments = NULL;
17959 subpass.colorAttachmentCount = 0;
17960 subpass.pColorAttachments = NULL;
17961 subpass.pResolveAttachments = NULL;
17962 subpass.pDepthStencilAttachment = &ref;
17963 subpass.preserveAttachmentCount = 0;
17964 subpass.pPreserveAttachments = NULL;
17965
17966 VkRenderPass rp;
17967 VkRenderPassCreateInfo rp_info = {};
17968 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17969 rp_info.attachmentCount = 1;
17970 rp_info.pAttachments = &att;
17971 rp_info.subpassCount = 1;
17972 rp_info.pSubpasses = &subpass;
17973 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17974 ASSERT_VK_SUCCESS(result);
17975
17976 VkImageView *depthView = m_depthStencil->BindInfo();
17977 VkFramebufferCreateInfo fb_info = {};
17978 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17979 fb_info.pNext = NULL;
17980 fb_info.renderPass = rp;
17981 fb_info.attachmentCount = 1;
17982 fb_info.pAttachments = depthView;
17983 fb_info.width = 100;
17984 fb_info.height = 100;
17985 fb_info.layers = 1;
17986 VkFramebuffer fb;
17987 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17988 ASSERT_VK_SUCCESS(result);
17989
17990 VkRenderPassBeginInfo rpbinfo = {};
17991 rpbinfo.clearValueCount = 1;
17992 rpbinfo.pClearValues = &clear;
17993 rpbinfo.pNext = NULL;
17994 rpbinfo.renderPass = rp;
17995 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17996 rpbinfo.renderArea.extent.width = 100;
17997 rpbinfo.renderArea.extent.height = 100;
17998 rpbinfo.renderArea.offset.x = 0;
17999 rpbinfo.renderArea.offset.y = 0;
18000 rpbinfo.framebuffer = fb;
18001
18002 VkFence fence = {};
18003 VkFenceCreateInfo fence_ci = {};
18004 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18005 fence_ci.pNext = nullptr;
18006 fence_ci.flags = 0;
18007 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18008 ASSERT_VK_SUCCESS(result);
18009
18010 m_commandBuffer->BeginCommandBuffer();
18011 m_commandBuffer->BeginRenderPass(rpbinfo);
18012 m_commandBuffer->EndRenderPass();
18013 m_commandBuffer->EndCommandBuffer();
18014 m_commandBuffer->QueueCommandBuffer(fence);
18015
18016 VkImageObj destImage(m_device);
18017 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18018 VK_IMAGE_TILING_OPTIMAL, 0);
18019 VkImageMemoryBarrier barrier = {};
18020 VkImageSubresourceRange range;
18021 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18022 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18023 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18024 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18025 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18026 barrier.image = m_depthStencil->handle();
18027 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18028 range.baseMipLevel = 0;
18029 range.levelCount = 1;
18030 range.baseArrayLayer = 0;
18031 range.layerCount = 1;
18032 barrier.subresourceRange = range;
18033 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18034 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18035 cmdbuf.BeginCommandBuffer();
18036 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18037 &barrier);
18038 barrier.srcAccessMask = 0;
18039 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18040 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18041 barrier.image = destImage.handle();
18042 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18043 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18044 &barrier);
18045 VkImageCopy cregion;
18046 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18047 cregion.srcSubresource.mipLevel = 0;
18048 cregion.srcSubresource.baseArrayLayer = 0;
18049 cregion.srcSubresource.layerCount = 1;
18050 cregion.srcOffset.x = 0;
18051 cregion.srcOffset.y = 0;
18052 cregion.srcOffset.z = 0;
18053 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18054 cregion.dstSubresource.mipLevel = 0;
18055 cregion.dstSubresource.baseArrayLayer = 0;
18056 cregion.dstSubresource.layerCount = 1;
18057 cregion.dstOffset.x = 0;
18058 cregion.dstOffset.y = 0;
18059 cregion.dstOffset.z = 0;
18060 cregion.extent.width = 100;
18061 cregion.extent.height = 100;
18062 cregion.extent.depth = 1;
18063 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
18064 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
18065 cmdbuf.EndCommandBuffer();
18066
18067 VkSubmitInfo submit_info;
18068 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18069 submit_info.pNext = NULL;
18070 submit_info.waitSemaphoreCount = 0;
18071 submit_info.pWaitSemaphores = NULL;
18072 submit_info.pWaitDstStageMask = NULL;
18073 submit_info.commandBufferCount = 1;
18074 submit_info.pCommandBuffers = &cmdbuf.handle();
18075 submit_info.signalSemaphoreCount = 0;
18076 submit_info.pSignalSemaphores = NULL;
18077
18078 m_errorMonitor->ExpectSuccess();
18079 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18080 m_errorMonitor->VerifyNotFound();
18081
18082 vkQueueWaitIdle(m_device->m_queue);
18083 vkDestroyFence(m_device->device(), fence, nullptr);
18084 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18085 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18086}
18087
18088// This is a positive test. No errors should be generated.
18089TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18090 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18091
18092 m_errorMonitor->ExpectSuccess();
18093 ASSERT_NO_FATAL_FAILURE(InitState());
18094
18095 VkEvent event;
18096 VkEventCreateInfo event_create_info{};
18097 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18098 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18099
18100 VkCommandPool command_pool;
18101 VkCommandPoolCreateInfo pool_create_info{};
18102 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18103 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18104 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18105 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18106
18107 VkCommandBuffer command_buffer;
18108 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18109 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18110 command_buffer_allocate_info.commandPool = command_pool;
18111 command_buffer_allocate_info.commandBufferCount = 1;
18112 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18113 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18114
18115 VkQueue queue = VK_NULL_HANDLE;
18116 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18117
18118 {
18119 VkCommandBufferBeginInfo begin_info{};
18120 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18121 vkBeginCommandBuffer(command_buffer, &begin_info);
18122
18123 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
18124 nullptr, 0, nullptr);
18125 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18126 vkEndCommandBuffer(command_buffer);
18127 }
18128 {
18129 VkSubmitInfo submit_info{};
18130 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18131 submit_info.commandBufferCount = 1;
18132 submit_info.pCommandBuffers = &command_buffer;
18133 submit_info.signalSemaphoreCount = 0;
18134 submit_info.pSignalSemaphores = nullptr;
18135 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18136 }
18137 { vkSetEvent(m_device->device(), event); }
18138
18139 vkQueueWaitIdle(queue);
18140
18141 vkDestroyEvent(m_device->device(), event, nullptr);
18142 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18143 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18144
18145 m_errorMonitor->VerifyNotFound();
18146}
18147// This is a positive test. No errors should be generated.
18148TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18149 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18150
18151 ASSERT_NO_FATAL_FAILURE(InitState());
18152 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18153 return;
18154
18155 m_errorMonitor->ExpectSuccess();
18156
18157 VkQueryPool query_pool;
18158 VkQueryPoolCreateInfo query_pool_create_info{};
18159 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18160 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18161 query_pool_create_info.queryCount = 1;
18162 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18163
18164 VkCommandPool command_pool;
18165 VkCommandPoolCreateInfo pool_create_info{};
18166 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18167 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18168 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18169 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18170
18171 VkCommandBuffer command_buffer;
18172 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18173 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18174 command_buffer_allocate_info.commandPool = command_pool;
18175 command_buffer_allocate_info.commandBufferCount = 1;
18176 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18177 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18178
18179 VkCommandBuffer secondary_command_buffer;
18180 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18181 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18182
18183 VkQueue queue = VK_NULL_HANDLE;
18184 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18185
18186 uint32_t qfi = 0;
18187 VkBufferCreateInfo buff_create_info = {};
18188 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18189 buff_create_info.size = 1024;
18190 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18191 buff_create_info.queueFamilyIndexCount = 1;
18192 buff_create_info.pQueueFamilyIndices = &qfi;
18193
18194 VkResult err;
18195 VkBuffer buffer;
18196 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18197 ASSERT_VK_SUCCESS(err);
18198 VkMemoryAllocateInfo mem_alloc = {};
18199 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18200 mem_alloc.pNext = NULL;
18201 mem_alloc.allocationSize = 1024;
18202 mem_alloc.memoryTypeIndex = 0;
18203
18204 VkMemoryRequirements memReqs;
18205 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18206 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18207 if (!pass) {
18208 vkDestroyBuffer(m_device->device(), buffer, NULL);
18209 return;
18210 }
18211
18212 VkDeviceMemory mem;
18213 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18214 ASSERT_VK_SUCCESS(err);
18215 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18216 ASSERT_VK_SUCCESS(err);
18217
18218 VkCommandBufferInheritanceInfo hinfo = {};
18219 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18220 hinfo.renderPass = VK_NULL_HANDLE;
18221 hinfo.subpass = 0;
18222 hinfo.framebuffer = VK_NULL_HANDLE;
18223 hinfo.occlusionQueryEnable = VK_FALSE;
18224 hinfo.queryFlags = 0;
18225 hinfo.pipelineStatistics = 0;
18226
18227 {
18228 VkCommandBufferBeginInfo begin_info{};
18229 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18230 begin_info.pInheritanceInfo = &hinfo;
18231 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18232
18233 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18234 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18235
18236 vkEndCommandBuffer(secondary_command_buffer);
18237
18238 begin_info.pInheritanceInfo = nullptr;
18239 vkBeginCommandBuffer(command_buffer, &begin_info);
18240
18241 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18242 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18243
18244 vkEndCommandBuffer(command_buffer);
18245 }
18246 {
18247 VkSubmitInfo submit_info{};
18248 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18249 submit_info.commandBufferCount = 1;
18250 submit_info.pCommandBuffers = &command_buffer;
18251 submit_info.signalSemaphoreCount = 0;
18252 submit_info.pSignalSemaphores = nullptr;
18253 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18254 }
18255
18256 vkQueueWaitIdle(queue);
18257
18258 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18259 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18260 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18261 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18262 vkDestroyBuffer(m_device->device(), buffer, NULL);
18263 vkFreeMemory(m_device->device(), mem, NULL);
18264
18265 m_errorMonitor->VerifyNotFound();
18266}
18267
18268// This is a positive test. No errors should be generated.
18269TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18270 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18271
18272 ASSERT_NO_FATAL_FAILURE(InitState());
18273 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18274 return;
18275
18276 m_errorMonitor->ExpectSuccess();
18277
18278 VkQueryPool query_pool;
18279 VkQueryPoolCreateInfo query_pool_create_info{};
18280 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18281 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18282 query_pool_create_info.queryCount = 1;
18283 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18284
18285 VkCommandPool command_pool;
18286 VkCommandPoolCreateInfo pool_create_info{};
18287 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18288 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18289 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18290 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18291
18292 VkCommandBuffer command_buffer[2];
18293 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18294 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18295 command_buffer_allocate_info.commandPool = command_pool;
18296 command_buffer_allocate_info.commandBufferCount = 2;
18297 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18298 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18299
18300 VkQueue queue = VK_NULL_HANDLE;
18301 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18302
18303 uint32_t qfi = 0;
18304 VkBufferCreateInfo buff_create_info = {};
18305 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18306 buff_create_info.size = 1024;
18307 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18308 buff_create_info.queueFamilyIndexCount = 1;
18309 buff_create_info.pQueueFamilyIndices = &qfi;
18310
18311 VkResult err;
18312 VkBuffer buffer;
18313 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18314 ASSERT_VK_SUCCESS(err);
18315 VkMemoryAllocateInfo mem_alloc = {};
18316 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18317 mem_alloc.pNext = NULL;
18318 mem_alloc.allocationSize = 1024;
18319 mem_alloc.memoryTypeIndex = 0;
18320
18321 VkMemoryRequirements memReqs;
18322 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18323 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18324 if (!pass) {
18325 vkDestroyBuffer(m_device->device(), buffer, NULL);
18326 return;
18327 }
18328
18329 VkDeviceMemory mem;
18330 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18331 ASSERT_VK_SUCCESS(err);
18332 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18333 ASSERT_VK_SUCCESS(err);
18334
18335 {
18336 VkCommandBufferBeginInfo begin_info{};
18337 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18338 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18339
18340 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18341 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18342
18343 vkEndCommandBuffer(command_buffer[0]);
18344
18345 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18346
18347 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18348
18349 vkEndCommandBuffer(command_buffer[1]);
18350 }
18351 {
18352 VkSubmitInfo submit_info{};
18353 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18354 submit_info.commandBufferCount = 2;
18355 submit_info.pCommandBuffers = command_buffer;
18356 submit_info.signalSemaphoreCount = 0;
18357 submit_info.pSignalSemaphores = nullptr;
18358 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18359 }
18360
18361 vkQueueWaitIdle(queue);
18362
18363 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18364 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18365 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18366 vkDestroyBuffer(m_device->device(), buffer, NULL);
18367 vkFreeMemory(m_device->device(), mem, NULL);
18368
18369 m_errorMonitor->VerifyNotFound();
18370}
18371
Tony Barbourc46924f2016-11-04 11:49:52 -060018372TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018373 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18374
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018375 ASSERT_NO_FATAL_FAILURE(InitState());
18376 VkEvent event;
18377 VkEventCreateInfo event_create_info{};
18378 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18379 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18380
18381 VkCommandPool command_pool;
18382 VkCommandPoolCreateInfo pool_create_info{};
18383 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18384 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18385 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18386 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18387
18388 VkCommandBuffer command_buffer;
18389 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18390 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18391 command_buffer_allocate_info.commandPool = command_pool;
18392 command_buffer_allocate_info.commandBufferCount = 1;
18393 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18394 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18395
18396 VkQueue queue = VK_NULL_HANDLE;
18397 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18398
18399 {
18400 VkCommandBufferBeginInfo begin_info{};
18401 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18402 vkBeginCommandBuffer(command_buffer, &begin_info);
18403
18404 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018405 vkEndCommandBuffer(command_buffer);
18406 }
18407 {
18408 VkSubmitInfo submit_info{};
18409 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18410 submit_info.commandBufferCount = 1;
18411 submit_info.pCommandBuffers = &command_buffer;
18412 submit_info.signalSemaphoreCount = 0;
18413 submit_info.pSignalSemaphores = nullptr;
18414 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18415 }
18416 {
18417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18418 "command buffer.");
18419 vkSetEvent(m_device->device(), event);
18420 m_errorMonitor->VerifyFound();
18421 }
18422
18423 vkQueueWaitIdle(queue);
18424
18425 vkDestroyEvent(m_device->device(), event, nullptr);
18426 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18427 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18428}
18429
18430// This is a positive test. No errors should be generated.
18431TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18432 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18433 "run through a Submit & WaitForFences cycle 3 times. This "
18434 "previously revealed a bug so running this positive test "
18435 "to prevent a regression.");
18436 m_errorMonitor->ExpectSuccess();
18437
18438 ASSERT_NO_FATAL_FAILURE(InitState());
18439 VkQueue queue = VK_NULL_HANDLE;
18440 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18441
18442 static const uint32_t NUM_OBJECTS = 2;
18443 static const uint32_t NUM_FRAMES = 3;
18444 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18445 VkFence fences[NUM_OBJECTS] = {};
18446
18447 VkCommandPool cmd_pool;
18448 VkCommandPoolCreateInfo cmd_pool_ci = {};
18449 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18450 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18451 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18452 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18453 ASSERT_VK_SUCCESS(err);
18454
18455 VkCommandBufferAllocateInfo cmd_buf_info = {};
18456 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18457 cmd_buf_info.commandPool = cmd_pool;
18458 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18459 cmd_buf_info.commandBufferCount = 1;
18460
18461 VkFenceCreateInfo fence_ci = {};
18462 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18463 fence_ci.pNext = nullptr;
18464 fence_ci.flags = 0;
18465
18466 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18467 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18468 ASSERT_VK_SUCCESS(err);
18469 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18470 ASSERT_VK_SUCCESS(err);
18471 }
18472
18473 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18474 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18475 // Create empty cmd buffer
18476 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18477 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18478
18479 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18480 ASSERT_VK_SUCCESS(err);
18481 err = vkEndCommandBuffer(cmd_buffers[obj]);
18482 ASSERT_VK_SUCCESS(err);
18483
18484 VkSubmitInfo submit_info = {};
18485 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18486 submit_info.commandBufferCount = 1;
18487 submit_info.pCommandBuffers = &cmd_buffers[obj];
18488 // Submit cmd buffer and wait for fence
18489 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18490 ASSERT_VK_SUCCESS(err);
18491 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18492 ASSERT_VK_SUCCESS(err);
18493 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18494 ASSERT_VK_SUCCESS(err);
18495 }
18496 }
18497 m_errorMonitor->VerifyNotFound();
18498 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18499 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18500 vkDestroyFence(m_device->device(), fences[i], nullptr);
18501 }
18502}
18503// This is a positive test. No errors should be generated.
18504TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18505
18506 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18507 "submitted on separate queues followed by a QueueWaitIdle.");
18508
18509 ASSERT_NO_FATAL_FAILURE(InitState());
18510 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18511 return;
18512
18513 m_errorMonitor->ExpectSuccess();
18514
18515 VkSemaphore semaphore;
18516 VkSemaphoreCreateInfo semaphore_create_info{};
18517 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18518 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18519
18520 VkCommandPool command_pool;
18521 VkCommandPoolCreateInfo pool_create_info{};
18522 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18523 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18524 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18525 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18526
18527 VkCommandBuffer command_buffer[2];
18528 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18529 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18530 command_buffer_allocate_info.commandPool = command_pool;
18531 command_buffer_allocate_info.commandBufferCount = 2;
18532 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18533 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18534
18535 VkQueue queue = VK_NULL_HANDLE;
18536 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18537
18538 {
18539 VkCommandBufferBeginInfo begin_info{};
18540 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18541 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18542
18543 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18544 nullptr, 0, nullptr, 0, nullptr);
18545
18546 VkViewport viewport{};
18547 viewport.maxDepth = 1.0f;
18548 viewport.minDepth = 0.0f;
18549 viewport.width = 512;
18550 viewport.height = 512;
18551 viewport.x = 0;
18552 viewport.y = 0;
18553 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18554 vkEndCommandBuffer(command_buffer[0]);
18555 }
18556 {
18557 VkCommandBufferBeginInfo begin_info{};
18558 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18559 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18560
18561 VkViewport viewport{};
18562 viewport.maxDepth = 1.0f;
18563 viewport.minDepth = 0.0f;
18564 viewport.width = 512;
18565 viewport.height = 512;
18566 viewport.x = 0;
18567 viewport.y = 0;
18568 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18569 vkEndCommandBuffer(command_buffer[1]);
18570 }
18571 {
18572 VkSubmitInfo submit_info{};
18573 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18574 submit_info.commandBufferCount = 1;
18575 submit_info.pCommandBuffers = &command_buffer[0];
18576 submit_info.signalSemaphoreCount = 1;
18577 submit_info.pSignalSemaphores = &semaphore;
18578 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18579 }
18580 {
18581 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18582 VkSubmitInfo submit_info{};
18583 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18584 submit_info.commandBufferCount = 1;
18585 submit_info.pCommandBuffers = &command_buffer[1];
18586 submit_info.waitSemaphoreCount = 1;
18587 submit_info.pWaitSemaphores = &semaphore;
18588 submit_info.pWaitDstStageMask = flags;
18589 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18590 }
18591
18592 vkQueueWaitIdle(m_device->m_queue);
18593
18594 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18595 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18596 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18597
18598 m_errorMonitor->VerifyNotFound();
18599}
18600
18601// This is a positive test. No errors should be generated.
18602TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18603
18604 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18605 "submitted on separate queues, the second having a fence"
18606 "followed by a QueueWaitIdle.");
18607
18608 ASSERT_NO_FATAL_FAILURE(InitState());
18609 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18610 return;
18611
18612 m_errorMonitor->ExpectSuccess();
18613
18614 VkFence fence;
18615 VkFenceCreateInfo fence_create_info{};
18616 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18617 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18618
18619 VkSemaphore semaphore;
18620 VkSemaphoreCreateInfo semaphore_create_info{};
18621 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18622 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18623
18624 VkCommandPool command_pool;
18625 VkCommandPoolCreateInfo pool_create_info{};
18626 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18627 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18628 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18629 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18630
18631 VkCommandBuffer command_buffer[2];
18632 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18633 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18634 command_buffer_allocate_info.commandPool = command_pool;
18635 command_buffer_allocate_info.commandBufferCount = 2;
18636 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18637 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18638
18639 VkQueue queue = VK_NULL_HANDLE;
18640 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18641
18642 {
18643 VkCommandBufferBeginInfo begin_info{};
18644 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18645 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18646
18647 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18648 nullptr, 0, nullptr, 0, nullptr);
18649
18650 VkViewport viewport{};
18651 viewport.maxDepth = 1.0f;
18652 viewport.minDepth = 0.0f;
18653 viewport.width = 512;
18654 viewport.height = 512;
18655 viewport.x = 0;
18656 viewport.y = 0;
18657 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18658 vkEndCommandBuffer(command_buffer[0]);
18659 }
18660 {
18661 VkCommandBufferBeginInfo begin_info{};
18662 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18663 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18664
18665 VkViewport viewport{};
18666 viewport.maxDepth = 1.0f;
18667 viewport.minDepth = 0.0f;
18668 viewport.width = 512;
18669 viewport.height = 512;
18670 viewport.x = 0;
18671 viewport.y = 0;
18672 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18673 vkEndCommandBuffer(command_buffer[1]);
18674 }
18675 {
18676 VkSubmitInfo submit_info{};
18677 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18678 submit_info.commandBufferCount = 1;
18679 submit_info.pCommandBuffers = &command_buffer[0];
18680 submit_info.signalSemaphoreCount = 1;
18681 submit_info.pSignalSemaphores = &semaphore;
18682 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18683 }
18684 {
18685 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18686 VkSubmitInfo submit_info{};
18687 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18688 submit_info.commandBufferCount = 1;
18689 submit_info.pCommandBuffers = &command_buffer[1];
18690 submit_info.waitSemaphoreCount = 1;
18691 submit_info.pWaitSemaphores = &semaphore;
18692 submit_info.pWaitDstStageMask = flags;
18693 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18694 }
18695
18696 vkQueueWaitIdle(m_device->m_queue);
18697
18698 vkDestroyFence(m_device->device(), fence, nullptr);
18699 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18700 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18701 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18702
18703 m_errorMonitor->VerifyNotFound();
18704}
18705
18706// This is a positive test. No errors should be generated.
18707TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18708
18709 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18710 "submitted on separate queues, the second having a fence"
18711 "followed by two consecutive WaitForFences calls on the same fence.");
18712
18713 ASSERT_NO_FATAL_FAILURE(InitState());
18714 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18715 return;
18716
18717 m_errorMonitor->ExpectSuccess();
18718
18719 VkFence fence;
18720 VkFenceCreateInfo fence_create_info{};
18721 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18722 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18723
18724 VkSemaphore semaphore;
18725 VkSemaphoreCreateInfo semaphore_create_info{};
18726 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18727 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18728
18729 VkCommandPool command_pool;
18730 VkCommandPoolCreateInfo pool_create_info{};
18731 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18732 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18733 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18734 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18735
18736 VkCommandBuffer command_buffer[2];
18737 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18738 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18739 command_buffer_allocate_info.commandPool = command_pool;
18740 command_buffer_allocate_info.commandBufferCount = 2;
18741 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18742 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18743
18744 VkQueue queue = VK_NULL_HANDLE;
18745 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18746
18747 {
18748 VkCommandBufferBeginInfo begin_info{};
18749 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18750 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18751
18752 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18753 nullptr, 0, nullptr, 0, nullptr);
18754
18755 VkViewport viewport{};
18756 viewport.maxDepth = 1.0f;
18757 viewport.minDepth = 0.0f;
18758 viewport.width = 512;
18759 viewport.height = 512;
18760 viewport.x = 0;
18761 viewport.y = 0;
18762 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18763 vkEndCommandBuffer(command_buffer[0]);
18764 }
18765 {
18766 VkCommandBufferBeginInfo begin_info{};
18767 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18768 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18769
18770 VkViewport viewport{};
18771 viewport.maxDepth = 1.0f;
18772 viewport.minDepth = 0.0f;
18773 viewport.width = 512;
18774 viewport.height = 512;
18775 viewport.x = 0;
18776 viewport.y = 0;
18777 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18778 vkEndCommandBuffer(command_buffer[1]);
18779 }
18780 {
18781 VkSubmitInfo submit_info{};
18782 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18783 submit_info.commandBufferCount = 1;
18784 submit_info.pCommandBuffers = &command_buffer[0];
18785 submit_info.signalSemaphoreCount = 1;
18786 submit_info.pSignalSemaphores = &semaphore;
18787 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18788 }
18789 {
18790 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18791 VkSubmitInfo submit_info{};
18792 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18793 submit_info.commandBufferCount = 1;
18794 submit_info.pCommandBuffers = &command_buffer[1];
18795 submit_info.waitSemaphoreCount = 1;
18796 submit_info.pWaitSemaphores = &semaphore;
18797 submit_info.pWaitDstStageMask = flags;
18798 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18799 }
18800
18801 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18802 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18803
18804 vkDestroyFence(m_device->device(), fence, nullptr);
18805 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18806 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18807 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18808
18809 m_errorMonitor->VerifyNotFound();
18810}
18811
18812TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18813
18814 ASSERT_NO_FATAL_FAILURE(InitState());
18815 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18816 printf("Test requires two queues, skipping\n");
18817 return;
18818 }
18819
18820 VkResult err;
18821
18822 m_errorMonitor->ExpectSuccess();
18823
18824 VkQueue q0 = m_device->m_queue;
18825 VkQueue q1 = nullptr;
18826 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18827 ASSERT_NE(q1, nullptr);
18828
18829 // An (empty) command buffer. We must have work in the first submission --
18830 // the layer treats unfenced work differently from fenced work.
18831 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18832 VkCommandPool pool;
18833 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18834 ASSERT_VK_SUCCESS(err);
18835 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18836 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18837 VkCommandBuffer cb;
18838 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18839 ASSERT_VK_SUCCESS(err);
18840 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18841 err = vkBeginCommandBuffer(cb, &cbbi);
18842 ASSERT_VK_SUCCESS(err);
18843 err = vkEndCommandBuffer(cb);
18844 ASSERT_VK_SUCCESS(err);
18845
18846 // A semaphore
18847 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18848 VkSemaphore s;
18849 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18850 ASSERT_VK_SUCCESS(err);
18851
18852 // First submission, to q0
18853 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18854
18855 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18856 ASSERT_VK_SUCCESS(err);
18857
18858 // Second submission, to q1, waiting on s
18859 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18860 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18861
18862 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18863 ASSERT_VK_SUCCESS(err);
18864
18865 // Wait for q0 idle
18866 err = vkQueueWaitIdle(q0);
18867 ASSERT_VK_SUCCESS(err);
18868
18869 // Command buffer should have been completed (it was on q0); reset the pool.
18870 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18871
18872 m_errorMonitor->VerifyNotFound();
18873
18874 // Force device completely idle and clean up resources
18875 vkDeviceWaitIdle(m_device->device());
18876 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18877 vkDestroySemaphore(m_device->device(), s, nullptr);
18878}
18879
18880// This is a positive test. No errors should be generated.
18881TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18882
18883 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18884 "submitted on separate queues, the second having a fence, "
18885 "followed by a WaitForFences call.");
18886
18887 ASSERT_NO_FATAL_FAILURE(InitState());
18888 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18889 return;
18890
18891 m_errorMonitor->ExpectSuccess();
18892
18893 ASSERT_NO_FATAL_FAILURE(InitState());
18894 VkFence fence;
18895 VkFenceCreateInfo fence_create_info{};
18896 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18897 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18898
18899 VkSemaphore semaphore;
18900 VkSemaphoreCreateInfo semaphore_create_info{};
18901 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18902 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18903
18904 VkCommandPool command_pool;
18905 VkCommandPoolCreateInfo pool_create_info{};
18906 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18907 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18908 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18909 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18910
18911 VkCommandBuffer command_buffer[2];
18912 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18913 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18914 command_buffer_allocate_info.commandPool = command_pool;
18915 command_buffer_allocate_info.commandBufferCount = 2;
18916 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18917 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18918
18919 VkQueue queue = VK_NULL_HANDLE;
18920 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18921
18922 {
18923 VkCommandBufferBeginInfo begin_info{};
18924 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18925 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18926
18927 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18928 nullptr, 0, nullptr, 0, nullptr);
18929
18930 VkViewport viewport{};
18931 viewport.maxDepth = 1.0f;
18932 viewport.minDepth = 0.0f;
18933 viewport.width = 512;
18934 viewport.height = 512;
18935 viewport.x = 0;
18936 viewport.y = 0;
18937 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18938 vkEndCommandBuffer(command_buffer[0]);
18939 }
18940 {
18941 VkCommandBufferBeginInfo begin_info{};
18942 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18943 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18944
18945 VkViewport viewport{};
18946 viewport.maxDepth = 1.0f;
18947 viewport.minDepth = 0.0f;
18948 viewport.width = 512;
18949 viewport.height = 512;
18950 viewport.x = 0;
18951 viewport.y = 0;
18952 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18953 vkEndCommandBuffer(command_buffer[1]);
18954 }
18955 {
18956 VkSubmitInfo submit_info{};
18957 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18958 submit_info.commandBufferCount = 1;
18959 submit_info.pCommandBuffers = &command_buffer[0];
18960 submit_info.signalSemaphoreCount = 1;
18961 submit_info.pSignalSemaphores = &semaphore;
18962 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18963 }
18964 {
18965 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18966 VkSubmitInfo submit_info{};
18967 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18968 submit_info.commandBufferCount = 1;
18969 submit_info.pCommandBuffers = &command_buffer[1];
18970 submit_info.waitSemaphoreCount = 1;
18971 submit_info.pWaitSemaphores = &semaphore;
18972 submit_info.pWaitDstStageMask = flags;
18973 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18974 }
18975
18976 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18977
18978 vkDestroyFence(m_device->device(), fence, nullptr);
18979 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18980 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18981 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18982
18983 m_errorMonitor->VerifyNotFound();
18984}
18985
18986// This is a positive test. No errors should be generated.
18987TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18988
18989 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18990 "on the same queue, sharing a signal/wait semaphore, the "
18991 "second having a fence, "
18992 "followed by a WaitForFences call.");
18993
18994 m_errorMonitor->ExpectSuccess();
18995
18996 ASSERT_NO_FATAL_FAILURE(InitState());
18997 VkFence fence;
18998 VkFenceCreateInfo fence_create_info{};
18999 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19000 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19001
19002 VkSemaphore semaphore;
19003 VkSemaphoreCreateInfo semaphore_create_info{};
19004 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19005 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19006
19007 VkCommandPool command_pool;
19008 VkCommandPoolCreateInfo pool_create_info{};
19009 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19010 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19011 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19012 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19013
19014 VkCommandBuffer command_buffer[2];
19015 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19016 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19017 command_buffer_allocate_info.commandPool = command_pool;
19018 command_buffer_allocate_info.commandBufferCount = 2;
19019 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19020 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19021
19022 {
19023 VkCommandBufferBeginInfo begin_info{};
19024 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19025 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19026
19027 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19028 nullptr, 0, nullptr, 0, nullptr);
19029
19030 VkViewport viewport{};
19031 viewport.maxDepth = 1.0f;
19032 viewport.minDepth = 0.0f;
19033 viewport.width = 512;
19034 viewport.height = 512;
19035 viewport.x = 0;
19036 viewport.y = 0;
19037 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19038 vkEndCommandBuffer(command_buffer[0]);
19039 }
19040 {
19041 VkCommandBufferBeginInfo begin_info{};
19042 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19043 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19044
19045 VkViewport viewport{};
19046 viewport.maxDepth = 1.0f;
19047 viewport.minDepth = 0.0f;
19048 viewport.width = 512;
19049 viewport.height = 512;
19050 viewport.x = 0;
19051 viewport.y = 0;
19052 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19053 vkEndCommandBuffer(command_buffer[1]);
19054 }
19055 {
19056 VkSubmitInfo submit_info{};
19057 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19058 submit_info.commandBufferCount = 1;
19059 submit_info.pCommandBuffers = &command_buffer[0];
19060 submit_info.signalSemaphoreCount = 1;
19061 submit_info.pSignalSemaphores = &semaphore;
19062 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19063 }
19064 {
19065 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19066 VkSubmitInfo submit_info{};
19067 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19068 submit_info.commandBufferCount = 1;
19069 submit_info.pCommandBuffers = &command_buffer[1];
19070 submit_info.waitSemaphoreCount = 1;
19071 submit_info.pWaitSemaphores = &semaphore;
19072 submit_info.pWaitDstStageMask = flags;
19073 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19074 }
19075
19076 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19077
19078 vkDestroyFence(m_device->device(), fence, nullptr);
19079 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19080 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19081 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19082
19083 m_errorMonitor->VerifyNotFound();
19084}
19085
19086// This is a positive test. No errors should be generated.
19087TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
19088
19089 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19090 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19091 "SubmitInfos but with a fence, followed by a WaitForFences call.");
19092
19093 m_errorMonitor->ExpectSuccess();
19094
19095 ASSERT_NO_FATAL_FAILURE(InitState());
19096 VkFence fence;
19097 VkFenceCreateInfo fence_create_info{};
19098 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19099 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19100
19101 VkCommandPool command_pool;
19102 VkCommandPoolCreateInfo pool_create_info{};
19103 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19104 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19105 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19106 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19107
19108 VkCommandBuffer command_buffer[2];
19109 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19110 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19111 command_buffer_allocate_info.commandPool = command_pool;
19112 command_buffer_allocate_info.commandBufferCount = 2;
19113 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19114 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19115
19116 {
19117 VkCommandBufferBeginInfo begin_info{};
19118 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19119 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19120
19121 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19122 nullptr, 0, nullptr, 0, nullptr);
19123
19124 VkViewport viewport{};
19125 viewport.maxDepth = 1.0f;
19126 viewport.minDepth = 0.0f;
19127 viewport.width = 512;
19128 viewport.height = 512;
19129 viewport.x = 0;
19130 viewport.y = 0;
19131 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19132 vkEndCommandBuffer(command_buffer[0]);
19133 }
19134 {
19135 VkCommandBufferBeginInfo begin_info{};
19136 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19137 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19138
19139 VkViewport viewport{};
19140 viewport.maxDepth = 1.0f;
19141 viewport.minDepth = 0.0f;
19142 viewport.width = 512;
19143 viewport.height = 512;
19144 viewport.x = 0;
19145 viewport.y = 0;
19146 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19147 vkEndCommandBuffer(command_buffer[1]);
19148 }
19149 {
19150 VkSubmitInfo submit_info{};
19151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19152 submit_info.commandBufferCount = 1;
19153 submit_info.pCommandBuffers = &command_buffer[0];
19154 submit_info.signalSemaphoreCount = 0;
19155 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19156 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19157 }
19158 {
19159 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19160 VkSubmitInfo submit_info{};
19161 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19162 submit_info.commandBufferCount = 1;
19163 submit_info.pCommandBuffers = &command_buffer[1];
19164 submit_info.waitSemaphoreCount = 0;
19165 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19166 submit_info.pWaitDstStageMask = flags;
19167 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19168 }
19169
19170 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19171
19172 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19173 ASSERT_VK_SUCCESS(err);
19174
19175 vkDestroyFence(m_device->device(), fence, nullptr);
19176 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19177 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19178
19179 m_errorMonitor->VerifyNotFound();
19180}
19181
19182// This is a positive test. No errors should be generated.
19183TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19184
19185 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19186 "on the same queue, the second having a fence, followed "
19187 "by a WaitForFences call.");
19188
19189 m_errorMonitor->ExpectSuccess();
19190
19191 ASSERT_NO_FATAL_FAILURE(InitState());
19192 VkFence fence;
19193 VkFenceCreateInfo fence_create_info{};
19194 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19195 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19196
19197 VkCommandPool command_pool;
19198 VkCommandPoolCreateInfo pool_create_info{};
19199 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19200 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19201 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19202 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19203
19204 VkCommandBuffer command_buffer[2];
19205 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19206 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19207 command_buffer_allocate_info.commandPool = command_pool;
19208 command_buffer_allocate_info.commandBufferCount = 2;
19209 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19210 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19211
19212 {
19213 VkCommandBufferBeginInfo begin_info{};
19214 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19215 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19216
19217 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19218 nullptr, 0, nullptr, 0, nullptr);
19219
19220 VkViewport viewport{};
19221 viewport.maxDepth = 1.0f;
19222 viewport.minDepth = 0.0f;
19223 viewport.width = 512;
19224 viewport.height = 512;
19225 viewport.x = 0;
19226 viewport.y = 0;
19227 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19228 vkEndCommandBuffer(command_buffer[0]);
19229 }
19230 {
19231 VkCommandBufferBeginInfo begin_info{};
19232 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19233 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19234
19235 VkViewport viewport{};
19236 viewport.maxDepth = 1.0f;
19237 viewport.minDepth = 0.0f;
19238 viewport.width = 512;
19239 viewport.height = 512;
19240 viewport.x = 0;
19241 viewport.y = 0;
19242 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19243 vkEndCommandBuffer(command_buffer[1]);
19244 }
19245 {
19246 VkSubmitInfo submit_info{};
19247 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19248 submit_info.commandBufferCount = 1;
19249 submit_info.pCommandBuffers = &command_buffer[0];
19250 submit_info.signalSemaphoreCount = 0;
19251 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19252 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19253 }
19254 {
19255 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19256 VkSubmitInfo submit_info{};
19257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19258 submit_info.commandBufferCount = 1;
19259 submit_info.pCommandBuffers = &command_buffer[1];
19260 submit_info.waitSemaphoreCount = 0;
19261 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19262 submit_info.pWaitDstStageMask = flags;
19263 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19264 }
19265
19266 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19267
19268 vkDestroyFence(m_device->device(), fence, nullptr);
19269 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19270 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19271
19272 m_errorMonitor->VerifyNotFound();
19273}
19274
19275// This is a positive test. No errors should be generated.
19276TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19277
19278 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19279 "QueueSubmit call followed by a WaitForFences call.");
19280 ASSERT_NO_FATAL_FAILURE(InitState());
19281
19282 m_errorMonitor->ExpectSuccess();
19283
19284 VkFence fence;
19285 VkFenceCreateInfo fence_create_info{};
19286 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19287 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19288
19289 VkSemaphore semaphore;
19290 VkSemaphoreCreateInfo semaphore_create_info{};
19291 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19292 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19293
19294 VkCommandPool command_pool;
19295 VkCommandPoolCreateInfo pool_create_info{};
19296 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19297 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19298 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19299 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19300
19301 VkCommandBuffer command_buffer[2];
19302 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19303 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19304 command_buffer_allocate_info.commandPool = command_pool;
19305 command_buffer_allocate_info.commandBufferCount = 2;
19306 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19307 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19308
19309 {
19310 VkCommandBufferBeginInfo begin_info{};
19311 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19312 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19313
19314 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19315 nullptr, 0, nullptr, 0, nullptr);
19316
19317 VkViewport viewport{};
19318 viewport.maxDepth = 1.0f;
19319 viewport.minDepth = 0.0f;
19320 viewport.width = 512;
19321 viewport.height = 512;
19322 viewport.x = 0;
19323 viewport.y = 0;
19324 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19325 vkEndCommandBuffer(command_buffer[0]);
19326 }
19327 {
19328 VkCommandBufferBeginInfo begin_info{};
19329 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19330 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19331
19332 VkViewport viewport{};
19333 viewport.maxDepth = 1.0f;
19334 viewport.minDepth = 0.0f;
19335 viewport.width = 512;
19336 viewport.height = 512;
19337 viewport.x = 0;
19338 viewport.y = 0;
19339 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19340 vkEndCommandBuffer(command_buffer[1]);
19341 }
19342 {
19343 VkSubmitInfo submit_info[2];
19344 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19345
19346 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19347 submit_info[0].pNext = NULL;
19348 submit_info[0].commandBufferCount = 1;
19349 submit_info[0].pCommandBuffers = &command_buffer[0];
19350 submit_info[0].signalSemaphoreCount = 1;
19351 submit_info[0].pSignalSemaphores = &semaphore;
19352 submit_info[0].waitSemaphoreCount = 0;
19353 submit_info[0].pWaitSemaphores = NULL;
19354 submit_info[0].pWaitDstStageMask = 0;
19355
19356 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19357 submit_info[1].pNext = NULL;
19358 submit_info[1].commandBufferCount = 1;
19359 submit_info[1].pCommandBuffers = &command_buffer[1];
19360 submit_info[1].waitSemaphoreCount = 1;
19361 submit_info[1].pWaitSemaphores = &semaphore;
19362 submit_info[1].pWaitDstStageMask = flags;
19363 submit_info[1].signalSemaphoreCount = 0;
19364 submit_info[1].pSignalSemaphores = NULL;
19365 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19366 }
19367
19368 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19369
19370 vkDestroyFence(m_device->device(), fence, nullptr);
19371 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19372 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19373 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19374
19375 m_errorMonitor->VerifyNotFound();
19376}
19377
19378TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19379 m_errorMonitor->ExpectSuccess();
19380
19381 ASSERT_NO_FATAL_FAILURE(InitState());
19382 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19383
Tony Barbour552f6c02016-12-21 14:34:07 -070019384 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019385
19386 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19387 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19388 m_errorMonitor->VerifyNotFound();
19389 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19390 m_errorMonitor->VerifyNotFound();
19391 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19392 m_errorMonitor->VerifyNotFound();
19393
19394 m_commandBuffer->EndCommandBuffer();
19395 m_errorMonitor->VerifyNotFound();
19396}
19397
19398TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19399 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19400 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19401 "has a valid layout, and a second subpass then uses a "
19402 "valid *READ_ONLY* layout.");
19403 m_errorMonitor->ExpectSuccess();
19404 ASSERT_NO_FATAL_FAILURE(InitState());
19405
19406 VkAttachmentReference attach[2] = {};
19407 attach[0].attachment = 0;
19408 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19409 attach[1].attachment = 0;
19410 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19411 VkSubpassDescription subpasses[2] = {};
19412 // First subpass clears DS attach on load
19413 subpasses[0].pDepthStencilAttachment = &attach[0];
19414 // 2nd subpass reads in DS as input attachment
19415 subpasses[1].inputAttachmentCount = 1;
19416 subpasses[1].pInputAttachments = &attach[1];
19417 VkAttachmentDescription attach_desc = {};
19418 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19419 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19420 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19421 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19422 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19423 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19424 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19425 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19426 VkRenderPassCreateInfo rpci = {};
19427 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19428 rpci.attachmentCount = 1;
19429 rpci.pAttachments = &attach_desc;
19430 rpci.subpassCount = 2;
19431 rpci.pSubpasses = subpasses;
19432
19433 // Now create RenderPass and verify no errors
19434 VkRenderPass rp;
19435 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19436 m_errorMonitor->VerifyNotFound();
19437
19438 vkDestroyRenderPass(m_device->device(), rp, NULL);
19439}
19440
19441TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19442 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19443 "as vertex attributes");
19444 m_errorMonitor->ExpectSuccess();
19445
19446 ASSERT_NO_FATAL_FAILURE(InitState());
19447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19448
19449 VkVertexInputBindingDescription input_binding;
19450 memset(&input_binding, 0, sizeof(input_binding));
19451
19452 VkVertexInputAttributeDescription input_attribs[2];
19453 memset(input_attribs, 0, sizeof(input_attribs));
19454
19455 for (int i = 0; i < 2; i++) {
19456 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19457 input_attribs[i].location = i;
19458 }
19459
19460 char const *vsSource = "#version 450\n"
19461 "\n"
19462 "layout(location=0) in mat2x4 x;\n"
19463 "out gl_PerVertex {\n"
19464 " vec4 gl_Position;\n"
19465 "};\n"
19466 "void main(){\n"
19467 " gl_Position = x[0] + x[1];\n"
19468 "}\n";
19469 char const *fsSource = "#version 450\n"
19470 "\n"
19471 "layout(location=0) out vec4 color;\n"
19472 "void main(){\n"
19473 " color = vec4(1);\n"
19474 "}\n";
19475
19476 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19477 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19478
19479 VkPipelineObj pipe(m_device);
19480 pipe.AddColorAttachment();
19481 pipe.AddShader(&vs);
19482 pipe.AddShader(&fs);
19483
19484 pipe.AddVertexInputBindings(&input_binding, 1);
19485 pipe.AddVertexInputAttribs(input_attribs, 2);
19486
19487 VkDescriptorSetObj descriptorSet(m_device);
19488 descriptorSet.AppendDummy();
19489 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19490
19491 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19492
19493 /* expect success */
19494 m_errorMonitor->VerifyNotFound();
19495}
19496
19497TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19498 m_errorMonitor->ExpectSuccess();
19499
19500 ASSERT_NO_FATAL_FAILURE(InitState());
19501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19502
19503 VkVertexInputBindingDescription input_binding;
19504 memset(&input_binding, 0, sizeof(input_binding));
19505
19506 VkVertexInputAttributeDescription input_attribs[2];
19507 memset(input_attribs, 0, sizeof(input_attribs));
19508
19509 for (int i = 0; i < 2; i++) {
19510 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19511 input_attribs[i].location = i;
19512 }
19513
19514 char const *vsSource = "#version 450\n"
19515 "\n"
19516 "layout(location=0) in vec4 x[2];\n"
19517 "out gl_PerVertex {\n"
19518 " vec4 gl_Position;\n"
19519 "};\n"
19520 "void main(){\n"
19521 " gl_Position = x[0] + x[1];\n"
19522 "}\n";
19523 char const *fsSource = "#version 450\n"
19524 "\n"
19525 "layout(location=0) out vec4 color;\n"
19526 "void main(){\n"
19527 " color = vec4(1);\n"
19528 "}\n";
19529
19530 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19531 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19532
19533 VkPipelineObj pipe(m_device);
19534 pipe.AddColorAttachment();
19535 pipe.AddShader(&vs);
19536 pipe.AddShader(&fs);
19537
19538 pipe.AddVertexInputBindings(&input_binding, 1);
19539 pipe.AddVertexInputAttribs(input_attribs, 2);
19540
19541 VkDescriptorSetObj descriptorSet(m_device);
19542 descriptorSet.AppendDummy();
19543 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19544
19545 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19546
19547 m_errorMonitor->VerifyNotFound();
19548}
19549
19550TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19551 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19552 "through multiple vertex shader inputs, each consuming a different "
19553 "subset of the components.");
19554 m_errorMonitor->ExpectSuccess();
19555
19556 ASSERT_NO_FATAL_FAILURE(InitState());
19557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19558
19559 VkVertexInputBindingDescription input_binding;
19560 memset(&input_binding, 0, sizeof(input_binding));
19561
19562 VkVertexInputAttributeDescription input_attribs[3];
19563 memset(input_attribs, 0, sizeof(input_attribs));
19564
19565 for (int i = 0; i < 3; i++) {
19566 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19567 input_attribs[i].location = i;
19568 }
19569
19570 char const *vsSource = "#version 450\n"
19571 "\n"
19572 "layout(location=0) in vec4 x;\n"
19573 "layout(location=1) in vec3 y1;\n"
19574 "layout(location=1, component=3) in float y2;\n"
19575 "layout(location=2) in vec4 z;\n"
19576 "out gl_PerVertex {\n"
19577 " vec4 gl_Position;\n"
19578 "};\n"
19579 "void main(){\n"
19580 " gl_Position = x + vec4(y1, y2) + z;\n"
19581 "}\n";
19582 char const *fsSource = "#version 450\n"
19583 "\n"
19584 "layout(location=0) out vec4 color;\n"
19585 "void main(){\n"
19586 " color = vec4(1);\n"
19587 "}\n";
19588
19589 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19590 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19591
19592 VkPipelineObj pipe(m_device);
19593 pipe.AddColorAttachment();
19594 pipe.AddShader(&vs);
19595 pipe.AddShader(&fs);
19596
19597 pipe.AddVertexInputBindings(&input_binding, 1);
19598 pipe.AddVertexInputAttribs(input_attribs, 3);
19599
19600 VkDescriptorSetObj descriptorSet(m_device);
19601 descriptorSet.AppendDummy();
19602 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19603
19604 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19605
19606 m_errorMonitor->VerifyNotFound();
19607}
19608
19609TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19610 m_errorMonitor->ExpectSuccess();
19611
19612 ASSERT_NO_FATAL_FAILURE(InitState());
19613 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19614
19615 char const *vsSource = "#version 450\n"
19616 "out gl_PerVertex {\n"
19617 " vec4 gl_Position;\n"
19618 "};\n"
19619 "void main(){\n"
19620 " gl_Position = vec4(0);\n"
19621 "}\n";
19622 char const *fsSource = "#version 450\n"
19623 "\n"
19624 "layout(location=0) out vec4 color;\n"
19625 "void main(){\n"
19626 " color = vec4(1);\n"
19627 "}\n";
19628
19629 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19630 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19631
19632 VkPipelineObj pipe(m_device);
19633 pipe.AddColorAttachment();
19634 pipe.AddShader(&vs);
19635 pipe.AddShader(&fs);
19636
19637 VkDescriptorSetObj descriptorSet(m_device);
19638 descriptorSet.AppendDummy();
19639 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19640
19641 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19642
19643 m_errorMonitor->VerifyNotFound();
19644}
19645
19646TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19647 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19648 "set out in 14.1.3: fundamental type must match, and producer side must "
19649 "have at least as many components");
19650 m_errorMonitor->ExpectSuccess();
19651
19652 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19653
19654 ASSERT_NO_FATAL_FAILURE(InitState());
19655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19656
19657 char const *vsSource = "#version 450\n"
19658 "out gl_PerVertex {\n"
19659 " vec4 gl_Position;\n"
19660 "};\n"
19661 "layout(location=0) out vec3 x;\n"
19662 "layout(location=1) out ivec3 y;\n"
19663 "layout(location=2) out vec3 z;\n"
19664 "void main(){\n"
19665 " gl_Position = vec4(0);\n"
19666 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19667 "}\n";
19668 char const *fsSource = "#version 450\n"
19669 "\n"
19670 "layout(location=0) out vec4 color;\n"
19671 "layout(location=0) in float x;\n"
19672 "layout(location=1) flat in int y;\n"
19673 "layout(location=2) in vec2 z;\n"
19674 "void main(){\n"
19675 " color = vec4(1 + x + y + z.x);\n"
19676 "}\n";
19677
19678 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19679 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19680
19681 VkPipelineObj pipe(m_device);
19682 pipe.AddColorAttachment();
19683 pipe.AddShader(&vs);
19684 pipe.AddShader(&fs);
19685
19686 VkDescriptorSetObj descriptorSet(m_device);
19687 descriptorSet.AppendDummy();
19688 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19689
19690 VkResult err = VK_SUCCESS;
19691 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19692 ASSERT_VK_SUCCESS(err);
19693
19694 m_errorMonitor->VerifyNotFound();
19695}
19696
19697TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19698 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19699 "passed between the TCS and TES stages");
19700 m_errorMonitor->ExpectSuccess();
19701
19702 ASSERT_NO_FATAL_FAILURE(InitState());
19703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19704
19705 if (!m_device->phy().features().tessellationShader) {
19706 printf("Device does not support tessellation shaders; skipped.\n");
19707 return;
19708 }
19709
19710 char const *vsSource = "#version 450\n"
19711 "void main(){}\n";
19712 char const *tcsSource = "#version 450\n"
19713 "layout(location=0) out int x[];\n"
19714 "layout(vertices=3) out;\n"
19715 "void main(){\n"
19716 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19717 " gl_TessLevelInner[0] = 1;\n"
19718 " x[gl_InvocationID] = gl_InvocationID;\n"
19719 "}\n";
19720 char const *tesSource = "#version 450\n"
19721 "layout(triangles, equal_spacing, cw) in;\n"
19722 "layout(location=0) in int x[];\n"
19723 "out gl_PerVertex { vec4 gl_Position; };\n"
19724 "void main(){\n"
19725 " gl_Position.xyz = gl_TessCoord;\n"
19726 " gl_Position.w = x[0] + x[1] + x[2];\n"
19727 "}\n";
19728 char const *fsSource = "#version 450\n"
19729 "layout(location=0) out vec4 color;\n"
19730 "void main(){\n"
19731 " color = vec4(1);\n"
19732 "}\n";
19733
19734 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19735 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19736 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19737 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19738
19739 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19740 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19741
19742 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19743
19744 VkPipelineObj pipe(m_device);
19745 pipe.SetInputAssembly(&iasci);
19746 pipe.SetTessellation(&tsci);
19747 pipe.AddColorAttachment();
19748 pipe.AddShader(&vs);
19749 pipe.AddShader(&tcs);
19750 pipe.AddShader(&tes);
19751 pipe.AddShader(&fs);
19752
19753 VkDescriptorSetObj descriptorSet(m_device);
19754 descriptorSet.AppendDummy();
19755 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19756
19757 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19758
19759 m_errorMonitor->VerifyNotFound();
19760}
19761
19762TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19763 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19764 "interface block passed into the geometry shader. This "
19765 "is interesting because the 'extra' array level is not "
19766 "present on the member type, but on the block instance.");
19767 m_errorMonitor->ExpectSuccess();
19768
19769 ASSERT_NO_FATAL_FAILURE(InitState());
19770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19771
19772 if (!m_device->phy().features().geometryShader) {
19773 printf("Device does not support geometry shaders; skipped.\n");
19774 return;
19775 }
19776
19777 char const *vsSource = "#version 450\n"
19778 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19779 "void main(){\n"
19780 " vs_out.x = vec4(1);\n"
19781 "}\n";
19782 char const *gsSource = "#version 450\n"
19783 "layout(triangles) in;\n"
19784 "layout(triangle_strip, max_vertices=3) out;\n"
19785 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19786 "out gl_PerVertex { vec4 gl_Position; };\n"
19787 "void main() {\n"
19788 " gl_Position = gs_in[0].x;\n"
19789 " EmitVertex();\n"
19790 "}\n";
19791 char const *fsSource = "#version 450\n"
19792 "layout(location=0) out vec4 color;\n"
19793 "void main(){\n"
19794 " color = vec4(1);\n"
19795 "}\n";
19796
19797 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19798 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19799 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19800
19801 VkPipelineObj pipe(m_device);
19802 pipe.AddColorAttachment();
19803 pipe.AddShader(&vs);
19804 pipe.AddShader(&gs);
19805 pipe.AddShader(&fs);
19806
19807 VkDescriptorSetObj descriptorSet(m_device);
19808 descriptorSet.AppendDummy();
19809 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19810
19811 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19812
19813 m_errorMonitor->VerifyNotFound();
19814}
19815
19816TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19817 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19818 "attributes. This is interesting because they consume multiple "
19819 "locations.");
19820 m_errorMonitor->ExpectSuccess();
19821
19822 ASSERT_NO_FATAL_FAILURE(InitState());
19823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19824
19825 if (!m_device->phy().features().shaderFloat64) {
19826 printf("Device does not support 64bit vertex attributes; skipped.\n");
19827 return;
19828 }
19829
19830 VkVertexInputBindingDescription input_bindings[1];
19831 memset(input_bindings, 0, sizeof(input_bindings));
19832
19833 VkVertexInputAttributeDescription input_attribs[4];
19834 memset(input_attribs, 0, sizeof(input_attribs));
19835 input_attribs[0].location = 0;
19836 input_attribs[0].offset = 0;
19837 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19838 input_attribs[1].location = 2;
19839 input_attribs[1].offset = 32;
19840 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19841 input_attribs[2].location = 4;
19842 input_attribs[2].offset = 64;
19843 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19844 input_attribs[3].location = 6;
19845 input_attribs[3].offset = 96;
19846 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19847
19848 char const *vsSource = "#version 450\n"
19849 "\n"
19850 "layout(location=0) in dmat4 x;\n"
19851 "out gl_PerVertex {\n"
19852 " vec4 gl_Position;\n"
19853 "};\n"
19854 "void main(){\n"
19855 " gl_Position = vec4(x[0][0]);\n"
19856 "}\n";
19857 char const *fsSource = "#version 450\n"
19858 "\n"
19859 "layout(location=0) out vec4 color;\n"
19860 "void main(){\n"
19861 " color = vec4(1);\n"
19862 "}\n";
19863
19864 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19865 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19866
19867 VkPipelineObj pipe(m_device);
19868 pipe.AddColorAttachment();
19869 pipe.AddShader(&vs);
19870 pipe.AddShader(&fs);
19871
19872 pipe.AddVertexInputBindings(input_bindings, 1);
19873 pipe.AddVertexInputAttribs(input_attribs, 4);
19874
19875 VkDescriptorSetObj descriptorSet(m_device);
19876 descriptorSet.AppendDummy();
19877 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19878
19879 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19880
19881 m_errorMonitor->VerifyNotFound();
19882}
19883
19884TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19885 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19886 m_errorMonitor->ExpectSuccess();
19887
19888 ASSERT_NO_FATAL_FAILURE(InitState());
19889
19890 char const *vsSource = "#version 450\n"
19891 "\n"
19892 "out gl_PerVertex {\n"
19893 " vec4 gl_Position;\n"
19894 "};\n"
19895 "void main(){\n"
19896 " gl_Position = vec4(1);\n"
19897 "}\n";
19898 char const *fsSource = "#version 450\n"
19899 "\n"
19900 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19901 "layout(location=0) out vec4 color;\n"
19902 "void main() {\n"
19903 " color = subpassLoad(x);\n"
19904 "}\n";
19905
19906 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19907 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19908
19909 VkPipelineObj pipe(m_device);
19910 pipe.AddShader(&vs);
19911 pipe.AddShader(&fs);
19912 pipe.AddColorAttachment();
19913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19914
19915 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19916 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19917 VkDescriptorSetLayout dsl;
19918 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19919 ASSERT_VK_SUCCESS(err);
19920
19921 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19922 VkPipelineLayout pl;
19923 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19924 ASSERT_VK_SUCCESS(err);
19925
19926 VkAttachmentDescription descs[2] = {
19927 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19928 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19929 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19930 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19931 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19932 };
19933 VkAttachmentReference color = {
19934 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19935 };
19936 VkAttachmentReference input = {
19937 1, VK_IMAGE_LAYOUT_GENERAL,
19938 };
19939
19940 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19941
19942 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19943 VkRenderPass rp;
19944 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19945 ASSERT_VK_SUCCESS(err);
19946
19947 // should be OK. would go wrong here if it's going to...
19948 pipe.CreateVKPipeline(pl, rp);
19949
19950 m_errorMonitor->VerifyNotFound();
19951
19952 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19953 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19954 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19955}
19956
19957TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19958 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19959 "descriptor-backed resource which is not provided, but the shader does not "
19960 "statically use it. This is interesting because it requires compute pipelines "
19961 "to have a proper descriptor use walk, which they didn't for some time.");
19962 m_errorMonitor->ExpectSuccess();
19963
19964 ASSERT_NO_FATAL_FAILURE(InitState());
19965
19966 char const *csSource = "#version 450\n"
19967 "\n"
19968 "layout(local_size_x=1) in;\n"
19969 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19970 "void main(){\n"
19971 " // x is not used.\n"
19972 "}\n";
19973
19974 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19975
19976 VkDescriptorSetObj descriptorSet(m_device);
19977 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19978
19979 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19980 nullptr,
19981 0,
19982 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19983 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19984 descriptorSet.GetPipelineLayout(),
19985 VK_NULL_HANDLE,
19986 -1 };
19987
19988 VkPipeline pipe;
19989 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19990
19991 m_errorMonitor->VerifyNotFound();
19992
19993 if (err == VK_SUCCESS) {
19994 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19995 }
19996}
19997
19998TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19999 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20000 "sampler portion of a combined image + sampler");
20001 m_errorMonitor->ExpectSuccess();
20002
20003 ASSERT_NO_FATAL_FAILURE(InitState());
20004
20005 VkDescriptorSetLayoutBinding bindings[] = {
20006 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20007 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20008 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20009 };
20010 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20011 VkDescriptorSetLayout dsl;
20012 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20013 ASSERT_VK_SUCCESS(err);
20014
20015 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20016 VkPipelineLayout pl;
20017 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20018 ASSERT_VK_SUCCESS(err);
20019
20020 char const *csSource = "#version 450\n"
20021 "\n"
20022 "layout(local_size_x=1) in;\n"
20023 "layout(set=0, binding=0) uniform sampler s;\n"
20024 "layout(set=0, binding=1) uniform texture2D t;\n"
20025 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20026 "void main() {\n"
20027 " x = texture(sampler2D(t, s), vec2(0));\n"
20028 "}\n";
20029 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20030
20031 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20032 nullptr,
20033 0,
20034 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20035 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20036 pl,
20037 VK_NULL_HANDLE,
20038 -1 };
20039
20040 VkPipeline pipe;
20041 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20042
20043 m_errorMonitor->VerifyNotFound();
20044
20045 if (err == VK_SUCCESS) {
20046 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20047 }
20048
20049 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20050 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20051}
20052
20053TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
20054 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20055 "image portion of a combined image + sampler");
20056 m_errorMonitor->ExpectSuccess();
20057
20058 ASSERT_NO_FATAL_FAILURE(InitState());
20059
20060 VkDescriptorSetLayoutBinding bindings[] = {
20061 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20062 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20063 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20064 };
20065 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20066 VkDescriptorSetLayout dsl;
20067 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20068 ASSERT_VK_SUCCESS(err);
20069
20070 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20071 VkPipelineLayout pl;
20072 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20073 ASSERT_VK_SUCCESS(err);
20074
20075 char const *csSource = "#version 450\n"
20076 "\n"
20077 "layout(local_size_x=1) in;\n"
20078 "layout(set=0, binding=0) uniform texture2D t;\n"
20079 "layout(set=0, binding=1) uniform sampler s;\n"
20080 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20081 "void main() {\n"
20082 " x = texture(sampler2D(t, s), vec2(0));\n"
20083 "}\n";
20084 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20085
20086 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20087 nullptr,
20088 0,
20089 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20090 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20091 pl,
20092 VK_NULL_HANDLE,
20093 -1 };
20094
20095 VkPipeline pipe;
20096 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20097
20098 m_errorMonitor->VerifyNotFound();
20099
20100 if (err == VK_SUCCESS) {
20101 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20102 }
20103
20104 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20105 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20106}
20107
20108TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
20109 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
20110 "both the sampler and the image of a combined image+sampler "
20111 "but via separate variables");
20112 m_errorMonitor->ExpectSuccess();
20113
20114 ASSERT_NO_FATAL_FAILURE(InitState());
20115
20116 VkDescriptorSetLayoutBinding bindings[] = {
20117 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20118 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20119 };
20120 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
20121 VkDescriptorSetLayout dsl;
20122 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20123 ASSERT_VK_SUCCESS(err);
20124
20125 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20126 VkPipelineLayout pl;
20127 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20128 ASSERT_VK_SUCCESS(err);
20129
20130 char const *csSource = "#version 450\n"
20131 "\n"
20132 "layout(local_size_x=1) in;\n"
20133 "layout(set=0, binding=0) uniform texture2D t;\n"
20134 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20135 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20136 "void main() {\n"
20137 " x = texture(sampler2D(t, s), vec2(0));\n"
20138 "}\n";
20139 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20140
20141 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20142 nullptr,
20143 0,
20144 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20145 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20146 pl,
20147 VK_NULL_HANDLE,
20148 -1 };
20149
20150 VkPipeline pipe;
20151 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20152
20153 m_errorMonitor->VerifyNotFound();
20154
20155 if (err == VK_SUCCESS) {
20156 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20157 }
20158
20159 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20160 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20161}
20162
20163TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20164 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20165
20166 ASSERT_NO_FATAL_FAILURE(InitState());
20167
20168 // Positive test to check parameter_validation and unique_objects support
20169 // for NV_dedicated_allocation
20170 uint32_t extension_count = 0;
20171 bool supports_nv_dedicated_allocation = false;
20172 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20173 ASSERT_VK_SUCCESS(err);
20174
20175 if (extension_count > 0) {
20176 std::vector<VkExtensionProperties> available_extensions(extension_count);
20177
20178 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20179 ASSERT_VK_SUCCESS(err);
20180
20181 for (const auto &extension_props : available_extensions) {
20182 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20183 supports_nv_dedicated_allocation = true;
20184 }
20185 }
20186 }
20187
20188 if (supports_nv_dedicated_allocation) {
20189 m_errorMonitor->ExpectSuccess();
20190
20191 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20192 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20193 dedicated_buffer_create_info.pNext = nullptr;
20194 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20195
20196 uint32_t queue_family_index = 0;
20197 VkBufferCreateInfo buffer_create_info = {};
20198 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20199 buffer_create_info.pNext = &dedicated_buffer_create_info;
20200 buffer_create_info.size = 1024;
20201 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20202 buffer_create_info.queueFamilyIndexCount = 1;
20203 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20204
20205 VkBuffer buffer;
20206 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20207 ASSERT_VK_SUCCESS(err);
20208
20209 VkMemoryRequirements memory_reqs;
20210 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20211
20212 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20213 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20214 dedicated_memory_info.pNext = nullptr;
20215 dedicated_memory_info.buffer = buffer;
20216 dedicated_memory_info.image = VK_NULL_HANDLE;
20217
20218 VkMemoryAllocateInfo memory_info = {};
20219 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20220 memory_info.pNext = &dedicated_memory_info;
20221 memory_info.allocationSize = memory_reqs.size;
20222
20223 bool pass;
20224 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20225 ASSERT_TRUE(pass);
20226
20227 VkDeviceMemory buffer_memory;
20228 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20229 ASSERT_VK_SUCCESS(err);
20230
20231 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20232 ASSERT_VK_SUCCESS(err);
20233
20234 vkDestroyBuffer(m_device->device(), buffer, NULL);
20235 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20236
20237 m_errorMonitor->VerifyNotFound();
20238 }
20239}
20240
20241TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20242 VkResult err;
20243
20244 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20245
20246 ASSERT_NO_FATAL_FAILURE(InitState());
20247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20248
20249 std::vector<const char *> device_extension_names;
20250 auto features = m_device->phy().features();
20251 // Artificially disable support for non-solid fill modes
20252 features.fillModeNonSolid = false;
20253 // The sacrificial device object
20254 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20255
20256 VkRenderpassObj render_pass(&test_device);
20257
20258 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20259 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20260 pipeline_layout_ci.setLayoutCount = 0;
20261 pipeline_layout_ci.pSetLayouts = NULL;
20262
20263 VkPipelineLayout pipeline_layout;
20264 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20265 ASSERT_VK_SUCCESS(err);
20266
20267 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20268 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20269 rs_ci.pNext = nullptr;
20270 rs_ci.lineWidth = 1.0f;
20271 rs_ci.rasterizerDiscardEnable = true;
20272
20273 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20274 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20275
20276 // Set polygonMode=FILL. No error is expected
20277 m_errorMonitor->ExpectSuccess();
20278 {
20279 VkPipelineObj pipe(&test_device);
20280 pipe.AddShader(&vs);
20281 pipe.AddShader(&fs);
20282 pipe.AddColorAttachment();
20283 // Set polygonMode to a good value
20284 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20285 pipe.SetRasterization(&rs_ci);
20286 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20287 }
20288 m_errorMonitor->VerifyNotFound();
20289
20290 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20291}
20292
20293TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20294 VkResult err;
20295 ASSERT_NO_FATAL_FAILURE(InitState());
20296 ASSERT_NO_FATAL_FAILURE(InitViewport());
20297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20298
20299 VkPipelineLayout pipeline_layout;
20300 VkPushConstantRange pc_range = {};
20301 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20302 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20303 pipeline_layout_ci.pushConstantRangeCount = 1;
20304 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20305
20306 //
20307 // Check for invalid push constant ranges in pipeline layouts.
20308 //
20309 struct PipelineLayoutTestCase {
20310 VkPushConstantRange const range;
20311 char const *msg;
20312 };
20313
20314 // Check for overlapping ranges
20315 const uint32_t ranges_per_test = 5;
20316 struct OverlappingRangeTestCase {
20317 VkPushConstantRange const ranges[ranges_per_test];
20318 char const *msg;
20319 };
20320
20321 // Run some positive tests to make sure overlap checking in the layer is OK
20322 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20323 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20324 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20325 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20326 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20327 "" },
20328 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20329 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20330 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20331 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20332 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20333 "" } } };
20334 for (const auto &iter : overlapping_range_tests_pos) {
20335 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20336 m_errorMonitor->ExpectSuccess();
20337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20338 m_errorMonitor->VerifyNotFound();
20339 if (VK_SUCCESS == err) {
20340 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20341 }
20342 }
20343
20344 //
20345 // CmdPushConstants tests
20346 //
20347 const uint8_t dummy_values[100] = {};
20348
Tony Barbour552f6c02016-12-21 14:34:07 -070020349 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020350
20351 // positive overlapping range tests with cmd
20352 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20353 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20354 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20355 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20356 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20357 } };
20358
20359 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20360 const VkPushConstantRange pc_range4[] = {
20361 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20362 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20363 };
20364
20365 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20366 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20367 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20368 ASSERT_VK_SUCCESS(err);
20369 for (const auto &iter : cmd_overlap_tests_pos) {
20370 m_errorMonitor->ExpectSuccess();
20371 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20372 iter.range.size, dummy_values);
20373 m_errorMonitor->VerifyNotFound();
20374 }
20375 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20376
Tony Barbour552f6c02016-12-21 14:34:07 -070020377 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020378}
20379
20380
20381
20382
20383
20384
20385
20386#if 0 // A few devices have issues with this test so disabling for now
20387TEST_F(VkPositiveLayerTest, LongFenceChain)
20388{
20389 m_errorMonitor->ExpectSuccess();
20390
20391 ASSERT_NO_FATAL_FAILURE(InitState());
20392 VkResult err;
20393
20394 std::vector<VkFence> fences;
20395
20396 const int chainLength = 32768;
20397
20398 for (int i = 0; i < chainLength; i++) {
20399 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20400 VkFence fence;
20401 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20402 ASSERT_VK_SUCCESS(err);
20403
20404 fences.push_back(fence);
20405
20406 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20407 0, nullptr, 0, nullptr };
20408 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20409 ASSERT_VK_SUCCESS(err);
20410
20411 }
20412
20413 // BOOM, stack overflow.
20414 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20415
20416 for (auto fence : fences)
20417 vkDestroyFence(m_device->device(), fence, nullptr);
20418
20419 m_errorMonitor->VerifyNotFound();
20420}
20421#endif
20422
20423
Cody Northrop1242dfd2016-07-13 17:24:59 -060020424#if defined(ANDROID) && defined(VALIDATION_APK)
20425static bool initialized = false;
20426static bool active = false;
20427
20428// Convert Intents to argv
20429// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020430std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020431 std::vector<std::string> args;
20432 JavaVM &vm = *app.activity->vm;
20433 JNIEnv *p_env;
20434 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20435 return args;
20436
20437 JNIEnv &env = *p_env;
20438 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020439 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020440 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020441 jmethodID get_string_extra_method =
20442 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020443 jvalue get_string_extra_args;
20444 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020445 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020446
20447 std::string args_str;
20448 if (extra_str) {
20449 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20450 args_str = extra_utf;
20451 env.ReleaseStringUTFChars(extra_str, extra_utf);
20452 env.DeleteLocalRef(extra_str);
20453 }
20454
20455 env.DeleteLocalRef(get_string_extra_args.l);
20456 env.DeleteLocalRef(intent);
20457 vm.DetachCurrentThread();
20458
20459 // split args_str
20460 std::stringstream ss(args_str);
20461 std::string arg;
20462 while (std::getline(ss, arg, ' ')) {
20463 if (!arg.empty())
20464 args.push_back(arg);
20465 }
20466
20467 return args;
20468}
20469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020470static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020472static void processCommand(struct android_app *app, int32_t cmd) {
20473 switch (cmd) {
20474 case APP_CMD_INIT_WINDOW: {
20475 if (app->window) {
20476 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020477 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020478 break;
20479 }
20480 case APP_CMD_GAINED_FOCUS: {
20481 active = true;
20482 break;
20483 }
20484 case APP_CMD_LOST_FOCUS: {
20485 active = false;
20486 break;
20487 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020488 }
20489}
20490
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020491void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020492 app_dummy();
20493
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020494 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020495
20496 int vulkanSupport = InitVulkan();
20497 if (vulkanSupport == 0) {
20498 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20499 return;
20500 }
20501
20502 app->onAppCmd = processCommand;
20503 app->onInputEvent = processInput;
20504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020505 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020506 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020507 struct android_poll_source *source;
20508 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020509 if (source) {
20510 source->process(app, source);
20511 }
20512
20513 if (app->destroyRequested != 0) {
20514 VkTestFramework::Finish();
20515 return;
20516 }
20517 }
20518
20519 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020520 // Use the following key to send arguments to gtest, i.e.
20521 // --es args "--gtest_filter=-VkLayerTest.foo"
20522 const char key[] = "args";
20523 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020525 std::string filter = "";
20526 if (args.size() > 0) {
20527 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20528 filter += args[0];
20529 } else {
20530 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20531 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020533 int argc = 2;
20534 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20535 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020536
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020537 // Route output to files until we can override the gtest output
20538 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20539 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020541 ::testing::InitGoogleTest(&argc, argv);
20542 VkTestFramework::InitArgs(&argc, argv);
20543 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020544
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020545 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020546
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020547 if (result != 0) {
20548 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20549 } else {
20550 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20551 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020552
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020553 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020554
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020555 fclose(stdout);
20556 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020558 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020560 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020561 }
20562 }
20563}
20564#endif
20565
Tony Barbour300a6082015-04-07 13:44:53 -060020566int main(int argc, char **argv) {
20567 int result;
20568
Cody Northrop8e54a402016-03-08 22:25:52 -070020569#ifdef ANDROID
20570 int vulkanSupport = InitVulkan();
20571 if (vulkanSupport == 0)
20572 return 1;
20573#endif
20574
Tony Barbour300a6082015-04-07 13:44:53 -060020575 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020576 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020577
20578 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20579
20580 result = RUN_ALL_TESTS();
20581
Tony Barbour6918cd52015-04-09 12:58:51 -060020582 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020583 return result;
20584}