blob: ae357f1c57f81c9fa96462e8fcc5289a4b5286d1 [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;
175 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600176 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600177 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600178 m_msgFound = VK_TRUE;
179 result = VK_TRUE;
180 // We only want one match for each expected error so remove from set here
181 // 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 -0600182 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186 for (auto desired_id : m_desired_message_ids) {
187 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
188 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
189 // Return true to avoid calling layers/driver with this error.
190 result = VK_TRUE;
191 } else if (desired_id == message_code) {
192 // Double-check that the string matches the error enum
193 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
194 found_expected = true;
195 result = VK_TRUE;
196 m_msgFound = VK_TRUE;
197 m_desired_message_ids.erase(desired_id);
198 break;
199 } else {
200 // Treat this message as a regular unexpected error, but print a warning jic
201 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
202 errorString.c_str(), desired_id, validation_error_map[desired_id]);
203 }
204 }
205 }
206
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200208 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600209 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600210 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600212 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600213 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600217 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
218
Karl Schultz6addd812016-02-02 17:17:23 -0700219 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220
Karl Schultz6addd812016-02-02 17:17:23 -0700221 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600222
Karl Schultz6addd812016-02-02 17:17:23 -0700223 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224 vector<string> otherMsgs = GetOtherFailureMsgs();
225 cout << "Other error messages logged for this test were:" << endl;
226 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
227 cout << " " << *iter << endl;
228 }
229 }
230
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600231 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
234 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
235 m_msgFlags = message_flag_mask;
236 // Match ANY message matching specified type
237 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200238 }
239
240 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600241 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200242 if (!DesiredMsgFound()) {
243 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600244 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600245 FAIL() << "Did not receive expected error '" << desired_msg << "'";
246 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200247 }
248 }
249
250 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600251 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 if (DesiredMsgFound()) {
253 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600254 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600255 FAIL() << "Expected to succeed but got error: " << msg;
256 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 }
258 }
259
Karl Schultz6addd812016-02-02 17:17:23 -0700260 private:
261 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600262 std::unordered_set<uint32_t>m_desired_message_ids;
263 std::unordered_set<string> m_desired_message_strings;
264 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700265 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600266 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700267 bool *m_bailout;
268 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600269};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500270
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600271static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
272 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
273 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600274 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
275 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600276 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600277 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600278 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600279}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500280
Karl Schultz6addd812016-02-02 17:17:23 -0700281class VkLayerTest : public VkRenderFramework {
282 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800283 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
284 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600285 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
286 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700287 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600288 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
289 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700290 }
Tony Barbour300a6082015-04-07 13:44:53 -0600291
Tony Barbourfe3351b2015-07-28 10:17:20 -0600292 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800294 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600295 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
296 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700297 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700299 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700301 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600302 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
303 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
304 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700305 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
306 }
307 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
308 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
309 }
310
311 protected:
312 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600313 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600314
315 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600316 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600317 std::vector<const char *> instance_extension_names;
318 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600319
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700320 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600321 /*
322 * Since CreateDbgMsgCallback is an instance level extension call
323 * any extension / layer that utilizes that feature also needs
324 * to be enabled at create instance time.
325 */
Karl Schultz6addd812016-02-02 17:17:23 -0700326 // Use Threading layer first to protect others from
327 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700328 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600329 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800330 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700331 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800332 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600333 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700334 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600335
Ian Elliott2c1daf52016-05-12 09:41:46 -0600336 if (m_enableWSI) {
337 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
338 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
339#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
340#if defined(VK_USE_PLATFORM_ANDROID_KHR)
341 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
342#endif // VK_USE_PLATFORM_ANDROID_KHR
343#if defined(VK_USE_PLATFORM_MIR_KHR)
344 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
345#endif // VK_USE_PLATFORM_MIR_KHR
346#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
347 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
348#endif // VK_USE_PLATFORM_WAYLAND_KHR
349#if defined(VK_USE_PLATFORM_WIN32_KHR)
350 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
351#endif // VK_USE_PLATFORM_WIN32_KHR
352#endif // NEED_TO_TEST_THIS_ON_PLATFORM
353#if defined(VK_USE_PLATFORM_XCB_KHR)
354 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
355#elif defined(VK_USE_PLATFORM_XLIB_KHR)
356 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
357#endif // VK_USE_PLATFORM_XLIB_KHR
358 }
359
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600360 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600361 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800362 this->app_info.pApplicationName = "layer_tests";
363 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600364 this->app_info.pEngineName = "unittest";
365 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600366 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600367
Tony Barbour15524c32015-04-29 17:34:29 -0600368 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600369 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600370 }
371
372 virtual void TearDown() {
373 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600374 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600375 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600376 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600377
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600378 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600379};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500380
Karl Schultz6addd812016-02-02 17:17:23 -0700381VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600382 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600383
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800384 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600385
386 /*
387 * For render test all drawing happens in a single render pass
388 * on a single command buffer.
389 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200390 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800391 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600392 }
393
394 return result;
395}
396
Karl Schultz6addd812016-02-02 17:17:23 -0700397VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600398 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600399
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200400 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800401 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200402 }
Tony Barbour300a6082015-04-07 13:44:53 -0600403
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800404 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600405
406 return result;
407}
408
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600409void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500410 // Create identity matrix
411 int i;
412 struct vktriangle_vs_uniform data;
413
414 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700415 glm::mat4 View = glm::mat4(1.0f);
416 glm::mat4 Model = glm::mat4(1.0f);
417 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500418 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700419 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500420
421 memcpy(&data.mvp, &MVP[0][0], matrixSize);
422
Karl Schultz6addd812016-02-02 17:17:23 -0700423 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600424 {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 -0500425 };
426
Karl Schultz6addd812016-02-02 17:17:23 -0700427 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500428 data.position[i][0] = tri_data[i].posX;
429 data.position[i][1] = tri_data[i].posY;
430 data.position[i][2] = tri_data[i].posZ;
431 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700432 data.color[i][0] = tri_data[i].r;
433 data.color[i][1] = tri_data[i].g;
434 data.color[i][2] = tri_data[i].b;
435 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500436 }
437
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500438 ASSERT_NO_FATAL_FAILURE(InitViewport());
439
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200440 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
441 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500442
Karl Schultz6addd812016-02-02 17:17:23 -0700443 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600444 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500445
446 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800447 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500448 pipelineobj.AddShader(&vs);
449 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600450 if (failMask & BsoFailLineWidth) {
451 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600452 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600453 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600454 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
455 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600456 }
457 if (failMask & BsoFailDepthBias) {
458 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600460 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600461 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600462 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600463 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600464 }
Karl Schultz6addd812016-02-02 17:17:23 -0700465 // Viewport and scissors must stay in synch or other errors will occur than
466 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600467 if (failMask & BsoFailViewport) {
468 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
469 }
470 if (failMask & BsoFailScissor) {
471 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
472 }
473 if (failMask & BsoFailBlend) {
474 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600475 VkPipelineColorBlendAttachmentState att_state = {};
476 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
477 att_state.blendEnable = VK_TRUE;
478 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600479 }
480 if (failMask & BsoFailDepthBounds) {
481 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
482 }
483 if (failMask & BsoFailStencilReadMask) {
484 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
485 }
486 if (failMask & BsoFailStencilWriteMask) {
487 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
488 }
489 if (failMask & BsoFailStencilReference) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
491 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500492
493 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600494 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500495
496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600497 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500498
Tony Barbourfe3351b2015-07-28 10:17:20 -0600499 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600502 if (failMask & BsoFailIndexBuffer) {
503 // Use DrawIndexed w/o an index buffer bound
504 DrawIndexed(3, 1, 0, 0, 0);
505 } else {
506 Draw(3, 1, 0, 0);
507 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508
Mark Muellerd4914412016-06-13 17:52:06 -0600509 if (failMask & BsoFailCmdClearAttachments) {
510 VkClearAttachment color_attachment = {};
511 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
512 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
513 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
514
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600515 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600516 }
517
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500518 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600519 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500520
Tony Barbourfe3351b2015-07-28 10:17:20 -0600521 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500522}
523
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600524void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
525 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500526 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600527 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500530 }
531
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800532 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700533 // Make sure depthWriteEnable is set so that Depth fail test will work
534 // correctly
535 // Make sure stencilTestEnable is set so that Stencil fail test will work
536 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600537 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800538 stencil.failOp = VK_STENCIL_OP_KEEP;
539 stencil.passOp = VK_STENCIL_OP_KEEP;
540 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
541 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600542
543 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
544 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600545 ds_ci.pNext = NULL;
546 ds_ci.depthTestEnable = VK_FALSE;
547 ds_ci.depthWriteEnable = VK_TRUE;
548 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
549 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600550 if (failMask & BsoFailDepthBounds) {
551 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600552 ds_ci.maxDepthBounds = 0.0f;
553 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600554 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600555 ds_ci.stencilTestEnable = VK_TRUE;
556 ds_ci.front = stencil;
557 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600558
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600559 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600560 pipelineobj.SetViewport(m_viewports);
561 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800562 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600563 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600564 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800565 commandBuffer->BindPipeline(pipelineobj);
566 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500567}
568
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600569class VkPositiveLayerTest : public VkLayerTest {
570 public:
571 protected:
572};
573
Ian Elliott2c1daf52016-05-12 09:41:46 -0600574class VkWsiEnabledLayerTest : public VkLayerTest {
575 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600576 protected:
577 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600578};
579
Mark Muellerdfe37552016-07-07 14:47:42 -0600580class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600582 enum eTestEnFlags {
583 eDoubleDelete,
584 eInvalidDeviceOffset,
585 eInvalidMemoryOffset,
586 eBindNullBuffer,
587 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600588 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600589 };
590
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600591 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600592
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
594 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600595 return true;
596 }
597 VkDeviceSize offset_limit = 0;
598 if (eInvalidMemoryOffset == aTestFlag) {
599 VkBuffer vulkanBuffer;
600 VkBufferCreateInfo buffer_create_info = {};
601 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
602 buffer_create_info.size = 32;
603 buffer_create_info.usage = aBufferUsage;
604
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600605 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600606 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600607
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600608 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600609 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
610 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600611 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
612 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600613 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600614 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600615 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600617 }
618 if (eOffsetAlignment < offset_limit) {
619 return true;
620 }
621 return false;
622 }
623
624 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600625 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
626 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600627
628 if (eBindNullBuffer == aTestFlag) {
629 VulkanMemory = 0;
630 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
631 } else {
632 VkBufferCreateInfo buffer_create_info = {};
633 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
634 buffer_create_info.size = 32;
635 buffer_create_info.usage = aBufferUsage;
636
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600637 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600638
639 CreateCurrent = true;
640
641 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 VkMemoryAllocateInfo memory_allocate_info = {};
645 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
646 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
648 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600649 if (!pass) {
650 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
651 return;
652 }
653
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600654 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600655 AllocateCurrent = true;
656 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600657 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
658 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600659 BoundCurrent = true;
660
661 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
662 }
663 }
664
665 ~VkBufferTest() {
666 if (CreateCurrent) {
667 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
668 }
669 if (AllocateCurrent) {
670 if (InvalidDeleteEn) {
671 union {
672 VkDeviceMemory device_memory;
673 unsigned long long index_access;
674 } bad_index;
675
676 bad_index.device_memory = VulkanMemory;
677 bad_index.index_access++;
678
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600679 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600680 }
681 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
682 }
683 }
684
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600685 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600686
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600687 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600688
689 void TestDoubleDestroy() {
690 // Destroy the buffer but leave the flag set, which will cause
691 // the buffer to be destroyed again in the destructor.
692 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
693 }
694
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600696 bool AllocateCurrent;
697 bool BoundCurrent;
698 bool CreateCurrent;
699 bool InvalidDeleteEn;
700
701 VkBuffer VulkanBuffer;
702 VkDevice VulkanDevice;
703 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600704};
705
706class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600707 public:
708 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600709 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600710 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600711 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
713 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 BindIdGenerator++; // NB: This can wrap w/misuse
715
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600716 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
717 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600718
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600719 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
720 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
721 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
722 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
723 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600724
725 unsigned i = 0;
726 do {
727 VertexInputAttributeDescription[i].binding = BindId;
728 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600729 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
730 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600731 i++;
732 } while (AttributeCount < i);
733
734 i = 0;
735 do {
736 VertexInputBindingDescription[i].binding = BindId;
737 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600738 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 i++;
740 } while (BindingCount < i);
741 }
742
743 ~VkVerticesObj() {
744 if (VertexInputAttributeDescription) {
745 delete[] VertexInputAttributeDescription;
746 }
747 if (VertexInputBindingDescription) {
748 delete[] VertexInputBindingDescription;
749 }
750 }
751
752 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600753 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
754 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600755 return true;
756 }
757
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600759 VkDeviceSize *offsetList;
760 unsigned offsetCount;
761
762 if (aOffsetCount) {
763 offsetList = aOffsetList;
764 offsetCount = aOffsetCount;
765 } else {
766 offsetList = new VkDeviceSize[1]();
767 offsetCount = 1;
768 }
769
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600770 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600771 BoundCurrent = true;
772
773 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600774 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600775 }
776 }
777
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600778 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600779 static uint32_t BindIdGenerator;
780
781 bool BoundCurrent;
782 unsigned AttributeCount;
783 unsigned BindingCount;
784 uint32_t BindId;
785
786 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
787 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
788 VkVertexInputBindingDescription *VertexInputBindingDescription;
789 VkConstantBufferObj VulkanMemoryBuffer;
790};
791
792uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500793// ********************************************************************************************************************
794// ********************************************************************************************************************
795// ********************************************************************************************************************
796// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600797#if PARAMETER_VALIDATION_TESTS
798TEST_F(VkLayerTest, RequiredParameter) {
799 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
800 "pointer, array, and array count parameters");
801
802 ASSERT_NO_FATAL_FAILURE(InitState());
803
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600805 // Specify NULL for a pointer to a handle
806 // Expected to trigger an error with
807 // parameter_validation::validate_required_pointer
808 vkGetPhysicalDeviceFeatures(gpu(), NULL);
809 m_errorMonitor->VerifyFound();
810
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
812 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600813 // Specify NULL for pointer to array count
814 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600815 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600816 m_errorMonitor->VerifyFound();
817
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600819 // Specify 0 for a required array count
820 // Expected to trigger an error with parameter_validation::validate_array
821 VkViewport view_port = {};
822 m_commandBuffer->SetViewport(0, 0, &view_port);
823 m_errorMonitor->VerifyFound();
824
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600826 // Specify NULL for a required array
827 // Expected to trigger an error with parameter_validation::validate_array
828 m_commandBuffer->SetViewport(0, 1, NULL);
829 m_errorMonitor->VerifyFound();
830
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600832 // Specify VK_NULL_HANDLE for a required handle
833 // Expected to trigger an error with
834 // parameter_validation::validate_required_handle
835 vkUnmapMemory(device(), VK_NULL_HANDLE);
836 m_errorMonitor->VerifyFound();
837
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
839 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600840 // Specify VK_NULL_HANDLE for a required handle array entry
841 // Expected to trigger an error with
842 // parameter_validation::validate_required_handle_array
843 VkFence fence = VK_NULL_HANDLE;
844 vkResetFences(device(), 1, &fence);
845 m_errorMonitor->VerifyFound();
846
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600848 // Specify NULL for a required struct pointer
849 // Expected to trigger an error with
850 // parameter_validation::validate_struct_type
851 VkDeviceMemory memory = VK_NULL_HANDLE;
852 vkAllocateMemory(device(), NULL, NULL, &memory);
853 m_errorMonitor->VerifyFound();
854
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600856 // Specify 0 for a required VkFlags parameter
857 // Expected to trigger an error with parameter_validation::validate_flags
858 m_commandBuffer->SetStencilReference(0, 0);
859 m_errorMonitor->VerifyFound();
860
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600861 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 -0600862 // Specify 0 for a required VkFlags array entry
863 // Expected to trigger an error with
864 // parameter_validation::validate_flags_array
865 VkSemaphore semaphore = VK_NULL_HANDLE;
866 VkPipelineStageFlags stageFlags = 0;
867 VkSubmitInfo submitInfo = {};
868 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
869 submitInfo.waitSemaphoreCount = 1;
870 submitInfo.pWaitSemaphores = &semaphore;
871 submitInfo.pWaitDstStageMask = &stageFlags;
872 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
873 m_errorMonitor->VerifyFound();
874}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600875
Dustin Gravesfce74c02016-05-10 11:42:58 -0600876TEST_F(VkLayerTest, ReservedParameter) {
877 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
878
879 ASSERT_NO_FATAL_FAILURE(InitState());
880
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600881 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600882 // Specify 0 for a reserved VkFlags parameter
883 // Expected to trigger an error with
884 // parameter_validation::validate_reserved_flags
885 VkEvent event_handle = VK_NULL_HANDLE;
886 VkEventCreateInfo event_info = {};
887 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
888 event_info.flags = 1;
889 vkCreateEvent(device(), &event_info, NULL, &event_handle);
890 m_errorMonitor->VerifyFound();
891}
892
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600893TEST_F(VkLayerTest, InvalidStructSType) {
894 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
895 "structure's sType field");
896
897 ASSERT_NO_FATAL_FAILURE(InitState());
898
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600900 // Zero struct memory, effectively setting sType to
901 // VK_STRUCTURE_TYPE_APPLICATION_INFO
902 // Expected to trigger an error with
903 // parameter_validation::validate_struct_type
904 VkMemoryAllocateInfo alloc_info = {};
905 VkDeviceMemory memory = VK_NULL_HANDLE;
906 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
907 m_errorMonitor->VerifyFound();
908
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600910 // Zero struct memory, effectively setting sType to
911 // VK_STRUCTURE_TYPE_APPLICATION_INFO
912 // Expected to trigger an error with
913 // parameter_validation::validate_struct_type_array
914 VkSubmitInfo submit_info = {};
915 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
916 m_errorMonitor->VerifyFound();
917}
918
919TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600920 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600921
922 ASSERT_NO_FATAL_FAILURE(InitState());
923
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600925 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600926 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600927 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600928 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600929 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600930 // Zero-initialization will provide the correct sType
931 VkApplicationInfo app_info = {};
932 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
933 event_alloc_info.pNext = &app_info;
934 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
935 m_errorMonitor->VerifyFound();
936
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
938 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600939 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
940 // a function that has allowed pNext structure types and specify
941 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600942 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600943 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600944 VkMemoryAllocateInfo memory_alloc_info = {};
945 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
946 memory_alloc_info.pNext = &app_info;
947 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600949}
Dustin Graves5d33d532016-05-09 16:21:12 -0600950
951TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600952 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600953
954 ASSERT_NO_FATAL_FAILURE(InitState());
955
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
957 "range of the core VkFormat "
958 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600959 // Specify an invalid VkFormat value
960 // Expected to trigger an error with
961 // parameter_validation::validate_ranged_enum
962 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600963 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 m_errorMonitor->VerifyFound();
965
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600966 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 -0600967 // Specify an invalid VkFlags bitmask value
968 // Expected to trigger an error with parameter_validation::validate_flags
969 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600970 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
971 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 m_errorMonitor->VerifyFound();
973
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600974 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 -0600975 // Specify an invalid VkFlags array entry
976 // Expected to trigger an error with
977 // parameter_validation::validate_flags_array
978 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 VkSubmitInfo submit_info = {};
981 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
982 submit_info.waitSemaphoreCount = 1;
983 submit_info.pWaitSemaphores = &semaphore;
984 submit_info.pWaitDstStageMask = &stage_flags;
985 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
986 m_errorMonitor->VerifyFound();
987
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600989 // Specify an invalid VkBool32 value
990 // Expected to trigger a warning with
991 // parameter_validation::validate_bool32
992 VkSampler sampler = VK_NULL_HANDLE;
993 VkSamplerCreateInfo sampler_info = {};
994 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
995 sampler_info.pNext = NULL;
996 sampler_info.magFilter = VK_FILTER_NEAREST;
997 sampler_info.minFilter = VK_FILTER_NEAREST;
998 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
999 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1000 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1001 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1002 sampler_info.mipLodBias = 1.0;
1003 sampler_info.maxAnisotropy = 1;
1004 sampler_info.compareEnable = VK_FALSE;
1005 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1006 sampler_info.minLod = 1.0;
1007 sampler_info.maxLod = 1.0;
1008 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1009 sampler_info.unnormalizedCoordinates = VK_FALSE;
1010 // Not VK_TRUE or VK_FALSE
1011 sampler_info.anisotropyEnable = 3;
1012 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1013 m_errorMonitor->VerifyFound();
1014}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001015
1016TEST_F(VkLayerTest, FailedReturnValue) {
1017 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1018
1019 ASSERT_NO_FATAL_FAILURE(InitState());
1020
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001021 // Find an unsupported image format
1022 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1023 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1024 VkFormat format = static_cast<VkFormat>(f);
1025 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001026 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001027 unsupported = format;
1028 break;
1029 }
1030 }
1031
1032 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1034 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001035 // Specify an unsupported VkFormat value to generate a
1036 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1037 // Expected to trigger a warning from
1038 // parameter_validation::validate_result
1039 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001040 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1041 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001042 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1043 m_errorMonitor->VerifyFound();
1044 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001045}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001046
1047TEST_F(VkLayerTest, UpdateBufferAlignment) {
1048 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001049 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001050
1051 ASSERT_NO_FATAL_FAILURE(InitState());
1052
1053 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1054 vk_testing::Buffer buffer;
1055 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1056
1057 BeginCommandBuffer();
1058 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001060 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1061 m_errorMonitor->VerifyFound();
1062
1063 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is < 0
1069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001070 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001071 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1072 m_errorMonitor->VerifyFound();
1073
1074 // Introduce failure by using dataSize that is > 65536
1075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001076 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001077 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1078 m_errorMonitor->VerifyFound();
1079
1080 EndCommandBuffer();
1081}
1082
1083TEST_F(VkLayerTest, FillBufferAlignment) {
1084 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1085
1086 ASSERT_NO_FATAL_FAILURE(InitState());
1087
1088 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1089 vk_testing::Buffer buffer;
1090 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1091
1092 BeginCommandBuffer();
1093
1094 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001096 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1097 m_errorMonitor->VerifyFound();
1098
1099 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 EndCommandBuffer();
1110}
Dustin Graves40f35822016-06-23 11:12:53 -06001111
Cortd889ff92016-07-27 09:51:27 -07001112TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1113 VkResult err;
1114
1115 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001116 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001117
1118 ASSERT_NO_FATAL_FAILURE(InitState());
1119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1120
1121 std::vector<const char *> device_extension_names;
1122 auto features = m_device->phy().features();
1123 // Artificially disable support for non-solid fill modes
1124 features.fillModeNonSolid = false;
1125 // The sacrificial device object
1126 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1127
1128 VkRenderpassObj render_pass(&test_device);
1129
1130 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1131 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1132 pipeline_layout_ci.setLayoutCount = 0;
1133 pipeline_layout_ci.pSetLayouts = NULL;
1134
1135 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001136 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001137 ASSERT_VK_SUCCESS(err);
1138
1139 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1140 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1141 rs_ci.pNext = nullptr;
1142 rs_ci.lineWidth = 1.0f;
1143 rs_ci.rasterizerDiscardEnable = true;
1144
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001145 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1146 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001147
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001148 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1150 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001151 {
1152 VkPipelineObj pipe(&test_device);
1153 pipe.AddShader(&vs);
1154 pipe.AddShader(&fs);
1155 pipe.AddColorAttachment();
1156 // Introduce failure by setting unsupported polygon mode
1157 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1158 pipe.SetRasterization(&rs_ci);
1159 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1160 }
1161 m_errorMonitor->VerifyFound();
1162
1163 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1165 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001166 {
1167 VkPipelineObj pipe(&test_device);
1168 pipe.AddShader(&vs);
1169 pipe.AddShader(&fs);
1170 pipe.AddColorAttachment();
1171 // Introduce failure by setting unsupported polygon mode
1172 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1173 pipe.SetRasterization(&rs_ci);
1174 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1175 }
1176 m_errorMonitor->VerifyFound();
1177
Cortd889ff92016-07-27 09:51:27 -07001178 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1179}
1180
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001181#endif // PARAMETER_VALIDATION_TESTS
1182
Tobin Ehlis0788f522015-05-26 16:11:58 -06001183#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001184#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001185TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001186{
1187 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001188 VkFenceCreateInfo fenceInfo = {};
1189 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1190 fenceInfo.pNext = NULL;
1191 fenceInfo.flags = 0;
1192
Mike Weiblencce7ec72016-10-17 19:33:05 -06001193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001194
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001195 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001196
1197 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1198 vk_testing::Buffer buffer;
1199 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200
Tony Barbourfe3351b2015-07-28 10:17:20 -06001201 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001202 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001203 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001204
1205 testFence.init(*m_device, fenceInfo);
1206
1207 // Bypass framework since it does the waits automatically
1208 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001209 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001210 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1211 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001212 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001213 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001214 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001215 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001216 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001219
1220 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001221 ASSERT_VK_SUCCESS( err );
1222
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001223 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001224 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001225
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001226 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001227}
1228
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230{
1231 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232 VkFenceCreateInfo fenceInfo = {};
1233 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1234 fenceInfo.pNext = NULL;
1235 fenceInfo.flags = 0;
1236
Mike Weiblencce7ec72016-10-17 19:33:05 -06001237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001238
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_NO_FATAL_FAILURE(InitState());
1240 ASSERT_NO_FATAL_FAILURE(InitViewport());
1241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1242
Tony Barbourfe3351b2015-07-28 10:17:20 -06001243 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001244 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001245 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001246
1247 testFence.init(*m_device, fenceInfo);
1248
1249 // Bypass framework since it does the waits automatically
1250 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001251 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001252 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1253 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001254 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001255 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001256 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001257 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001258 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001261
1262 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001263 ASSERT_VK_SUCCESS( err );
1264
Jon Ashburnf19916e2016-01-11 13:12:43 -07001265 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001266 VkCommandBufferBeginInfo info = {};
1267 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1268 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001269 info.renderPass = VK_NULL_HANDLE;
1270 info.subpass = 0;
1271 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001272 info.occlusionQueryEnable = VK_FALSE;
1273 info.queryFlags = 0;
1274 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001275
1276 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001277 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001278
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001279 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001280}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001281#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001282
Tobin Ehlisf11be982016-05-11 13:52:53 -06001283TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1284 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1285 "buffer and image to memory such that they will alias.");
1286 VkResult err;
1287 bool pass;
1288 ASSERT_NO_FATAL_FAILURE(InitState());
1289
Tobin Ehlis077ded32016-05-12 17:39:13 -06001290 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001291 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001292 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001293 VkDeviceMemory mem; // buffer will be bound first
1294 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296
1297 VkBufferCreateInfo buf_info = {};
1298 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1299 buf_info.pNext = NULL;
1300 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1301 buf_info.size = 256;
1302 buf_info.queueFamilyIndexCount = 0;
1303 buf_info.pQueueFamilyIndices = NULL;
1304 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1305 buf_info.flags = 0;
1306 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1307 ASSERT_VK_SUCCESS(err);
1308
Tobin Ehlis077ded32016-05-12 17:39:13 -06001309 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001310
1311 VkImageCreateInfo image_create_info = {};
1312 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1313 image_create_info.pNext = NULL;
1314 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1315 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1316 image_create_info.extent.width = 64;
1317 image_create_info.extent.height = 64;
1318 image_create_info.extent.depth = 1;
1319 image_create_info.mipLevels = 1;
1320 image_create_info.arrayLayers = 1;
1321 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001322 // Image tiling must be optimal to trigger error when aliasing linear buffer
1323 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001324 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1325 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1326 image_create_info.queueFamilyIndexCount = 0;
1327 image_create_info.pQueueFamilyIndices = NULL;
1328 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1329 image_create_info.flags = 0;
1330
Tobin Ehlisf11be982016-05-11 13:52:53 -06001331 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1332 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001333 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1334 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001335
Tobin Ehlis077ded32016-05-12 17:39:13 -06001336 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1337
1338 VkMemoryAllocateInfo alloc_info = {};
1339 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1340 alloc_info.pNext = NULL;
1341 alloc_info.memoryTypeIndex = 0;
1342 // Ensure memory is big enough for both bindings
1343 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001344 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1345 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001346 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001347 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001348 vkDestroyImage(m_device->device(), image, NULL);
1349 return;
1350 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001351 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1352 ASSERT_VK_SUCCESS(err);
1353 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1354 ASSERT_VK_SUCCESS(err);
1355
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001357 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001358 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1359 m_errorMonitor->VerifyFound();
1360
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001361 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // aliasing buffer2
1363 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1364 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001365 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1366 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001367 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001368 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001370 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001371 m_errorMonitor->VerifyFound();
1372
1373 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001374 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001375 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001376 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001377 vkFreeMemory(m_device->device(), mem, NULL);
1378 vkFreeMemory(m_device->device(), mem_img, NULL);
1379}
1380
Tobin Ehlis35372522016-05-12 08:32:31 -06001381TEST_F(VkLayerTest, InvalidMemoryMapping) {
1382 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1383 VkResult err;
1384 bool pass;
1385 ASSERT_NO_FATAL_FAILURE(InitState());
1386
1387 VkBuffer buffer;
1388 VkDeviceMemory mem;
1389 VkMemoryRequirements mem_reqs;
1390
1391 VkBufferCreateInfo buf_info = {};
1392 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1393 buf_info.pNext = NULL;
1394 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1395 buf_info.size = 256;
1396 buf_info.queueFamilyIndexCount = 0;
1397 buf_info.pQueueFamilyIndices = NULL;
1398 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1399 buf_info.flags = 0;
1400 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1401 ASSERT_VK_SUCCESS(err);
1402
1403 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1404 VkMemoryAllocateInfo alloc_info = {};
1405 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1406 alloc_info.pNext = NULL;
1407 alloc_info.memoryTypeIndex = 0;
1408
1409 // Ensure memory is big enough for both bindings
1410 static const VkDeviceSize allocation_size = 0x10000;
1411 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001412 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 -06001413 if (!pass) {
1414 vkDestroyBuffer(m_device->device(), buffer, NULL);
1415 return;
1416 }
1417 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1418 ASSERT_VK_SUCCESS(err);
1419
1420 uint8_t *pData;
1421 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001422 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 -06001423 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1424 m_errorMonitor->VerifyFound();
1425 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001426 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001427 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1429 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1430 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001431 m_errorMonitor->VerifyFound();
1432
1433 // Unmap the memory to avoid re-map error
1434 vkUnmapMemory(m_device->device(), mem);
1435 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1437 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1438 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001439 m_errorMonitor->VerifyFound();
1440 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1442 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001443 m_errorMonitor->VerifyFound();
1444 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001446 vkUnmapMemory(m_device->device(), mem);
1447 m_errorMonitor->VerifyFound();
1448 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001449 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001450 ASSERT_VK_SUCCESS(err);
1451 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001452 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001453 mmr.memory = mem;
1454 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1457 m_errorMonitor->VerifyFound();
1458 // Now flush range that oversteps mapped range
1459 vkUnmapMemory(m_device->device(), mem);
1460 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1461 ASSERT_VK_SUCCESS(err);
1462 mmr.offset = 16;
1463 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001465 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1466 m_errorMonitor->VerifyFound();
1467
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001468 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1469 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 if (!pass) {
1471 vkFreeMemory(m_device->device(), mem, NULL);
1472 vkDestroyBuffer(m_device->device(), buffer, NULL);
1473 return;
1474 }
1475 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1476 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1477
1478 vkDestroyBuffer(m_device->device(), buffer, NULL);
1479 vkFreeMemory(m_device->device(), mem, NULL);
1480}
1481
Ian Elliott1c32c772016-04-28 14:47:13 -06001482TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1483 VkResult err;
1484 bool pass;
1485
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001486 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1487 // following declaration (which is temporarily being moved below):
1488 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001489 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1490 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1491 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001492 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001493 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001494 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001495
1496 ASSERT_NO_FATAL_FAILURE(InitState());
1497
Ian Elliott3f06ce52016-04-29 14:46:21 -06001498#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1499#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1500 // Use the functions from the VK_KHR_android_surface extension without
1501 // enabling that extension:
1502
1503 // Create a surface:
1504 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1506 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001507 pass = (err != VK_SUCCESS);
1508 ASSERT_TRUE(pass);
1509 m_errorMonitor->VerifyFound();
1510#endif // VK_USE_PLATFORM_ANDROID_KHR
1511
Ian Elliott3f06ce52016-04-29 14:46:21 -06001512#if defined(VK_USE_PLATFORM_MIR_KHR)
1513 // Use the functions from the VK_KHR_mir_surface extension without enabling
1514 // that extension:
1515
1516 // Create a surface:
1517 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001519 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1520 pass = (err != VK_SUCCESS);
1521 ASSERT_TRUE(pass);
1522 m_errorMonitor->VerifyFound();
1523
1524 // Tell whether an mir_connection supports presentation:
1525 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1527 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001528 m_errorMonitor->VerifyFound();
1529#endif // VK_USE_PLATFORM_MIR_KHR
1530
Ian Elliott3f06ce52016-04-29 14:46:21 -06001531#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1532 // Use the functions from the VK_KHR_wayland_surface extension without
1533 // enabling that extension:
1534
1535 // Create a surface:
1536 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1538 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001539 pass = (err != VK_SUCCESS);
1540 ASSERT_TRUE(pass);
1541 m_errorMonitor->VerifyFound();
1542
1543 // Tell whether an wayland_display supports presentation:
1544 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1546 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001547 m_errorMonitor->VerifyFound();
1548#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001549#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550
Ian Elliott3f06ce52016-04-29 14:46:21 -06001551#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001552 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1553 // TO NON-LINUX PLATFORMS:
1554 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555 // Use the functions from the VK_KHR_win32_surface extension without
1556 // enabling that extension:
1557
1558 // Create a surface:
1559 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1561 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001562 pass = (err != VK_SUCCESS);
1563 ASSERT_TRUE(pass);
1564 m_errorMonitor->VerifyFound();
1565
1566 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001568 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001569 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001570// Set this (for now, until all platforms are supported and tested):
1571#define NEED_TO_TEST_THIS_ON_PLATFORM
1572#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001573
Ian Elliott1c32c772016-04-28 14:47:13 -06001574#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001575 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1576 // TO NON-LINUX PLATFORMS:
1577 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001578 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1579 // that extension:
1580
1581 // Create a surface:
1582 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001584 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1585 pass = (err != VK_SUCCESS);
1586 ASSERT_TRUE(pass);
1587 m_errorMonitor->VerifyFound();
1588
1589 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001590 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001591 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1593 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001594 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001595// Set this (for now, until all platforms are supported and tested):
1596#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001597#endif // VK_USE_PLATFORM_XCB_KHR
1598
Ian Elliott12630812016-04-29 14:35:43 -06001599#if defined(VK_USE_PLATFORM_XLIB_KHR)
1600 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1601 // that extension:
1602
1603 // Create a surface:
1604 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001606 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1607 pass = (err != VK_SUCCESS);
1608 ASSERT_TRUE(pass);
1609 m_errorMonitor->VerifyFound();
1610
1611 // Tell whether an Xlib VisualID supports presentation:
1612 Display *dpy = NULL;
1613 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001615 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1616 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001617// Set this (for now, until all platforms are supported and tested):
1618#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001619#endif // VK_USE_PLATFORM_XLIB_KHR
1620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001621// Use the functions from the VK_KHR_surface extension without enabling
1622// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001623
Ian Elliott489eec02016-05-05 14:12:44 -06001624#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001625 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001627 vkDestroySurfaceKHR(instance(), surface, NULL);
1628 m_errorMonitor->VerifyFound();
1629
1630 // Check if surface supports presentation:
1631 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001633 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1634 pass = (err != VK_SUCCESS);
1635 ASSERT_TRUE(pass);
1636 m_errorMonitor->VerifyFound();
1637
1638 // Check surface capabilities:
1639 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1641 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001642 pass = (err != VK_SUCCESS);
1643 ASSERT_TRUE(pass);
1644 m_errorMonitor->VerifyFound();
1645
1646 // Check surface formats:
1647 uint32_t format_count = 0;
1648 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1650 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001651 pass = (err != VK_SUCCESS);
1652 ASSERT_TRUE(pass);
1653 m_errorMonitor->VerifyFound();
1654
1655 // Check surface present modes:
1656 uint32_t present_mode_count = 0;
1657 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1659 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001660 pass = (err != VK_SUCCESS);
1661 ASSERT_TRUE(pass);
1662 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001663#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001664
Ian Elliott1c32c772016-04-28 14:47:13 -06001665 // Use the functions from the VK_KHR_swapchain extension without enabling
1666 // that extension:
1667
1668 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001670 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1671 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001672 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001673 pass = (err != VK_SUCCESS);
1674 ASSERT_TRUE(pass);
1675 m_errorMonitor->VerifyFound();
1676
1677 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1679 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001680 pass = (err != VK_SUCCESS);
1681 ASSERT_TRUE(pass);
1682 m_errorMonitor->VerifyFound();
1683
Chris Forbeseb7d5502016-09-13 18:19:21 +12001684 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1685 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1686 VkFence fence;
1687 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1688
Ian Elliott1c32c772016-04-28 14:47:13 -06001689 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001691 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001692 pass = (err != VK_SUCCESS);
1693 ASSERT_TRUE(pass);
1694 m_errorMonitor->VerifyFound();
1695
Chris Forbeseb7d5502016-09-13 18:19:21 +12001696 vkDestroyFence(m_device->device(), fence, nullptr);
1697
Ian Elliott1c32c772016-04-28 14:47:13 -06001698 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001699 //
1700 // NOTE: Currently can't test this because a real swapchain is needed (as
1701 // opposed to the fake one we created) in order for the layer to lookup the
1702 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001703
1704 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001706 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1707 m_errorMonitor->VerifyFound();
1708}
1709
Karl Schultz6addd812016-02-02 17:17:23 -07001710TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1711 VkResult err;
1712 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1715 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001716
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001717 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001718
1719 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001720 VkImage image;
1721 VkDeviceMemory mem;
1722 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001723
Karl Schultz6addd812016-02-02 17:17:23 -07001724 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1725 const int32_t tex_width = 32;
1726 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001727
Tony Barboureb254902015-07-15 12:50:33 -06001728 VkImageCreateInfo image_create_info = {};
1729 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001730 image_create_info.pNext = NULL;
1731 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1732 image_create_info.format = tex_format;
1733 image_create_info.extent.width = tex_width;
1734 image_create_info.extent.height = tex_height;
1735 image_create_info.extent.depth = 1;
1736 image_create_info.mipLevels = 1;
1737 image_create_info.arrayLayers = 1;
1738 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1739 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1740 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1741 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001742 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001743
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001744 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001745 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001746 mem_alloc.pNext = NULL;
1747 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001748
Chia-I Wuf7458c52015-10-26 21:10:41 +08001749 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001750 ASSERT_VK_SUCCESS(err);
1751
Karl Schultz6addd812016-02-02 17:17:23 -07001752 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001753
Mark Lobodzinski23065352015-05-29 09:32:35 -05001754 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001756 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 -07001757 if (!pass) { // If we can't find any unmappable memory this test doesn't
1758 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001759 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001760 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001761 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001762
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001763 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001764 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001765 ASSERT_VK_SUCCESS(err);
1766
1767 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001768 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001769 ASSERT_VK_SUCCESS(err);
1770
1771 // Map memory as if to initialize the image
1772 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001773 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001775 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001776
Chia-I Wuf7458c52015-10-26 21:10:41 +08001777 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001778 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001779}
1780
Karl Schultz6addd812016-02-02 17:17:23 -07001781TEST_F(VkLayerTest, RebindMemory) {
1782 VkResult err;
1783 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001786
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001787 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001788
1789 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001790 VkImage image;
1791 VkDeviceMemory mem1;
1792 VkDeviceMemory mem2;
1793 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001794
Karl Schultz6addd812016-02-02 17:17:23 -07001795 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1796 const int32_t tex_width = 32;
1797 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001798
Tony Barboureb254902015-07-15 12:50:33 -06001799 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001800 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1801 image_create_info.pNext = NULL;
1802 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1803 image_create_info.format = tex_format;
1804 image_create_info.extent.width = tex_width;
1805 image_create_info.extent.height = tex_height;
1806 image_create_info.extent.depth = 1;
1807 image_create_info.mipLevels = 1;
1808 image_create_info.arrayLayers = 1;
1809 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1810 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1811 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1812 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001813
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001814 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001815 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1816 mem_alloc.pNext = NULL;
1817 mem_alloc.allocationSize = 0;
1818 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001819
Karl Schultz6addd812016-02-02 17:17:23 -07001820 // Introduce failure, do NOT set memProps to
1821 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001822 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001823 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001824 ASSERT_VK_SUCCESS(err);
1825
Karl Schultz6addd812016-02-02 17:17:23 -07001826 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001827
1828 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001829 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001830 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001831
1832 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001833 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001834 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001835 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001836 ASSERT_VK_SUCCESS(err);
1837
1838 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001839 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001840 ASSERT_VK_SUCCESS(err);
1841
Karl Schultz6addd812016-02-02 17:17:23 -07001842 // Introduce validation failure, try to bind a different memory object to
1843 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001844 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001845
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001846 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001847
Chia-I Wuf7458c52015-10-26 21:10:41 +08001848 vkDestroyImage(m_device->device(), image, NULL);
1849 vkFreeMemory(m_device->device(), mem1, NULL);
1850 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001851}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001852
Karl Schultz6addd812016-02-02 17:17:23 -07001853TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001854 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1857 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001858
1859 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001860 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1861 fenceInfo.pNext = NULL;
1862 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001863
Tony Barbour300a6082015-04-07 13:44:53 -06001864 ASSERT_NO_FATAL_FAILURE(InitState());
1865 ASSERT_NO_FATAL_FAILURE(InitViewport());
1866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1867
Tony Barbourfe3351b2015-07-28 10:17:20 -06001868 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001870 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001871
1872 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001873
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001874 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001875 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1876 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001877 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001878 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001879 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001880 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001881 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001882 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001883 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001884
1885 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001886 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001887
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001888 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001889}
Chris Forbes4e44c912016-06-16 10:20:00 +12001890
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001891TEST_F(VkLayerTest, InvalidUsageBits) {
1892 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1893 "Initialize buffer with wrong usage then perform copy expecting errors "
1894 "from both the image and the buffer (2 calls)");
1895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001896
1897 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001898 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001899 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001900 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001901 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001902
Tony Barbourf92621a2016-05-02 14:28:12 -06001903 VkImageView dsv;
1904 VkImageViewCreateInfo dsvci = {};
1905 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1906 dsvci.image = image.handle();
1907 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1908 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1909 dsvci.subresourceRange.layerCount = 1;
1910 dsvci.subresourceRange.baseMipLevel = 0;
1911 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001912 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001913
Tony Barbourf92621a2016-05-02 14:28:12 -06001914 // Create a view with depth / stencil aspect for image with different usage
1915 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001916
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001917 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001918
1919 // Initialize buffer with TRANSFER_DST usage
1920 vk_testing::Buffer buffer;
1921 VkMemoryPropertyFlags reqs = 0;
1922 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1923 VkBufferImageCopy region = {};
1924 region.bufferRowLength = 128;
1925 region.bufferImageHeight = 128;
1926 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1927 region.imageSubresource.layerCount = 1;
1928 region.imageExtent.height = 16;
1929 region.imageExtent.width = 16;
1930 region.imageExtent.depth = 1;
1931
Tony Barbourf92621a2016-05-02 14:28:12 -06001932 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1933 // TRANSFER_DST
1934 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001935
Chris Forbesda581202016-10-06 18:25:26 +13001936 // two separate errors from this call:
1937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1939
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001940 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1941 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001942 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001943}
Tony Barbour75d79f02016-08-30 09:39:07 -06001944
Tony Barbour75d79f02016-08-30 09:39:07 -06001945
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001946#endif // MEM_TRACKER_TESTS
1947
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001948#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001949
1950TEST_F(VkLayerTest, LeakAnObject) {
1951 VkResult err;
1952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001953 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001954
1955 // Note that we have to create a new device since destroying the
1956 // framework's device causes Teardown() to fail and just calling Teardown
1957 // will destroy the errorMonitor.
1958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001960
1961 ASSERT_NO_FATAL_FAILURE(InitState());
1962
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001963 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001964 std::vector<VkDeviceQueueCreateInfo> queue_info;
1965 queue_info.reserve(queue_props.size());
1966 std::vector<std::vector<float>> queue_priorities;
1967 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
1968 VkDeviceQueueCreateInfo qi = {};
1969 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
1970 qi.pNext = NULL;
1971 qi.queueFamilyIndex = i;
1972 qi.queueCount = queue_props[i].queueCount;
1973 queue_priorities.emplace_back(qi.queueCount, 0.0f);
1974 qi.pQueuePriorities = queue_priorities[i].data();
1975 queue_info.push_back(qi);
1976 }
1977
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001978 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001979
1980 // The sacrificial device object
1981 VkDevice testDevice;
1982 VkDeviceCreateInfo device_create_info = {};
1983 auto features = m_device->phy().features();
1984 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
1985 device_create_info.pNext = NULL;
1986 device_create_info.queueCreateInfoCount = queue_info.size();
1987 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06001988 device_create_info.enabledLayerCount = 0;
1989 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001990 device_create_info.pEnabledFeatures = &features;
1991 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
1992 ASSERT_VK_SUCCESS(err);
1993
1994 VkFence fence;
1995 VkFenceCreateInfo fence_create_info = {};
1996 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1997 fence_create_info.pNext = NULL;
1998 fence_create_info.flags = 0;
1999 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2000 ASSERT_VK_SUCCESS(err);
2001
2002 // Induce failure by not calling vkDestroyFence
2003 vkDestroyDevice(testDevice, NULL);
2004 m_errorMonitor->VerifyFound();
2005}
2006
2007TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2008
2009 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2010 "attempt to delete them from another.");
2011
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002013
Cody Northropc31a84f2016-08-22 10:41:47 -06002014 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002015 VkCommandPool command_pool_one;
2016 VkCommandPool command_pool_two;
2017
2018 VkCommandPoolCreateInfo pool_create_info{};
2019 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2020 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2021 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2022
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002023 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002025 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002026
2027 VkCommandBuffer command_buffer[9];
2028 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002029 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002030 command_buffer_allocate_info.commandPool = command_pool_one;
2031 command_buffer_allocate_info.commandBufferCount = 9;
2032 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002033 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002034
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002035 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002036
2037 m_errorMonitor->VerifyFound();
2038
2039 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2040 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2041}
2042
2043TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2044 VkResult err;
2045
2046 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002047 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002048
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002050
2051 ASSERT_NO_FATAL_FAILURE(InitState());
2052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2053
2054 VkDescriptorPoolSize ds_type_count = {};
2055 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2056 ds_type_count.descriptorCount = 1;
2057
2058 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2059 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2060 ds_pool_ci.pNext = NULL;
2061 ds_pool_ci.flags = 0;
2062 ds_pool_ci.maxSets = 1;
2063 ds_pool_ci.poolSizeCount = 1;
2064 ds_pool_ci.pPoolSizes = &ds_type_count;
2065
2066 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002067 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002068 ASSERT_VK_SUCCESS(err);
2069
2070 // Create a second descriptor pool
2071 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002072 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002073 ASSERT_VK_SUCCESS(err);
2074
2075 VkDescriptorSetLayoutBinding dsl_binding = {};
2076 dsl_binding.binding = 0;
2077 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2078 dsl_binding.descriptorCount = 1;
2079 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2080 dsl_binding.pImmutableSamplers = NULL;
2081
2082 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2083 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2084 ds_layout_ci.pNext = NULL;
2085 ds_layout_ci.bindingCount = 1;
2086 ds_layout_ci.pBindings = &dsl_binding;
2087
2088 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002089 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002090 ASSERT_VK_SUCCESS(err);
2091
2092 VkDescriptorSet descriptorSet;
2093 VkDescriptorSetAllocateInfo alloc_info = {};
2094 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2095 alloc_info.descriptorSetCount = 1;
2096 alloc_info.descriptorPool = ds_pool_one;
2097 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002098 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002099 ASSERT_VK_SUCCESS(err);
2100
2101 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2102
2103 m_errorMonitor->VerifyFound();
2104
2105 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2106 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2107 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2108}
2109
2110TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002112
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002113 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002114
2115 ASSERT_NO_FATAL_FAILURE(InitState());
2116
2117 // Pass bogus handle into GetImageMemoryRequirements
2118 VkMemoryRequirements mem_reqs;
2119 uint64_t fakeImageHandle = 0xCADECADE;
2120 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2121
2122 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2123
2124 m_errorMonitor->VerifyFound();
2125}
2126
Karl Schultz6addd812016-02-02 17:17:23 -07002127TEST_F(VkLayerTest, PipelineNotBound) {
2128 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002130 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002133
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002134 ASSERT_NO_FATAL_FAILURE(InitState());
2135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002136
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002137 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002138 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2139 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002140
2141 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002142 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2143 ds_pool_ci.pNext = NULL;
2144 ds_pool_ci.maxSets = 1;
2145 ds_pool_ci.poolSizeCount = 1;
2146 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002147
2148 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002149 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002150 ASSERT_VK_SUCCESS(err);
2151
2152 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002153 dsl_binding.binding = 0;
2154 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2155 dsl_binding.descriptorCount = 1;
2156 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2157 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002158
2159 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002160 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2161 ds_layout_ci.pNext = NULL;
2162 ds_layout_ci.bindingCount = 1;
2163 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002164
2165 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002166 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002167 ASSERT_VK_SUCCESS(err);
2168
2169 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002170 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002171 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002172 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002173 alloc_info.descriptorPool = ds_pool;
2174 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002175 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002176 ASSERT_VK_SUCCESS(err);
2177
2178 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002179 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2180 pipeline_layout_ci.pNext = NULL;
2181 pipeline_layout_ci.setLayoutCount = 1;
2182 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002183
2184 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002185 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002186 ASSERT_VK_SUCCESS(err);
2187
Mark Youngad779052016-01-06 14:26:04 -07002188 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002189
2190 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002191 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002192
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002193 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002194
Chia-I Wuf7458c52015-10-26 21:10:41 +08002195 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2196 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2197 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002198}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002199
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002200TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2201 VkResult err;
2202
2203 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2204 "during bind[Buffer|Image]Memory time");
2205
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002206 ASSERT_NO_FATAL_FAILURE(InitState());
2207
2208 // Create an image, allocate memory, set a bad typeIndex and then try to
2209 // bind it
2210 VkImage image;
2211 VkDeviceMemory mem;
2212 VkMemoryRequirements mem_reqs;
2213 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2214 const int32_t tex_width = 32;
2215 const int32_t tex_height = 32;
2216
2217 VkImageCreateInfo image_create_info = {};
2218 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2219 image_create_info.pNext = NULL;
2220 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2221 image_create_info.format = tex_format;
2222 image_create_info.extent.width = tex_width;
2223 image_create_info.extent.height = tex_height;
2224 image_create_info.extent.depth = 1;
2225 image_create_info.mipLevels = 1;
2226 image_create_info.arrayLayers = 1;
2227 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2228 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2229 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2230 image_create_info.flags = 0;
2231
2232 VkMemoryAllocateInfo mem_alloc = {};
2233 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2234 mem_alloc.pNext = NULL;
2235 mem_alloc.allocationSize = 0;
2236 mem_alloc.memoryTypeIndex = 0;
2237
2238 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2239 ASSERT_VK_SUCCESS(err);
2240
2241 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2242 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002243
2244 // Introduce Failure, select invalid TypeIndex
2245 VkPhysicalDeviceMemoryProperties memory_info;
2246
2247 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2248 unsigned int i;
2249 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2250 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2251 mem_alloc.memoryTypeIndex = i;
2252 break;
2253 }
2254 }
2255 if (i >= memory_info.memoryTypeCount) {
2256 printf("No invalid memory type index could be found; skipped.\n");
2257 vkDestroyImage(m_device->device(), image, NULL);
2258 return;
2259 }
2260
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002261 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 -06002262
2263 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2264 ASSERT_VK_SUCCESS(err);
2265
2266 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2267 (void)err;
2268
2269 m_errorMonitor->VerifyFound();
2270
2271 vkDestroyImage(m_device->device(), image, NULL);
2272 vkFreeMemory(m_device->device(), mem, NULL);
2273}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002274
Karl Schultz6addd812016-02-02 17:17:23 -07002275TEST_F(VkLayerTest, BindInvalidMemory) {
2276 VkResult err;
2277 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002280
Tobin Ehlisec598302015-09-15 15:02:17 -06002281 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002282
2283 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002284 VkImage image;
2285 VkDeviceMemory mem;
2286 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002287
Karl Schultz6addd812016-02-02 17:17:23 -07002288 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2289 const int32_t tex_width = 32;
2290 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002291
2292 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002293 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2294 image_create_info.pNext = NULL;
2295 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2296 image_create_info.format = tex_format;
2297 image_create_info.extent.width = tex_width;
2298 image_create_info.extent.height = tex_height;
2299 image_create_info.extent.depth = 1;
2300 image_create_info.mipLevels = 1;
2301 image_create_info.arrayLayers = 1;
2302 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2303 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2304 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2305 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002306
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002307 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002308 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2309 mem_alloc.pNext = NULL;
2310 mem_alloc.allocationSize = 0;
2311 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002312
Chia-I Wuf7458c52015-10-26 21:10:41 +08002313 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002314 ASSERT_VK_SUCCESS(err);
2315
Karl Schultz6addd812016-02-02 17:17:23 -07002316 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002317
2318 mem_alloc.allocationSize = mem_reqs.size;
2319
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002320 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002321 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002322
2323 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002324 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002325 ASSERT_VK_SUCCESS(err);
2326
2327 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002328 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002329
2330 // Try to bind free memory that has been freed
2331 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2332 // This may very well return an error.
2333 (void)err;
2334
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002335 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002336
Chia-I Wuf7458c52015-10-26 21:10:41 +08002337 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002338}
2339
Karl Schultz6addd812016-02-02 17:17:23 -07002340TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2341 VkResult err;
2342 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002343
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002345
Tobin Ehlisec598302015-09-15 15:02:17 -06002346 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002347
Karl Schultz6addd812016-02-02 17:17:23 -07002348 // Create an image object, allocate memory, destroy the object and then try
2349 // to bind it
2350 VkImage image;
2351 VkDeviceMemory mem;
2352 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002353
Karl Schultz6addd812016-02-02 17:17:23 -07002354 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2355 const int32_t tex_width = 32;
2356 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002357
2358 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002359 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2360 image_create_info.pNext = NULL;
2361 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2362 image_create_info.format = tex_format;
2363 image_create_info.extent.width = tex_width;
2364 image_create_info.extent.height = tex_height;
2365 image_create_info.extent.depth = 1;
2366 image_create_info.mipLevels = 1;
2367 image_create_info.arrayLayers = 1;
2368 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2369 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2370 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2371 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002372
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002373 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002374 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2375 mem_alloc.pNext = NULL;
2376 mem_alloc.allocationSize = 0;
2377 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002378
Chia-I Wuf7458c52015-10-26 21:10:41 +08002379 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002380 ASSERT_VK_SUCCESS(err);
2381
Karl Schultz6addd812016-02-02 17:17:23 -07002382 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002383
2384 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002385 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002386 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002387
2388 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002389 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002390 ASSERT_VK_SUCCESS(err);
2391
2392 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002393 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002394 ASSERT_VK_SUCCESS(err);
2395
2396 // Now Try to bind memory to this destroyed object
2397 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2398 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002399 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002400
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002401 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002402
Chia-I Wuf7458c52015-10-26 21:10:41 +08002403 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002404}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002405
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002406#endif // OBJ_TRACKER_TESTS
2407
Tobin Ehlis0788f522015-05-26 16:11:58 -06002408#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002409
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002410TEST_F(VkLayerTest, ImageSampleCounts) {
2411
2412 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2413 "validation errors.");
2414 ASSERT_NO_FATAL_FAILURE(InitState());
2415
2416 VkMemoryPropertyFlags reqs = 0;
2417 VkImageCreateInfo image_create_info = {};
2418 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2419 image_create_info.pNext = NULL;
2420 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2421 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2422 image_create_info.extent.width = 256;
2423 image_create_info.extent.height = 256;
2424 image_create_info.extent.depth = 1;
2425 image_create_info.mipLevels = 1;
2426 image_create_info.arrayLayers = 1;
2427 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2428 image_create_info.flags = 0;
2429
2430 VkImageBlit blit_region = {};
2431 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2432 blit_region.srcSubresource.baseArrayLayer = 0;
2433 blit_region.srcSubresource.layerCount = 1;
2434 blit_region.srcSubresource.mipLevel = 0;
2435 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2436 blit_region.dstSubresource.baseArrayLayer = 0;
2437 blit_region.dstSubresource.layerCount = 1;
2438 blit_region.dstSubresource.mipLevel = 0;
2439
2440 // Create two images, the source with sampleCount = 2, and attempt to blit
2441 // between them
2442 {
2443 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002444 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002445 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002446 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002447 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002448 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002449 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002450 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002451 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2453 "of VK_SAMPLE_COUNT_2_BIT but "
2454 "must be VK_SAMPLE_COUNT_1_BIT");
2455 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2456 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002457 m_errorMonitor->VerifyFound();
2458 m_commandBuffer->EndCommandBuffer();
2459 }
2460
2461 // Create two images, the dest with sampleCount = 4, and attempt to blit
2462 // between them
2463 {
2464 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002465 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002466 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002467 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002468 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002469 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002470 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002471 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002472 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2474 "of VK_SAMPLE_COUNT_4_BIT but "
2475 "must be VK_SAMPLE_COUNT_1_BIT");
2476 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2477 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002478 m_errorMonitor->VerifyFound();
2479 m_commandBuffer->EndCommandBuffer();
2480 }
2481
2482 VkBufferImageCopy copy_region = {};
2483 copy_region.bufferRowLength = 128;
2484 copy_region.bufferImageHeight = 128;
2485 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2486 copy_region.imageSubresource.layerCount = 1;
2487 copy_region.imageExtent.height = 64;
2488 copy_region.imageExtent.width = 64;
2489 copy_region.imageExtent.depth = 1;
2490
2491 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2492 // buffer to image
2493 {
2494 vk_testing::Buffer src_buffer;
2495 VkMemoryPropertyFlags reqs = 0;
2496 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2497 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002498 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002499 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002500 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002501 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2503 "of VK_SAMPLE_COUNT_8_BIT but "
2504 "must be VK_SAMPLE_COUNT_1_BIT");
2505 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2506 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002507 m_errorMonitor->VerifyFound();
2508 m_commandBuffer->EndCommandBuffer();
2509 }
2510
2511 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2512 // image to buffer
2513 {
2514 vk_testing::Buffer dst_buffer;
2515 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2516 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002517 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002518 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002519 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002520 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2522 "of VK_SAMPLE_COUNT_2_BIT but "
2523 "must be VK_SAMPLE_COUNT_1_BIT");
2524 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002525 dst_buffer.handle(), 1, &copy_region);
2526 m_errorMonitor->VerifyFound();
2527 m_commandBuffer->EndCommandBuffer();
2528 }
2529}
2530
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002531TEST_F(VkLayerTest, BlitImageFormats) {
2532
2533 // Image blit with mismatched formats
2534 const char * expected_message =
2535 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2536 " the other one must also have signed/unsigned integer format";
2537
2538 ASSERT_NO_FATAL_FAILURE(InitState());
2539
2540 VkImageObj src_image(m_device);
2541 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2542 VkImageObj dst_image(m_device);
2543 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2544 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002545 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 -06002546
2547 VkImageBlit blitRegion = {};
2548 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2549 blitRegion.srcSubresource.baseArrayLayer = 0;
2550 blitRegion.srcSubresource.layerCount = 1;
2551 blitRegion.srcSubresource.mipLevel = 0;
2552 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2553 blitRegion.dstSubresource.baseArrayLayer = 0;
2554 blitRegion.dstSubresource.layerCount = 1;
2555 blitRegion.dstSubresource.mipLevel = 0;
2556
2557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2558
2559 // Unsigned int vs not an int
2560 BeginCommandBuffer();
2561 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2562 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2563
2564 m_errorMonitor->VerifyFound();
2565
2566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2567
2568 // Unsigned int vs signed int
2569 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2570 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2571
2572 m_errorMonitor->VerifyFound();
2573
2574 EndCommandBuffer();
2575}
2576
2577
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002578TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2579 VkResult err;
2580 bool pass;
2581
2582 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2583 ASSERT_NO_FATAL_FAILURE(InitState());
2584
2585 // If w/d/h granularity is 1, test is not meaningful
2586 // TODO: When virtual device limits are available, create a set of limits for this test that
2587 // will always have a granularity of > 1 for w, h, and d
2588 auto index = m_device->graphics_queue_node_index_;
2589 auto queue_family_properties = m_device->phy().queue_properties();
2590
2591 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2592 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2593 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2594 return;
2595 }
2596
2597 // Create two images of different types and try to copy between them
2598 VkImage srcImage;
2599 VkImage dstImage;
2600 VkDeviceMemory srcMem;
2601 VkDeviceMemory destMem;
2602 VkMemoryRequirements memReqs;
2603
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002604 VkImageCreateInfo image_create_info = {};
2605 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2606 image_create_info.pNext = NULL;
2607 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2608 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2609 image_create_info.extent.width = 32;
2610 image_create_info.extent.height = 32;
2611 image_create_info.extent.depth = 1;
2612 image_create_info.mipLevels = 1;
2613 image_create_info.arrayLayers = 4;
2614 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2615 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2616 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2617 image_create_info.flags = 0;
2618
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002620 ASSERT_VK_SUCCESS(err);
2621
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002622 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002623 ASSERT_VK_SUCCESS(err);
2624
2625 // Allocate memory
2626 VkMemoryAllocateInfo memAlloc = {};
2627 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2628 memAlloc.pNext = NULL;
2629 memAlloc.allocationSize = 0;
2630 memAlloc.memoryTypeIndex = 0;
2631
2632 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2633 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002634 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002635 ASSERT_TRUE(pass);
2636 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2637 ASSERT_VK_SUCCESS(err);
2638
2639 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2640 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002641 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002642 ASSERT_VK_SUCCESS(err);
2643 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2644 ASSERT_VK_SUCCESS(err);
2645
2646 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2647 ASSERT_VK_SUCCESS(err);
2648 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2649 ASSERT_VK_SUCCESS(err);
2650
2651 BeginCommandBuffer();
2652 VkImageCopy copyRegion;
2653 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2654 copyRegion.srcSubresource.mipLevel = 0;
2655 copyRegion.srcSubresource.baseArrayLayer = 0;
2656 copyRegion.srcSubresource.layerCount = 1;
2657 copyRegion.srcOffset.x = 0;
2658 copyRegion.srcOffset.y = 0;
2659 copyRegion.srcOffset.z = 0;
2660 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2661 copyRegion.dstSubresource.mipLevel = 0;
2662 copyRegion.dstSubresource.baseArrayLayer = 0;
2663 copyRegion.dstSubresource.layerCount = 1;
2664 copyRegion.dstOffset.x = 0;
2665 copyRegion.dstOffset.y = 0;
2666 copyRegion.dstOffset.z = 0;
2667 copyRegion.extent.width = 1;
2668 copyRegion.extent.height = 1;
2669 copyRegion.extent.depth = 1;
2670
2671 // Introduce failure by setting srcOffset to a bad granularity value
2672 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2674 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002675 m_errorMonitor->VerifyFound();
2676
2677 // Introduce failure by setting extent to a bad granularity value
2678 copyRegion.srcOffset.y = 0;
2679 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2681 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002682 m_errorMonitor->VerifyFound();
2683
2684 // Now do some buffer/image copies
2685 vk_testing::Buffer buffer;
2686 VkMemoryPropertyFlags reqs = 0;
2687 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2688 VkBufferImageCopy region = {};
2689 region.bufferOffset = 0;
2690 region.bufferRowLength = 3;
2691 region.bufferImageHeight = 128;
2692 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2693 region.imageSubresource.layerCount = 1;
2694 region.imageExtent.height = 16;
2695 region.imageExtent.width = 16;
2696 region.imageExtent.depth = 1;
2697 region.imageOffset.x = 0;
2698 region.imageOffset.y = 0;
2699 region.imageOffset.z = 0;
2700
2701 // Introduce failure by setting bufferRowLength to a bad granularity value
2702 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2704 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2705 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002706 m_errorMonitor->VerifyFound();
2707 region.bufferRowLength = 128;
2708
2709 // Introduce failure by setting bufferOffset to a bad granularity value
2710 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2712 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2713 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002714 m_errorMonitor->VerifyFound();
2715 region.bufferOffset = 0;
2716
2717 // Introduce failure by setting bufferImageHeight to a bad granularity value
2718 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2720 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2721 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002722 m_errorMonitor->VerifyFound();
2723 region.bufferImageHeight = 128;
2724
2725 // Introduce failure by setting imageExtent to a bad granularity value
2726 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2728 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2729 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002730 m_errorMonitor->VerifyFound();
2731 region.imageExtent.width = 16;
2732
2733 // Introduce failure by setting imageOffset to a bad granularity value
2734 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2736 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2737 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002738 m_errorMonitor->VerifyFound();
2739
2740 EndCommandBuffer();
2741
2742 vkDestroyImage(m_device->device(), srcImage, NULL);
2743 vkDestroyImage(m_device->device(), dstImage, NULL);
2744 vkFreeMemory(m_device->device(), srcMem, NULL);
2745 vkFreeMemory(m_device->device(), destMem, NULL);
2746}
2747
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002748TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002749 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2750 "attempt to submit them on a queue created in a different "
2751 "queue family.");
2752
Cody Northropc31a84f2016-08-22 10:41:47 -06002753 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002754 // This test is meaningless unless we have multiple queue families
2755 auto queue_family_properties = m_device->phy().queue_properties();
2756 if (queue_family_properties.size() < 2) {
2757 return;
2758 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002760 // Get safe index of another queue family
2761 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2762 ASSERT_NO_FATAL_FAILURE(InitState());
2763 // Create a second queue using a different queue family
2764 VkQueue other_queue;
2765 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2766
2767 // Record an empty cmd buffer
2768 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2769 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2770 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2771 vkEndCommandBuffer(m_commandBuffer->handle());
2772
2773 // And submit on the wrong queue
2774 VkSubmitInfo submit_info = {};
2775 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2776 submit_info.commandBufferCount = 1;
2777 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002778 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002779
2780 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002781}
2782
Chris Forbesa58c4522016-09-28 15:19:39 +13002783TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2784 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2785 ASSERT_NO_FATAL_FAILURE(InitState());
2786
2787 // A renderpass with two subpasses, both writing the same attachment.
2788 VkAttachmentDescription attach[] = {
2789 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2790 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2791 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2792 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2793 },
2794 };
2795 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2796 VkSubpassDescription subpasses[] = {
2797 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2798 1, &ref, nullptr, nullptr, 0, nullptr },
2799 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2800 1, &ref, nullptr, nullptr, 0, nullptr },
2801 };
2802 VkSubpassDependency dep = {
2803 0, 1,
2804 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2805 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2806 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2807 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2808 VK_DEPENDENCY_BY_REGION_BIT
2809 };
2810 VkRenderPassCreateInfo rpci = {
2811 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2812 0, 1, attach, 2, subpasses, 1, &dep
2813 };
2814 VkRenderPass rp;
2815 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2816 ASSERT_VK_SUCCESS(err);
2817
2818 VkImageObj image(m_device);
2819 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2820 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2821 VK_IMAGE_TILING_OPTIMAL, 0);
2822 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2823
2824 VkFramebufferCreateInfo fbci = {
2825 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2826 0, rp, 1, &imageView, 32, 32, 1
2827 };
2828 VkFramebuffer fb;
2829 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2830 ASSERT_VK_SUCCESS(err);
2831
2832 char const *vsSource =
2833 "#version 450\n"
2834 "void main() { gl_Position = vec4(1); }\n";
2835 char const *fsSource =
2836 "#version 450\n"
2837 "layout(location=0) out vec4 color;\n"
2838 "void main() { color = vec4(1); }\n";
2839
2840 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2841 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2842 VkPipelineObj pipe(m_device);
2843 pipe.AddColorAttachment();
2844 pipe.AddShader(&vs);
2845 pipe.AddShader(&fs);
2846 VkViewport view_port = {};
2847 m_viewports.push_back(view_port);
2848 pipe.SetViewport(m_viewports);
2849 VkRect2D rect = {};
2850 m_scissors.push_back(rect);
2851 pipe.SetScissor(m_scissors);
2852
2853 VkPipelineLayoutCreateInfo plci = {
2854 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2855 0, 0, nullptr, 0, nullptr
2856 };
2857 VkPipelineLayout pl;
2858 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2859 ASSERT_VK_SUCCESS(err);
2860 pipe.CreateVKPipeline(pl, rp);
2861
2862 BeginCommandBuffer();
2863
2864 VkRenderPassBeginInfo rpbi = {
2865 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2866 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2867 };
2868
2869 // subtest 1: bind in the wrong subpass
2870 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2871 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2873 "built for subpass 0 but used in subpass 1");
2874 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2875 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2876 m_errorMonitor->VerifyFound();
2877
2878 vkCmdEndRenderPass(m_commandBuffer->handle());
2879
2880 // subtest 2: bind in correct subpass, then transition to next subpass
2881 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2882 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2883 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2885 "built for subpass 0 but used in subpass 1");
2886 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2887 m_errorMonitor->VerifyFound();
2888
2889 vkCmdEndRenderPass(m_commandBuffer->handle());
2890
2891 EndCommandBuffer();
2892
2893 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
2894 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2895 vkDestroyRenderPass(m_device->device(), rp, nullptr);
2896}
2897
Tony Barbour4e919972016-08-09 13:27:40 -06002898TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
2899 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
2900 "with extent outside of framebuffer");
2901 ASSERT_NO_FATAL_FAILURE(InitState());
2902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
2905 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06002906
2907 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
2908 m_renderPassBeginInfo.renderArea.extent.width = 257;
2909 m_renderPassBeginInfo.renderArea.extent.height = 257;
2910 BeginCommandBuffer();
2911 m_errorMonitor->VerifyFound();
2912}
2913
2914TEST_F(VkLayerTest, DisabledIndependentBlend) {
2915 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
2916 "blend and then specifying different blend states for two "
2917 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06002918 VkPhysicalDeviceFeatures features = {};
2919 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06002920 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06002921
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2923 "Invalid Pipeline CreateInfo: If independent blend feature not "
2924 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06002925
Cody Northropc31a84f2016-08-22 10:41:47 -06002926 VkDescriptorSetObj descriptorSet(m_device);
2927 descriptorSet.AppendDummy();
2928 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06002929
Cody Northropc31a84f2016-08-22 10:41:47 -06002930 VkPipelineObj pipeline(m_device);
2931 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002932 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06002933 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06002934
Cody Northropc31a84f2016-08-22 10:41:47 -06002935 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
2936 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2937 att_state1.blendEnable = VK_TRUE;
2938 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2939 att_state2.blendEnable = VK_FALSE;
2940 pipeline.AddColorAttachment(0, &att_state1);
2941 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002942 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06002943 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06002944}
2945
2946TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
2947 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
2948 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06002949 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06002950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2952 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06002953
2954 // Create a renderPass with a single color attachment
2955 VkAttachmentReference attach = {};
2956 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2957 VkSubpassDescription subpass = {};
2958 VkRenderPassCreateInfo rpci = {};
2959 rpci.subpassCount = 1;
2960 rpci.pSubpasses = &subpass;
2961 rpci.attachmentCount = 1;
2962 VkAttachmentDescription attach_desc = {};
2963 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
2964 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
2965 rpci.pAttachments = &attach_desc;
2966 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2967 VkRenderPass rp;
2968 subpass.pDepthStencilAttachment = &attach;
2969 subpass.pColorAttachments = NULL;
2970 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
2971 m_errorMonitor->VerifyFound();
2972}
2973
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002974TEST_F(VkLayerTest, UnusedPreserveAttachment) {
2975 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
2976 "attachment reference of VK_ATTACHMENT_UNUSED");
2977
2978 ASSERT_NO_FATAL_FAILURE(InitState());
2979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002982
2983 VkAttachmentReference color_attach = {};
2984 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
2985 color_attach.attachment = 0;
2986 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
2987 VkSubpassDescription subpass = {};
2988 subpass.colorAttachmentCount = 1;
2989 subpass.pColorAttachments = &color_attach;
2990 subpass.preserveAttachmentCount = 1;
2991 subpass.pPreserveAttachments = &preserve_attachment;
2992
2993 VkRenderPassCreateInfo rpci = {};
2994 rpci.subpassCount = 1;
2995 rpci.pSubpasses = &subpass;
2996 rpci.attachmentCount = 1;
2997 VkAttachmentDescription attach_desc = {};
2998 attach_desc.format = VK_FORMAT_UNDEFINED;
2999 rpci.pAttachments = &attach_desc;
3000 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3001 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003002 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003003
3004 m_errorMonitor->VerifyFound();
3005
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003006 if (result == VK_SUCCESS) {
3007 vkDestroyRenderPass(m_device->device(), rp, NULL);
3008 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003009}
3010
Chris Forbesc5389742016-06-29 11:49:23 +12003011TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003012 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3013 "when the source of a subpass multisample resolve "
3014 "does not have multiple samples.");
3015
Chris Forbesc5389742016-06-29 11:49:23 +12003016 ASSERT_NO_FATAL_FAILURE(InitState());
3017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3019 "Subpass 0 requests multisample resolve from attachment 0 which has "
3020 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003021
3022 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003023 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3024 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3025 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3026 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3027 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3028 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003029 };
3030
3031 VkAttachmentReference color = {
3032 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3033 };
3034
3035 VkAttachmentReference resolve = {
3036 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3037 };
3038
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003039 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003040
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003041 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003042
3043 VkRenderPass rp;
3044 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3045
3046 m_errorMonitor->VerifyFound();
3047
3048 if (err == VK_SUCCESS)
3049 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3050}
3051
3052TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003053 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3054 "when a subpass multisample resolve operation is "
3055 "requested, and the destination of that resolve has "
3056 "multiple samples.");
3057
Chris Forbesc5389742016-06-29 11:49:23 +12003058 ASSERT_NO_FATAL_FAILURE(InitState());
3059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3061 "Subpass 0 requests multisample resolve into attachment 1, which "
3062 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003063
3064 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003065 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3066 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3067 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3068 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3069 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3070 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003071 };
3072
3073 VkAttachmentReference color = {
3074 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3075 };
3076
3077 VkAttachmentReference resolve = {
3078 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3079 };
3080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003081 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003082
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003083 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003084
3085 VkRenderPass rp;
3086 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3087
3088 m_errorMonitor->VerifyFound();
3089
3090 if (err == VK_SUCCESS)
3091 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3092}
3093
Chris Forbes3f128ef2016-06-29 14:58:53 +12003094TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003095 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3096 "when the color and depth attachments used by a subpass "
3097 "have inconsistent sample counts");
3098
Chris Forbes3f128ef2016-06-29 14:58:53 +12003099 ASSERT_NO_FATAL_FAILURE(InitState());
3100
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3102 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003103
3104 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003105 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3106 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3107 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3108 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3109 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3110 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003111 };
3112
3113 VkAttachmentReference color[] = {
3114 {
3115 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3116 },
3117 {
3118 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3119 },
3120 };
3121
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003124 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003125
3126 VkRenderPass rp;
3127 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3128
3129 m_errorMonitor->VerifyFound();
3130
3131 if (err == VK_SUCCESS)
3132 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3133}
3134
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003135TEST_F(VkLayerTest, FramebufferCreateErrors) {
3136 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003137 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003138 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003139 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3140 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3141 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3142 " 6. Framebuffer attachment where dimensions don't match\n"
3143 " 7. Framebuffer attachment w/o identity swizzle\n"
3144 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003145
3146 ASSERT_NO_FATAL_FAILURE(InitState());
3147 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3148
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3150 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3151 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003152
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003153 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003154 VkAttachmentReference attach = {};
3155 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3156 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003157 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003158 VkRenderPassCreateInfo rpci = {};
3159 rpci.subpassCount = 1;
3160 rpci.pSubpasses = &subpass;
3161 rpci.attachmentCount = 1;
3162 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003163 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003164 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003165 rpci.pAttachments = &attach_desc;
3166 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3167 VkRenderPass rp;
3168 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3169 ASSERT_VK_SUCCESS(err);
3170
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003171 VkImageView ivs[2];
3172 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3173 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003174 VkFramebufferCreateInfo fb_info = {};
3175 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3176 fb_info.pNext = NULL;
3177 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003178 // Set mis-matching attachmentCount
3179 fb_info.attachmentCount = 2;
3180 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003181 fb_info.width = 100;
3182 fb_info.height = 100;
3183 fb_info.layers = 1;
3184
3185 VkFramebuffer fb;
3186 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3187
3188 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003189 if (err == VK_SUCCESS) {
3190 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3191 }
3192 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003193
3194 // Create a renderPass with a depth-stencil attachment created with
3195 // IMAGE_USAGE_COLOR_ATTACHMENT
3196 // Add our color attachment to pDepthStencilAttachment
3197 subpass.pDepthStencilAttachment = &attach;
3198 subpass.pColorAttachments = NULL;
3199 VkRenderPass rp_ds;
3200 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3201 ASSERT_VK_SUCCESS(err);
3202 // Set correct attachment count, but attachment has COLOR usage bit set
3203 fb_info.attachmentCount = 1;
3204 fb_info.renderPass = rp_ds;
3205
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003207 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3208
3209 m_errorMonitor->VerifyFound();
3210 if (err == VK_SUCCESS) {
3211 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3212 }
3213 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003214
3215 // Create new renderpass with alternate attachment format from fb
3216 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3217 subpass.pDepthStencilAttachment = NULL;
3218 subpass.pColorAttachments = &attach;
3219 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3220 ASSERT_VK_SUCCESS(err);
3221
3222 // Cause error due to mis-matched formats between rp & fb
3223 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3224 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3226 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003227 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3228
3229 m_errorMonitor->VerifyFound();
3230 if (err == VK_SUCCESS) {
3231 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3232 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003233 vkDestroyRenderPass(m_device->device(), rp, NULL);
3234
3235 // Create new renderpass with alternate sample count from fb
3236 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3237 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3238 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3239 ASSERT_VK_SUCCESS(err);
3240
3241 // Cause error due to mis-matched sample count between rp & fb
3242 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3244 "that do not match the "
3245 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003246 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3247
3248 m_errorMonitor->VerifyFound();
3249 if (err == VK_SUCCESS) {
3250 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3251 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003252
3253 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003254
3255 // Create a custom imageView with non-1 mip levels
3256 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003257 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 -06003258 ASSERT_TRUE(image.initialized());
3259
3260 VkImageView view;
3261 VkImageViewCreateInfo ivci = {};
3262 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3263 ivci.image = image.handle();
3264 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3265 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3266 ivci.subresourceRange.layerCount = 1;
3267 ivci.subresourceRange.baseMipLevel = 0;
3268 // Set level count 2 (only 1 is allowed for FB attachment)
3269 ivci.subresourceRange.levelCount = 2;
3270 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3271 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3272 ASSERT_VK_SUCCESS(err);
3273 // Re-create renderpass to have matching sample count
3274 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3275 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3276 ASSERT_VK_SUCCESS(err);
3277
3278 fb_info.renderPass = rp;
3279 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003281 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3282
3283 m_errorMonitor->VerifyFound();
3284 if (err == VK_SUCCESS) {
3285 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3286 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003287 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003288 // Update view to original color buffer and grow FB dimensions too big
3289 fb_info.pAttachments = ivs;
3290 fb_info.height = 1024;
3291 fb_info.width = 1024;
3292 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3294 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003295 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3296
3297 m_errorMonitor->VerifyFound();
3298 if (err == VK_SUCCESS) {
3299 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3300 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003301 // Create view attachment with non-identity swizzle
3302 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3303 ivci.image = image.handle();
3304 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3305 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3306 ivci.subresourceRange.layerCount = 1;
3307 ivci.subresourceRange.baseMipLevel = 0;
3308 ivci.subresourceRange.levelCount = 1;
3309 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3310 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3311 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3312 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3313 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3314 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3315 ASSERT_VK_SUCCESS(err);
3316
3317 fb_info.pAttachments = &view;
3318 fb_info.height = 100;
3319 fb_info.width = 100;
3320 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3322 "framebuffer attachments must have "
3323 "been created with the identity "
3324 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003325 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3326
3327 m_errorMonitor->VerifyFound();
3328 if (err == VK_SUCCESS) {
3329 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3330 }
3331 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003332 // Request fb that exceeds max dimensions
3333 // reset attachment to color attachment
3334 fb_info.pAttachments = ivs;
3335 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3336 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3337 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3339 "dimensions exceed physical device "
3340 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003341 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3342
3343 m_errorMonitor->VerifyFound();
3344 if (err == VK_SUCCESS) {
3345 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3346 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003347
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003348 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003349}
3350
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003351TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003352 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3353 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003354
Cody Northropc31a84f2016-08-22 10:41:47 -06003355 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003356 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3358 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003359 m_errorMonitor->VerifyFound();
3360}
3361
3362TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003363 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3364 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003365
Cody Northropc31a84f2016-08-22 10:41:47 -06003366 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003367 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3369 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003370 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003371}
3372
3373TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003374 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3375 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003376
Cody Northropc31a84f2016-08-22 10:41:47 -06003377 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003378 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003379 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 -06003380 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003381 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003382}
3383
3384TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003385 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3386 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003387
Cody Northropc31a84f2016-08-22 10:41:47 -06003388 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003389 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003390 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 -06003391 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003392 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003393}
3394
Cortd713fe82016-07-27 09:51:27 -07003395TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003396 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3397 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003398
3399 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003400 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3402 "Dynamic blend constants state not set for this command buffer");
3403 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003404 m_errorMonitor->VerifyFound();
3405}
3406
3407TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003408 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3409 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003410
3411 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003412 if (!m_device->phy().features().depthBounds) {
3413 printf("Device does not support depthBounds test; skipped.\n");
3414 return;
3415 }
3416 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3418 "Dynamic depth bounds state not set for this command buffer");
3419 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003420 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003421}
3422
3423TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003424 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3425 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003426
3427 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003428 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3430 "Dynamic stencil read mask state not set for this command buffer");
3431 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003432 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003433}
3434
3435TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003436 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3437 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003438
3439 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003440 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3442 "Dynamic stencil write mask state not set for this command buffer");
3443 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003444 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003445}
3446
3447TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003448 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3449 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003450
3451 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003452 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3454 "Dynamic stencil reference state not set for this command buffer");
3455 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003456 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003457}
3458
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003459TEST_F(VkLayerTest, IndexBufferNotBound) {
3460 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003461
3462 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3464 "Index buffer object not bound to this command buffer when Indexed ");
3465 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003466 m_errorMonitor->VerifyFound();
3467}
3468
Karl Schultz6addd812016-02-02 17:17:23 -07003469TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3471 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3472 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003473
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003474 ASSERT_NO_FATAL_FAILURE(InitState());
3475 ASSERT_NO_FATAL_FAILURE(InitViewport());
3476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3477
Karl Schultz6addd812016-02-02 17:17:23 -07003478 // We luck out b/c by default the framework creates CB w/ the
3479 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003480 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003481 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003482 EndCommandBuffer();
3483
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003484 // Bypass framework since it does the waits automatically
3485 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003486 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003487 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3488 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003489 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003490 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003491 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003492 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003493 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003494 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003495 submit_info.pSignalSemaphores = NULL;
3496
Chris Forbes40028e22016-06-13 09:59:34 +12003497 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003498 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003499
Karl Schultz6addd812016-02-02 17:17:23 -07003500 // Cause validation error by re-submitting cmd buffer that should only be
3501 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003502 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003503
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003504 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003505}
3506
Karl Schultz6addd812016-02-02 17:17:23 -07003507TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003508 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003509 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003510
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3512 "type "
3513 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003514
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003515 ASSERT_NO_FATAL_FAILURE(InitState());
3516 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003517
Karl Schultz6addd812016-02-02 17:17:23 -07003518 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3519 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003520 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003521 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3522 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003523
3524 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003525 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3526 ds_pool_ci.pNext = NULL;
3527 ds_pool_ci.flags = 0;
3528 ds_pool_ci.maxSets = 1;
3529 ds_pool_ci.poolSizeCount = 1;
3530 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003531
3532 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003533 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003534 ASSERT_VK_SUCCESS(err);
3535
3536 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003537 dsl_binding.binding = 0;
3538 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3539 dsl_binding.descriptorCount = 1;
3540 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3541 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003542
3543 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003544 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3545 ds_layout_ci.pNext = NULL;
3546 ds_layout_ci.bindingCount = 1;
3547 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003548
3549 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003550 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003551 ASSERT_VK_SUCCESS(err);
3552
3553 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003554 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003555 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003556 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003557 alloc_info.descriptorPool = ds_pool;
3558 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003560
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003561 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003562
Chia-I Wuf7458c52015-10-26 21:10:41 +08003563 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3564 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003565}
3566
Karl Schultz6addd812016-02-02 17:17:23 -07003567TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3568 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003569
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3571 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3572 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003573
Tobin Ehlise735c692015-10-08 13:13:50 -06003574 ASSERT_NO_FATAL_FAILURE(InitState());
3575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003576
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003577 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003578 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3579 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003580
3581 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003582 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3583 ds_pool_ci.pNext = NULL;
3584 ds_pool_ci.maxSets = 1;
3585 ds_pool_ci.poolSizeCount = 1;
3586 ds_pool_ci.flags = 0;
3587 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3588 // app can only call vkResetDescriptorPool on this pool.;
3589 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003590
3591 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003592 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003593 ASSERT_VK_SUCCESS(err);
3594
3595 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003596 dsl_binding.binding = 0;
3597 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3598 dsl_binding.descriptorCount = 1;
3599 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3600 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003601
3602 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003603 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3604 ds_layout_ci.pNext = NULL;
3605 ds_layout_ci.bindingCount = 1;
3606 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003607
3608 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003609 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003610 ASSERT_VK_SUCCESS(err);
3611
3612 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003613 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003614 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003615 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003616 alloc_info.descriptorPool = ds_pool;
3617 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003618 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003619 ASSERT_VK_SUCCESS(err);
3620
3621 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003622 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003623
Chia-I Wuf7458c52015-10-26 21:10:41 +08003624 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003626}
3627
Karl Schultz6addd812016-02-02 17:17:23 -07003628TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003629 // Attempt to clear Descriptor Pool with bad object.
3630 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003631
3632 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003634 uint64_t fake_pool_handle = 0xbaad6001;
3635 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3636 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003637 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003638}
3639
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003640TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003641 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3642 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003643 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003644 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003645
3646 uint64_t fake_set_handle = 0xbaad6001;
3647 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003648 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003650
3651 ASSERT_NO_FATAL_FAILURE(InitState());
3652
3653 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3654 layout_bindings[0].binding = 0;
3655 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3656 layout_bindings[0].descriptorCount = 1;
3657 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3658 layout_bindings[0].pImmutableSamplers = NULL;
3659
3660 VkDescriptorSetLayout descriptor_set_layout;
3661 VkDescriptorSetLayoutCreateInfo dslci = {};
3662 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3663 dslci.pNext = NULL;
3664 dslci.bindingCount = 1;
3665 dslci.pBindings = layout_bindings;
3666 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003667 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003668
3669 VkPipelineLayout pipeline_layout;
3670 VkPipelineLayoutCreateInfo plci = {};
3671 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3672 plci.pNext = NULL;
3673 plci.setLayoutCount = 1;
3674 plci.pSetLayouts = &descriptor_set_layout;
3675 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003676 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003677
3678 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003679 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3680 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003681 m_errorMonitor->VerifyFound();
3682 EndCommandBuffer();
3683 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3684 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003685}
3686
Karl Schultz6addd812016-02-02 17:17:23 -07003687TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003688 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3689 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003690 uint64_t fake_layout_handle = 0xbaad6001;
3691 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003693 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003694 VkPipelineLayout pipeline_layout;
3695 VkPipelineLayoutCreateInfo plci = {};
3696 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3697 plci.pNext = NULL;
3698 plci.setLayoutCount = 1;
3699 plci.pSetLayouts = &bad_layout;
3700 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3701
3702 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003703}
3704
Mark Muellerd4914412016-06-13 17:52:06 -06003705TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3706 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3707 "1) A uniform buffer update must have a valid buffer index."
3708 "2) When using an array of descriptors in a single WriteDescriptor,"
3709 " the descriptor types and stageflags must all be the same."
3710 "3) Immutable Sampler state must match across descriptors");
3711
3712 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003713 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3714 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3715 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3716 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3717 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003718
Mark Muellerd4914412016-06-13 17:52:06 -06003719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3720
3721 ASSERT_NO_FATAL_FAILURE(InitState());
3722 VkDescriptorPoolSize ds_type_count[4] = {};
3723 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3724 ds_type_count[0].descriptorCount = 1;
3725 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3726 ds_type_count[1].descriptorCount = 1;
3727 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3728 ds_type_count[2].descriptorCount = 1;
3729 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3730 ds_type_count[3].descriptorCount = 1;
3731
3732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3734 ds_pool_ci.maxSets = 1;
3735 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3736 ds_pool_ci.pPoolSizes = ds_type_count;
3737
3738 VkDescriptorPool ds_pool;
3739 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3740 ASSERT_VK_SUCCESS(err);
3741
Mark Muellerb9896722016-06-16 09:54:29 -06003742 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003743 layout_binding[0].binding = 0;
3744 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3745 layout_binding[0].descriptorCount = 1;
3746 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3747 layout_binding[0].pImmutableSamplers = NULL;
3748
3749 layout_binding[1].binding = 1;
3750 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3751 layout_binding[1].descriptorCount = 1;
3752 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3753 layout_binding[1].pImmutableSamplers = NULL;
3754
3755 VkSamplerCreateInfo sampler_ci = {};
3756 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3757 sampler_ci.pNext = NULL;
3758 sampler_ci.magFilter = VK_FILTER_NEAREST;
3759 sampler_ci.minFilter = VK_FILTER_NEAREST;
3760 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3761 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3762 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3763 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3764 sampler_ci.mipLodBias = 1.0;
3765 sampler_ci.anisotropyEnable = VK_FALSE;
3766 sampler_ci.maxAnisotropy = 1;
3767 sampler_ci.compareEnable = VK_FALSE;
3768 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3769 sampler_ci.minLod = 1.0;
3770 sampler_ci.maxLod = 1.0;
3771 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3772 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3773 VkSampler sampler;
3774
3775 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3776 ASSERT_VK_SUCCESS(err);
3777
3778 layout_binding[2].binding = 2;
3779 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3780 layout_binding[2].descriptorCount = 1;
3781 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3782 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3783
Mark Muellerd4914412016-06-13 17:52:06 -06003784 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3785 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3786 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3787 ds_layout_ci.pBindings = layout_binding;
3788 VkDescriptorSetLayout ds_layout;
3789 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3790 ASSERT_VK_SUCCESS(err);
3791
3792 VkDescriptorSetAllocateInfo alloc_info = {};
3793 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3794 alloc_info.descriptorSetCount = 1;
3795 alloc_info.descriptorPool = ds_pool;
3796 alloc_info.pSetLayouts = &ds_layout;
3797 VkDescriptorSet descriptorSet;
3798 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3799 ASSERT_VK_SUCCESS(err);
3800
3801 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3802 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3803 pipeline_layout_ci.pNext = NULL;
3804 pipeline_layout_ci.setLayoutCount = 1;
3805 pipeline_layout_ci.pSetLayouts = &ds_layout;
3806
3807 VkPipelineLayout pipeline_layout;
3808 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3809 ASSERT_VK_SUCCESS(err);
3810
Mark Mueller5c838ce2016-06-16 09:54:29 -06003811 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003812 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3813 descriptor_write.dstSet = descriptorSet;
3814 descriptor_write.dstBinding = 0;
3815 descriptor_write.descriptorCount = 1;
3816 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3817
Mark Mueller5c838ce2016-06-16 09:54:29 -06003818 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003819 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3820 m_errorMonitor->VerifyFound();
3821
3822 // Create a buffer to update the descriptor with
3823 uint32_t qfi = 0;
3824 VkBufferCreateInfo buffCI = {};
3825 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3826 buffCI.size = 1024;
3827 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3828 buffCI.queueFamilyIndexCount = 1;
3829 buffCI.pQueueFamilyIndices = &qfi;
3830
3831 VkBuffer dyub;
3832 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3833 ASSERT_VK_SUCCESS(err);
3834 VkDescriptorBufferInfo buffInfo = {};
3835 buffInfo.buffer = dyub;
3836 buffInfo.offset = 0;
3837 buffInfo.range = 1024;
3838
3839 descriptor_write.pBufferInfo = &buffInfo;
3840 descriptor_write.descriptorCount = 2;
3841
Mark Mueller5c838ce2016-06-16 09:54:29 -06003842 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3844 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3845 m_errorMonitor->VerifyFound();
3846
Mark Mueller5c838ce2016-06-16 09:54:29 -06003847 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3848 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003849 descriptor_write.dstBinding = 1;
3850 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003851
Mark Mueller5c838ce2016-06-16 09:54:29 -06003852 // Make pImageInfo index non-null to avoid complaints of it missing
3853 VkDescriptorImageInfo imageInfo = {};
3854 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3855 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3857 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3858 m_errorMonitor->VerifyFound();
3859
Mark Muellerd4914412016-06-13 17:52:06 -06003860 vkDestroyBuffer(m_device->device(), dyub, NULL);
3861 vkDestroySampler(m_device->device(), sampler, NULL);
3862 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3863 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3864 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3865}
3866
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003867TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3868 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3869 "due to a buffer dependency being destroyed.");
3870 ASSERT_NO_FATAL_FAILURE(InitState());
3871
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003872 VkBuffer buffer;
3873 VkDeviceMemory mem;
3874 VkMemoryRequirements mem_reqs;
3875
3876 VkBufferCreateInfo buf_info = {};
3877 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12003878 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003879 buf_info.size = 256;
3880 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3881 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
3882 ASSERT_VK_SUCCESS(err);
3883
3884 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
3885
3886 VkMemoryAllocateInfo alloc_info = {};
3887 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3888 alloc_info.allocationSize = 256;
3889 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003890 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 -06003891 if (!pass) {
3892 vkDestroyBuffer(m_device->device(), buffer, NULL);
3893 return;
3894 }
3895 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
3896 ASSERT_VK_SUCCESS(err);
3897
3898 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3899 ASSERT_VK_SUCCESS(err);
3900
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003901 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12003902 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003903 m_commandBuffer->EndCommandBuffer();
3904
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003906 // Destroy buffer dependency prior to submit to cause ERROR
3907 vkDestroyBuffer(m_device->device(), buffer, NULL);
3908
3909 VkSubmitInfo submit_info = {};
3910 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3911 submit_info.commandBufferCount = 1;
3912 submit_info.pCommandBuffers = &m_commandBuffer->handle();
3913 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3914
3915 m_errorMonitor->VerifyFound();
3916 vkFreeMemory(m_device->handle(), mem, NULL);
3917}
3918
Tobin Ehlisea413442016-09-28 10:23:59 -06003919TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
3920 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
3921
3922 ASSERT_NO_FATAL_FAILURE(InitState());
3923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3924
3925 VkDescriptorPoolSize ds_type_count;
3926 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3927 ds_type_count.descriptorCount = 1;
3928
3929 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3930 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3931 ds_pool_ci.maxSets = 1;
3932 ds_pool_ci.poolSizeCount = 1;
3933 ds_pool_ci.pPoolSizes = &ds_type_count;
3934
3935 VkDescriptorPool ds_pool;
3936 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3937 ASSERT_VK_SUCCESS(err);
3938
3939 VkDescriptorSetLayoutBinding layout_binding;
3940 layout_binding.binding = 0;
3941 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3942 layout_binding.descriptorCount = 1;
3943 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3944 layout_binding.pImmutableSamplers = NULL;
3945
3946 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3947 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3948 ds_layout_ci.bindingCount = 1;
3949 ds_layout_ci.pBindings = &layout_binding;
3950 VkDescriptorSetLayout ds_layout;
3951 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3952 ASSERT_VK_SUCCESS(err);
3953
3954 VkDescriptorSetAllocateInfo alloc_info = {};
3955 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3956 alloc_info.descriptorSetCount = 1;
3957 alloc_info.descriptorPool = ds_pool;
3958 alloc_info.pSetLayouts = &ds_layout;
3959 VkDescriptorSet descriptor_set;
3960 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
3961 ASSERT_VK_SUCCESS(err);
3962
3963 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3964 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3965 pipeline_layout_ci.pNext = NULL;
3966 pipeline_layout_ci.setLayoutCount = 1;
3967 pipeline_layout_ci.pSetLayouts = &ds_layout;
3968
3969 VkPipelineLayout pipeline_layout;
3970 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3971 ASSERT_VK_SUCCESS(err);
3972
3973 VkBuffer buffer;
3974 uint32_t queue_family_index = 0;
3975 VkBufferCreateInfo buffer_create_info = {};
3976 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3977 buffer_create_info.size = 1024;
3978 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
3979 buffer_create_info.queueFamilyIndexCount = 1;
3980 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
3981
3982 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
3983 ASSERT_VK_SUCCESS(err);
3984
3985 VkMemoryRequirements memory_reqs;
3986 VkDeviceMemory buffer_memory;
3987
3988 VkMemoryAllocateInfo memory_info = {};
3989 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3990 memory_info.allocationSize = 0;
3991 memory_info.memoryTypeIndex = 0;
3992
3993 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
3994 memory_info.allocationSize = memory_reqs.size;
3995 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
3996 ASSERT_TRUE(pass);
3997
3998 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
3999 ASSERT_VK_SUCCESS(err);
4000 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4001 ASSERT_VK_SUCCESS(err);
4002
4003 VkBufferView view;
4004 VkBufferViewCreateInfo bvci = {};
4005 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4006 bvci.buffer = buffer;
4007 bvci.format = VK_FORMAT_R8_UNORM;
4008 bvci.range = VK_WHOLE_SIZE;
4009
4010 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4011 ASSERT_VK_SUCCESS(err);
4012
4013 VkWriteDescriptorSet descriptor_write = {};
4014 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4015 descriptor_write.dstSet = descriptor_set;
4016 descriptor_write.dstBinding = 0;
4017 descriptor_write.descriptorCount = 1;
4018 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4019 descriptor_write.pTexelBufferView = &view;
4020
4021 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4022
4023 char const *vsSource = "#version 450\n"
4024 "\n"
4025 "out gl_PerVertex { \n"
4026 " vec4 gl_Position;\n"
4027 "};\n"
4028 "void main(){\n"
4029 " gl_Position = vec4(1);\n"
4030 "}\n";
4031 char const *fsSource = "#version 450\n"
4032 "\n"
4033 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4034 "layout(location=0) out vec4 x;\n"
4035 "void main(){\n"
4036 " x = imageLoad(s, 0);\n"
4037 "}\n";
4038 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4039 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4040 VkPipelineObj pipe(m_device);
4041 pipe.AddShader(&vs);
4042 pipe.AddShader(&fs);
4043 pipe.AddColorAttachment();
4044 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4045
4046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4048
4049 BeginCommandBuffer();
4050 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4051 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4052 VkRect2D scissor = {{0, 0}, {16, 16}};
4053 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4054 // Bind pipeline to cmd buffer
4055 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4056 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4057 &descriptor_set, 0, nullptr);
4058 Draw(1, 0, 0, 0);
4059 EndCommandBuffer();
4060
4061 // Delete BufferView in order to invalidate cmd buffer
4062 vkDestroyBufferView(m_device->device(), view, NULL);
4063 // Now attempt submit of cmd buffer
4064 VkSubmitInfo submit_info = {};
4065 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4066 submit_info.commandBufferCount = 1;
4067 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4068 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4069 m_errorMonitor->VerifyFound();
4070
4071 // Clean-up
4072 vkDestroyBuffer(m_device->device(), buffer, NULL);
4073 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4074 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4075 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4076 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4077}
4078
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004079TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4080 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4081 "due to an image dependency being destroyed.");
4082 ASSERT_NO_FATAL_FAILURE(InitState());
4083
4084 VkImage image;
4085 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4086 VkImageCreateInfo image_create_info = {};
4087 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4088 image_create_info.pNext = NULL;
4089 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4090 image_create_info.format = tex_format;
4091 image_create_info.extent.width = 32;
4092 image_create_info.extent.height = 32;
4093 image_create_info.extent.depth = 1;
4094 image_create_info.mipLevels = 1;
4095 image_create_info.arrayLayers = 1;
4096 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4097 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004098 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004099 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004100 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004101 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004102 // Have to bind memory to image before recording cmd in cmd buffer using it
4103 VkMemoryRequirements mem_reqs;
4104 VkDeviceMemory image_mem;
4105 bool pass;
4106 VkMemoryAllocateInfo mem_alloc = {};
4107 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4108 mem_alloc.pNext = NULL;
4109 mem_alloc.memoryTypeIndex = 0;
4110 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4111 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004112 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004113 ASSERT_TRUE(pass);
4114 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4115 ASSERT_VK_SUCCESS(err);
4116 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4117 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004118
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004119 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004120 VkClearColorValue ccv;
4121 ccv.float32[0] = 1.0f;
4122 ccv.float32[1] = 1.0f;
4123 ccv.float32[2] = 1.0f;
4124 ccv.float32[3] = 1.0f;
4125 VkImageSubresourceRange isr = {};
4126 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004127 isr.baseArrayLayer = 0;
4128 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004129 isr.layerCount = 1;
4130 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004131 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004132 m_commandBuffer->EndCommandBuffer();
4133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004135 // Destroy image dependency prior to submit to cause ERROR
4136 vkDestroyImage(m_device->device(), image, NULL);
4137
4138 VkSubmitInfo submit_info = {};
4139 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4140 submit_info.commandBufferCount = 1;
4141 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4142 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4143
4144 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004145 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004146}
4147
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004148TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4149 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4150 "due to a framebuffer image dependency being destroyed.");
4151 VkFormatProperties format_properties;
4152 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004153 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4154 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004155 return;
4156 }
4157
4158 ASSERT_NO_FATAL_FAILURE(InitState());
4159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4160
4161 VkImageCreateInfo image_ci = {};
4162 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4163 image_ci.pNext = NULL;
4164 image_ci.imageType = VK_IMAGE_TYPE_2D;
4165 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4166 image_ci.extent.width = 32;
4167 image_ci.extent.height = 32;
4168 image_ci.extent.depth = 1;
4169 image_ci.mipLevels = 1;
4170 image_ci.arrayLayers = 1;
4171 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4172 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004173 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004174 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4175 image_ci.flags = 0;
4176 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004177 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004178
4179 VkMemoryRequirements memory_reqs;
4180 VkDeviceMemory image_memory;
4181 bool pass;
4182 VkMemoryAllocateInfo memory_info = {};
4183 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4184 memory_info.pNext = NULL;
4185 memory_info.allocationSize = 0;
4186 memory_info.memoryTypeIndex = 0;
4187 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4188 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004189 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004190 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004191 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004192 ASSERT_VK_SUCCESS(err);
4193 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4194 ASSERT_VK_SUCCESS(err);
4195
4196 VkImageViewCreateInfo ivci = {
4197 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4198 nullptr,
4199 0,
4200 image,
4201 VK_IMAGE_VIEW_TYPE_2D,
4202 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004203 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004204 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4205 };
4206 VkImageView view;
4207 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4208 ASSERT_VK_SUCCESS(err);
4209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004210 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004211 VkFramebuffer fb;
4212 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4213 ASSERT_VK_SUCCESS(err);
4214
4215 // Just use default renderpass with our framebuffer
4216 m_renderPassBeginInfo.framebuffer = fb;
4217 // Create Null cmd buffer for submit
4218 BeginCommandBuffer();
4219 EndCommandBuffer();
4220 // Destroy image attached to framebuffer to invalidate cmd buffer
4221 vkDestroyImage(m_device->device(), image, NULL);
4222 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004224 QueueCommandBuffer(false);
4225 m_errorMonitor->VerifyFound();
4226
4227 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4228 vkDestroyImageView(m_device->device(), view, nullptr);
4229 vkFreeMemory(m_device->device(), image_memory, nullptr);
4230}
4231
Tobin Ehlisb329f992016-10-12 13:20:29 -06004232TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4233 TEST_DESCRIPTION("Delete in-use framebuffer.");
4234 VkFormatProperties format_properties;
4235 VkResult err = VK_SUCCESS;
4236 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4237
4238 ASSERT_NO_FATAL_FAILURE(InitState());
4239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4240
4241 VkImageObj image(m_device);
4242 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4243 ASSERT_TRUE(image.initialized());
4244 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4245
4246 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4247 VkFramebuffer fb;
4248 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4249 ASSERT_VK_SUCCESS(err);
4250
4251 // Just use default renderpass with our framebuffer
4252 m_renderPassBeginInfo.framebuffer = fb;
4253 // Create Null cmd buffer for submit
4254 BeginCommandBuffer();
4255 EndCommandBuffer();
4256 // Submit cmd buffer to put it in-flight
4257 VkSubmitInfo submit_info = {};
4258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4259 submit_info.commandBufferCount = 1;
4260 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4261 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4262 // Destroy framebuffer while in-flight
4263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4264 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4265 m_errorMonitor->VerifyFound();
4266 // Wait for queue to complete so we can safely destroy everything
4267 vkQueueWaitIdle(m_device->m_queue);
4268 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4269}
4270
Tobin Ehlis88becd72016-09-21 14:33:41 -06004271TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4272 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4273 VkFormatProperties format_properties;
4274 VkResult err = VK_SUCCESS;
4275 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004276
4277 ASSERT_NO_FATAL_FAILURE(InitState());
4278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4279
4280 VkImageCreateInfo image_ci = {};
4281 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4282 image_ci.pNext = NULL;
4283 image_ci.imageType = VK_IMAGE_TYPE_2D;
4284 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4285 image_ci.extent.width = 256;
4286 image_ci.extent.height = 256;
4287 image_ci.extent.depth = 1;
4288 image_ci.mipLevels = 1;
4289 image_ci.arrayLayers = 1;
4290 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4291 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004292 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004293 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4294 image_ci.flags = 0;
4295 VkImage image;
4296 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4297
4298 VkMemoryRequirements memory_reqs;
4299 VkDeviceMemory image_memory;
4300 bool pass;
4301 VkMemoryAllocateInfo memory_info = {};
4302 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4303 memory_info.pNext = NULL;
4304 memory_info.allocationSize = 0;
4305 memory_info.memoryTypeIndex = 0;
4306 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4307 memory_info.allocationSize = memory_reqs.size;
4308 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4309 ASSERT_TRUE(pass);
4310 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4311 ASSERT_VK_SUCCESS(err);
4312 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4313 ASSERT_VK_SUCCESS(err);
4314
4315 VkImageViewCreateInfo ivci = {
4316 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4317 nullptr,
4318 0,
4319 image,
4320 VK_IMAGE_VIEW_TYPE_2D,
4321 VK_FORMAT_B8G8R8A8_UNORM,
4322 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4323 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4324 };
4325 VkImageView view;
4326 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4327 ASSERT_VK_SUCCESS(err);
4328
4329 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4330 VkFramebuffer fb;
4331 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4332 ASSERT_VK_SUCCESS(err);
4333
4334 // Just use default renderpass with our framebuffer
4335 m_renderPassBeginInfo.framebuffer = fb;
4336 // Create Null cmd buffer for submit
4337 BeginCommandBuffer();
4338 EndCommandBuffer();
4339 // Submit cmd buffer to put it (and attached imageView) in-flight
4340 VkSubmitInfo submit_info = {};
4341 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4342 submit_info.commandBufferCount = 1;
4343 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4344 // Submit cmd buffer to put framebuffer and children in-flight
4345 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4346 // Destroy image attached to framebuffer while in-flight
4347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4348 vkDestroyImage(m_device->device(), image, NULL);
4349 m_errorMonitor->VerifyFound();
4350 // Wait for queue to complete so we can safely destroy image and other objects
4351 vkQueueWaitIdle(m_device->m_queue);
4352 vkDestroyImage(m_device->device(), image, NULL);
4353 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4354 vkDestroyImageView(m_device->device(), view, nullptr);
4355 vkFreeMemory(m_device->device(), image_memory, nullptr);
4356}
4357
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004358TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4359 TEST_DESCRIPTION("Delete in-use renderPass.");
4360
4361 ASSERT_NO_FATAL_FAILURE(InitState());
4362 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4363
4364 // Create simple renderpass
4365 VkAttachmentReference attach = {};
4366 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4367 VkSubpassDescription subpass = {};
4368 subpass.pColorAttachments = &attach;
4369 VkRenderPassCreateInfo rpci = {};
4370 rpci.subpassCount = 1;
4371 rpci.pSubpasses = &subpass;
4372 rpci.attachmentCount = 1;
4373 VkAttachmentDescription attach_desc = {};
4374 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4375 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4376 rpci.pAttachments = &attach_desc;
4377 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4378 VkRenderPass rp;
4379 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4380 ASSERT_VK_SUCCESS(err);
4381
4382 // Create a pipeline that uses the given renderpass
4383 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4384 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4385
4386 VkPipelineLayout pipeline_layout;
4387 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4388 ASSERT_VK_SUCCESS(err);
4389
4390 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4391 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4392 vp_state_ci.viewportCount = 1;
4393 VkViewport vp = {}; // Just need dummy vp to point to
4394 vp_state_ci.pViewports = &vp;
4395 vp_state_ci.scissorCount = 1;
4396 VkRect2D scissors = {}; // Dummy scissors to point to
4397 vp_state_ci.pScissors = &scissors;
4398
4399 VkPipelineShaderStageCreateInfo shaderStages[2];
4400 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4401
4402 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4403 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4404 // but add it to be able to run on more devices
4405 shaderStages[0] = vs.GetStageCreateInfo();
4406 shaderStages[1] = fs.GetStageCreateInfo();
4407
4408 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4409 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4410
4411 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4412 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4413 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4414
4415 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4416 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4417 rs_ci.rasterizerDiscardEnable = true;
4418 rs_ci.lineWidth = 1.0f;
4419
4420 VkPipelineColorBlendAttachmentState att = {};
4421 att.blendEnable = VK_FALSE;
4422 att.colorWriteMask = 0xf;
4423
4424 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4425 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4426 cb_ci.attachmentCount = 1;
4427 cb_ci.pAttachments = &att;
4428
4429 VkGraphicsPipelineCreateInfo gp_ci = {};
4430 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4431 gp_ci.stageCount = 2;
4432 gp_ci.pStages = shaderStages;
4433 gp_ci.pVertexInputState = &vi_ci;
4434 gp_ci.pInputAssemblyState = &ia_ci;
4435 gp_ci.pViewportState = &vp_state_ci;
4436 gp_ci.pRasterizationState = &rs_ci;
4437 gp_ci.pColorBlendState = &cb_ci;
4438 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4439 gp_ci.layout = pipeline_layout;
4440 gp_ci.renderPass = rp;
4441
4442 VkPipelineCacheCreateInfo pc_ci = {};
4443 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4444
4445 VkPipeline pipeline;
4446 VkPipelineCache pipe_cache;
4447 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4448 ASSERT_VK_SUCCESS(err);
4449
4450 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4451 ASSERT_VK_SUCCESS(err);
4452 // Bind pipeline to cmd buffer, will also bind renderpass
4453 m_commandBuffer->BeginCommandBuffer();
4454 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4455 m_commandBuffer->EndCommandBuffer();
4456
4457 VkSubmitInfo submit_info = {};
4458 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4459 submit_info.commandBufferCount = 1;
4460 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4461 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4462
4463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4464 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4465 m_errorMonitor->VerifyFound();
4466
4467 // Wait for queue to complete so we can safely destroy everything
4468 vkQueueWaitIdle(m_device->m_queue);
4469 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4470 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4471 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4472 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4473}
4474
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004475TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004476 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004477 ASSERT_NO_FATAL_FAILURE(InitState());
4478
4479 VkImage image;
4480 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4481 VkImageCreateInfo image_create_info = {};
4482 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4483 image_create_info.pNext = NULL;
4484 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4485 image_create_info.format = tex_format;
4486 image_create_info.extent.width = 32;
4487 image_create_info.extent.height = 32;
4488 image_create_info.extent.depth = 1;
4489 image_create_info.mipLevels = 1;
4490 image_create_info.arrayLayers = 1;
4491 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4492 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004493 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004494 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004495 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004496 ASSERT_VK_SUCCESS(err);
4497 // Have to bind memory to image before recording cmd in cmd buffer using it
4498 VkMemoryRequirements mem_reqs;
4499 VkDeviceMemory image_mem;
4500 bool pass;
4501 VkMemoryAllocateInfo mem_alloc = {};
4502 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4503 mem_alloc.pNext = NULL;
4504 mem_alloc.memoryTypeIndex = 0;
4505 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4506 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004507 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004508 ASSERT_TRUE(pass);
4509 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4510 ASSERT_VK_SUCCESS(err);
4511
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004512 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004514 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004515
4516 m_commandBuffer->BeginCommandBuffer();
4517 VkClearColorValue ccv;
4518 ccv.float32[0] = 1.0f;
4519 ccv.float32[1] = 1.0f;
4520 ccv.float32[2] = 1.0f;
4521 ccv.float32[3] = 1.0f;
4522 VkImageSubresourceRange isr = {};
4523 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4524 isr.baseArrayLayer = 0;
4525 isr.baseMipLevel = 0;
4526 isr.layerCount = 1;
4527 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004528 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004529 m_commandBuffer->EndCommandBuffer();
4530
4531 m_errorMonitor->VerifyFound();
4532 vkDestroyImage(m_device->device(), image, NULL);
4533 vkFreeMemory(m_device->device(), image_mem, nullptr);
4534}
4535
4536TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004537 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004538 ASSERT_NO_FATAL_FAILURE(InitState());
4539
4540 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004541 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 -06004542 VK_IMAGE_TILING_OPTIMAL, 0);
4543 ASSERT_TRUE(image.initialized());
4544
4545 VkBuffer buffer;
4546 VkDeviceMemory mem;
4547 VkMemoryRequirements mem_reqs;
4548
4549 VkBufferCreateInfo buf_info = {};
4550 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004551 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004552 buf_info.size = 256;
4553 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4554 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4555 ASSERT_VK_SUCCESS(err);
4556
4557 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4558
4559 VkMemoryAllocateInfo alloc_info = {};
4560 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4561 alloc_info.allocationSize = 256;
4562 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004563 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 -06004564 if (!pass) {
4565 vkDestroyBuffer(m_device->device(), buffer, NULL);
4566 return;
4567 }
4568 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4569 ASSERT_VK_SUCCESS(err);
4570
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004571 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004573 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004574 VkBufferImageCopy region = {};
4575 region.bufferRowLength = 128;
4576 region.bufferImageHeight = 128;
4577 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4578
4579 region.imageSubresource.layerCount = 1;
4580 region.imageExtent.height = 4;
4581 region.imageExtent.width = 4;
4582 region.imageExtent.depth = 1;
4583 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004584 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4585 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004586 m_commandBuffer->EndCommandBuffer();
4587
4588 m_errorMonitor->VerifyFound();
4589
4590 vkDestroyBuffer(m_device->device(), buffer, NULL);
4591 vkFreeMemory(m_device->handle(), mem, NULL);
4592}
4593
Tobin Ehlis85940f52016-07-07 16:57:21 -06004594TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4595 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4596 "due to an event dependency being destroyed.");
4597 ASSERT_NO_FATAL_FAILURE(InitState());
4598
4599 VkEvent event;
4600 VkEventCreateInfo evci = {};
4601 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4602 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4603 ASSERT_VK_SUCCESS(result);
4604
4605 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004606 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004607 m_commandBuffer->EndCommandBuffer();
4608
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004610 // Destroy event dependency prior to submit to cause ERROR
4611 vkDestroyEvent(m_device->device(), event, NULL);
4612
4613 VkSubmitInfo submit_info = {};
4614 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4615 submit_info.commandBufferCount = 1;
4616 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4617 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4618
4619 m_errorMonitor->VerifyFound();
4620}
4621
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004622TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4623 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4624 "due to a query pool dependency being destroyed.");
4625 ASSERT_NO_FATAL_FAILURE(InitState());
4626
4627 VkQueryPool query_pool;
4628 VkQueryPoolCreateInfo qpci{};
4629 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4630 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4631 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004632 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004633 ASSERT_VK_SUCCESS(result);
4634
4635 m_commandBuffer->BeginCommandBuffer();
4636 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4637 m_commandBuffer->EndCommandBuffer();
4638
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004640 // Destroy query pool dependency prior to submit to cause ERROR
4641 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4642
4643 VkSubmitInfo submit_info = {};
4644 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4645 submit_info.commandBufferCount = 1;
4646 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4647 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4648
4649 m_errorMonitor->VerifyFound();
4650}
4651
Tobin Ehlis24130d92016-07-08 15:50:53 -06004652TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4653 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4654 "due to a pipeline dependency being destroyed.");
4655 ASSERT_NO_FATAL_FAILURE(InitState());
4656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4657
4658 VkResult err;
4659
4660 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4661 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4662
4663 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004664 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004665 ASSERT_VK_SUCCESS(err);
4666
4667 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4668 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4669 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004670 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004671 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004672 vp_state_ci.scissorCount = 1;
4673 VkRect2D scissors = {}; // Dummy scissors to point to
4674 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004675
4676 VkPipelineShaderStageCreateInfo shaderStages[2];
4677 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4678
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004679 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4680 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4681 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004682 shaderStages[0] = vs.GetStageCreateInfo();
4683 shaderStages[1] = fs.GetStageCreateInfo();
4684
4685 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4686 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4687
4688 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4689 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4690 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4691
4692 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4693 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004694 rs_ci.rasterizerDiscardEnable = true;
4695 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004696
4697 VkPipelineColorBlendAttachmentState att = {};
4698 att.blendEnable = VK_FALSE;
4699 att.colorWriteMask = 0xf;
4700
4701 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4702 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4703 cb_ci.attachmentCount = 1;
4704 cb_ci.pAttachments = &att;
4705
4706 VkGraphicsPipelineCreateInfo gp_ci = {};
4707 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4708 gp_ci.stageCount = 2;
4709 gp_ci.pStages = shaderStages;
4710 gp_ci.pVertexInputState = &vi_ci;
4711 gp_ci.pInputAssemblyState = &ia_ci;
4712 gp_ci.pViewportState = &vp_state_ci;
4713 gp_ci.pRasterizationState = &rs_ci;
4714 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004715 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4716 gp_ci.layout = pipeline_layout;
4717 gp_ci.renderPass = renderPass();
4718
4719 VkPipelineCacheCreateInfo pc_ci = {};
4720 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4721
4722 VkPipeline pipeline;
4723 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004724 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004725 ASSERT_VK_SUCCESS(err);
4726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004727 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004728 ASSERT_VK_SUCCESS(err);
4729
4730 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004731 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004732 m_commandBuffer->EndCommandBuffer();
4733 // Now destroy pipeline in order to cause error when submitting
4734 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4735
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004737
4738 VkSubmitInfo submit_info = {};
4739 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4740 submit_info.commandBufferCount = 1;
4741 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4742 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4743
4744 m_errorMonitor->VerifyFound();
4745 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4746 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4747}
4748
Tobin Ehlis31289162016-08-17 14:57:58 -06004749TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4750 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4751 "due to a bound descriptor set with a buffer dependency "
4752 "being destroyed.");
4753 ASSERT_NO_FATAL_FAILURE(InitState());
4754 ASSERT_NO_FATAL_FAILURE(InitViewport());
4755 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4756
4757 VkDescriptorPoolSize ds_type_count = {};
4758 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4759 ds_type_count.descriptorCount = 1;
4760
4761 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4762 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4763 ds_pool_ci.pNext = NULL;
4764 ds_pool_ci.maxSets = 1;
4765 ds_pool_ci.poolSizeCount = 1;
4766 ds_pool_ci.pPoolSizes = &ds_type_count;
4767
4768 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004769 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004770 ASSERT_VK_SUCCESS(err);
4771
4772 VkDescriptorSetLayoutBinding dsl_binding = {};
4773 dsl_binding.binding = 0;
4774 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4775 dsl_binding.descriptorCount = 1;
4776 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4777 dsl_binding.pImmutableSamplers = NULL;
4778
4779 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4780 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4781 ds_layout_ci.pNext = NULL;
4782 ds_layout_ci.bindingCount = 1;
4783 ds_layout_ci.pBindings = &dsl_binding;
4784 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004785 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004786 ASSERT_VK_SUCCESS(err);
4787
4788 VkDescriptorSet descriptorSet;
4789 VkDescriptorSetAllocateInfo alloc_info = {};
4790 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4791 alloc_info.descriptorSetCount = 1;
4792 alloc_info.descriptorPool = ds_pool;
4793 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004794 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004795 ASSERT_VK_SUCCESS(err);
4796
4797 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4798 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4799 pipeline_layout_ci.pNext = NULL;
4800 pipeline_layout_ci.setLayoutCount = 1;
4801 pipeline_layout_ci.pSetLayouts = &ds_layout;
4802
4803 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004804 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004805 ASSERT_VK_SUCCESS(err);
4806
4807 // Create a buffer to update the descriptor with
4808 uint32_t qfi = 0;
4809 VkBufferCreateInfo buffCI = {};
4810 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4811 buffCI.size = 1024;
4812 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4813 buffCI.queueFamilyIndexCount = 1;
4814 buffCI.pQueueFamilyIndices = &qfi;
4815
4816 VkBuffer buffer;
4817 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4818 ASSERT_VK_SUCCESS(err);
4819 // Allocate memory and bind to buffer so we can make it to the appropriate
4820 // error
4821 VkMemoryAllocateInfo mem_alloc = {};
4822 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4823 mem_alloc.pNext = NULL;
4824 mem_alloc.allocationSize = 1024;
4825 mem_alloc.memoryTypeIndex = 0;
4826
4827 VkMemoryRequirements memReqs;
4828 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004829 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004830 if (!pass) {
4831 vkDestroyBuffer(m_device->device(), buffer, NULL);
4832 return;
4833 }
4834
4835 VkDeviceMemory mem;
4836 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4837 ASSERT_VK_SUCCESS(err);
4838 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4839 ASSERT_VK_SUCCESS(err);
4840 // Correctly update descriptor to avoid "NOT_UPDATED" error
4841 VkDescriptorBufferInfo buffInfo = {};
4842 buffInfo.buffer = buffer;
4843 buffInfo.offset = 0;
4844 buffInfo.range = 1024;
4845
4846 VkWriteDescriptorSet descriptor_write;
4847 memset(&descriptor_write, 0, sizeof(descriptor_write));
4848 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4849 descriptor_write.dstSet = descriptorSet;
4850 descriptor_write.dstBinding = 0;
4851 descriptor_write.descriptorCount = 1;
4852 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4853 descriptor_write.pBufferInfo = &buffInfo;
4854
4855 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4856
4857 // Create PSO to be used for draw-time errors below
4858 char const *vsSource = "#version 450\n"
4859 "\n"
4860 "out gl_PerVertex { \n"
4861 " vec4 gl_Position;\n"
4862 "};\n"
4863 "void main(){\n"
4864 " gl_Position = vec4(1);\n"
4865 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004866 char const *fsSource = "#version 450\n"
4867 "\n"
4868 "layout(location=0) out vec4 x;\n"
4869 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4870 "void main(){\n"
4871 " x = vec4(bar.y);\n"
4872 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004873 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4874 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4875 VkPipelineObj pipe(m_device);
4876 pipe.AddShader(&vs);
4877 pipe.AddShader(&fs);
4878 pipe.AddColorAttachment();
4879 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4880
4881 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004882 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4883 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4884 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06004885 Draw(1, 0, 0, 0);
4886 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06004888 // Destroy buffer should invalidate the cmd buffer, causing error on submit
4889 vkDestroyBuffer(m_device->device(), buffer, NULL);
4890 // Attempt to submit cmd buffer
4891 VkSubmitInfo submit_info = {};
4892 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4893 submit_info.commandBufferCount = 1;
4894 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4895 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4896 m_errorMonitor->VerifyFound();
4897 // Cleanup
4898 vkFreeMemory(m_device->device(), mem, NULL);
4899
4900 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4901 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4902 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4903}
4904
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004905TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
4906 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4907 "due to a bound descriptor sets with a combined image "
4908 "sampler having their image, sampler, and descriptor set "
4909 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06004910 "submit associated cmd buffers. Attempt to destroy a "
4911 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004912 ASSERT_NO_FATAL_FAILURE(InitState());
4913 ASSERT_NO_FATAL_FAILURE(InitViewport());
4914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4915
4916 VkDescriptorPoolSize ds_type_count = {};
4917 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4918 ds_type_count.descriptorCount = 1;
4919
4920 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4921 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4922 ds_pool_ci.pNext = NULL;
4923 ds_pool_ci.maxSets = 1;
4924 ds_pool_ci.poolSizeCount = 1;
4925 ds_pool_ci.pPoolSizes = &ds_type_count;
4926
4927 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004928 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004929 ASSERT_VK_SUCCESS(err);
4930
4931 VkDescriptorSetLayoutBinding dsl_binding = {};
4932 dsl_binding.binding = 0;
4933 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4934 dsl_binding.descriptorCount = 1;
4935 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4936 dsl_binding.pImmutableSamplers = NULL;
4937
4938 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4939 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4940 ds_layout_ci.pNext = NULL;
4941 ds_layout_ci.bindingCount = 1;
4942 ds_layout_ci.pBindings = &dsl_binding;
4943 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004944 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004945 ASSERT_VK_SUCCESS(err);
4946
4947 VkDescriptorSet descriptorSet;
4948 VkDescriptorSetAllocateInfo alloc_info = {};
4949 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4950 alloc_info.descriptorSetCount = 1;
4951 alloc_info.descriptorPool = ds_pool;
4952 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004953 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004954 ASSERT_VK_SUCCESS(err);
4955
4956 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4957 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4958 pipeline_layout_ci.pNext = NULL;
4959 pipeline_layout_ci.setLayoutCount = 1;
4960 pipeline_layout_ci.pSetLayouts = &ds_layout;
4961
4962 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004963 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004964 ASSERT_VK_SUCCESS(err);
4965
4966 // Create images to update the descriptor with
4967 VkImage image;
4968 VkImage image2;
4969 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4970 const int32_t tex_width = 32;
4971 const int32_t tex_height = 32;
4972 VkImageCreateInfo image_create_info = {};
4973 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4974 image_create_info.pNext = NULL;
4975 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4976 image_create_info.format = tex_format;
4977 image_create_info.extent.width = tex_width;
4978 image_create_info.extent.height = tex_height;
4979 image_create_info.extent.depth = 1;
4980 image_create_info.mipLevels = 1;
4981 image_create_info.arrayLayers = 1;
4982 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4983 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
4984 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4985 image_create_info.flags = 0;
4986 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
4987 ASSERT_VK_SUCCESS(err);
4988 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
4989 ASSERT_VK_SUCCESS(err);
4990
4991 VkMemoryRequirements memory_reqs;
4992 VkDeviceMemory image_memory;
4993 bool pass;
4994 VkMemoryAllocateInfo memory_info = {};
4995 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4996 memory_info.pNext = NULL;
4997 memory_info.allocationSize = 0;
4998 memory_info.memoryTypeIndex = 0;
4999 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5000 // Allocate enough memory for both images
5001 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005002 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005003 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005004 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005005 ASSERT_VK_SUCCESS(err);
5006 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5007 ASSERT_VK_SUCCESS(err);
5008 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005009 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005010 ASSERT_VK_SUCCESS(err);
5011
5012 VkImageViewCreateInfo image_view_create_info = {};
5013 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5014 image_view_create_info.image = image;
5015 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5016 image_view_create_info.format = tex_format;
5017 image_view_create_info.subresourceRange.layerCount = 1;
5018 image_view_create_info.subresourceRange.baseMipLevel = 0;
5019 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005020 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005021
5022 VkImageView view;
5023 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005024 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005025 ASSERT_VK_SUCCESS(err);
5026 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005027 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005028 ASSERT_VK_SUCCESS(err);
5029 // Create Samplers
5030 VkSamplerCreateInfo sampler_ci = {};
5031 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5032 sampler_ci.pNext = NULL;
5033 sampler_ci.magFilter = VK_FILTER_NEAREST;
5034 sampler_ci.minFilter = VK_FILTER_NEAREST;
5035 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5036 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5037 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5038 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5039 sampler_ci.mipLodBias = 1.0;
5040 sampler_ci.anisotropyEnable = VK_FALSE;
5041 sampler_ci.maxAnisotropy = 1;
5042 sampler_ci.compareEnable = VK_FALSE;
5043 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5044 sampler_ci.minLod = 1.0;
5045 sampler_ci.maxLod = 1.0;
5046 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5047 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5048 VkSampler sampler;
5049 VkSampler sampler2;
5050 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5051 ASSERT_VK_SUCCESS(err);
5052 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5053 ASSERT_VK_SUCCESS(err);
5054 // Update descriptor with image and sampler
5055 VkDescriptorImageInfo img_info = {};
5056 img_info.sampler = sampler;
5057 img_info.imageView = view;
5058 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5059
5060 VkWriteDescriptorSet descriptor_write;
5061 memset(&descriptor_write, 0, sizeof(descriptor_write));
5062 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5063 descriptor_write.dstSet = descriptorSet;
5064 descriptor_write.dstBinding = 0;
5065 descriptor_write.descriptorCount = 1;
5066 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5067 descriptor_write.pImageInfo = &img_info;
5068
5069 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5070
5071 // Create PSO to be used for draw-time errors below
5072 char const *vsSource = "#version 450\n"
5073 "\n"
5074 "out gl_PerVertex { \n"
5075 " vec4 gl_Position;\n"
5076 "};\n"
5077 "void main(){\n"
5078 " gl_Position = vec4(1);\n"
5079 "}\n";
5080 char const *fsSource = "#version 450\n"
5081 "\n"
5082 "layout(set=0, binding=0) uniform sampler2D s;\n"
5083 "layout(location=0) out vec4 x;\n"
5084 "void main(){\n"
5085 " x = texture(s, vec2(1));\n"
5086 "}\n";
5087 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5088 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5089 VkPipelineObj pipe(m_device);
5090 pipe.AddShader(&vs);
5091 pipe.AddShader(&fs);
5092 pipe.AddColorAttachment();
5093 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5094
5095 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005097 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005098 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5099 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5100 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005101 Draw(1, 0, 0, 0);
5102 EndCommandBuffer();
5103 // Destroy sampler invalidates the cmd buffer, causing error on submit
5104 vkDestroySampler(m_device->device(), sampler, NULL);
5105 // Attempt to submit cmd buffer
5106 VkSubmitInfo submit_info = {};
5107 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5108 submit_info.commandBufferCount = 1;
5109 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5110 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5111 m_errorMonitor->VerifyFound();
5112 // Now re-update descriptor with valid sampler and delete image
5113 img_info.sampler = sampler2;
5114 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005116 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005117 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5118 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5119 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005120 Draw(1, 0, 0, 0);
5121 EndCommandBuffer();
5122 // Destroy image invalidates the cmd buffer, causing error on submit
5123 vkDestroyImage(m_device->device(), image, NULL);
5124 // Attempt to submit cmd buffer
5125 submit_info = {};
5126 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5127 submit_info.commandBufferCount = 1;
5128 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5129 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5130 m_errorMonitor->VerifyFound();
5131 // Now update descriptor to be valid, but then free descriptor
5132 img_info.imageView = view2;
5133 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005135 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005136 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5137 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5138 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005139 Draw(1, 0, 0, 0);
5140 EndCommandBuffer();
5141 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005143 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005144 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005145 // Attempt to submit cmd buffer
5146 submit_info = {};
5147 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5148 submit_info.commandBufferCount = 1;
5149 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5150 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5151 m_errorMonitor->VerifyFound();
5152 // Cleanup
5153 vkFreeMemory(m_device->device(), image_memory, NULL);
5154 vkDestroySampler(m_device->device(), sampler2, NULL);
5155 vkDestroyImage(m_device->device(), image2, NULL);
5156 vkDestroyImageView(m_device->device(), view, NULL);
5157 vkDestroyImageView(m_device->device(), view2, NULL);
5158 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5159 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5160 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5161}
5162
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005163TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5164 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5165 ASSERT_NO_FATAL_FAILURE(InitState());
5166 ASSERT_NO_FATAL_FAILURE(InitViewport());
5167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5168
5169 VkDescriptorPoolSize ds_type_count = {};
5170 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5171 ds_type_count.descriptorCount = 1;
5172
5173 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5174 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5175 ds_pool_ci.pNext = NULL;
5176 ds_pool_ci.maxSets = 1;
5177 ds_pool_ci.poolSizeCount = 1;
5178 ds_pool_ci.pPoolSizes = &ds_type_count;
5179
5180 VkDescriptorPool ds_pool;
5181 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5182 ASSERT_VK_SUCCESS(err);
5183
5184 VkDescriptorSetLayoutBinding dsl_binding = {};
5185 dsl_binding.binding = 0;
5186 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5187 dsl_binding.descriptorCount = 1;
5188 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5189 dsl_binding.pImmutableSamplers = NULL;
5190
5191 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5192 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5193 ds_layout_ci.pNext = NULL;
5194 ds_layout_ci.bindingCount = 1;
5195 ds_layout_ci.pBindings = &dsl_binding;
5196 VkDescriptorSetLayout ds_layout;
5197 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5198 ASSERT_VK_SUCCESS(err);
5199
5200 VkDescriptorSet descriptor_set;
5201 VkDescriptorSetAllocateInfo alloc_info = {};
5202 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5203 alloc_info.descriptorSetCount = 1;
5204 alloc_info.descriptorPool = ds_pool;
5205 alloc_info.pSetLayouts = &ds_layout;
5206 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5207 ASSERT_VK_SUCCESS(err);
5208
5209 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5210 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5211 pipeline_layout_ci.pNext = NULL;
5212 pipeline_layout_ci.setLayoutCount = 1;
5213 pipeline_layout_ci.pSetLayouts = &ds_layout;
5214
5215 VkPipelineLayout pipeline_layout;
5216 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5217 ASSERT_VK_SUCCESS(err);
5218
5219 // Create image to update the descriptor with
5220 VkImageObj image(m_device);
5221 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5222 ASSERT_TRUE(image.initialized());
5223
5224 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5225 // Create Sampler
5226 VkSamplerCreateInfo sampler_ci = {};
5227 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5228 sampler_ci.pNext = NULL;
5229 sampler_ci.magFilter = VK_FILTER_NEAREST;
5230 sampler_ci.minFilter = VK_FILTER_NEAREST;
5231 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5232 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5233 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5234 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5235 sampler_ci.mipLodBias = 1.0;
5236 sampler_ci.anisotropyEnable = VK_FALSE;
5237 sampler_ci.maxAnisotropy = 1;
5238 sampler_ci.compareEnable = VK_FALSE;
5239 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5240 sampler_ci.minLod = 1.0;
5241 sampler_ci.maxLod = 1.0;
5242 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5243 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5244 VkSampler sampler;
5245 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5246 ASSERT_VK_SUCCESS(err);
5247 // Update descriptor with image and sampler
5248 VkDescriptorImageInfo img_info = {};
5249 img_info.sampler = sampler;
5250 img_info.imageView = view;
5251 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5252
5253 VkWriteDescriptorSet descriptor_write;
5254 memset(&descriptor_write, 0, sizeof(descriptor_write));
5255 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5256 descriptor_write.dstSet = descriptor_set;
5257 descriptor_write.dstBinding = 0;
5258 descriptor_write.descriptorCount = 1;
5259 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5260 descriptor_write.pImageInfo = &img_info;
5261
5262 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5263
5264 // Create PSO to be used for draw-time errors below
5265 char const *vsSource = "#version 450\n"
5266 "\n"
5267 "out gl_PerVertex { \n"
5268 " vec4 gl_Position;\n"
5269 "};\n"
5270 "void main(){\n"
5271 " gl_Position = vec4(1);\n"
5272 "}\n";
5273 char const *fsSource = "#version 450\n"
5274 "\n"
5275 "layout(set=0, binding=0) uniform sampler2D s;\n"
5276 "layout(location=0) out vec4 x;\n"
5277 "void main(){\n"
5278 " x = texture(s, vec2(1));\n"
5279 "}\n";
5280 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5281 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5282 VkPipelineObj pipe(m_device);
5283 pipe.AddShader(&vs);
5284 pipe.AddShader(&fs);
5285 pipe.AddColorAttachment();
5286 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5287
5288 BeginCommandBuffer();
5289 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5290 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5291 &descriptor_set, 0, NULL);
5292 Draw(1, 0, 0, 0);
5293 EndCommandBuffer();
5294 // Submit cmd buffer to put pool in-flight
5295 VkSubmitInfo submit_info = {};
5296 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5297 submit_info.commandBufferCount = 1;
5298 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5299 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5300 // Destroy pool while in-flight, causing error
5301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5302 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5303 m_errorMonitor->VerifyFound();
5304 vkQueueWaitIdle(m_device->m_queue);
5305 // Cleanup
5306 vkDestroySampler(m_device->device(), sampler, NULL);
5307 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5308 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5309 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5310}
5311
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005312TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5313 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5314 ASSERT_NO_FATAL_FAILURE(InitState());
5315 ASSERT_NO_FATAL_FAILURE(InitViewport());
5316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5317
5318 VkDescriptorPoolSize ds_type_count = {};
5319 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5320 ds_type_count.descriptorCount = 1;
5321
5322 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5323 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5324 ds_pool_ci.pNext = NULL;
5325 ds_pool_ci.maxSets = 1;
5326 ds_pool_ci.poolSizeCount = 1;
5327 ds_pool_ci.pPoolSizes = &ds_type_count;
5328
5329 VkDescriptorPool ds_pool;
5330 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5331 ASSERT_VK_SUCCESS(err);
5332
5333 VkDescriptorSetLayoutBinding dsl_binding = {};
5334 dsl_binding.binding = 0;
5335 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5336 dsl_binding.descriptorCount = 1;
5337 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5338 dsl_binding.pImmutableSamplers = NULL;
5339
5340 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5341 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5342 ds_layout_ci.pNext = NULL;
5343 ds_layout_ci.bindingCount = 1;
5344 ds_layout_ci.pBindings = &dsl_binding;
5345 VkDescriptorSetLayout ds_layout;
5346 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5347 ASSERT_VK_SUCCESS(err);
5348
5349 VkDescriptorSet descriptorSet;
5350 VkDescriptorSetAllocateInfo alloc_info = {};
5351 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5352 alloc_info.descriptorSetCount = 1;
5353 alloc_info.descriptorPool = ds_pool;
5354 alloc_info.pSetLayouts = &ds_layout;
5355 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5356 ASSERT_VK_SUCCESS(err);
5357
5358 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5359 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5360 pipeline_layout_ci.pNext = NULL;
5361 pipeline_layout_ci.setLayoutCount = 1;
5362 pipeline_layout_ci.pSetLayouts = &ds_layout;
5363
5364 VkPipelineLayout pipeline_layout;
5365 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5366 ASSERT_VK_SUCCESS(err);
5367
5368 // Create images to update the descriptor with
5369 VkImage image;
5370 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5371 const int32_t tex_width = 32;
5372 const int32_t tex_height = 32;
5373 VkImageCreateInfo image_create_info = {};
5374 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5375 image_create_info.pNext = NULL;
5376 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5377 image_create_info.format = tex_format;
5378 image_create_info.extent.width = tex_width;
5379 image_create_info.extent.height = tex_height;
5380 image_create_info.extent.depth = 1;
5381 image_create_info.mipLevels = 1;
5382 image_create_info.arrayLayers = 1;
5383 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5384 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5385 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5386 image_create_info.flags = 0;
5387 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5388 ASSERT_VK_SUCCESS(err);
5389 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5390 VkMemoryRequirements memory_reqs;
5391 VkDeviceMemory image_memory;
5392 bool pass;
5393 VkMemoryAllocateInfo memory_info = {};
5394 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5395 memory_info.pNext = NULL;
5396 memory_info.allocationSize = 0;
5397 memory_info.memoryTypeIndex = 0;
5398 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5399 // Allocate enough memory for image
5400 memory_info.allocationSize = memory_reqs.size;
5401 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5402 ASSERT_TRUE(pass);
5403 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5404 ASSERT_VK_SUCCESS(err);
5405 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5406 ASSERT_VK_SUCCESS(err);
5407
5408 VkImageViewCreateInfo image_view_create_info = {};
5409 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5410 image_view_create_info.image = image;
5411 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5412 image_view_create_info.format = tex_format;
5413 image_view_create_info.subresourceRange.layerCount = 1;
5414 image_view_create_info.subresourceRange.baseMipLevel = 0;
5415 image_view_create_info.subresourceRange.levelCount = 1;
5416 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5417
5418 VkImageView view;
5419 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5420 ASSERT_VK_SUCCESS(err);
5421 // Create Samplers
5422 VkSamplerCreateInfo sampler_ci = {};
5423 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5424 sampler_ci.pNext = NULL;
5425 sampler_ci.magFilter = VK_FILTER_NEAREST;
5426 sampler_ci.minFilter = VK_FILTER_NEAREST;
5427 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5428 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5429 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5430 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5431 sampler_ci.mipLodBias = 1.0;
5432 sampler_ci.anisotropyEnable = VK_FALSE;
5433 sampler_ci.maxAnisotropy = 1;
5434 sampler_ci.compareEnable = VK_FALSE;
5435 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5436 sampler_ci.minLod = 1.0;
5437 sampler_ci.maxLod = 1.0;
5438 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5439 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5440 VkSampler sampler;
5441 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5442 ASSERT_VK_SUCCESS(err);
5443 // Update descriptor with image and sampler
5444 VkDescriptorImageInfo img_info = {};
5445 img_info.sampler = sampler;
5446 img_info.imageView = view;
5447 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5448
5449 VkWriteDescriptorSet descriptor_write;
5450 memset(&descriptor_write, 0, sizeof(descriptor_write));
5451 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5452 descriptor_write.dstSet = descriptorSet;
5453 descriptor_write.dstBinding = 0;
5454 descriptor_write.descriptorCount = 1;
5455 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5456 descriptor_write.pImageInfo = &img_info;
5457 // Break memory binding and attempt update
5458 vkFreeMemory(m_device->device(), image_memory, nullptr);
5459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005460 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5462 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5463 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5464 m_errorMonitor->VerifyFound();
5465 // Cleanup
5466 vkDestroyImage(m_device->device(), image, NULL);
5467 vkDestroySampler(m_device->device(), sampler, NULL);
5468 vkDestroyImageView(m_device->device(), view, NULL);
5469 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5470 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5471 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5472}
5473
Karl Schultz6addd812016-02-02 17:17:23 -07005474TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005475 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5476 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005477 // Create a valid cmd buffer
5478 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005479 uint64_t fake_pipeline_handle = 0xbaad6001;
5480 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005481 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5483
5484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005485 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005486 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005487 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005488
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005489 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005490 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 -06005491 Draw(1, 0, 0, 0);
5492 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005493
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005494 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005495 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 +12005496 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005497 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5498 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005499}
5500
Karl Schultz6addd812016-02-02 17:17:23 -07005501TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005502 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005503 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005504
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005506
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005507 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005508 ASSERT_NO_FATAL_FAILURE(InitViewport());
5509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005510 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005511 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5512 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005513
5514 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005515 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5516 ds_pool_ci.pNext = NULL;
5517 ds_pool_ci.maxSets = 1;
5518 ds_pool_ci.poolSizeCount = 1;
5519 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005520
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005521 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005522 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005523 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005524
Tony Barboureb254902015-07-15 12:50:33 -06005525 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005526 dsl_binding.binding = 0;
5527 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5528 dsl_binding.descriptorCount = 1;
5529 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5530 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005531
Tony Barboureb254902015-07-15 12:50:33 -06005532 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005533 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5534 ds_layout_ci.pNext = NULL;
5535 ds_layout_ci.bindingCount = 1;
5536 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005537 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005538 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005539 ASSERT_VK_SUCCESS(err);
5540
5541 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005542 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005543 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005544 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005545 alloc_info.descriptorPool = ds_pool;
5546 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005547 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005548 ASSERT_VK_SUCCESS(err);
5549
Tony Barboureb254902015-07-15 12:50:33 -06005550 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005551 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5552 pipeline_layout_ci.pNext = NULL;
5553 pipeline_layout_ci.setLayoutCount = 1;
5554 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005555
5556 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005557 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005558 ASSERT_VK_SUCCESS(err);
5559
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005560 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005561 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005562 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005563 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005564
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005565 VkPipelineObj pipe(m_device);
5566 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005567 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005568 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005569 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005570
5571 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005572 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5573 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5574 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005575
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005576 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005577
Chia-I Wuf7458c52015-10-26 21:10:41 +08005578 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5579 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5580 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005581}
5582
Karl Schultz6addd812016-02-02 17:17:23 -07005583TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005584 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005585 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005586
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5588 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005589
5590 ASSERT_NO_FATAL_FAILURE(InitState());
5591 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005592 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5593 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005594
5595 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005596 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5597 ds_pool_ci.pNext = NULL;
5598 ds_pool_ci.maxSets = 1;
5599 ds_pool_ci.poolSizeCount = 1;
5600 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005601
5602 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005603 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005604 ASSERT_VK_SUCCESS(err);
5605
5606 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005607 dsl_binding.binding = 0;
5608 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5609 dsl_binding.descriptorCount = 1;
5610 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5611 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005612
5613 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005614 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5615 ds_layout_ci.pNext = NULL;
5616 ds_layout_ci.bindingCount = 1;
5617 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005618 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005619 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005620 ASSERT_VK_SUCCESS(err);
5621
5622 VkDescriptorSet descriptorSet;
5623 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005624 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005625 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005626 alloc_info.descriptorPool = ds_pool;
5627 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005628 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005629 ASSERT_VK_SUCCESS(err);
5630
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005631 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005632 VkWriteDescriptorSet descriptor_write;
5633 memset(&descriptor_write, 0, sizeof(descriptor_write));
5634 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5635 descriptor_write.dstSet = descriptorSet;
5636 descriptor_write.dstBinding = 0;
5637 descriptor_write.descriptorCount = 1;
5638 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5639 descriptor_write.pTexelBufferView = &view;
5640
5641 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5642
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005643 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005644
5645 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5646 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5647}
5648
Mark Youngd339ba32016-05-30 13:28:35 -06005649TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005650 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 -06005651
5652 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005654 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005655
5656 ASSERT_NO_FATAL_FAILURE(InitState());
5657
5658 // Create a buffer with no bound memory and then attempt to create
5659 // a buffer view.
5660 VkBufferCreateInfo buff_ci = {};
5661 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005662 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005663 buff_ci.size = 256;
5664 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5665 VkBuffer buffer;
5666 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5667 ASSERT_VK_SUCCESS(err);
5668
5669 VkBufferViewCreateInfo buff_view_ci = {};
5670 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5671 buff_view_ci.buffer = buffer;
5672 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5673 buff_view_ci.range = VK_WHOLE_SIZE;
5674 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005675 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005676
5677 m_errorMonitor->VerifyFound();
5678 vkDestroyBuffer(m_device->device(), buffer, NULL);
5679 // If last error is success, it still created the view, so delete it.
5680 if (err == VK_SUCCESS) {
5681 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5682 }
5683}
5684
Karl Schultz6addd812016-02-02 17:17:23 -07005685TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5686 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5687 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005688 // 1. No dynamicOffset supplied
5689 // 2. Too many dynamicOffsets supplied
5690 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005691 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5693 "0 dynamicOffsets are left in "
5694 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005695
5696 ASSERT_NO_FATAL_FAILURE(InitState());
5697 ASSERT_NO_FATAL_FAILURE(InitViewport());
5698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5699
5700 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005701 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5702 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005703
5704 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005705 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5706 ds_pool_ci.pNext = NULL;
5707 ds_pool_ci.maxSets = 1;
5708 ds_pool_ci.poolSizeCount = 1;
5709 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005710
5711 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005712 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005713 ASSERT_VK_SUCCESS(err);
5714
5715 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005716 dsl_binding.binding = 0;
5717 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5718 dsl_binding.descriptorCount = 1;
5719 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5720 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005721
5722 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005723 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5724 ds_layout_ci.pNext = NULL;
5725 ds_layout_ci.bindingCount = 1;
5726 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005727 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005728 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005729 ASSERT_VK_SUCCESS(err);
5730
5731 VkDescriptorSet descriptorSet;
5732 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005733 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005734 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005735 alloc_info.descriptorPool = ds_pool;
5736 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005737 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005738 ASSERT_VK_SUCCESS(err);
5739
5740 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005741 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5742 pipeline_layout_ci.pNext = NULL;
5743 pipeline_layout_ci.setLayoutCount = 1;
5744 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005745
5746 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005747 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005748 ASSERT_VK_SUCCESS(err);
5749
5750 // Create a buffer to update the descriptor with
5751 uint32_t qfi = 0;
5752 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005753 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5754 buffCI.size = 1024;
5755 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5756 buffCI.queueFamilyIndexCount = 1;
5757 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005758
5759 VkBuffer dyub;
5760 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5761 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005762 // Allocate memory and bind to buffer so we can make it to the appropriate
5763 // error
5764 VkMemoryAllocateInfo mem_alloc = {};
5765 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5766 mem_alloc.pNext = NULL;
5767 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005768 mem_alloc.memoryTypeIndex = 0;
5769
5770 VkMemoryRequirements memReqs;
5771 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005772 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005773 if (!pass) {
5774 vkDestroyBuffer(m_device->device(), dyub, NULL);
5775 return;
5776 }
5777
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005778 VkDeviceMemory mem;
5779 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5780 ASSERT_VK_SUCCESS(err);
5781 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5782 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005783 // Correctly update descriptor to avoid "NOT_UPDATED" error
5784 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005785 buffInfo.buffer = dyub;
5786 buffInfo.offset = 0;
5787 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005788
5789 VkWriteDescriptorSet descriptor_write;
5790 memset(&descriptor_write, 0, sizeof(descriptor_write));
5791 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5792 descriptor_write.dstSet = descriptorSet;
5793 descriptor_write.dstBinding = 0;
5794 descriptor_write.descriptorCount = 1;
5795 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5796 descriptor_write.pBufferInfo = &buffInfo;
5797
5798 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5799
5800 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005801 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5802 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005803 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005804 uint32_t pDynOff[2] = {512, 756};
5805 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5807 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5808 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5809 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005810 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005811 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5813 "offset 0 and range 1024 that "
5814 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005815 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005816 char const *vsSource = "#version 450\n"
5817 "\n"
5818 "out gl_PerVertex { \n"
5819 " vec4 gl_Position;\n"
5820 "};\n"
5821 "void main(){\n"
5822 " gl_Position = vec4(1);\n"
5823 "}\n";
5824 char const *fsSource = "#version 450\n"
5825 "\n"
5826 "layout(location=0) out vec4 x;\n"
5827 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5828 "void main(){\n"
5829 " x = vec4(bar.y);\n"
5830 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005831 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5832 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5833 VkPipelineObj pipe(m_device);
5834 pipe.AddShader(&vs);
5835 pipe.AddShader(&fs);
5836 pipe.AddColorAttachment();
5837 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5838
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005839 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005840 // This update should succeed, but offset size of 512 will overstep buffer
5841 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005842 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5843 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005844 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005845 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005846
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005847 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005848 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005849
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005850 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005851 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005852 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5853}
5854
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005855TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5856 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5857 "that doesn't have memory bound");
5858 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005860 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5862 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005863
5864 ASSERT_NO_FATAL_FAILURE(InitState());
5865 ASSERT_NO_FATAL_FAILURE(InitViewport());
5866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5867
5868 VkDescriptorPoolSize ds_type_count = {};
5869 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5870 ds_type_count.descriptorCount = 1;
5871
5872 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5873 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5874 ds_pool_ci.pNext = NULL;
5875 ds_pool_ci.maxSets = 1;
5876 ds_pool_ci.poolSizeCount = 1;
5877 ds_pool_ci.pPoolSizes = &ds_type_count;
5878
5879 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005880 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005881 ASSERT_VK_SUCCESS(err);
5882
5883 VkDescriptorSetLayoutBinding dsl_binding = {};
5884 dsl_binding.binding = 0;
5885 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5886 dsl_binding.descriptorCount = 1;
5887 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5888 dsl_binding.pImmutableSamplers = NULL;
5889
5890 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5891 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5892 ds_layout_ci.pNext = NULL;
5893 ds_layout_ci.bindingCount = 1;
5894 ds_layout_ci.pBindings = &dsl_binding;
5895 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005896 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005897 ASSERT_VK_SUCCESS(err);
5898
5899 VkDescriptorSet descriptorSet;
5900 VkDescriptorSetAllocateInfo alloc_info = {};
5901 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5902 alloc_info.descriptorSetCount = 1;
5903 alloc_info.descriptorPool = ds_pool;
5904 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005905 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005906 ASSERT_VK_SUCCESS(err);
5907
5908 // Create a buffer to update the descriptor with
5909 uint32_t qfi = 0;
5910 VkBufferCreateInfo buffCI = {};
5911 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5912 buffCI.size = 1024;
5913 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5914 buffCI.queueFamilyIndexCount = 1;
5915 buffCI.pQueueFamilyIndices = &qfi;
5916
5917 VkBuffer dyub;
5918 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5919 ASSERT_VK_SUCCESS(err);
5920
5921 // Attempt to update descriptor without binding memory to it
5922 VkDescriptorBufferInfo buffInfo = {};
5923 buffInfo.buffer = dyub;
5924 buffInfo.offset = 0;
5925 buffInfo.range = 1024;
5926
5927 VkWriteDescriptorSet descriptor_write;
5928 memset(&descriptor_write, 0, sizeof(descriptor_write));
5929 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5930 descriptor_write.dstSet = descriptorSet;
5931 descriptor_write.dstBinding = 0;
5932 descriptor_write.descriptorCount = 1;
5933 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5934 descriptor_write.pBufferInfo = &buffInfo;
5935
5936 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5937 m_errorMonitor->VerifyFound();
5938
5939 vkDestroyBuffer(m_device->device(), dyub, NULL);
5940 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5941 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5942}
5943
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005944TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005945 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005946 ASSERT_NO_FATAL_FAILURE(InitState());
5947 ASSERT_NO_FATAL_FAILURE(InitViewport());
5948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5949
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005950 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005951 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005952 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5953 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5954 pipeline_layout_ci.pushConstantRangeCount = 1;
5955 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5956
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005957 //
5958 // Check for invalid push constant ranges in pipeline layouts.
5959 //
5960 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005961 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005962 char const *msg;
5963 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005964
Karl Schultzc81037d2016-05-12 08:11:23 -06005965 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5966 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5967 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5968 "vkCreatePipelineLayout() call has push constants index 0 with "
5969 "size 0."},
5970 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5971 "vkCreatePipelineLayout() call has push constants index 0 with "
5972 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005973 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06005974 "vkCreatePipelineLayout() call has push constants index 0 with "
5975 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005976 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06005977 "vkCreatePipelineLayout() call has push constants index 0 with "
5978 "size 0."},
5979 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5980 "vkCreatePipelineLayout() call has push constants index 0 with "
5981 "offset 1. Offset must"},
5982 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5983 "vkCreatePipelineLayout() call has push constants index 0 "
5984 "with offset "},
5985 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5986 "vkCreatePipelineLayout() call has push constants "
5987 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005988 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06005989 "vkCreatePipelineLayout() call has push constants index 0 "
5990 "with offset "},
5991 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5992 "vkCreatePipelineLayout() call has push "
5993 "constants index 0 with offset "},
5994 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
5995 "vkCreatePipelineLayout() call has push "
5996 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005997 }};
5998
5999 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006000 for (const auto &iter : range_tests) {
6001 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6003 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006004 m_errorMonitor->VerifyFound();
6005 if (VK_SUCCESS == err) {
6006 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6007 }
6008 }
6009
6010 // Check for invalid stage flag
6011 pc_range.offset = 0;
6012 pc_range.size = 16;
6013 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006014 m_errorMonitor->SetDesiredFailureMsg(
6015 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6016 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006017 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006018 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006019 if (VK_SUCCESS == err) {
6020 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6021 }
6022
6023 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006024 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006025 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006026 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006027 char const *msg;
6028 };
6029
Karl Schultzc81037d2016-05-12 08:11:23 -06006030 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006031 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6032 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6033 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6034 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6035 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006036 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006037 {
6038 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6039 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6040 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6041 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6042 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006043 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006044 },
6045 {
6046 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6047 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6048 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6049 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6050 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006051 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006052 },
6053 {
6054 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6055 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6056 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6057 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6058 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006059 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006060 },
6061 {
6062 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6063 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6064 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6065 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6066 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006067 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006068 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006069
Karl Schultzc81037d2016-05-12 08:11:23 -06006070 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006071 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006072 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6074 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006075 m_errorMonitor->VerifyFound();
6076 if (VK_SUCCESS == err) {
6077 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6078 }
6079 }
6080
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006081 //
6082 // CmdPushConstants tests
6083 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006084 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006085
6086 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006087 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6088 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006089 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6090 "vkCmdPushConstants() call has push constants with size 1. Size "
6091 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006092 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006093 "vkCmdPushConstants() call has push constants with size 1. Size "
6094 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006095 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006096 "vkCmdPushConstants() call has push constants with offset 1. "
6097 "Offset must be a multiple of 4."},
6098 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6099 "vkCmdPushConstants() call has push constants with offset 1. "
6100 "Offset must be a multiple of 4."},
6101 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6102 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6103 "0x1 not within flag-matching ranges in pipeline layout"},
6104 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6105 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6106 "0x1 not within flag-matching ranges in pipeline layout"},
6107 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6108 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6109 "0x1 not within flag-matching ranges in pipeline layout"},
6110 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6111 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6112 "0x1 not within flag-matching ranges in pipeline layout"},
6113 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6114 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6115 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006116 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006117 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6118 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006119 }};
6120
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006121 BeginCommandBuffer();
6122
6123 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006124 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006125 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006126 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006127 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006128 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006129 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006130 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006131 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6133 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006134 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006135 m_errorMonitor->VerifyFound();
6136 }
6137
6138 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006140 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006141 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006142 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006143
Karl Schultzc81037d2016-05-12 08:11:23 -06006144 // overlapping range tests with cmd
6145 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6146 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6147 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6148 "0x1 not within flag-matching ranges in pipeline layout"},
6149 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6150 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6151 "0x1 not within flag-matching ranges in pipeline layout"},
6152 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6153 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6154 "0x1 not within flag-matching ranges in pipeline layout"},
6155 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006156 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006157 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006158 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6159 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006160 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006161 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006162 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006163 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006164 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006165 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6167 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006168 iter.range.size, dummy_values);
6169 m_errorMonitor->VerifyFound();
6170 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006171 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6172
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006173 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006174}
6175
Karl Schultz6addd812016-02-02 17:17:23 -07006176TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006177 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006178 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006179
6180 ASSERT_NO_FATAL_FAILURE(InitState());
6181 ASSERT_NO_FATAL_FAILURE(InitViewport());
6182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6183
Mike Stroyanb8a61002016-06-20 16:00:28 -06006184 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6185 VkImageTiling tiling;
6186 VkFormatProperties format_properties;
6187 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006188 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006189 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006190 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006191 tiling = VK_IMAGE_TILING_OPTIMAL;
6192 } else {
6193 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6194 "skipped.\n");
6195 return;
6196 }
6197
Tobin Ehlis559c6382015-11-05 09:52:49 -07006198 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6199 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006200 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6201 ds_type_count[0].descriptorCount = 10;
6202 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6203 ds_type_count[1].descriptorCount = 2;
6204 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6205 ds_type_count[2].descriptorCount = 2;
6206 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6207 ds_type_count[3].descriptorCount = 5;
6208 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6209 // type
6210 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6211 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6212 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006213
6214 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006215 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6216 ds_pool_ci.pNext = NULL;
6217 ds_pool_ci.maxSets = 5;
6218 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6219 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006220
6221 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006222 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006223 ASSERT_VK_SUCCESS(err);
6224
6225 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6226 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006227 dsl_binding[0].binding = 0;
6228 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6229 dsl_binding[0].descriptorCount = 5;
6230 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6231 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006232
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006233 // Create layout identical to set0 layout but w/ different stageFlags
6234 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006235 dsl_fs_stage_only.binding = 0;
6236 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6237 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006238 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6239 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006240 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006241 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006242 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6243 ds_layout_ci.pNext = NULL;
6244 ds_layout_ci.bindingCount = 1;
6245 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006246 static const uint32_t NUM_LAYOUTS = 4;
6247 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006248 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006249 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6250 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006251 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006252 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006253 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006254 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006255 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006256 dsl_binding[0].binding = 0;
6257 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006258 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006259 dsl_binding[1].binding = 1;
6260 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6261 dsl_binding[1].descriptorCount = 2;
6262 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6263 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006264 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006265 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006266 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006267 ASSERT_VK_SUCCESS(err);
6268 dsl_binding[0].binding = 0;
6269 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006270 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006271 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006272 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006273 ASSERT_VK_SUCCESS(err);
6274 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006275 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006276 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006277 ASSERT_VK_SUCCESS(err);
6278
6279 static const uint32_t NUM_SETS = 4;
6280 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6281 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006282 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006283 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006284 alloc_info.descriptorPool = ds_pool;
6285 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006286 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006287 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006288 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006289 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006290 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006291 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006292 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006293
6294 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006295 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6296 pipeline_layout_ci.pNext = NULL;
6297 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6298 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006299
6300 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006301 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006302 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006303 // Create pipelineLayout with only one setLayout
6304 pipeline_layout_ci.setLayoutCount = 1;
6305 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006306 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006307 ASSERT_VK_SUCCESS(err);
6308 // Create pipelineLayout with 2 descriptor setLayout at index 0
6309 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6310 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006311 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006312 ASSERT_VK_SUCCESS(err);
6313 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6314 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6315 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006316 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006317 ASSERT_VK_SUCCESS(err);
6318 // Create pipelineLayout with UB type, but stageFlags for FS only
6319 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6320 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006321 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006322 ASSERT_VK_SUCCESS(err);
6323 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6324 VkDescriptorSetLayout pl_bad_s0[2] = {};
6325 pl_bad_s0[0] = ds_layout_fs_only;
6326 pl_bad_s0[1] = ds_layout[1];
6327 pipeline_layout_ci.setLayoutCount = 2;
6328 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6329 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006330 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006331 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006332
6333 // Create a buffer to update the descriptor with
6334 uint32_t qfi = 0;
6335 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006336 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6337 buffCI.size = 1024;
6338 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6339 buffCI.queueFamilyIndexCount = 1;
6340 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006341
6342 VkBuffer dyub;
6343 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6344 ASSERT_VK_SUCCESS(err);
6345 // Correctly update descriptor to avoid "NOT_UPDATED" error
6346 static const uint32_t NUM_BUFFS = 5;
6347 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006348 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006349 buffInfo[i].buffer = dyub;
6350 buffInfo[i].offset = 0;
6351 buffInfo[i].range = 1024;
6352 }
Karl Schultz6addd812016-02-02 17:17:23 -07006353 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006354 const int32_t tex_width = 32;
6355 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006356 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006357 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6358 image_create_info.pNext = NULL;
6359 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6360 image_create_info.format = tex_format;
6361 image_create_info.extent.width = tex_width;
6362 image_create_info.extent.height = tex_height;
6363 image_create_info.extent.depth = 1;
6364 image_create_info.mipLevels = 1;
6365 image_create_info.arrayLayers = 1;
6366 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006367 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006368 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006369 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006370 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006372
Karl Schultz6addd812016-02-02 17:17:23 -07006373 VkMemoryRequirements memReqs;
6374 VkDeviceMemory imageMem;
6375 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006376 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006377 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6378 memAlloc.pNext = NULL;
6379 memAlloc.allocationSize = 0;
6380 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006381 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6382 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006383 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006384 ASSERT_TRUE(pass);
6385 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6386 ASSERT_VK_SUCCESS(err);
6387 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6388 ASSERT_VK_SUCCESS(err);
6389
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006390 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006391 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6392 image_view_create_info.image = image;
6393 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6394 image_view_create_info.format = tex_format;
6395 image_view_create_info.subresourceRange.layerCount = 1;
6396 image_view_create_info.subresourceRange.baseMipLevel = 0;
6397 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006398 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006399
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006400 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006401 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006402 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006403 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006404 imageInfo[0].imageView = view;
6405 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6406 imageInfo[1].imageView = view;
6407 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006408 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006409 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006410 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006411 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006412
6413 static const uint32_t NUM_SET_UPDATES = 3;
6414 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6415 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6416 descriptor_write[0].dstSet = descriptorSet[0];
6417 descriptor_write[0].dstBinding = 0;
6418 descriptor_write[0].descriptorCount = 5;
6419 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6420 descriptor_write[0].pBufferInfo = buffInfo;
6421 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6422 descriptor_write[1].dstSet = descriptorSet[1];
6423 descriptor_write[1].dstBinding = 0;
6424 descriptor_write[1].descriptorCount = 2;
6425 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6426 descriptor_write[1].pImageInfo = imageInfo;
6427 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6428 descriptor_write[2].dstSet = descriptorSet[1];
6429 descriptor_write[2].dstBinding = 1;
6430 descriptor_write[2].descriptorCount = 2;
6431 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006432 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006433
6434 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006435
Tobin Ehlis88452832015-12-03 09:40:56 -07006436 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006437 char const *vsSource = "#version 450\n"
6438 "\n"
6439 "out gl_PerVertex {\n"
6440 " vec4 gl_Position;\n"
6441 "};\n"
6442 "void main(){\n"
6443 " gl_Position = vec4(1);\n"
6444 "}\n";
6445 char const *fsSource = "#version 450\n"
6446 "\n"
6447 "layout(location=0) out vec4 x;\n"
6448 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6449 "void main(){\n"
6450 " x = vec4(bar.y);\n"
6451 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006452 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6453 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006454 VkPipelineObj pipe(m_device);
6455 pipe.AddShader(&vs);
6456 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006457 pipe.AddColorAttachment();
6458 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006459
6460 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006462 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006463 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6464 // of PSO
6465 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6466 // cmd_pipeline.c
6467 // due to the fact that cmd_alloc_dset_data() has not been called in
6468 // cmd_bind_graphics_pipeline()
6469 // TODO : Want to cause various binding incompatibility issues here to test
6470 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006471 // First cause various verify_layout_compatibility() fails
6472 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006473 // verify_set_layout_compatibility fail cases:
6474 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6476 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6477 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006478 m_errorMonitor->VerifyFound();
6479
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006480 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6482 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6483 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006484 m_errorMonitor->VerifyFound();
6485
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006486 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006487 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6488 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6490 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6491 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006492 m_errorMonitor->VerifyFound();
6493
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006494 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6495 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6497 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6498 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006499 m_errorMonitor->VerifyFound();
6500
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006501 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6502 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6504 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6505 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6506 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006507 m_errorMonitor->VerifyFound();
6508
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006509 // Cause INFO messages due to disturbing previously bound Sets
6510 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006511 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6512 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006513 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6515 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6516 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006517 m_errorMonitor->VerifyFound();
6518
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006519 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6520 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006521 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6523 "any subsequent sets were disturbed ");
6524 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6525 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006526 m_errorMonitor->VerifyFound();
6527
Tobin Ehlis10fad692016-07-07 12:00:36 -06006528 // Now that we're done actively using the pipelineLayout that gfx pipeline
6529 // was created with, we should be able to delete it. Do that now to verify
6530 // that validation obeys pipelineLayout lifetime
6531 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6532
Tobin Ehlis88452832015-12-03 09:40:56 -07006533 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006534 // 1. Error due to not binding required set (we actually use same code as
6535 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006536 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6537 &descriptorSet[0], 0, NULL);
6538 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6539 &descriptorSet[1], 0, NULL);
6540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Tobin Ehlis88452832015-12-03 09:40:56 -07006541 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006542 m_errorMonitor->VerifyFound();
6543
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006544 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006545 // 2. Error due to bound set not being compatible with PSO's
6546 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006547 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6548 &descriptorSet[0], 0, NULL);
6549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006550 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006551 m_errorMonitor->VerifyFound();
6552
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006553 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006554 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006555 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6556 }
6557 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006558 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006559 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6560 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006561 vkFreeMemory(m_device->device(), imageMem, NULL);
6562 vkDestroyImage(m_device->device(), image, NULL);
6563 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006564}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006565
Karl Schultz6addd812016-02-02 17:17:23 -07006566TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006567
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6569 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006570
6571 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006572 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006573 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006574 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006575
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006576 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006577}
6578
Karl Schultz6addd812016-02-02 17:17:23 -07006579TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6580 VkResult err;
6581 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006582
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006584
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006585 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006586
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006587 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006588 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006589 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006590 cmd.commandPool = m_commandPool;
6591 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006592 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006593
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006594 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006595 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006596
6597 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006598 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006599 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006600 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006601 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006602 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 -07006603 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006604
6605 // The error should be caught by validation of the BeginCommandBuffer call
6606 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6607
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006608 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006609 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006610}
6611
Karl Schultz6addd812016-02-02 17:17:23 -07006612TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006613 // Cause error due to Begin while recording CB
6614 // Then cause 2 errors for attempting to reset CB w/o having
6615 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6616 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006618
6619 ASSERT_NO_FATAL_FAILURE(InitState());
6620
6621 // Calls AllocateCommandBuffers
6622 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6623
Karl Schultz6addd812016-02-02 17:17:23 -07006624 // Force the failure by setting the Renderpass and Framebuffer fields with
6625 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006626 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006627 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006628 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6629 cmd_buf_info.pNext = NULL;
6630 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006631 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006632
6633 // Begin CB to transition to recording state
6634 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6635 // Can't re-begin. This should trigger error
6636 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006637 m_errorMonitor->VerifyFound();
6638
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006640 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6641 // Reset attempt will trigger error due to incorrect CommandPool state
6642 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006643 m_errorMonitor->VerifyFound();
6644
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006646 // Transition CB to RECORDED state
6647 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6648 // Now attempting to Begin will implicitly reset, which triggers error
6649 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006650 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006651}
6652
Karl Schultz6addd812016-02-02 17:17:23 -07006653TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006654 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006655 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006656
Mike Weiblencce7ec72016-10-17 19:33:05 -06006657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006658
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006659 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006661
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006662 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006663 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6664 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006665
6666 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006667 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6668 ds_pool_ci.pNext = NULL;
6669 ds_pool_ci.maxSets = 1;
6670 ds_pool_ci.poolSizeCount = 1;
6671 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006672
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006673 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006674 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006675 ASSERT_VK_SUCCESS(err);
6676
Tony Barboureb254902015-07-15 12:50:33 -06006677 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006678 dsl_binding.binding = 0;
6679 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6680 dsl_binding.descriptorCount = 1;
6681 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6682 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006683
Tony Barboureb254902015-07-15 12:50:33 -06006684 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006685 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6686 ds_layout_ci.pNext = NULL;
6687 ds_layout_ci.bindingCount = 1;
6688 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006689
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006690 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006691 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006692 ASSERT_VK_SUCCESS(err);
6693
6694 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006695 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006696 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006697 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006698 alloc_info.descriptorPool = ds_pool;
6699 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006700 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006701 ASSERT_VK_SUCCESS(err);
6702
Tony Barboureb254902015-07-15 12:50:33 -06006703 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006704 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6705 pipeline_layout_ci.setLayoutCount = 1;
6706 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006707
6708 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006709 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006710 ASSERT_VK_SUCCESS(err);
6711
Tobin Ehlise68360f2015-10-01 11:15:13 -06006712 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006713 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006714
6715 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006716 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6717 vp_state_ci.scissorCount = 1;
6718 vp_state_ci.pScissors = &sc;
6719 vp_state_ci.viewportCount = 1;
6720 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006721
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006722 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6723 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6724 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6725 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6726 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6727 rs_state_ci.depthClampEnable = VK_FALSE;
6728 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6729 rs_state_ci.depthBiasEnable = VK_FALSE;
6730
Tony Barboureb254902015-07-15 12:50:33 -06006731 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006732 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6733 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006734 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006735 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6736 gp_ci.layout = pipeline_layout;
6737 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006738
6739 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006740 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6741 pc_ci.initialDataSize = 0;
6742 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006743
6744 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006745 VkPipelineCache pipelineCache;
6746
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006747 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006748 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006749 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006750
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006751 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006752
Chia-I Wuf7458c52015-10-26 21:10:41 +08006753 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6754 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6755 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6756 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006757}
Tobin Ehlis912df022015-09-17 08:46:18 -06006758/*// TODO : This test should be good, but needs Tess support in compiler to run
6759TEST_F(VkLayerTest, InvalidPatchControlPoints)
6760{
6761 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006762 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006763
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006765 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6766primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006767
Tobin Ehlis912df022015-09-17 08:46:18 -06006768 ASSERT_NO_FATAL_FAILURE(InitState());
6769 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006770
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006771 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006772 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006773 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006774
6775 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6776 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6777 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006778 ds_pool_ci.poolSizeCount = 1;
6779 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006780
6781 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006782 err = vkCreateDescriptorPool(m_device->device(),
6783VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006784 ASSERT_VK_SUCCESS(err);
6785
6786 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006787 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006788 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006789 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006790 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6791 dsl_binding.pImmutableSamplers = NULL;
6792
6793 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006794 ds_layout_ci.sType =
6795VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006796 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006797 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006798 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006799
6800 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006801 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6802&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006803 ASSERT_VK_SUCCESS(err);
6804
6805 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006806 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6807VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006808 ASSERT_VK_SUCCESS(err);
6809
6810 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006811 pipeline_layout_ci.sType =
6812VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006813 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006814 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006815 pipeline_layout_ci.pSetLayouts = &ds_layout;
6816
6817 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006818 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6819&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006820 ASSERT_VK_SUCCESS(err);
6821
6822 VkPipelineShaderStageCreateInfo shaderStages[3];
6823 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6824
Karl Schultz6addd812016-02-02 17:17:23 -07006825 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6826this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006827 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006828 VkShaderObj
6829tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6830this);
6831 VkShaderObj
6832te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6833this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006834
Karl Schultz6addd812016-02-02 17:17:23 -07006835 shaderStages[0].sType =
6836VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006837 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006838 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006839 shaderStages[1].sType =
6840VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006841 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006842 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006843 shaderStages[2].sType =
6844VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006845 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006846 shaderStages[2].shader = te.handle();
6847
6848 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006849 iaCI.sType =
6850VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006851 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006852
6853 VkPipelineTessellationStateCreateInfo tsCI = {};
6854 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6855 tsCI.patchControlPoints = 0; // This will cause an error
6856
6857 VkGraphicsPipelineCreateInfo gp_ci = {};
6858 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6859 gp_ci.pNext = NULL;
6860 gp_ci.stageCount = 3;
6861 gp_ci.pStages = shaderStages;
6862 gp_ci.pVertexInputState = NULL;
6863 gp_ci.pInputAssemblyState = &iaCI;
6864 gp_ci.pTessellationState = &tsCI;
6865 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006866 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006867 gp_ci.pMultisampleState = NULL;
6868 gp_ci.pDepthStencilState = NULL;
6869 gp_ci.pColorBlendState = NULL;
6870 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6871 gp_ci.layout = pipeline_layout;
6872 gp_ci.renderPass = renderPass();
6873
6874 VkPipelineCacheCreateInfo pc_ci = {};
6875 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6876 pc_ci.pNext = NULL;
6877 pc_ci.initialSize = 0;
6878 pc_ci.initialData = 0;
6879 pc_ci.maxSize = 0;
6880
6881 VkPipeline pipeline;
6882 VkPipelineCache pipelineCache;
6883
Karl Schultz6addd812016-02-02 17:17:23 -07006884 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6885&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006886 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006887 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6888&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006889
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006890 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006891
Chia-I Wuf7458c52015-10-26 21:10:41 +08006892 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6893 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6894 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6895 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006896}
6897*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006898// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006899TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006900 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6903 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006904
Tobin Ehlise68360f2015-10-01 11:15:13 -06006905 ASSERT_NO_FATAL_FAILURE(InitState());
6906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006907
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006908 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006909 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6910 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006911
6912 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006913 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6914 ds_pool_ci.maxSets = 1;
6915 ds_pool_ci.poolSizeCount = 1;
6916 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006917
6918 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006919 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006920 ASSERT_VK_SUCCESS(err);
6921
6922 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006923 dsl_binding.binding = 0;
6924 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6925 dsl_binding.descriptorCount = 1;
6926 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006927
6928 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006929 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6930 ds_layout_ci.bindingCount = 1;
6931 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006932
6933 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006934 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006935 ASSERT_VK_SUCCESS(err);
6936
6937 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006938 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006940 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006941 alloc_info.descriptorPool = ds_pool;
6942 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006943 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006944 ASSERT_VK_SUCCESS(err);
6945
6946 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006947 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6948 pipeline_layout_ci.setLayoutCount = 1;
6949 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006950
6951 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006952 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006953 ASSERT_VK_SUCCESS(err);
6954
6955 VkViewport vp = {}; // Just need dummy vp to point to
6956
6957 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006958 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6959 vp_state_ci.scissorCount = 0;
6960 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6961 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006962
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006963 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6964 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6965 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6966 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6967 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6968 rs_state_ci.depthClampEnable = VK_FALSE;
6969 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6970 rs_state_ci.depthBiasEnable = VK_FALSE;
6971
Cody Northropeb3a6c12015-10-05 14:44:45 -06006972 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006973 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006975 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6976 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
6977 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006978 shaderStages[0] = vs.GetStageCreateInfo();
6979 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006980
6981 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006982 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6983 gp_ci.stageCount = 2;
6984 gp_ci.pStages = shaderStages;
6985 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006986 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006987 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6988 gp_ci.layout = pipeline_layout;
6989 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006990
6991 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006992 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006993
6994 VkPipeline pipeline;
6995 VkPipelineCache pipelineCache;
6996
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006997 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006998 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006999 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007000
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007001 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007002
Chia-I Wuf7458c52015-10-26 21:10:41 +08007003 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7004 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7005 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7006 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007007}
Karl Schultz6addd812016-02-02 17:17:23 -07007008// Don't set viewport state in PSO. This is an error b/c we always need this
7009// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007010// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007011TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007012 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007013 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007014
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007016
Tobin Ehlise68360f2015-10-01 11:15:13 -06007017 ASSERT_NO_FATAL_FAILURE(InitState());
7018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007019
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007020 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007021 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7022 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007023
7024 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007025 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7026 ds_pool_ci.maxSets = 1;
7027 ds_pool_ci.poolSizeCount = 1;
7028 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007029
7030 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007031 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007032 ASSERT_VK_SUCCESS(err);
7033
7034 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007035 dsl_binding.binding = 0;
7036 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7037 dsl_binding.descriptorCount = 1;
7038 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007039
7040 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007041 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7042 ds_layout_ci.bindingCount = 1;
7043 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007044
7045 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007046 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007047 ASSERT_VK_SUCCESS(err);
7048
7049 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007050 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007051 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007052 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007053 alloc_info.descriptorPool = ds_pool;
7054 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007055 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007056 ASSERT_VK_SUCCESS(err);
7057
7058 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007059 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7060 pipeline_layout_ci.setLayoutCount = 1;
7061 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007062
7063 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007064 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007065 ASSERT_VK_SUCCESS(err);
7066
7067 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7068 // Set scissor as dynamic to avoid second error
7069 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007070 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7071 dyn_state_ci.dynamicStateCount = 1;
7072 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007073
Cody Northropeb3a6c12015-10-05 14:44:45 -06007074 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007075 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007076
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007077 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7078 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7079 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007080 shaderStages[0] = vs.GetStageCreateInfo();
7081 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007082
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007083 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7084 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7085 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7086 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7087 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7088 rs_state_ci.depthClampEnable = VK_FALSE;
7089 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7090 rs_state_ci.depthBiasEnable = VK_FALSE;
7091
Tobin Ehlise68360f2015-10-01 11:15:13 -06007092 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007093 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7094 gp_ci.stageCount = 2;
7095 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007096 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007097 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7098 // should cause validation error
7099 gp_ci.pDynamicState = &dyn_state_ci;
7100 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7101 gp_ci.layout = pipeline_layout;
7102 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007103
7104 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007105 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007106
7107 VkPipeline pipeline;
7108 VkPipelineCache pipelineCache;
7109
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007110 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007111 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007112 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007113
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007114 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007115
Chia-I Wuf7458c52015-10-26 21:10:41 +08007116 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7117 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7118 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7119 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007120}
7121// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007122// Then run second test where dynamic scissor count doesn't match PSO scissor
7123// count
7124TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7125 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7128 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007129
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007131
7132 if (!m_device->phy().features().multiViewport) {
7133 printf("Device does not support multiple viewports/scissors; skipped.\n");
7134 return;
7135 }
7136
Tobin Ehlise68360f2015-10-01 11:15:13 -06007137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007138
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007139 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007140 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7141 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007142
7143 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007144 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7145 ds_pool_ci.maxSets = 1;
7146 ds_pool_ci.poolSizeCount = 1;
7147 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007148
7149 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007150 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151 ASSERT_VK_SUCCESS(err);
7152
7153 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007154 dsl_binding.binding = 0;
7155 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7156 dsl_binding.descriptorCount = 1;
7157 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007158
7159 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007160 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7161 ds_layout_ci.bindingCount = 1;
7162 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007163
7164 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166 ASSERT_VK_SUCCESS(err);
7167
7168 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007169 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007170 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007171 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007172 alloc_info.descriptorPool = ds_pool;
7173 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007174 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007175 ASSERT_VK_SUCCESS(err);
7176
7177 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007178 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7179 pipeline_layout_ci.setLayoutCount = 1;
7180 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007181
7182 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007183 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007184 ASSERT_VK_SUCCESS(err);
7185
7186 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007187 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7188 vp_state_ci.viewportCount = 1;
7189 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7190 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007191 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007192
7193 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7194 // Set scissor as dynamic to avoid that error
7195 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007196 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7197 dyn_state_ci.dynamicStateCount = 1;
7198 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007199
Cody Northropeb3a6c12015-10-05 14:44:45 -06007200 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007201 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007203 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7204 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7205 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007206 shaderStages[0] = vs.GetStageCreateInfo();
7207 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007208
Cody Northropf6622dc2015-10-06 10:33:21 -06007209 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7210 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7211 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007212 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007213 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007214 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007215 vi_ci.pVertexAttributeDescriptions = nullptr;
7216
7217 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7218 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7219 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7220
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007221 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007222 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007223 rs_ci.pNext = nullptr;
7224
Mark Youngc89c6312016-03-31 16:03:20 -06007225 VkPipelineColorBlendAttachmentState att = {};
7226 att.blendEnable = VK_FALSE;
7227 att.colorWriteMask = 0xf;
7228
Cody Northropf6622dc2015-10-06 10:33:21 -06007229 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7230 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7231 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007232 cb_ci.attachmentCount = 1;
7233 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007234
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007236 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7237 gp_ci.stageCount = 2;
7238 gp_ci.pStages = shaderStages;
7239 gp_ci.pVertexInputState = &vi_ci;
7240 gp_ci.pInputAssemblyState = &ia_ci;
7241 gp_ci.pViewportState = &vp_state_ci;
7242 gp_ci.pRasterizationState = &rs_ci;
7243 gp_ci.pColorBlendState = &cb_ci;
7244 gp_ci.pDynamicState = &dyn_state_ci;
7245 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7246 gp_ci.layout = pipeline_layout;
7247 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007248
7249 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007250 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007251
7252 VkPipeline pipeline;
7253 VkPipelineCache pipelineCache;
7254
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007255 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007256 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007258
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007259 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007260
Tobin Ehlisd332f282015-10-02 11:00:56 -06007261 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007262 // First need to successfully create the PSO from above by setting
7263 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007264 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 -07007265
7266 VkViewport vp = {}; // Just need dummy vp to point to
7267 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007268 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007269 ASSERT_VK_SUCCESS(err);
7270 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007271 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007272 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007273 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007274 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007275 Draw(1, 0, 0, 0);
7276
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007277 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007278
7279 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7280 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007283 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007284}
7285// Create PSO w/o non-zero scissorCount but no scissor data
7286// Then run second test where dynamic viewportCount doesn't match PSO
7287// viewportCount
7288TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7289 VkResult err;
7290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline scissorCount is 1, but pScissors is NULL. ");
Karl Schultz6addd812016-02-02 17:17:23 -07007292
7293 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007294
7295 if (!m_device->phy().features().multiViewport) {
7296 printf("Device does not support multiple viewports/scissors; skipped.\n");
7297 return;
7298 }
7299
Karl Schultz6addd812016-02-02 17:17:23 -07007300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7301
7302 VkDescriptorPoolSize ds_type_count = {};
7303 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7304 ds_type_count.descriptorCount = 1;
7305
7306 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7307 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7308 ds_pool_ci.maxSets = 1;
7309 ds_pool_ci.poolSizeCount = 1;
7310 ds_pool_ci.pPoolSizes = &ds_type_count;
7311
7312 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007314 ASSERT_VK_SUCCESS(err);
7315
7316 VkDescriptorSetLayoutBinding dsl_binding = {};
7317 dsl_binding.binding = 0;
7318 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7319 dsl_binding.descriptorCount = 1;
7320 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7321
7322 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7323 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7324 ds_layout_ci.bindingCount = 1;
7325 ds_layout_ci.pBindings = &dsl_binding;
7326
7327 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007328 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007329 ASSERT_VK_SUCCESS(err);
7330
7331 VkDescriptorSet descriptorSet;
7332 VkDescriptorSetAllocateInfo alloc_info = {};
7333 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7334 alloc_info.descriptorSetCount = 1;
7335 alloc_info.descriptorPool = ds_pool;
7336 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007337 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007338 ASSERT_VK_SUCCESS(err);
7339
7340 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7341 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7342 pipeline_layout_ci.setLayoutCount = 1;
7343 pipeline_layout_ci.pSetLayouts = &ds_layout;
7344
7345 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007346 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007347 ASSERT_VK_SUCCESS(err);
7348
7349 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7350 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7351 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007352 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007353 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007354 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007355
7356 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7357 // Set scissor as dynamic to avoid that error
7358 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7359 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7360 dyn_state_ci.dynamicStateCount = 1;
7361 dyn_state_ci.pDynamicStates = &vp_state;
7362
7363 VkPipelineShaderStageCreateInfo shaderStages[2];
7364 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7365
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007366 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7367 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7368 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007369 shaderStages[0] = vs.GetStageCreateInfo();
7370 shaderStages[1] = fs.GetStageCreateInfo();
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 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7381 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7382 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7383
7384 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7385 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7386 rs_ci.pNext = nullptr;
7387
Mark Youngc89c6312016-03-31 16:03:20 -06007388 VkPipelineColorBlendAttachmentState att = {};
7389 att.blendEnable = VK_FALSE;
7390 att.colorWriteMask = 0xf;
7391
Karl Schultz6addd812016-02-02 17:17:23 -07007392 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7393 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7394 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007395 cb_ci.attachmentCount = 1;
7396 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007397
7398 VkGraphicsPipelineCreateInfo gp_ci = {};
7399 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7400 gp_ci.stageCount = 2;
7401 gp_ci.pStages = shaderStages;
7402 gp_ci.pVertexInputState = &vi_ci;
7403 gp_ci.pInputAssemblyState = &ia_ci;
7404 gp_ci.pViewportState = &vp_state_ci;
7405 gp_ci.pRasterizationState = &rs_ci;
7406 gp_ci.pColorBlendState = &cb_ci;
7407 gp_ci.pDynamicState = &dyn_state_ci;
7408 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7409 gp_ci.layout = pipeline_layout;
7410 gp_ci.renderPass = renderPass();
7411
7412 VkPipelineCacheCreateInfo pc_ci = {};
7413 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7414
7415 VkPipeline pipeline;
7416 VkPipelineCache pipelineCache;
7417
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007418 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007419 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007420 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007421
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007422 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007423
7424 // Now hit second fail case where we set scissor w/ different count than PSO
7425 // First need to successfully create the PSO from above by setting
7426 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007427 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 -06007428
Tobin Ehlisd332f282015-10-02 11:00:56 -06007429 VkRect2D sc = {}; // Just need dummy vp to point to
7430 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007431 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007432 ASSERT_VK_SUCCESS(err);
7433 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007434 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007435 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007436 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007437 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007438 Draw(1, 0, 0, 0);
7439
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007440 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007441
Chia-I Wuf7458c52015-10-26 21:10:41 +08007442 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7443 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7444 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7445 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007446 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007447}
7448
Mark Young7394fdd2016-03-31 14:56:43 -06007449TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7450 VkResult err;
7451
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007453
7454 ASSERT_NO_FATAL_FAILURE(InitState());
7455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7456
7457 VkDescriptorPoolSize ds_type_count = {};
7458 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7459 ds_type_count.descriptorCount = 1;
7460
7461 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7462 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7463 ds_pool_ci.maxSets = 1;
7464 ds_pool_ci.poolSizeCount = 1;
7465 ds_pool_ci.pPoolSizes = &ds_type_count;
7466
7467 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007468 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007469 ASSERT_VK_SUCCESS(err);
7470
7471 VkDescriptorSetLayoutBinding dsl_binding = {};
7472 dsl_binding.binding = 0;
7473 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7474 dsl_binding.descriptorCount = 1;
7475 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7476
7477 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7478 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7479 ds_layout_ci.bindingCount = 1;
7480 ds_layout_ci.pBindings = &dsl_binding;
7481
7482 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007483 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007484 ASSERT_VK_SUCCESS(err);
7485
7486 VkDescriptorSet descriptorSet;
7487 VkDescriptorSetAllocateInfo alloc_info = {};
7488 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7489 alloc_info.descriptorSetCount = 1;
7490 alloc_info.descriptorPool = ds_pool;
7491 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007492 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007493 ASSERT_VK_SUCCESS(err);
7494
7495 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7496 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7497 pipeline_layout_ci.setLayoutCount = 1;
7498 pipeline_layout_ci.pSetLayouts = &ds_layout;
7499
7500 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007501 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007502 ASSERT_VK_SUCCESS(err);
7503
7504 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7505 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7506 vp_state_ci.scissorCount = 1;
7507 vp_state_ci.pScissors = NULL;
7508 vp_state_ci.viewportCount = 1;
7509 vp_state_ci.pViewports = NULL;
7510
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007511 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007512 // Set scissor as dynamic to avoid that error
7513 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7514 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7515 dyn_state_ci.dynamicStateCount = 2;
7516 dyn_state_ci.pDynamicStates = dynamic_states;
7517
7518 VkPipelineShaderStageCreateInfo shaderStages[2];
7519 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7520
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007521 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7522 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007523 this); // TODO - We shouldn't need a fragment shader
7524 // but add it to be able to run on more devices
7525 shaderStages[0] = vs.GetStageCreateInfo();
7526 shaderStages[1] = fs.GetStageCreateInfo();
7527
7528 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7529 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7530 vi_ci.pNext = nullptr;
7531 vi_ci.vertexBindingDescriptionCount = 0;
7532 vi_ci.pVertexBindingDescriptions = nullptr;
7533 vi_ci.vertexAttributeDescriptionCount = 0;
7534 vi_ci.pVertexAttributeDescriptions = nullptr;
7535
7536 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7537 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7538 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7539
7540 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7541 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7542 rs_ci.pNext = nullptr;
7543
Mark Young47107952016-05-02 15:59:55 -06007544 // Check too low (line width of -1.0f).
7545 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007546
7547 VkPipelineColorBlendAttachmentState att = {};
7548 att.blendEnable = VK_FALSE;
7549 att.colorWriteMask = 0xf;
7550
7551 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7552 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7553 cb_ci.pNext = nullptr;
7554 cb_ci.attachmentCount = 1;
7555 cb_ci.pAttachments = &att;
7556
7557 VkGraphicsPipelineCreateInfo gp_ci = {};
7558 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7559 gp_ci.stageCount = 2;
7560 gp_ci.pStages = shaderStages;
7561 gp_ci.pVertexInputState = &vi_ci;
7562 gp_ci.pInputAssemblyState = &ia_ci;
7563 gp_ci.pViewportState = &vp_state_ci;
7564 gp_ci.pRasterizationState = &rs_ci;
7565 gp_ci.pColorBlendState = &cb_ci;
7566 gp_ci.pDynamicState = &dyn_state_ci;
7567 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7568 gp_ci.layout = pipeline_layout;
7569 gp_ci.renderPass = renderPass();
7570
7571 VkPipelineCacheCreateInfo pc_ci = {};
7572 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7573
7574 VkPipeline pipeline;
7575 VkPipelineCache pipelineCache;
7576
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007577 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007578 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007579 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007580
7581 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007582 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007585
7586 // Check too high (line width of 65536.0f).
7587 rs_ci.lineWidth = 65536.0f;
7588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007589 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007590 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007591 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007592
7593 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007594 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007595
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007597
7598 dyn_state_ci.dynamicStateCount = 3;
7599
7600 rs_ci.lineWidth = 1.0f;
7601
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007602 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007603 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007604 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007605 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007606 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007607
7608 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007609 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007610 m_errorMonitor->VerifyFound();
7611
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007613
7614 // Check too high with dynamic setting.
7615 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7616 m_errorMonitor->VerifyFound();
7617 EndCommandBuffer();
7618
7619 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7620 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7621 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7622 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007623 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007624}
7625
Karl Schultz6addd812016-02-02 17:17:23 -07007626TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007627 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7629 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007630
7631 ASSERT_NO_FATAL_FAILURE(InitState());
7632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007633
Tony Barbourfe3351b2015-07-28 10:17:20 -06007634 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007635 // Don't care about RenderPass handle b/c error should be flagged before
7636 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007637 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007638
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007639 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007640}
7641
Karl Schultz6addd812016-02-02 17:17:23 -07007642TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007643 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7645 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007646
7647 ASSERT_NO_FATAL_FAILURE(InitState());
7648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007649
Tony Barbourfe3351b2015-07-28 10:17:20 -06007650 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007651 // Just create a dummy Renderpass that's non-NULL so we can get to the
7652 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007653 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007654
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007655 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007656}
7657
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007658TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7659 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7660 "the number of renderPass attachments that use loadOp"
7661 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7662
7663 ASSERT_NO_FATAL_FAILURE(InitState());
7664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7665
7666 // Create a renderPass with a single attachment that uses loadOp CLEAR
7667 VkAttachmentReference attach = {};
7668 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7669 VkSubpassDescription subpass = {};
7670 subpass.inputAttachmentCount = 1;
7671 subpass.pInputAttachments = &attach;
7672 VkRenderPassCreateInfo rpci = {};
7673 rpci.subpassCount = 1;
7674 rpci.pSubpasses = &subpass;
7675 rpci.attachmentCount = 1;
7676 VkAttachmentDescription attach_desc = {};
7677 attach_desc.format = VK_FORMAT_UNDEFINED;
7678 // Set loadOp to CLEAR
7679 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7680 rpci.pAttachments = &attach_desc;
7681 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7682 VkRenderPass rp;
7683 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7684
7685 VkCommandBufferInheritanceInfo hinfo = {};
7686 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7687 hinfo.renderPass = VK_NULL_HANDLE;
7688 hinfo.subpass = 0;
7689 hinfo.framebuffer = VK_NULL_HANDLE;
7690 hinfo.occlusionQueryEnable = VK_FALSE;
7691 hinfo.queryFlags = 0;
7692 hinfo.pipelineStatistics = 0;
7693 VkCommandBufferBeginInfo info = {};
7694 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7695 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7696 info.pInheritanceInfo = &hinfo;
7697
7698 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7699 VkRenderPassBeginInfo rp_begin = {};
7700 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7701 rp_begin.pNext = NULL;
7702 rp_begin.renderPass = renderPass();
7703 rp_begin.framebuffer = framebuffer();
7704 rp_begin.clearValueCount = 0; // Should be 1
7705
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7707 "there must be at least 1 entries in "
7708 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007709
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007710 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007711
7712 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007713
7714 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007715}
7716
Cody Northrop3bb4d962016-05-09 16:15:57 -06007717TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7718
7719 TEST_DESCRIPTION("End a command buffer with an active render pass");
7720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7722 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007723
7724 ASSERT_NO_FATAL_FAILURE(InitState());
7725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7726
7727 // The framework's BeginCommandBuffer calls CreateRenderPass
7728 BeginCommandBuffer();
7729
7730 // Call directly into vkEndCommandBuffer instead of the
7731 // the framework's EndCommandBuffer, which inserts a
7732 // vkEndRenderPass
7733 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7734
7735 m_errorMonitor->VerifyFound();
7736
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007737 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7738 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007739}
7740
Karl Schultz6addd812016-02-02 17:17:23 -07007741TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007742 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7744 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007745
7746 ASSERT_NO_FATAL_FAILURE(InitState());
7747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007748
7749 // Renderpass is started here
7750 BeginCommandBuffer();
7751
7752 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007753 vk_testing::Buffer dstBuffer;
7754 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007755
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007756 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007757
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007758 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007759}
7760
Karl Schultz6addd812016-02-02 17:17:23 -07007761TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007762 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7764 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007765
7766 ASSERT_NO_FATAL_FAILURE(InitState());
7767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007768
7769 // Renderpass is started here
7770 BeginCommandBuffer();
7771
7772 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007773 vk_testing::Buffer dstBuffer;
7774 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007775
Karl Schultz6addd812016-02-02 17:17:23 -07007776 VkDeviceSize dstOffset = 0;
7777 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007778 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007779
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007780 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007781
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007782 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007783}
7784
Karl Schultz6addd812016-02-02 17:17:23 -07007785TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007786 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7788 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007789
7790 ASSERT_NO_FATAL_FAILURE(InitState());
7791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007792
7793 // Renderpass is started here
7794 BeginCommandBuffer();
7795
Michael Lentine0a369f62016-02-03 16:51:46 -06007796 VkClearColorValue clear_color;
7797 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007798 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7799 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7800 const int32_t tex_width = 32;
7801 const int32_t tex_height = 32;
7802 VkImageCreateInfo image_create_info = {};
7803 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7804 image_create_info.pNext = NULL;
7805 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7806 image_create_info.format = tex_format;
7807 image_create_info.extent.width = tex_width;
7808 image_create_info.extent.height = tex_height;
7809 image_create_info.extent.depth = 1;
7810 image_create_info.mipLevels = 1;
7811 image_create_info.arrayLayers = 1;
7812 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7813 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7814 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007815
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007816 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007817 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007819 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007820
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007821 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007822
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007823 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007824}
7825
Karl Schultz6addd812016-02-02 17:17:23 -07007826TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007827 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7829 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007830
7831 ASSERT_NO_FATAL_FAILURE(InitState());
7832 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007833
7834 // Renderpass is started here
7835 BeginCommandBuffer();
7836
7837 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007838 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007839 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7840 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7841 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7842 image_create_info.extent.width = 64;
7843 image_create_info.extent.height = 64;
7844 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7845 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007846
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007847 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007848 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007850 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007851
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007852 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7853 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007854
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007855 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007856}
7857
Karl Schultz6addd812016-02-02 17:17:23 -07007858TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007859 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007860 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7863 "must be issued inside an active "
7864 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007865
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007866 ASSERT_NO_FATAL_FAILURE(InitState());
7867 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007868
7869 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007870 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007871 ASSERT_VK_SUCCESS(err);
7872
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007873 VkClearAttachment color_attachment;
7874 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7875 color_attachment.clearValue.color.float32[0] = 0;
7876 color_attachment.clearValue.color.float32[1] = 0;
7877 color_attachment.clearValue.color.float32[2] = 0;
7878 color_attachment.clearValue.color.float32[3] = 0;
7879 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007880 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007881 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007882
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007883 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007884}
7885
Chris Forbes3b97e932016-09-07 11:29:24 +12007886TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
7887 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
7888 "called too many times in a renderpass instance");
7889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
7891 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12007892
7893 ASSERT_NO_FATAL_FAILURE(InitState());
7894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7895
7896 BeginCommandBuffer();
7897
7898 // error here.
7899 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
7900 m_errorMonitor->VerifyFound();
7901
7902 EndCommandBuffer();
7903}
7904
Chris Forbes6d624702016-09-07 13:57:05 +12007905TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
7906 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
7907 "called before the final subpass has been reached");
7908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
7910 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12007911
7912 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007913 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
7914 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12007915
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007916 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12007917
7918 VkRenderPass rp;
7919 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
7920 ASSERT_VK_SUCCESS(err);
7921
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007922 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12007923
7924 VkFramebuffer fb;
7925 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
7926 ASSERT_VK_SUCCESS(err);
7927
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007928 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12007929
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007930 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 +12007931
7932 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
7933
7934 // Error here.
7935 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7936 m_errorMonitor->VerifyFound();
7937
7938 // Clean up.
7939 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
7940 vkDestroyRenderPass(m_device->device(), rp, nullptr);
7941}
7942
Karl Schultz9e66a292016-04-21 15:57:51 -06007943TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7944 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7946 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06007947
7948 ASSERT_NO_FATAL_FAILURE(InitState());
7949 BeginCommandBuffer();
7950
7951 VkBufferMemoryBarrier buf_barrier = {};
7952 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7953 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7954 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7955 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7956 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7957 buf_barrier.buffer = VK_NULL_HANDLE;
7958 buf_barrier.offset = 0;
7959 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7961 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06007962
7963 m_errorMonitor->VerifyFound();
7964}
7965
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007966TEST_F(VkLayerTest, InvalidBarriers) {
7967 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007970
7971 ASSERT_NO_FATAL_FAILURE(InitState());
7972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7973
7974 VkMemoryBarrier mem_barrier = {};
7975 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7976 mem_barrier.pNext = NULL;
7977 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7978 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7979 BeginCommandBuffer();
7980 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007981 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007982 &mem_barrier, 0, nullptr, 0, nullptr);
7983 m_errorMonitor->VerifyFound();
7984
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007986 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007987 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 -06007988 ASSERT_TRUE(image.initialized());
7989 VkImageMemoryBarrier img_barrier = {};
7990 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7991 img_barrier.pNext = NULL;
7992 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7993 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7994 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
7995 // New layout can't be UNDEFINED
7996 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
7997 img_barrier.image = image.handle();
7998 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7999 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8000 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8001 img_barrier.subresourceRange.baseArrayLayer = 0;
8002 img_barrier.subresourceRange.baseMipLevel = 0;
8003 img_barrier.subresourceRange.layerCount = 1;
8004 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008005 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8006 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008007 m_errorMonitor->VerifyFound();
8008 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8011 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008012 // baseArrayLayer + layerCount must be <= image's arrayLayers
8013 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008014 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8015 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008016 m_errorMonitor->VerifyFound();
8017 img_barrier.subresourceRange.baseArrayLayer = 0;
8018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008020 // baseMipLevel + levelCount must be <= image's mipLevels
8021 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8023 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008024 m_errorMonitor->VerifyFound();
8025 img_barrier.subresourceRange.baseMipLevel = 0;
8026
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008027 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 -06008028 vk_testing::Buffer buffer;
8029 buffer.init(*m_device, 256);
8030 VkBufferMemoryBarrier buf_barrier = {};
8031 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8032 buf_barrier.pNext = NULL;
8033 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8034 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8035 buf_barrier.buffer = buffer.handle();
8036 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8037 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8038 buf_barrier.offset = 0;
8039 buf_barrier.size = VK_WHOLE_SIZE;
8040 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008041 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8042 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008043 m_errorMonitor->VerifyFound();
8044 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8045
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008047 buf_barrier.offset = 257;
8048 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008049 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8050 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008051 m_errorMonitor->VerifyFound();
8052 buf_barrier.offset = 0;
8053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008055 buf_barrier.size = 257;
8056 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008057 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8058 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008059 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008060
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008061 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008062 m_errorMonitor->SetDesiredFailureMsg(
8063 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8064 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8065 m_errorMonitor->SetDesiredFailureMsg(
8066 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8067 "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 -06008068 VkDepthStencilObj ds_image(m_device);
8069 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8070 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008071 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8072 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008073 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008074 // Use of COLOR aspect on DS image is error
8075 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008076 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8077 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008078 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008079 // Now test depth-only
8080 VkFormatProperties format_props;
8081
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008082 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8083 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8085 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8087 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008088 VkDepthStencilObj d_image(m_device);
8089 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8090 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008091 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008092 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008093 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008094 // Use of COLOR aspect on depth image is error
8095 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008096 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8097 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008098 m_errorMonitor->VerifyFound();
8099 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008100 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8101 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008102 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8104 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008105 VkDepthStencilObj s_image(m_device);
8106 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8107 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008108 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008109 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008110 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008111 // Use of COLOR aspect on depth image is error
8112 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008113 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8114 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008115 m_errorMonitor->VerifyFound();
8116 }
8117 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8119 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8121 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008122 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008123 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 -06008124 ASSERT_TRUE(c_image.initialized());
8125 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8126 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8127 img_barrier.image = c_image.handle();
8128 // Set aspect to depth (non-color)
8129 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008130 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8131 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008132 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008133}
8134
Tony Barbour18ba25c2016-09-29 13:42:40 -06008135TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8136 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8137
8138 m_errorMonitor->SetDesiredFailureMsg(
8139 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8140 "must have required access bit");
8141 ASSERT_NO_FATAL_FAILURE(InitState());
8142 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008143 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 -06008144 ASSERT_TRUE(image.initialized());
8145
8146 VkImageMemoryBarrier barrier = {};
8147 VkImageSubresourceRange range;
8148 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8149 barrier.srcAccessMask = 0;
8150 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8151 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8152 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8153 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8154 barrier.image = image.handle();
8155 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8156 range.baseMipLevel = 0;
8157 range.levelCount = 1;
8158 range.baseArrayLayer = 0;
8159 range.layerCount = 1;
8160 barrier.subresourceRange = range;
8161 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8162 cmdbuf.BeginCommandBuffer();
8163 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8164 &barrier);
8165 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8166 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8167 barrier.srcAccessMask = 0;
8168 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8169 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8170 &barrier);
8171
8172 m_errorMonitor->VerifyFound();
8173}
8174
Karl Schultz6addd812016-02-02 17:17:23 -07008175TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008176 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008177 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008178
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008180
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008181 ASSERT_NO_FATAL_FAILURE(InitState());
8182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008183 uint32_t qfi = 0;
8184 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008185 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8186 buffCI.size = 1024;
8187 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8188 buffCI.queueFamilyIndexCount = 1;
8189 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008190
8191 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008192 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008193 ASSERT_VK_SUCCESS(err);
8194
8195 BeginCommandBuffer();
8196 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008197 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8198 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008199 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008200 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008201
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008202 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008203
Chia-I Wuf7458c52015-10-26 21:10:41 +08008204 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008205}
8206
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008207TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8208 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8210 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8211 "of the indices specified when the device was created, via the "
8212 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008213
8214 ASSERT_NO_FATAL_FAILURE(InitState());
8215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8216 VkBufferCreateInfo buffCI = {};
8217 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8218 buffCI.size = 1024;
8219 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8220 buffCI.queueFamilyIndexCount = 1;
8221 // Introduce failure by specifying invalid queue_family_index
8222 uint32_t qfi = 777;
8223 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008224 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008225
8226 VkBuffer ib;
8227 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8228
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008229 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008230 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008231}
8232
Karl Schultz6addd812016-02-02 17:17:23 -07008233TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008234TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008235 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008236
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008237 ASSERT_NO_FATAL_FAILURE(InitState());
8238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008239
Chris Forbesf29a84f2016-10-06 18:39:28 +13008240 // An empty primary command buffer
8241 VkCommandBufferObj cb(m_device, m_commandPool);
8242 cb.BeginCommandBuffer();
8243 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008244
Chris Forbesf29a84f2016-10-06 18:39:28 +13008245 m_commandBuffer->BeginCommandBuffer();
8246 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8247 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008248
Chris Forbesf29a84f2016-10-06 18:39:28 +13008249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8250 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008251 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008252}
8253
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008254TEST_F(VkLayerTest, DSUsageBitsErrors) {
8255 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8256 "that do not have correct usage bits sets.");
8257 VkResult err;
8258
8259 ASSERT_NO_FATAL_FAILURE(InitState());
8260 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8261 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8262 ds_type_count[i].type = VkDescriptorType(i);
8263 ds_type_count[i].descriptorCount = 1;
8264 }
8265 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8266 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8267 ds_pool_ci.pNext = NULL;
8268 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8269 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8270 ds_pool_ci.pPoolSizes = ds_type_count;
8271
8272 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008273 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008274 ASSERT_VK_SUCCESS(err);
8275
8276 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008277 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008278 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8279 dsl_binding[i].binding = 0;
8280 dsl_binding[i].descriptorType = VkDescriptorType(i);
8281 dsl_binding[i].descriptorCount = 1;
8282 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8283 dsl_binding[i].pImmutableSamplers = NULL;
8284 }
8285
8286 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8287 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8288 ds_layout_ci.pNext = NULL;
8289 ds_layout_ci.bindingCount = 1;
8290 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8291 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8292 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008293 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008294 ASSERT_VK_SUCCESS(err);
8295 }
8296 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8297 VkDescriptorSetAllocateInfo alloc_info = {};
8298 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8299 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8300 alloc_info.descriptorPool = ds_pool;
8301 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008302 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008303 ASSERT_VK_SUCCESS(err);
8304
8305 // Create a buffer & bufferView to be used for invalid updates
8306 VkBufferCreateInfo buff_ci = {};
8307 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8308 // This usage is not valid for any descriptor type
8309 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8310 buff_ci.size = 256;
8311 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8312 VkBuffer buffer;
8313 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8314 ASSERT_VK_SUCCESS(err);
8315
8316 VkBufferViewCreateInfo buff_view_ci = {};
8317 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8318 buff_view_ci.buffer = buffer;
8319 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8320 buff_view_ci.range = VK_WHOLE_SIZE;
8321 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008322 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008323 ASSERT_VK_SUCCESS(err);
8324
8325 // Create an image to be used for invalid updates
8326 VkImageCreateInfo image_ci = {};
8327 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8328 image_ci.imageType = VK_IMAGE_TYPE_2D;
8329 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8330 image_ci.extent.width = 64;
8331 image_ci.extent.height = 64;
8332 image_ci.extent.depth = 1;
8333 image_ci.mipLevels = 1;
8334 image_ci.arrayLayers = 1;
8335 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8336 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8337 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8338 // This usage is not valid for any descriptor type
8339 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8340 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8341 VkImage image;
8342 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8343 ASSERT_VK_SUCCESS(err);
8344 // Bind memory to image
8345 VkMemoryRequirements mem_reqs;
8346 VkDeviceMemory image_mem;
8347 bool pass;
8348 VkMemoryAllocateInfo mem_alloc = {};
8349 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8350 mem_alloc.pNext = NULL;
8351 mem_alloc.allocationSize = 0;
8352 mem_alloc.memoryTypeIndex = 0;
8353 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8354 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008355 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008356 ASSERT_TRUE(pass);
8357 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8358 ASSERT_VK_SUCCESS(err);
8359 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8360 ASSERT_VK_SUCCESS(err);
8361 // Now create view for image
8362 VkImageViewCreateInfo image_view_ci = {};
8363 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8364 image_view_ci.image = image;
8365 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8366 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8367 image_view_ci.subresourceRange.layerCount = 1;
8368 image_view_ci.subresourceRange.baseArrayLayer = 0;
8369 image_view_ci.subresourceRange.levelCount = 1;
8370 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8371 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008372 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008373 ASSERT_VK_SUCCESS(err);
8374
8375 VkDescriptorBufferInfo buff_info = {};
8376 buff_info.buffer = buffer;
8377 VkDescriptorImageInfo img_info = {};
8378 img_info.imageView = image_view;
8379 VkWriteDescriptorSet descriptor_write = {};
8380 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8381 descriptor_write.dstBinding = 0;
8382 descriptor_write.descriptorCount = 1;
8383 descriptor_write.pTexelBufferView = &buff_view;
8384 descriptor_write.pBufferInfo = &buff_info;
8385 descriptor_write.pImageInfo = &img_info;
8386
8387 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008388 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8389 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8390 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8391 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8392 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8393 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8394 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8395 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8396 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8397 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8398 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008399 // Start loop at 1 as SAMPLER desc type has no usage bit error
8400 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8401 descriptor_write.descriptorType = VkDescriptorType(i);
8402 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008406
8407 m_errorMonitor->VerifyFound();
8408 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8409 }
8410 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8411 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008412 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008413 vkDestroyImageView(m_device->device(), image_view, NULL);
8414 vkDestroyBuffer(m_device->device(), buffer, NULL);
8415 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008416 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008417 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8418}
8419
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008420TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008421 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8422 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8423 "1. offset value greater than buffer size\n"
8424 "2. range value of 0\n"
8425 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008426 VkResult err;
8427
8428 ASSERT_NO_FATAL_FAILURE(InitState());
8429 VkDescriptorPoolSize ds_type_count = {};
8430 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8431 ds_type_count.descriptorCount = 1;
8432
8433 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8434 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8435 ds_pool_ci.pNext = NULL;
8436 ds_pool_ci.maxSets = 1;
8437 ds_pool_ci.poolSizeCount = 1;
8438 ds_pool_ci.pPoolSizes = &ds_type_count;
8439
8440 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008441 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008442 ASSERT_VK_SUCCESS(err);
8443
8444 // Create layout with single uniform buffer descriptor
8445 VkDescriptorSetLayoutBinding dsl_binding = {};
8446 dsl_binding.binding = 0;
8447 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8448 dsl_binding.descriptorCount = 1;
8449 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8450 dsl_binding.pImmutableSamplers = NULL;
8451
8452 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8453 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8454 ds_layout_ci.pNext = NULL;
8455 ds_layout_ci.bindingCount = 1;
8456 ds_layout_ci.pBindings = &dsl_binding;
8457 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008459 ASSERT_VK_SUCCESS(err);
8460
8461 VkDescriptorSet descriptor_set = {};
8462 VkDescriptorSetAllocateInfo alloc_info = {};
8463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8464 alloc_info.descriptorSetCount = 1;
8465 alloc_info.descriptorPool = ds_pool;
8466 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008468 ASSERT_VK_SUCCESS(err);
8469
8470 // Create a buffer to be used for invalid updates
8471 VkBufferCreateInfo buff_ci = {};
8472 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8473 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8474 buff_ci.size = 256;
8475 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8476 VkBuffer buffer;
8477 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8478 ASSERT_VK_SUCCESS(err);
8479 // Have to bind memory to buffer before descriptor update
8480 VkMemoryAllocateInfo mem_alloc = {};
8481 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8482 mem_alloc.pNext = NULL;
8483 mem_alloc.allocationSize = 256;
8484 mem_alloc.memoryTypeIndex = 0;
8485
8486 VkMemoryRequirements mem_reqs;
8487 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008488 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008489 if (!pass) {
8490 vkDestroyBuffer(m_device->device(), buffer, NULL);
8491 return;
8492 }
8493
8494 VkDeviceMemory mem;
8495 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8496 ASSERT_VK_SUCCESS(err);
8497 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8498 ASSERT_VK_SUCCESS(err);
8499
8500 VkDescriptorBufferInfo buff_info = {};
8501 buff_info.buffer = buffer;
8502 // First make offset 1 larger than buffer size
8503 buff_info.offset = 257;
8504 buff_info.range = VK_WHOLE_SIZE;
8505 VkWriteDescriptorSet descriptor_write = {};
8506 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8507 descriptor_write.dstBinding = 0;
8508 descriptor_write.descriptorCount = 1;
8509 descriptor_write.pTexelBufferView = nullptr;
8510 descriptor_write.pBufferInfo = &buff_info;
8511 descriptor_write.pImageInfo = nullptr;
8512
8513 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8514 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008516
8517 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8518
8519 m_errorMonitor->VerifyFound();
8520 // Now cause error due to range of 0
8521 buff_info.offset = 0;
8522 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8524 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008525
8526 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8527
8528 m_errorMonitor->VerifyFound();
8529 // Now cause error due to range exceeding buffer size - offset
8530 buff_info.offset = 128;
8531 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " range is 200 which is greater than buffer size ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008533
8534 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8535
8536 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008537 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008538 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8539 vkDestroyBuffer(m_device->device(), buffer, NULL);
8540 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8541 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8542}
8543
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008544TEST_F(VkLayerTest, DSAspectBitsErrors) {
8545 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8546 // are set, but could expand this test to hit more cases.
8547 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8548 "that do not have correct aspect bits sets.");
8549 VkResult err;
8550
8551 ASSERT_NO_FATAL_FAILURE(InitState());
8552 VkDescriptorPoolSize ds_type_count = {};
8553 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8554 ds_type_count.descriptorCount = 1;
8555
8556 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8557 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8558 ds_pool_ci.pNext = NULL;
8559 ds_pool_ci.maxSets = 5;
8560 ds_pool_ci.poolSizeCount = 1;
8561 ds_pool_ci.pPoolSizes = &ds_type_count;
8562
8563 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008564 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008565 ASSERT_VK_SUCCESS(err);
8566
8567 VkDescriptorSetLayoutBinding dsl_binding = {};
8568 dsl_binding.binding = 0;
8569 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8570 dsl_binding.descriptorCount = 1;
8571 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8572 dsl_binding.pImmutableSamplers = NULL;
8573
8574 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8575 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8576 ds_layout_ci.pNext = NULL;
8577 ds_layout_ci.bindingCount = 1;
8578 ds_layout_ci.pBindings = &dsl_binding;
8579 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008580 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008581 ASSERT_VK_SUCCESS(err);
8582
8583 VkDescriptorSet descriptor_set = {};
8584 VkDescriptorSetAllocateInfo alloc_info = {};
8585 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8586 alloc_info.descriptorSetCount = 1;
8587 alloc_info.descriptorPool = ds_pool;
8588 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008589 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008590 ASSERT_VK_SUCCESS(err);
8591
8592 // Create an image to be used for invalid updates
8593 VkImageCreateInfo image_ci = {};
8594 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8595 image_ci.imageType = VK_IMAGE_TYPE_2D;
8596 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8597 image_ci.extent.width = 64;
8598 image_ci.extent.height = 64;
8599 image_ci.extent.depth = 1;
8600 image_ci.mipLevels = 1;
8601 image_ci.arrayLayers = 1;
8602 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8603 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8604 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8605 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8606 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8607 VkImage image;
8608 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8609 ASSERT_VK_SUCCESS(err);
8610 // Bind memory to image
8611 VkMemoryRequirements mem_reqs;
8612 VkDeviceMemory image_mem;
8613 bool pass;
8614 VkMemoryAllocateInfo mem_alloc = {};
8615 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8616 mem_alloc.pNext = NULL;
8617 mem_alloc.allocationSize = 0;
8618 mem_alloc.memoryTypeIndex = 0;
8619 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8620 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008621 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008622 ASSERT_TRUE(pass);
8623 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8624 ASSERT_VK_SUCCESS(err);
8625 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8626 ASSERT_VK_SUCCESS(err);
8627 // Now create view for image
8628 VkImageViewCreateInfo image_view_ci = {};
8629 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8630 image_view_ci.image = image;
8631 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8632 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8633 image_view_ci.subresourceRange.layerCount = 1;
8634 image_view_ci.subresourceRange.baseArrayLayer = 0;
8635 image_view_ci.subresourceRange.levelCount = 1;
8636 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008637 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008638
8639 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008640 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008641 ASSERT_VK_SUCCESS(err);
8642
8643 VkDescriptorImageInfo img_info = {};
8644 img_info.imageView = image_view;
8645 VkWriteDescriptorSet descriptor_write = {};
8646 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8647 descriptor_write.dstBinding = 0;
8648 descriptor_write.descriptorCount = 1;
8649 descriptor_write.pTexelBufferView = NULL;
8650 descriptor_write.pBufferInfo = NULL;
8651 descriptor_write.pImageInfo = &img_info;
8652 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8653 descriptor_write.dstSet = descriptor_set;
8654 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8655 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008657
8658 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8659
8660 m_errorMonitor->VerifyFound();
8661 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8662 vkDestroyImage(m_device->device(), image, NULL);
8663 vkFreeMemory(m_device->device(), image_mem, NULL);
8664 vkDestroyImageView(m_device->device(), image_view, NULL);
8665 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8666 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8667}
8668
Karl Schultz6addd812016-02-02 17:17:23 -07008669TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008670 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008671 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008672
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8674 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8675 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008676
Tobin Ehlis3b780662015-05-28 12:11:26 -06008677 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008678 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008679 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008680 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8681 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008682
8683 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008684 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8685 ds_pool_ci.pNext = NULL;
8686 ds_pool_ci.maxSets = 1;
8687 ds_pool_ci.poolSizeCount = 1;
8688 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008689
Tobin Ehlis3b780662015-05-28 12:11:26 -06008690 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008691 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008692 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008693 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008694 dsl_binding.binding = 0;
8695 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8696 dsl_binding.descriptorCount = 1;
8697 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8698 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008699
Tony Barboureb254902015-07-15 12:50:33 -06008700 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008701 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8702 ds_layout_ci.pNext = NULL;
8703 ds_layout_ci.bindingCount = 1;
8704 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008705
Tobin Ehlis3b780662015-05-28 12:11:26 -06008706 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008707 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008708 ASSERT_VK_SUCCESS(err);
8709
8710 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008711 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008712 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008713 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008714 alloc_info.descriptorPool = ds_pool;
8715 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008716 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008717 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008718
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008719 VkSamplerCreateInfo sampler_ci = {};
8720 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8721 sampler_ci.pNext = NULL;
8722 sampler_ci.magFilter = VK_FILTER_NEAREST;
8723 sampler_ci.minFilter = VK_FILTER_NEAREST;
8724 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8725 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8726 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8727 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8728 sampler_ci.mipLodBias = 1.0;
8729 sampler_ci.anisotropyEnable = VK_FALSE;
8730 sampler_ci.maxAnisotropy = 1;
8731 sampler_ci.compareEnable = VK_FALSE;
8732 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8733 sampler_ci.minLod = 1.0;
8734 sampler_ci.maxLod = 1.0;
8735 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8736 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8737 VkSampler sampler;
8738 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8739 ASSERT_VK_SUCCESS(err);
8740
8741 VkDescriptorImageInfo info = {};
8742 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008743
8744 VkWriteDescriptorSet descriptor_write;
8745 memset(&descriptor_write, 0, sizeof(descriptor_write));
8746 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008747 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008748 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008749 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008750 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008751 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008752
8753 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8754
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008755 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008756
Chia-I Wuf7458c52015-10-26 21:10:41 +08008757 vkDestroySampler(m_device->device(), sampler, NULL);
8758 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8759 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008760}
8761
Karl Schultz6addd812016-02-02 17:17:23 -07008762TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008763 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008764 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008765
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8767 " binding #0 with 1 total descriptors but update of 1 descriptors "
8768 "starting at binding offset of 0 combined with update array element "
8769 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008770
Tobin Ehlis3b780662015-05-28 12:11:26 -06008771 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008772 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008773 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008774 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8775 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008776
8777 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008778 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8779 ds_pool_ci.pNext = NULL;
8780 ds_pool_ci.maxSets = 1;
8781 ds_pool_ci.poolSizeCount = 1;
8782 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008783
Tobin Ehlis3b780662015-05-28 12:11:26 -06008784 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008785 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008786 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008787
Tony Barboureb254902015-07-15 12:50:33 -06008788 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008789 dsl_binding.binding = 0;
8790 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8791 dsl_binding.descriptorCount = 1;
8792 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8793 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008794
8795 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008796 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8797 ds_layout_ci.pNext = NULL;
8798 ds_layout_ci.bindingCount = 1;
8799 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008800
Tobin Ehlis3b780662015-05-28 12:11:26 -06008801 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008802 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008803 ASSERT_VK_SUCCESS(err);
8804
8805 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008806 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008807 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008808 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008809 alloc_info.descriptorPool = ds_pool;
8810 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008811 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008812 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008813
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008814 // Correctly update descriptor to avoid "NOT_UPDATED" error
8815 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008816 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008817 buff_info.offset = 0;
8818 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008819
8820 VkWriteDescriptorSet descriptor_write;
8821 memset(&descriptor_write, 0, sizeof(descriptor_write));
8822 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008823 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008824 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008825 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008826 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8827 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008828
8829 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8830
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008831 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008832
Chia-I Wuf7458c52015-10-26 21:10:41 +08008833 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8834 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008835}
8836
Karl Schultz6addd812016-02-02 17:17:23 -07008837TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8838 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8839 // index 2
8840 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008841
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008843
Tobin Ehlis3b780662015-05-28 12:11:26 -06008844 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008845 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008846 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008847 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8848 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008849
8850 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008851 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8852 ds_pool_ci.pNext = NULL;
8853 ds_pool_ci.maxSets = 1;
8854 ds_pool_ci.poolSizeCount = 1;
8855 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008856
Tobin Ehlis3b780662015-05-28 12:11:26 -06008857 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008858 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008859 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008860
Tony Barboureb254902015-07-15 12:50:33 -06008861 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008862 dsl_binding.binding = 0;
8863 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8864 dsl_binding.descriptorCount = 1;
8865 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8866 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008867
8868 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008869 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8870 ds_layout_ci.pNext = NULL;
8871 ds_layout_ci.bindingCount = 1;
8872 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008873 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008874 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008875 ASSERT_VK_SUCCESS(err);
8876
8877 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008878 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008879 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008880 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008881 alloc_info.descriptorPool = ds_pool;
8882 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008883 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008884 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008885
Tony Barboureb254902015-07-15 12:50:33 -06008886 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008887 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8888 sampler_ci.pNext = NULL;
8889 sampler_ci.magFilter = VK_FILTER_NEAREST;
8890 sampler_ci.minFilter = VK_FILTER_NEAREST;
8891 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8892 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8893 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8894 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8895 sampler_ci.mipLodBias = 1.0;
8896 sampler_ci.anisotropyEnable = VK_FALSE;
8897 sampler_ci.maxAnisotropy = 1;
8898 sampler_ci.compareEnable = VK_FALSE;
8899 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8900 sampler_ci.minLod = 1.0;
8901 sampler_ci.maxLod = 1.0;
8902 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8903 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008904
Tobin Ehlis3b780662015-05-28 12:11:26 -06008905 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008906 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008907 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008908
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008909 VkDescriptorImageInfo info = {};
8910 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008911
8912 VkWriteDescriptorSet descriptor_write;
8913 memset(&descriptor_write, 0, sizeof(descriptor_write));
8914 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008915 descriptor_write.dstSet = descriptorSet;
8916 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008917 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008918 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008919 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008920 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008921
8922 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8923
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008924 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008925
Chia-I Wuf7458c52015-10-26 21:10:41 +08008926 vkDestroySampler(m_device->device(), sampler, NULL);
8927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008929}
8930
Karl Schultz6addd812016-02-02 17:17:23 -07008931TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8932 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8933 // types
8934 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008936 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 -06008937
Tobin Ehlis3b780662015-05-28 12:11:26 -06008938 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008939
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008940 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008941 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8942 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008943
8944 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008945 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8946 ds_pool_ci.pNext = NULL;
8947 ds_pool_ci.maxSets = 1;
8948 ds_pool_ci.poolSizeCount = 1;
8949 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008950
Tobin Ehlis3b780662015-05-28 12:11:26 -06008951 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008952 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008953 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008954 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008955 dsl_binding.binding = 0;
8956 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8957 dsl_binding.descriptorCount = 1;
8958 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8959 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008960
Tony Barboureb254902015-07-15 12:50:33 -06008961 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008962 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8963 ds_layout_ci.pNext = NULL;
8964 ds_layout_ci.bindingCount = 1;
8965 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008966
Tobin Ehlis3b780662015-05-28 12:11:26 -06008967 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008968 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008969 ASSERT_VK_SUCCESS(err);
8970
8971 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008972 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008973 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008974 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008975 alloc_info.descriptorPool = ds_pool;
8976 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008977 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008978 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008979
Tony Barboureb254902015-07-15 12:50:33 -06008980 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008981 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8982 sampler_ci.pNext = NULL;
8983 sampler_ci.magFilter = VK_FILTER_NEAREST;
8984 sampler_ci.minFilter = VK_FILTER_NEAREST;
8985 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8986 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8987 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8988 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8989 sampler_ci.mipLodBias = 1.0;
8990 sampler_ci.anisotropyEnable = VK_FALSE;
8991 sampler_ci.maxAnisotropy = 1;
8992 sampler_ci.compareEnable = VK_FALSE;
8993 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8994 sampler_ci.minLod = 1.0;
8995 sampler_ci.maxLod = 1.0;
8996 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8997 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008998 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008999 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009000 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009001
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009002 VkDescriptorImageInfo info = {};
9003 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009004
9005 VkWriteDescriptorSet descriptor_write;
9006 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009007 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009008 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009009 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009010 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009011 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009012 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009013
9014 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9015
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009016 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009017
Chia-I Wuf7458c52015-10-26 21:10:41 +08009018 vkDestroySampler(m_device->device(), sampler, NULL);
9019 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9020 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009021}
9022
Karl Schultz6addd812016-02-02 17:17:23 -07009023TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009024 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009025 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009026
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9028 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009029
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009030 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009031 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9032 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009033 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009034 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9035 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009036
9037 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009038 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9039 ds_pool_ci.pNext = NULL;
9040 ds_pool_ci.maxSets = 1;
9041 ds_pool_ci.poolSizeCount = 1;
9042 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009043
9044 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009045 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009046 ASSERT_VK_SUCCESS(err);
9047
9048 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009049 dsl_binding.binding = 0;
9050 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9051 dsl_binding.descriptorCount = 1;
9052 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9053 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009054
9055 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009056 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9057 ds_layout_ci.pNext = NULL;
9058 ds_layout_ci.bindingCount = 1;
9059 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009060 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009061 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009062 ASSERT_VK_SUCCESS(err);
9063
9064 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009065 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009066 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009067 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009068 alloc_info.descriptorPool = ds_pool;
9069 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009070 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009071 ASSERT_VK_SUCCESS(err);
9072
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009073 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009074
9075 VkDescriptorImageInfo descriptor_info;
9076 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9077 descriptor_info.sampler = sampler;
9078
9079 VkWriteDescriptorSet descriptor_write;
9080 memset(&descriptor_write, 0, sizeof(descriptor_write));
9081 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009082 descriptor_write.dstSet = descriptorSet;
9083 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009084 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009085 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9086 descriptor_write.pImageInfo = &descriptor_info;
9087
9088 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9089
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009090 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009091
Chia-I Wuf7458c52015-10-26 21:10:41 +08009092 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9093 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009094}
9095
Karl Schultz6addd812016-02-02 17:17:23 -07009096TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9097 // Create a single combined Image/Sampler descriptor and send it an invalid
9098 // imageView
9099 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009100
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9102 "image sampler descriptor failed due "
9103 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009104
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009105 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009106 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009107 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9108 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009109
9110 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009111 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9112 ds_pool_ci.pNext = NULL;
9113 ds_pool_ci.maxSets = 1;
9114 ds_pool_ci.poolSizeCount = 1;
9115 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009116
9117 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009118 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009119 ASSERT_VK_SUCCESS(err);
9120
9121 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009122 dsl_binding.binding = 0;
9123 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9124 dsl_binding.descriptorCount = 1;
9125 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9126 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009127
9128 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009129 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9130 ds_layout_ci.pNext = NULL;
9131 ds_layout_ci.bindingCount = 1;
9132 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009133 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009134 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009135 ASSERT_VK_SUCCESS(err);
9136
9137 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009138 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009139 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009140 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009141 alloc_info.descriptorPool = ds_pool;
9142 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009143 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009144 ASSERT_VK_SUCCESS(err);
9145
9146 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009147 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9148 sampler_ci.pNext = NULL;
9149 sampler_ci.magFilter = VK_FILTER_NEAREST;
9150 sampler_ci.minFilter = VK_FILTER_NEAREST;
9151 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9152 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9153 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9154 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9155 sampler_ci.mipLodBias = 1.0;
9156 sampler_ci.anisotropyEnable = VK_FALSE;
9157 sampler_ci.maxAnisotropy = 1;
9158 sampler_ci.compareEnable = VK_FALSE;
9159 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9160 sampler_ci.minLod = 1.0;
9161 sampler_ci.maxLod = 1.0;
9162 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9163 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009164
9165 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009166 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009167 ASSERT_VK_SUCCESS(err);
9168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009169 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009170
9171 VkDescriptorImageInfo descriptor_info;
9172 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9173 descriptor_info.sampler = sampler;
9174 descriptor_info.imageView = view;
9175
9176 VkWriteDescriptorSet descriptor_write;
9177 memset(&descriptor_write, 0, sizeof(descriptor_write));
9178 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009179 descriptor_write.dstSet = descriptorSet;
9180 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009181 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009182 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9183 descriptor_write.pImageInfo = &descriptor_info;
9184
9185 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009187 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009188
Chia-I Wuf7458c52015-10-26 21:10:41 +08009189 vkDestroySampler(m_device->device(), sampler, NULL);
9190 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9191 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009192}
9193
Karl Schultz6addd812016-02-02 17:17:23 -07009194TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9195 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9196 // into the other
9197 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009198
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9200 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9201 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009202
Tobin Ehlis04356f92015-10-27 16:35:27 -06009203 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009204 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009205 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009206 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9207 ds_type_count[0].descriptorCount = 1;
9208 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9209 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009210
9211 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009212 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9213 ds_pool_ci.pNext = NULL;
9214 ds_pool_ci.maxSets = 1;
9215 ds_pool_ci.poolSizeCount = 2;
9216 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009217
9218 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009219 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009220 ASSERT_VK_SUCCESS(err);
9221 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009222 dsl_binding[0].binding = 0;
9223 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9224 dsl_binding[0].descriptorCount = 1;
9225 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9226 dsl_binding[0].pImmutableSamplers = NULL;
9227 dsl_binding[1].binding = 1;
9228 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9229 dsl_binding[1].descriptorCount = 1;
9230 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9231 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009232
9233 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009234 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9235 ds_layout_ci.pNext = NULL;
9236 ds_layout_ci.bindingCount = 2;
9237 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009238
9239 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009240 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009241 ASSERT_VK_SUCCESS(err);
9242
9243 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009244 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009245 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009246 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009247 alloc_info.descriptorPool = ds_pool;
9248 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009249 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009250 ASSERT_VK_SUCCESS(err);
9251
9252 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009253 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9254 sampler_ci.pNext = NULL;
9255 sampler_ci.magFilter = VK_FILTER_NEAREST;
9256 sampler_ci.minFilter = VK_FILTER_NEAREST;
9257 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9258 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9259 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9260 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9261 sampler_ci.mipLodBias = 1.0;
9262 sampler_ci.anisotropyEnable = VK_FALSE;
9263 sampler_ci.maxAnisotropy = 1;
9264 sampler_ci.compareEnable = VK_FALSE;
9265 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9266 sampler_ci.minLod = 1.0;
9267 sampler_ci.maxLod = 1.0;
9268 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9269 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009270
9271 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009272 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009273 ASSERT_VK_SUCCESS(err);
9274
9275 VkDescriptorImageInfo info = {};
9276 info.sampler = sampler;
9277
9278 VkWriteDescriptorSet descriptor_write;
9279 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9280 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009281 descriptor_write.dstSet = descriptorSet;
9282 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009283 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009284 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9285 descriptor_write.pImageInfo = &info;
9286 // This write update should succeed
9287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9288 // Now perform a copy update that fails due to type mismatch
9289 VkCopyDescriptorSet copy_ds_update;
9290 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9291 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9292 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009293 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009294 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009295 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009296 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009297 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9298
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009299 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009300 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009301 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 -06009302 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9303 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9304 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009305 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009306 copy_ds_update.dstSet = descriptorSet;
9307 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009308 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009309 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9310
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009311 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009312
Tobin Ehlis04356f92015-10-27 16:35:27 -06009313 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9315 "update array offset of 0 and update of "
9316 "5 descriptors oversteps total number "
9317 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009318
Tobin Ehlis04356f92015-10-27 16:35:27 -06009319 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9320 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9321 copy_ds_update.srcSet = descriptorSet;
9322 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009323 copy_ds_update.dstSet = descriptorSet;
9324 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009325 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009326 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9327
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009328 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009329
Chia-I Wuf7458c52015-10-26 21:10:41 +08009330 vkDestroySampler(m_device->device(), sampler, NULL);
9331 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9332 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009333}
9334
Karl Schultz6addd812016-02-02 17:17:23 -07009335TEST_F(VkLayerTest, NumSamplesMismatch) {
9336 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9337 // sampleCount
9338 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009339
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009341
Tobin Ehlis3b780662015-05-28 12:11:26 -06009342 ASSERT_NO_FATAL_FAILURE(InitState());
9343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009344 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009345 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009346 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009347
9348 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009349 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9350 ds_pool_ci.pNext = NULL;
9351 ds_pool_ci.maxSets = 1;
9352 ds_pool_ci.poolSizeCount = 1;
9353 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009354
Tobin Ehlis3b780662015-05-28 12:11:26 -06009355 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009356 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009357 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009358
Tony Barboureb254902015-07-15 12:50:33 -06009359 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009360 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009361 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009362 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009363 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9364 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009365
Tony Barboureb254902015-07-15 12:50:33 -06009366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9368 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009369 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009370 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009371
Tobin Ehlis3b780662015-05-28 12:11:26 -06009372 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009373 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009374 ASSERT_VK_SUCCESS(err);
9375
9376 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009377 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009378 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009379 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009380 alloc_info.descriptorPool = ds_pool;
9381 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009382 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009383 ASSERT_VK_SUCCESS(err);
9384
Tony Barboureb254902015-07-15 12:50:33 -06009385 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009386 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009387 pipe_ms_state_ci.pNext = NULL;
9388 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9389 pipe_ms_state_ci.sampleShadingEnable = 0;
9390 pipe_ms_state_ci.minSampleShading = 1.0;
9391 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009392
Tony Barboureb254902015-07-15 12:50:33 -06009393 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009394 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9395 pipeline_layout_ci.pNext = NULL;
9396 pipeline_layout_ci.setLayoutCount = 1;
9397 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009398
9399 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009400 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009401 ASSERT_VK_SUCCESS(err);
9402
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009403 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9404 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9405 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009406 VkPipelineObj pipe(m_device);
9407 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009408 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009409 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009410 pipe.SetMSAA(&pipe_ms_state_ci);
9411 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009412
Tony Barbourfe3351b2015-07-28 10:17:20 -06009413 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009414 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009415
Mark Young29927482016-05-04 14:38:51 -06009416 // Render triangle (the error should trigger on the attempt to draw).
9417 Draw(3, 1, 0, 0);
9418
9419 // Finalize recording of the command buffer
9420 EndCommandBuffer();
9421
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009422 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009423
Chia-I Wuf7458c52015-10-26 21:10:41 +08009424 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9425 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9426 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009427}
Mark Young29927482016-05-04 14:38:51 -06009428
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009429TEST_F(VkLayerTest, RenderPassIncompatible) {
9430 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9431 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009432 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009433 VkResult err;
9434
9435 ASSERT_NO_FATAL_FAILURE(InitState());
9436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9437
9438 VkDescriptorSetLayoutBinding dsl_binding = {};
9439 dsl_binding.binding = 0;
9440 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9441 dsl_binding.descriptorCount = 1;
9442 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9443 dsl_binding.pImmutableSamplers = NULL;
9444
9445 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9446 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9447 ds_layout_ci.pNext = NULL;
9448 ds_layout_ci.bindingCount = 1;
9449 ds_layout_ci.pBindings = &dsl_binding;
9450
9451 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009452 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009453 ASSERT_VK_SUCCESS(err);
9454
9455 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9456 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9457 pipeline_layout_ci.pNext = NULL;
9458 pipeline_layout_ci.setLayoutCount = 1;
9459 pipeline_layout_ci.pSetLayouts = &ds_layout;
9460
9461 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009462 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009463 ASSERT_VK_SUCCESS(err);
9464
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009465 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9466 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9467 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009468 // Create a renderpass that will be incompatible with default renderpass
9469 VkAttachmentReference attach = {};
9470 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9471 VkAttachmentReference color_att = {};
9472 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9473 VkSubpassDescription subpass = {};
9474 subpass.inputAttachmentCount = 1;
9475 subpass.pInputAttachments = &attach;
9476 subpass.colorAttachmentCount = 1;
9477 subpass.pColorAttachments = &color_att;
9478 VkRenderPassCreateInfo rpci = {};
9479 rpci.subpassCount = 1;
9480 rpci.pSubpasses = &subpass;
9481 rpci.attachmentCount = 1;
9482 VkAttachmentDescription attach_desc = {};
9483 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009484 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9485 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009486 rpci.pAttachments = &attach_desc;
9487 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9488 VkRenderPass rp;
9489 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9490 VkPipelineObj pipe(m_device);
9491 pipe.AddShader(&vs);
9492 pipe.AddShader(&fs);
9493 pipe.AddColorAttachment();
9494 VkViewport view_port = {};
9495 m_viewports.push_back(view_port);
9496 pipe.SetViewport(m_viewports);
9497 VkRect2D rect = {};
9498 m_scissors.push_back(rect);
9499 pipe.SetScissor(m_scissors);
9500 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9501
9502 VkCommandBufferInheritanceInfo cbii = {};
9503 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9504 cbii.renderPass = rp;
9505 cbii.subpass = 0;
9506 VkCommandBufferBeginInfo cbbi = {};
9507 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9508 cbbi.pInheritanceInfo = &cbii;
9509 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9510 VkRenderPassBeginInfo rpbi = {};
9511 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9512 rpbi.framebuffer = m_framebuffer;
9513 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009514 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9515 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009516
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009518 // Render triangle (the error should trigger on the attempt to draw).
9519 Draw(3, 1, 0, 0);
9520
9521 // Finalize recording of the command buffer
9522 EndCommandBuffer();
9523
9524 m_errorMonitor->VerifyFound();
9525
9526 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9527 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9528 vkDestroyRenderPass(m_device->device(), rp, NULL);
9529}
9530
Mark Youngc89c6312016-03-31 16:03:20 -06009531TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9532 // Create Pipeline where the number of blend attachments doesn't match the
9533 // number of color attachments. In this case, we don't add any color
9534 // blend attachments even though we have a color attachment.
9535 VkResult err;
9536
9537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009538 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009539
9540 ASSERT_NO_FATAL_FAILURE(InitState());
9541 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9542 VkDescriptorPoolSize ds_type_count = {};
9543 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9544 ds_type_count.descriptorCount = 1;
9545
9546 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9547 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9548 ds_pool_ci.pNext = NULL;
9549 ds_pool_ci.maxSets = 1;
9550 ds_pool_ci.poolSizeCount = 1;
9551 ds_pool_ci.pPoolSizes = &ds_type_count;
9552
9553 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009554 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009555 ASSERT_VK_SUCCESS(err);
9556
9557 VkDescriptorSetLayoutBinding dsl_binding = {};
9558 dsl_binding.binding = 0;
9559 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9560 dsl_binding.descriptorCount = 1;
9561 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9562 dsl_binding.pImmutableSamplers = NULL;
9563
9564 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9565 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9566 ds_layout_ci.pNext = NULL;
9567 ds_layout_ci.bindingCount = 1;
9568 ds_layout_ci.pBindings = &dsl_binding;
9569
9570 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009571 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009572 ASSERT_VK_SUCCESS(err);
9573
9574 VkDescriptorSet descriptorSet;
9575 VkDescriptorSetAllocateInfo alloc_info = {};
9576 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9577 alloc_info.descriptorSetCount = 1;
9578 alloc_info.descriptorPool = ds_pool;
9579 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009580 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009581 ASSERT_VK_SUCCESS(err);
9582
9583 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009584 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009585 pipe_ms_state_ci.pNext = NULL;
9586 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9587 pipe_ms_state_ci.sampleShadingEnable = 0;
9588 pipe_ms_state_ci.minSampleShading = 1.0;
9589 pipe_ms_state_ci.pSampleMask = NULL;
9590
9591 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9592 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9593 pipeline_layout_ci.pNext = NULL;
9594 pipeline_layout_ci.setLayoutCount = 1;
9595 pipeline_layout_ci.pSetLayouts = &ds_layout;
9596
9597 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009598 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009599 ASSERT_VK_SUCCESS(err);
9600
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009601 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9602 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9603 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009604 VkPipelineObj pipe(m_device);
9605 pipe.AddShader(&vs);
9606 pipe.AddShader(&fs);
9607 pipe.SetMSAA(&pipe_ms_state_ci);
9608 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9609
9610 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009611 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009612
Mark Young29927482016-05-04 14:38:51 -06009613 // Render triangle (the error should trigger on the attempt to draw).
9614 Draw(3, 1, 0, 0);
9615
9616 // Finalize recording of the command buffer
9617 EndCommandBuffer();
9618
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009619 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009620
9621 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9622 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9623 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9624}
Mark Young29927482016-05-04 14:38:51 -06009625
Mark Muellerd4914412016-06-13 17:52:06 -06009626TEST_F(VkLayerTest, MissingClearAttachment) {
9627 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9628 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009629 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009631 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009632
9633 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9634 m_errorMonitor->VerifyFound();
9635}
9636
Karl Schultz6addd812016-02-02 17:17:23 -07009637TEST_F(VkLayerTest, ClearCmdNoDraw) {
9638 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9639 // to issuing a Draw
9640 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009641
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009643 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009644
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009645 ASSERT_NO_FATAL_FAILURE(InitState());
9646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009647
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009648 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009649 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9650 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009651
9652 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009653 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9654 ds_pool_ci.pNext = NULL;
9655 ds_pool_ci.maxSets = 1;
9656 ds_pool_ci.poolSizeCount = 1;
9657 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009658
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009659 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009660 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009661 ASSERT_VK_SUCCESS(err);
9662
Tony Barboureb254902015-07-15 12:50:33 -06009663 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009664 dsl_binding.binding = 0;
9665 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9666 dsl_binding.descriptorCount = 1;
9667 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9668 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009669
Tony Barboureb254902015-07-15 12:50:33 -06009670 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009671 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9672 ds_layout_ci.pNext = NULL;
9673 ds_layout_ci.bindingCount = 1;
9674 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009675
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009676 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009678 ASSERT_VK_SUCCESS(err);
9679
9680 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009681 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009682 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009683 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009684 alloc_info.descriptorPool = ds_pool;
9685 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009686 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009687 ASSERT_VK_SUCCESS(err);
9688
Tony Barboureb254902015-07-15 12:50:33 -06009689 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009690 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009691 pipe_ms_state_ci.pNext = NULL;
9692 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9693 pipe_ms_state_ci.sampleShadingEnable = 0;
9694 pipe_ms_state_ci.minSampleShading = 1.0;
9695 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009696
Tony Barboureb254902015-07-15 12:50:33 -06009697 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009698 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9699 pipeline_layout_ci.pNext = NULL;
9700 pipeline_layout_ci.setLayoutCount = 1;
9701 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009702
9703 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009704 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009705 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009707 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009708 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009709 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009710 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009711
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009712 VkPipelineObj pipe(m_device);
9713 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009714 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009715 pipe.SetMSAA(&pipe_ms_state_ci);
9716 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009717
9718 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009719
Karl Schultz6addd812016-02-02 17:17:23 -07009720 // Main thing we care about for this test is that the VkImage obj we're
9721 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009722 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009723 VkClearAttachment color_attachment;
9724 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9725 color_attachment.clearValue.color.float32[0] = 1.0;
9726 color_attachment.clearValue.color.float32[1] = 1.0;
9727 color_attachment.clearValue.color.float32[2] = 1.0;
9728 color_attachment.clearValue.color.float32[3] = 1.0;
9729 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009730 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009731
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009732 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009733
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009734 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009735
Chia-I Wuf7458c52015-10-26 21:10:41 +08009736 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9737 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9738 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009739}
9740
Karl Schultz6addd812016-02-02 17:17:23 -07009741TEST_F(VkLayerTest, VtxBufferBadIndex) {
9742 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9745 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009746
Tobin Ehlis502480b2015-06-24 15:53:07 -06009747 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009748 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009750
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009751 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009752 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9753 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009754
9755 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009756 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9757 ds_pool_ci.pNext = NULL;
9758 ds_pool_ci.maxSets = 1;
9759 ds_pool_ci.poolSizeCount = 1;
9760 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009761
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009762 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009763 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009764 ASSERT_VK_SUCCESS(err);
9765
Tony Barboureb254902015-07-15 12:50:33 -06009766 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009767 dsl_binding.binding = 0;
9768 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9769 dsl_binding.descriptorCount = 1;
9770 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9771 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009772
Tony Barboureb254902015-07-15 12:50:33 -06009773 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009774 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9775 ds_layout_ci.pNext = NULL;
9776 ds_layout_ci.bindingCount = 1;
9777 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009778
Tobin Ehlis502480b2015-06-24 15:53:07 -06009779 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009780 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009781 ASSERT_VK_SUCCESS(err);
9782
9783 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009784 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009785 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009786 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009787 alloc_info.descriptorPool = ds_pool;
9788 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009789 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009790 ASSERT_VK_SUCCESS(err);
9791
Tony Barboureb254902015-07-15 12:50:33 -06009792 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009793 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009794 pipe_ms_state_ci.pNext = NULL;
9795 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9796 pipe_ms_state_ci.sampleShadingEnable = 0;
9797 pipe_ms_state_ci.minSampleShading = 1.0;
9798 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009799
Tony Barboureb254902015-07-15 12:50:33 -06009800 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009801 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9802 pipeline_layout_ci.pNext = NULL;
9803 pipeline_layout_ci.setLayoutCount = 1;
9804 pipeline_layout_ci.pSetLayouts = &ds_layout;
9805 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009806
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009807 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009808 ASSERT_VK_SUCCESS(err);
9809
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009810 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9811 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9812 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009813 VkPipelineObj pipe(m_device);
9814 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009815 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009816 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009817 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009818 pipe.SetViewport(m_viewports);
9819 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009820 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009821
9822 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009823 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009824 // Don't care about actual data, just need to get to draw to flag error
9825 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009826 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009827 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009828 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009829
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009830 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009831
Chia-I Wuf7458c52015-10-26 21:10:41 +08009832 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9833 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9834 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009835}
Mark Muellerdfe37552016-07-07 14:47:42 -06009836
Mark Mueller2ee294f2016-08-04 12:59:48 -06009837TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9838 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9839 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009840 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009841
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009842 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9843 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009844
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009845 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9846 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009847
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009848 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009851 // The following test fails with recent NVidia drivers.
9852 // By the time core_validation is reached, the NVidia
9853 // driver has sanitized the invalid condition and core_validation
9854 // is not introduced to the failure condition. This is not the case
9855 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009856 // uint32_t count = static_cast<uint32_t>(~0);
9857 // VkPhysicalDevice physical_device;
9858 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9859 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009862 float queue_priority = 0.0;
9863
9864 VkDeviceQueueCreateInfo queue_create_info = {};
9865 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9866 queue_create_info.queueCount = 1;
9867 queue_create_info.pQueuePriorities = &queue_priority;
9868 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9869
9870 VkPhysicalDeviceFeatures features = m_device->phy().features();
9871 VkDevice testDevice;
9872 VkDeviceCreateInfo device_create_info = {};
9873 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9874 device_create_info.queueCreateInfoCount = 1;
9875 device_create_info.pQueueCreateInfos = &queue_create_info;
9876 device_create_info.pEnabledFeatures = &features;
9877 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9878 m_errorMonitor->VerifyFound();
9879
9880 queue_create_info.queueFamilyIndex = 1;
9881
9882 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
9883 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
9884 for (unsigned i = 0; i < feature_count; i++) {
9885 if (VK_FALSE == feature_array[i]) {
9886 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009888 device_create_info.pEnabledFeatures = &features;
9889 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9890 m_errorMonitor->VerifyFound();
9891 break;
9892 }
9893 }
9894}
9895
9896TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
9897 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
9898 "End a command buffer with a query still in progress.");
9899
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009900 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
9901 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
9902 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009904 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009905
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009907
9908 ASSERT_NO_FATAL_FAILURE(InitState());
9909
9910 VkEvent event;
9911 VkEventCreateInfo event_create_info{};
9912 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9913 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9914
Mark Mueller2ee294f2016-08-04 12:59:48 -06009915 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009916 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009917
9918 BeginCommandBuffer();
9919
9920 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009921 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 -06009922 ASSERT_TRUE(image.initialized());
9923 VkImageMemoryBarrier img_barrier = {};
9924 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9925 img_barrier.pNext = NULL;
9926 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9927 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9928 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9929 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9930 img_barrier.image = image.handle();
9931 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -06009932
9933 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
9934 // that layer validation catches the case when it is not.
9935 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -06009936 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9937 img_barrier.subresourceRange.baseArrayLayer = 0;
9938 img_barrier.subresourceRange.baseMipLevel = 0;
9939 img_barrier.subresourceRange.layerCount = 1;
9940 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009941 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
9942 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009943 m_errorMonitor->VerifyFound();
9944
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009946
9947 VkQueryPool query_pool;
9948 VkQueryPoolCreateInfo query_pool_create_info = {};
9949 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
9950 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
9951 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009953
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009954 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009955 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
9956
9957 vkEndCommandBuffer(m_commandBuffer->handle());
9958 m_errorMonitor->VerifyFound();
9959
9960 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
9961 vkDestroyEvent(m_device->device(), event, nullptr);
9962}
9963
Mark Muellerdfe37552016-07-07 14:47:42 -06009964TEST_F(VkLayerTest, VertexBufferInvalid) {
9965 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
9966 "delete a buffer twice, use an invalid offset for each "
9967 "buffer type, and attempt to bind a null buffer");
9968
9969 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
9970 "using deleted buffer ";
9971 const char *double_destroy_message = "Cannot free buffer 0x";
9972 const char *invalid_offset_message = "vkBindBufferMemory(): "
9973 "memoryOffset is 0x";
9974 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
9975 "storage memoryOffset "
9976 "is 0x";
9977 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
9978 "texel memoryOffset "
9979 "is 0x";
9980 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
9981 "uniform memoryOffset "
9982 "is 0x";
9983 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
9984 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -06009985 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -06009986
9987 ASSERT_NO_FATAL_FAILURE(InitState());
9988 ASSERT_NO_FATAL_FAILURE(InitViewport());
9989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9990
9991 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009992 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -06009993 pipe_ms_state_ci.pNext = NULL;
9994 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9995 pipe_ms_state_ci.sampleShadingEnable = 0;
9996 pipe_ms_state_ci.minSampleShading = 1.0;
9997 pipe_ms_state_ci.pSampleMask = nullptr;
9998
9999 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10000 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10001 VkPipelineLayout pipeline_layout;
10002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010003 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010004 ASSERT_VK_SUCCESS(err);
10005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010006 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10007 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010008 VkPipelineObj pipe(m_device);
10009 pipe.AddShader(&vs);
10010 pipe.AddShader(&fs);
10011 pipe.AddColorAttachment();
10012 pipe.SetMSAA(&pipe_ms_state_ci);
10013 pipe.SetViewport(m_viewports);
10014 pipe.SetScissor(m_scissors);
10015 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10016
10017 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010018 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010019
10020 {
10021 // Create and bind a vertex buffer in a reduced scope, which will cause
10022 // it to be deleted upon leaving this scope
10023 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010024 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010025 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10026 draw_verticies.AddVertexInputToPipe(pipe);
10027 }
10028
10029 Draw(1, 0, 0, 0);
10030
10031 EndCommandBuffer();
10032
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010034 QueueCommandBuffer(false);
10035 m_errorMonitor->VerifyFound();
10036
10037 {
10038 // Create and bind a vertex buffer in a reduced scope, and delete it
10039 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010040 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010042 buffer_test.TestDoubleDestroy();
10043 }
10044 m_errorMonitor->VerifyFound();
10045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010046 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010047 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10049 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10050 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010051 m_errorMonitor->VerifyFound();
10052 }
10053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010054 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10055 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010056 // Create and bind a memory buffer with an invalid offset again,
10057 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10059 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10060 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010061 m_errorMonitor->VerifyFound();
10062 }
10063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010064 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010065 // Create and bind a memory buffer with an invalid offset again, but
10066 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10068 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10069 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010070 m_errorMonitor->VerifyFound();
10071 }
10072
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010073 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010074 // Create and bind a memory buffer with an invalid offset again, but
10075 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10077 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10078 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010079 m_errorMonitor->VerifyFound();
10080 }
10081
10082 {
10083 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10085 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10086 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010087 m_errorMonitor->VerifyFound();
10088 }
10089
10090 {
10091 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10093 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10094 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010095 }
10096 m_errorMonitor->VerifyFound();
10097
10098 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10099}
10100
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010101// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10102TEST_F(VkLayerTest, InvalidImageLayout) {
10103 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010104 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10105 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010106 // 3 in ValidateCmdBufImageLayouts
10107 // * -1 Attempt to submit cmd buf w/ deleted image
10108 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10109 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10111 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010112
10113 ASSERT_NO_FATAL_FAILURE(InitState());
10114 // Create src & dst images to use for copy operations
10115 VkImage src_image;
10116 VkImage dst_image;
10117
10118 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10119 const int32_t tex_width = 32;
10120 const int32_t tex_height = 32;
10121
10122 VkImageCreateInfo image_create_info = {};
10123 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10124 image_create_info.pNext = NULL;
10125 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10126 image_create_info.format = tex_format;
10127 image_create_info.extent.width = tex_width;
10128 image_create_info.extent.height = tex_height;
10129 image_create_info.extent.depth = 1;
10130 image_create_info.mipLevels = 1;
10131 image_create_info.arrayLayers = 4;
10132 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10133 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10134 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10135 image_create_info.flags = 0;
10136
10137 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10138 ASSERT_VK_SUCCESS(err);
10139 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10140 ASSERT_VK_SUCCESS(err);
10141
10142 BeginCommandBuffer();
10143 VkImageCopy copyRegion;
10144 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10145 copyRegion.srcSubresource.mipLevel = 0;
10146 copyRegion.srcSubresource.baseArrayLayer = 0;
10147 copyRegion.srcSubresource.layerCount = 1;
10148 copyRegion.srcOffset.x = 0;
10149 copyRegion.srcOffset.y = 0;
10150 copyRegion.srcOffset.z = 0;
10151 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10152 copyRegion.dstSubresource.mipLevel = 0;
10153 copyRegion.dstSubresource.baseArrayLayer = 0;
10154 copyRegion.dstSubresource.layerCount = 1;
10155 copyRegion.dstOffset.x = 0;
10156 copyRegion.dstOffset.y = 0;
10157 copyRegion.dstOffset.z = 0;
10158 copyRegion.extent.width = 1;
10159 copyRegion.extent.height = 1;
10160 copyRegion.extent.depth = 1;
10161 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10162 m_errorMonitor->VerifyFound();
10163 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10165 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10166 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010167 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10168 m_errorMonitor->VerifyFound();
10169 // Final src error is due to bad layout type
10170 m_errorMonitor->SetDesiredFailureMsg(
10171 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10172 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10173 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10174 m_errorMonitor->VerifyFound();
10175 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10177 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010178 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10179 m_errorMonitor->VerifyFound();
10180 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10182 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10183 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010184 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10185 m_errorMonitor->VerifyFound();
10186 m_errorMonitor->SetDesiredFailureMsg(
10187 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10188 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10189 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10190 m_errorMonitor->VerifyFound();
10191 // Now cause error due to bad image layout transition in PipelineBarrier
10192 VkImageMemoryBarrier image_barrier[1] = {};
10193 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10194 image_barrier[0].image = src_image;
10195 image_barrier[0].subresourceRange.layerCount = 2;
10196 image_barrier[0].subresourceRange.levelCount = 2;
10197 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10199 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10200 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10201 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10202 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010203 m_errorMonitor->VerifyFound();
10204
10205 // Finally some layout errors at RenderPass create time
10206 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10207 VkAttachmentReference attach = {};
10208 // perf warning for GENERAL layout w/ non-DS input attachment
10209 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10210 VkSubpassDescription subpass = {};
10211 subpass.inputAttachmentCount = 1;
10212 subpass.pInputAttachments = &attach;
10213 VkRenderPassCreateInfo rpci = {};
10214 rpci.subpassCount = 1;
10215 rpci.pSubpasses = &subpass;
10216 rpci.attachmentCount = 1;
10217 VkAttachmentDescription attach_desc = {};
10218 attach_desc.format = VK_FORMAT_UNDEFINED;
10219 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010220 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010221 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10223 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010224 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10225 m_errorMonitor->VerifyFound();
10226 // error w/ non-general layout
10227 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10228
10229 m_errorMonitor->SetDesiredFailureMsg(
10230 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10231 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10232 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10233 m_errorMonitor->VerifyFound();
10234 subpass.inputAttachmentCount = 0;
10235 subpass.colorAttachmentCount = 1;
10236 subpass.pColorAttachments = &attach;
10237 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10238 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10240 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010241 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10242 m_errorMonitor->VerifyFound();
10243 // error w/ non-color opt or GENERAL layout for color attachment
10244 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10245 m_errorMonitor->SetDesiredFailureMsg(
10246 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10247 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10248 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10249 m_errorMonitor->VerifyFound();
10250 subpass.colorAttachmentCount = 0;
10251 subpass.pDepthStencilAttachment = &attach;
10252 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10253 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10255 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010256 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10257 m_errorMonitor->VerifyFound();
10258 // error w/ non-ds opt or GENERAL layout for color attachment
10259 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10261 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10262 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010263 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10264 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010265 // For this error we need a valid renderpass so create default one
10266 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10267 attach.attachment = 0;
10268 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10269 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10270 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10271 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10272 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10273 // Can't do a CLEAR load on READ_ONLY initialLayout
10274 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10275 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10276 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10278 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10279 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010280 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10281 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010282
10283 vkDestroyImage(m_device->device(), src_image, NULL);
10284 vkDestroyImage(m_device->device(), dst_image, NULL);
10285}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010286
Tobin Ehlise0936662016-10-11 08:10:51 -060010287TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10288 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10289 VkResult err;
10290
10291 ASSERT_NO_FATAL_FAILURE(InitState());
10292
10293 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10294 VkImageTiling tiling;
10295 VkFormatProperties format_properties;
10296 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10297 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10298 tiling = VK_IMAGE_TILING_LINEAR;
10299 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10300 tiling = VK_IMAGE_TILING_OPTIMAL;
10301 } else {
10302 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10303 "skipped.\n");
10304 return;
10305 }
10306
10307 VkDescriptorPoolSize ds_type = {};
10308 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10309 ds_type.descriptorCount = 1;
10310
10311 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10312 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10313 ds_pool_ci.maxSets = 1;
10314 ds_pool_ci.poolSizeCount = 1;
10315 ds_pool_ci.pPoolSizes = &ds_type;
10316 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10317
10318 VkDescriptorPool ds_pool;
10319 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10320 ASSERT_VK_SUCCESS(err);
10321
10322 VkDescriptorSetLayoutBinding dsl_binding = {};
10323 dsl_binding.binding = 0;
10324 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10325 dsl_binding.descriptorCount = 1;
10326 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10327 dsl_binding.pImmutableSamplers = NULL;
10328
10329 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10330 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10331 ds_layout_ci.pNext = NULL;
10332 ds_layout_ci.bindingCount = 1;
10333 ds_layout_ci.pBindings = &dsl_binding;
10334
10335 VkDescriptorSetLayout ds_layout;
10336 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10337 ASSERT_VK_SUCCESS(err);
10338
10339 VkDescriptorSetAllocateInfo alloc_info = {};
10340 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10341 alloc_info.descriptorSetCount = 1;
10342 alloc_info.descriptorPool = ds_pool;
10343 alloc_info.pSetLayouts = &ds_layout;
10344 VkDescriptorSet descriptor_set;
10345 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10346 ASSERT_VK_SUCCESS(err);
10347
10348 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10349 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10350 pipeline_layout_ci.pNext = NULL;
10351 pipeline_layout_ci.setLayoutCount = 1;
10352 pipeline_layout_ci.pSetLayouts = &ds_layout;
10353 VkPipelineLayout pipeline_layout;
10354 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10355 ASSERT_VK_SUCCESS(err);
10356
10357 VkImageObj image(m_device);
10358 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10359 ASSERT_TRUE(image.initialized());
10360 VkImageView view = image.targetView(tex_format);
10361
10362 VkDescriptorImageInfo image_info = {};
10363 image_info.imageView = view;
10364 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10365
10366 VkWriteDescriptorSet descriptor_write = {};
10367 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10368 descriptor_write.dstSet = descriptor_set;
10369 descriptor_write.dstBinding = 0;
10370 descriptor_write.descriptorCount = 1;
10371 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10372 descriptor_write.pImageInfo = &image_info;
10373
10374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10375 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10376 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10377 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10378 m_errorMonitor->VerifyFound();
10379
10380 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10381 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10382 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10383 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10384}
10385
Mark Mueller93b938f2016-08-18 10:27:40 -060010386TEST_F(VkLayerTest, SimultaneousUse) {
10387 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10388 "in primary and secondary command buffers.");
10389
10390 ASSERT_NO_FATAL_FAILURE(InitState());
10391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10392
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010393 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010394 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10395 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010396
10397 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010398 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010399 command_buffer_allocate_info.commandPool = m_commandPool;
10400 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10401 command_buffer_allocate_info.commandBufferCount = 1;
10402
10403 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010404 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010405 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10406 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010407 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010408 command_buffer_inheritance_info.renderPass = m_renderPass;
10409 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10410 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010411 command_buffer_begin_info.flags =
10412 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010413 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10414
10415 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010416 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10417 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010418 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010419 vkEndCommandBuffer(secondary_command_buffer);
10420
Mark Mueller93b938f2016-08-18 10:27:40 -060010421 VkSubmitInfo submit_info = {};
10422 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10423 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010424 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010425 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010426
Mark Mueller4042b652016-09-05 22:52:21 -060010427 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010428 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10430 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010431 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010432 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10433 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010434
10435 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010436 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10437
Mark Mueller4042b652016-09-05 22:52:21 -060010438 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010439 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010440 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010441
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10443 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010444 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010445 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10446 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010447}
10448
Mark Mueller917f6bc2016-08-30 10:57:19 -060010449TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10450 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10451 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010452 "Delete objects that are inuse. Call VkQueueSubmit "
10453 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010454
10455 ASSERT_NO_FATAL_FAILURE(InitState());
10456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10457
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010458 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10459 const char *cannot_delete_event_message = "Cannot delete event 0x";
10460 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10461 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010462
10463 BeginCommandBuffer();
10464
10465 VkEvent event;
10466 VkEventCreateInfo event_create_info = {};
10467 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10468 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010469 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010470
Mark Muellerc8d441e2016-08-23 17:36:00 -060010471 EndCommandBuffer();
10472 vkDestroyEvent(m_device->device(), event, nullptr);
10473
10474 VkSubmitInfo submit_info = {};
10475 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10476 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010477 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010479 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10480 m_errorMonitor->VerifyFound();
10481
10482 m_errorMonitor->SetDesiredFailureMsg(0, "");
10483 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10484
10485 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10486
Mark Mueller917f6bc2016-08-30 10:57:19 -060010487 VkSemaphoreCreateInfo semaphore_create_info = {};
10488 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10489 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010490 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010491 VkFenceCreateInfo fence_create_info = {};
10492 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10493 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010494 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010495
10496 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010497 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010498 descriptor_pool_type_count.descriptorCount = 1;
10499
10500 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10501 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10502 descriptor_pool_create_info.maxSets = 1;
10503 descriptor_pool_create_info.poolSizeCount = 1;
10504 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010505 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010506
10507 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010508 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010509
10510 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010511 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010512 descriptorset_layout_binding.descriptorCount = 1;
10513 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10514
10515 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010516 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010517 descriptorset_layout_create_info.bindingCount = 1;
10518 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10519
10520 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010521 ASSERT_VK_SUCCESS(
10522 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010523
10524 VkDescriptorSet descriptorset;
10525 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010526 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010527 descriptorset_allocate_info.descriptorSetCount = 1;
10528 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10529 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010530 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010531
Mark Mueller4042b652016-09-05 22:52:21 -060010532 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10533
10534 VkDescriptorBufferInfo buffer_info = {};
10535 buffer_info.buffer = buffer_test.GetBuffer();
10536 buffer_info.offset = 0;
10537 buffer_info.range = 1024;
10538
10539 VkWriteDescriptorSet write_descriptor_set = {};
10540 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10541 write_descriptor_set.dstSet = descriptorset;
10542 write_descriptor_set.descriptorCount = 1;
10543 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10544 write_descriptor_set.pBufferInfo = &buffer_info;
10545
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010546 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010548 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10549 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010550
10551 VkPipelineObj pipe(m_device);
10552 pipe.AddColorAttachment();
10553 pipe.AddShader(&vs);
10554 pipe.AddShader(&fs);
10555
10556 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010557 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010558 pipeline_layout_create_info.setLayoutCount = 1;
10559 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10560
10561 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010562 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010563
10564 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10565
Mark Muellerc8d441e2016-08-23 17:36:00 -060010566 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010567 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010568
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010569 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10570 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10571 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010572
Mark Muellerc8d441e2016-08-23 17:36:00 -060010573 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010574
Mark Mueller917f6bc2016-08-30 10:57:19 -060010575 submit_info.signalSemaphoreCount = 1;
10576 submit_info.pSignalSemaphores = &semaphore;
10577 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010580 vkDestroyEvent(m_device->device(), event, nullptr);
10581 m_errorMonitor->VerifyFound();
10582
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010584 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10585 m_errorMonitor->VerifyFound();
10586
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010588 vkDestroyFence(m_device->device(), fence, nullptr);
10589 m_errorMonitor->VerifyFound();
10590
Tobin Ehlis122207b2016-09-01 08:50:06 -070010591 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010592 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10593 vkDestroyFence(m_device->device(), fence, nullptr);
10594 vkDestroyEvent(m_device->device(), event, nullptr);
10595 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010596 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010597 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10598}
10599
Tobin Ehlis2adda372016-09-01 08:51:06 -070010600TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10601 TEST_DESCRIPTION("Delete in-use query pool.");
10602
10603 ASSERT_NO_FATAL_FAILURE(InitState());
10604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10605
10606 VkQueryPool query_pool;
10607 VkQueryPoolCreateInfo query_pool_ci{};
10608 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10609 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10610 query_pool_ci.queryCount = 1;
10611 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10612 BeginCommandBuffer();
10613 // Reset query pool to create binding with cmd buffer
10614 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10615
10616 EndCommandBuffer();
10617
10618 VkSubmitInfo submit_info = {};
10619 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10620 submit_info.commandBufferCount = 1;
10621 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10622 // Submit cmd buffer and then destroy query pool while in-flight
10623 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010626 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10627 m_errorMonitor->VerifyFound();
10628
10629 vkQueueWaitIdle(m_device->m_queue);
10630 // Now that cmd buffer done we can safely destroy query_pool
10631 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10632}
10633
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010634TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10635 TEST_DESCRIPTION("Delete in-use pipeline.");
10636
10637 ASSERT_NO_FATAL_FAILURE(InitState());
10638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10639
10640 // Empty pipeline layout used for binding PSO
10641 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10642 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10643 pipeline_layout_ci.setLayoutCount = 0;
10644 pipeline_layout_ci.pSetLayouts = NULL;
10645
10646 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010647 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010648 ASSERT_VK_SUCCESS(err);
10649
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010651 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010652 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10653 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010654 // Store pipeline handle so we can actually delete it before test finishes
10655 VkPipeline delete_this_pipeline;
10656 { // Scope pipeline so it will be auto-deleted
10657 VkPipelineObj pipe(m_device);
10658 pipe.AddShader(&vs);
10659 pipe.AddShader(&fs);
10660 pipe.AddColorAttachment();
10661 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10662 delete_this_pipeline = pipe.handle();
10663
10664 BeginCommandBuffer();
10665 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010666 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010667
10668 EndCommandBuffer();
10669
10670 VkSubmitInfo submit_info = {};
10671 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10672 submit_info.commandBufferCount = 1;
10673 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10674 // Submit cmd buffer and then pipeline destroyed while in-flight
10675 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10676 } // Pipeline deletion triggered here
10677 m_errorMonitor->VerifyFound();
10678 // Make sure queue finished and then actually delete pipeline
10679 vkQueueWaitIdle(m_device->m_queue);
10680 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10681 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10682}
10683
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010684TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10685 TEST_DESCRIPTION("Delete in-use imageView.");
10686
10687 ASSERT_NO_FATAL_FAILURE(InitState());
10688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10689
10690 VkDescriptorPoolSize ds_type_count;
10691 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10692 ds_type_count.descriptorCount = 1;
10693
10694 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10695 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10696 ds_pool_ci.maxSets = 1;
10697 ds_pool_ci.poolSizeCount = 1;
10698 ds_pool_ci.pPoolSizes = &ds_type_count;
10699
10700 VkDescriptorPool ds_pool;
10701 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10702 ASSERT_VK_SUCCESS(err);
10703
10704 VkSamplerCreateInfo sampler_ci = {};
10705 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10706 sampler_ci.pNext = NULL;
10707 sampler_ci.magFilter = VK_FILTER_NEAREST;
10708 sampler_ci.minFilter = VK_FILTER_NEAREST;
10709 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10710 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10711 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10712 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10713 sampler_ci.mipLodBias = 1.0;
10714 sampler_ci.anisotropyEnable = VK_FALSE;
10715 sampler_ci.maxAnisotropy = 1;
10716 sampler_ci.compareEnable = VK_FALSE;
10717 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10718 sampler_ci.minLod = 1.0;
10719 sampler_ci.maxLod = 1.0;
10720 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10721 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10722 VkSampler sampler;
10723
10724 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10725 ASSERT_VK_SUCCESS(err);
10726
10727 VkDescriptorSetLayoutBinding layout_binding;
10728 layout_binding.binding = 0;
10729 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10730 layout_binding.descriptorCount = 1;
10731 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10732 layout_binding.pImmutableSamplers = NULL;
10733
10734 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10735 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10736 ds_layout_ci.bindingCount = 1;
10737 ds_layout_ci.pBindings = &layout_binding;
10738 VkDescriptorSetLayout ds_layout;
10739 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10740 ASSERT_VK_SUCCESS(err);
10741
10742 VkDescriptorSetAllocateInfo alloc_info = {};
10743 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10744 alloc_info.descriptorSetCount = 1;
10745 alloc_info.descriptorPool = ds_pool;
10746 alloc_info.pSetLayouts = &ds_layout;
10747 VkDescriptorSet descriptor_set;
10748 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10749 ASSERT_VK_SUCCESS(err);
10750
10751 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10752 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10753 pipeline_layout_ci.pNext = NULL;
10754 pipeline_layout_ci.setLayoutCount = 1;
10755 pipeline_layout_ci.pSetLayouts = &ds_layout;
10756
10757 VkPipelineLayout pipeline_layout;
10758 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10759 ASSERT_VK_SUCCESS(err);
10760
10761 VkImageObj image(m_device);
10762 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10763 ASSERT_TRUE(image.initialized());
10764
10765 VkImageView view;
10766 VkImageViewCreateInfo ivci = {};
10767 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10768 ivci.image = image.handle();
10769 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10770 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10771 ivci.subresourceRange.layerCount = 1;
10772 ivci.subresourceRange.baseMipLevel = 0;
10773 ivci.subresourceRange.levelCount = 1;
10774 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10775
10776 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10777 ASSERT_VK_SUCCESS(err);
10778
10779 VkDescriptorImageInfo image_info{};
10780 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10781 image_info.imageView = view;
10782 image_info.sampler = sampler;
10783
10784 VkWriteDescriptorSet descriptor_write = {};
10785 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10786 descriptor_write.dstSet = descriptor_set;
10787 descriptor_write.dstBinding = 0;
10788 descriptor_write.descriptorCount = 1;
10789 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10790 descriptor_write.pImageInfo = &image_info;
10791
10792 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10793
10794 // Create PSO to use the sampler
10795 char const *vsSource = "#version 450\n"
10796 "\n"
10797 "out gl_PerVertex { \n"
10798 " vec4 gl_Position;\n"
10799 "};\n"
10800 "void main(){\n"
10801 " gl_Position = vec4(1);\n"
10802 "}\n";
10803 char const *fsSource = "#version 450\n"
10804 "\n"
10805 "layout(set=0, binding=0) uniform sampler2D s;\n"
10806 "layout(location=0) out vec4 x;\n"
10807 "void main(){\n"
10808 " x = texture(s, vec2(1));\n"
10809 "}\n";
10810 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10811 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10812 VkPipelineObj pipe(m_device);
10813 pipe.AddShader(&vs);
10814 pipe.AddShader(&fs);
10815 pipe.AddColorAttachment();
10816 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10817
10818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10819
10820 BeginCommandBuffer();
10821 // Bind pipeline to cmd buffer
10822 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10823 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10824 &descriptor_set, 0, nullptr);
10825 Draw(1, 0, 0, 0);
10826 EndCommandBuffer();
10827 // Submit cmd buffer then destroy sampler
10828 VkSubmitInfo submit_info = {};
10829 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10830 submit_info.commandBufferCount = 1;
10831 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10832 // Submit cmd buffer and then destroy imageView while in-flight
10833 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10834
10835 vkDestroyImageView(m_device->device(), view, nullptr);
10836 m_errorMonitor->VerifyFound();
10837 vkQueueWaitIdle(m_device->m_queue);
10838 // Now we can actually destroy imageView
10839 vkDestroyImageView(m_device->device(), view, NULL);
10840 vkDestroySampler(m_device->device(), sampler, nullptr);
10841 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10842 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10843 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10844}
10845
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010846TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10847 TEST_DESCRIPTION("Delete in-use bufferView.");
10848
10849 ASSERT_NO_FATAL_FAILURE(InitState());
10850 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10851
10852 VkDescriptorPoolSize ds_type_count;
10853 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10854 ds_type_count.descriptorCount = 1;
10855
10856 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10857 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10858 ds_pool_ci.maxSets = 1;
10859 ds_pool_ci.poolSizeCount = 1;
10860 ds_pool_ci.pPoolSizes = &ds_type_count;
10861
10862 VkDescriptorPool ds_pool;
10863 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10864 ASSERT_VK_SUCCESS(err);
10865
10866 VkDescriptorSetLayoutBinding layout_binding;
10867 layout_binding.binding = 0;
10868 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10869 layout_binding.descriptorCount = 1;
10870 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10871 layout_binding.pImmutableSamplers = NULL;
10872
10873 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10874 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10875 ds_layout_ci.bindingCount = 1;
10876 ds_layout_ci.pBindings = &layout_binding;
10877 VkDescriptorSetLayout ds_layout;
10878 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10879 ASSERT_VK_SUCCESS(err);
10880
10881 VkDescriptorSetAllocateInfo alloc_info = {};
10882 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10883 alloc_info.descriptorSetCount = 1;
10884 alloc_info.descriptorPool = ds_pool;
10885 alloc_info.pSetLayouts = &ds_layout;
10886 VkDescriptorSet descriptor_set;
10887 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10888 ASSERT_VK_SUCCESS(err);
10889
10890 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10891 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10892 pipeline_layout_ci.pNext = NULL;
10893 pipeline_layout_ci.setLayoutCount = 1;
10894 pipeline_layout_ci.pSetLayouts = &ds_layout;
10895
10896 VkPipelineLayout pipeline_layout;
10897 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10898 ASSERT_VK_SUCCESS(err);
10899
10900 VkBuffer buffer;
10901 uint32_t queue_family_index = 0;
10902 VkBufferCreateInfo buffer_create_info = {};
10903 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10904 buffer_create_info.size = 1024;
10905 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10906 buffer_create_info.queueFamilyIndexCount = 1;
10907 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
10908
10909 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
10910 ASSERT_VK_SUCCESS(err);
10911
10912 VkMemoryRequirements memory_reqs;
10913 VkDeviceMemory buffer_memory;
10914
10915 VkMemoryAllocateInfo memory_info = {};
10916 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10917 memory_info.allocationSize = 0;
10918 memory_info.memoryTypeIndex = 0;
10919
10920 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
10921 memory_info.allocationSize = memory_reqs.size;
10922 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
10923 ASSERT_TRUE(pass);
10924
10925 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
10926 ASSERT_VK_SUCCESS(err);
10927 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
10928 ASSERT_VK_SUCCESS(err);
10929
10930 VkBufferView view;
10931 VkBufferViewCreateInfo bvci = {};
10932 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10933 bvci.buffer = buffer;
10934 bvci.format = VK_FORMAT_R8_UNORM;
10935 bvci.range = VK_WHOLE_SIZE;
10936
10937 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
10938 ASSERT_VK_SUCCESS(err);
10939
10940 VkWriteDescriptorSet descriptor_write = {};
10941 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10942 descriptor_write.dstSet = descriptor_set;
10943 descriptor_write.dstBinding = 0;
10944 descriptor_write.descriptorCount = 1;
10945 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10946 descriptor_write.pTexelBufferView = &view;
10947
10948 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10949
10950 char const *vsSource = "#version 450\n"
10951 "\n"
10952 "out gl_PerVertex { \n"
10953 " vec4 gl_Position;\n"
10954 "};\n"
10955 "void main(){\n"
10956 " gl_Position = vec4(1);\n"
10957 "}\n";
10958 char const *fsSource = "#version 450\n"
10959 "\n"
10960 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
10961 "layout(location=0) out vec4 x;\n"
10962 "void main(){\n"
10963 " x = imageLoad(s, 0);\n"
10964 "}\n";
10965 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10966 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10967 VkPipelineObj pipe(m_device);
10968 pipe.AddShader(&vs);
10969 pipe.AddShader(&fs);
10970 pipe.AddColorAttachment();
10971 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10972
10973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
10974
10975 BeginCommandBuffer();
10976 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10977 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10978 VkRect2D scissor = {{0, 0}, {16, 16}};
10979 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10980 // Bind pipeline to cmd buffer
10981 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10982 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10983 &descriptor_set, 0, nullptr);
10984 Draw(1, 0, 0, 0);
10985 EndCommandBuffer();
10986
10987 VkSubmitInfo submit_info = {};
10988 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10989 submit_info.commandBufferCount = 1;
10990 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10991 // Submit cmd buffer and then destroy bufferView while in-flight
10992 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10993
10994 vkDestroyBufferView(m_device->device(), view, nullptr);
10995 m_errorMonitor->VerifyFound();
10996 vkQueueWaitIdle(m_device->m_queue);
10997 // Now we can actually destroy bufferView
10998 vkDestroyBufferView(m_device->device(), view, NULL);
10999 vkDestroyBuffer(m_device->device(), buffer, NULL);
11000 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11001 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11002 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11003 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11004}
11005
Tobin Ehlis209532e2016-09-07 13:52:18 -060011006TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11007 TEST_DESCRIPTION("Delete in-use sampler.");
11008
11009 ASSERT_NO_FATAL_FAILURE(InitState());
11010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11011
11012 VkDescriptorPoolSize ds_type_count;
11013 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11014 ds_type_count.descriptorCount = 1;
11015
11016 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11017 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11018 ds_pool_ci.maxSets = 1;
11019 ds_pool_ci.poolSizeCount = 1;
11020 ds_pool_ci.pPoolSizes = &ds_type_count;
11021
11022 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011023 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011024 ASSERT_VK_SUCCESS(err);
11025
11026 VkSamplerCreateInfo sampler_ci = {};
11027 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11028 sampler_ci.pNext = NULL;
11029 sampler_ci.magFilter = VK_FILTER_NEAREST;
11030 sampler_ci.minFilter = VK_FILTER_NEAREST;
11031 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11032 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11033 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11034 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11035 sampler_ci.mipLodBias = 1.0;
11036 sampler_ci.anisotropyEnable = VK_FALSE;
11037 sampler_ci.maxAnisotropy = 1;
11038 sampler_ci.compareEnable = VK_FALSE;
11039 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11040 sampler_ci.minLod = 1.0;
11041 sampler_ci.maxLod = 1.0;
11042 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11043 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11044 VkSampler sampler;
11045
11046 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11047 ASSERT_VK_SUCCESS(err);
11048
11049 VkDescriptorSetLayoutBinding layout_binding;
11050 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011051 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011052 layout_binding.descriptorCount = 1;
11053 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11054 layout_binding.pImmutableSamplers = NULL;
11055
11056 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11057 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11058 ds_layout_ci.bindingCount = 1;
11059 ds_layout_ci.pBindings = &layout_binding;
11060 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011061 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011062 ASSERT_VK_SUCCESS(err);
11063
11064 VkDescriptorSetAllocateInfo alloc_info = {};
11065 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11066 alloc_info.descriptorSetCount = 1;
11067 alloc_info.descriptorPool = ds_pool;
11068 alloc_info.pSetLayouts = &ds_layout;
11069 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011070 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011071 ASSERT_VK_SUCCESS(err);
11072
11073 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11074 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11075 pipeline_layout_ci.pNext = NULL;
11076 pipeline_layout_ci.setLayoutCount = 1;
11077 pipeline_layout_ci.pSetLayouts = &ds_layout;
11078
11079 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011080 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011081 ASSERT_VK_SUCCESS(err);
11082
11083 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011084 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 -060011085 ASSERT_TRUE(image.initialized());
11086
11087 VkImageView view;
11088 VkImageViewCreateInfo ivci = {};
11089 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11090 ivci.image = image.handle();
11091 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11092 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11093 ivci.subresourceRange.layerCount = 1;
11094 ivci.subresourceRange.baseMipLevel = 0;
11095 ivci.subresourceRange.levelCount = 1;
11096 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11097
11098 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11099 ASSERT_VK_SUCCESS(err);
11100
11101 VkDescriptorImageInfo image_info{};
11102 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11103 image_info.imageView = view;
11104 image_info.sampler = sampler;
11105
11106 VkWriteDescriptorSet descriptor_write = {};
11107 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11108 descriptor_write.dstSet = descriptor_set;
11109 descriptor_write.dstBinding = 0;
11110 descriptor_write.descriptorCount = 1;
11111 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11112 descriptor_write.pImageInfo = &image_info;
11113
11114 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11115
11116 // Create PSO to use the sampler
11117 char const *vsSource = "#version 450\n"
11118 "\n"
11119 "out gl_PerVertex { \n"
11120 " vec4 gl_Position;\n"
11121 "};\n"
11122 "void main(){\n"
11123 " gl_Position = vec4(1);\n"
11124 "}\n";
11125 char const *fsSource = "#version 450\n"
11126 "\n"
11127 "layout(set=0, binding=0) uniform sampler2D s;\n"
11128 "layout(location=0) out vec4 x;\n"
11129 "void main(){\n"
11130 " x = texture(s, vec2(1));\n"
11131 "}\n";
11132 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11133 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11134 VkPipelineObj pipe(m_device);
11135 pipe.AddShader(&vs);
11136 pipe.AddShader(&fs);
11137 pipe.AddColorAttachment();
11138 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011141
11142 BeginCommandBuffer();
11143 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011144 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11145 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11146 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011147 Draw(1, 0, 0, 0);
11148 EndCommandBuffer();
11149 // Submit cmd buffer then destroy sampler
11150 VkSubmitInfo submit_info = {};
11151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11152 submit_info.commandBufferCount = 1;
11153 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11154 // Submit cmd buffer and then destroy sampler while in-flight
11155 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11156
11157 vkDestroySampler(m_device->device(), sampler, nullptr);
11158 m_errorMonitor->VerifyFound();
11159 vkQueueWaitIdle(m_device->m_queue);
11160 // Now we can actually destroy sampler
11161 vkDestroySampler(m_device->device(), sampler, nullptr);
11162 vkDestroyImageView(m_device->device(), view, NULL);
11163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11164 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11165 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11166}
11167
Mark Mueller1cd9f412016-08-25 13:23:52 -060011168TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011169 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011170 "signaled but not waited on by the queue. Wait on a "
11171 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011172
11173 ASSERT_NO_FATAL_FAILURE(InitState());
11174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011176 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11177 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11178 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011179
11180 BeginCommandBuffer();
11181 EndCommandBuffer();
11182
11183 VkSemaphoreCreateInfo semaphore_create_info = {};
11184 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11185 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011186 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011187 VkSubmitInfo submit_info = {};
11188 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11189 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011190 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011191 submit_info.signalSemaphoreCount = 1;
11192 submit_info.pSignalSemaphores = &semaphore;
11193 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11194 m_errorMonitor->SetDesiredFailureMsg(0, "");
11195 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11196 BeginCommandBuffer();
11197 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011199 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11200 m_errorMonitor->VerifyFound();
11201
Mark Mueller1cd9f412016-08-25 13:23:52 -060011202 VkFenceCreateInfo fence_create_info = {};
11203 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11204 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011205 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011208 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11209 m_errorMonitor->VerifyFound();
11210
Mark Mueller4042b652016-09-05 22:52:21 -060011211 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011212 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011213 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11214}
11215
Tobin Ehlis4af23302016-07-19 10:50:30 -060011216TEST_F(VkLayerTest, FramebufferIncompatible) {
11217 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11218 "that does not match the framebuffer for the active "
11219 "renderpass.");
11220 ASSERT_NO_FATAL_FAILURE(InitState());
11221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11222
11223 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011224 VkAttachmentDescription attachment = {0,
11225 VK_FORMAT_B8G8R8A8_UNORM,
11226 VK_SAMPLE_COUNT_1_BIT,
11227 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11228 VK_ATTACHMENT_STORE_OP_STORE,
11229 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11230 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11231 VK_IMAGE_LAYOUT_UNDEFINED,
11232 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011234 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011236 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011238 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011239
11240 VkRenderPass rp;
11241 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11242 ASSERT_VK_SUCCESS(err);
11243
11244 // A compatible framebuffer.
11245 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011246 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 -060011247 ASSERT_TRUE(image.initialized());
11248
11249 VkImageViewCreateInfo ivci = {
11250 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11251 nullptr,
11252 0,
11253 image.handle(),
11254 VK_IMAGE_VIEW_TYPE_2D,
11255 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011256 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11257 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011258 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11259 };
11260 VkImageView view;
11261 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11262 ASSERT_VK_SUCCESS(err);
11263
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011264 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011265 VkFramebuffer fb;
11266 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11267 ASSERT_VK_SUCCESS(err);
11268
11269 VkCommandBufferAllocateInfo cbai = {};
11270 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11271 cbai.commandPool = m_commandPool;
11272 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11273 cbai.commandBufferCount = 1;
11274
11275 VkCommandBuffer sec_cb;
11276 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11277 ASSERT_VK_SUCCESS(err);
11278 VkCommandBufferBeginInfo cbbi = {};
11279 VkCommandBufferInheritanceInfo cbii = {};
11280 cbii.renderPass = renderPass();
11281 cbii.framebuffer = fb;
11282 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11283 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011284 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 -060011285 cbbi.pInheritanceInfo = &cbii;
11286 vkBeginCommandBuffer(sec_cb, &cbbi);
11287 vkEndCommandBuffer(sec_cb);
11288
Chris Forbes3400bc52016-09-13 18:10:34 +120011289 VkCommandBufferBeginInfo cbbi2 = {
11290 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11291 0, nullptr
11292 };
11293 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11294 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011297 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011298 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11299 m_errorMonitor->VerifyFound();
11300 // Cleanup
11301 vkDestroyImageView(m_device->device(), view, NULL);
11302 vkDestroyRenderPass(m_device->device(), rp, NULL);
11303 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11304}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011305
11306TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11307 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11308 "invalid value. If logicOp is not available, attempt to "
11309 "use it and verify that we see the correct error.");
11310 ASSERT_NO_FATAL_FAILURE(InitState());
11311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11312
11313 auto features = m_device->phy().features();
11314 // Set the expected error depending on whether or not logicOp available
11315 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11317 "enabled, logicOpEnable must be "
11318 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011319 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011321 }
11322 // Create a pipeline using logicOp
11323 VkResult err;
11324
11325 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11326 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11327
11328 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011329 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011330 ASSERT_VK_SUCCESS(err);
11331
11332 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11333 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11334 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011335 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011336 vp_state_ci.pViewports = &vp;
11337 vp_state_ci.scissorCount = 1;
11338 VkRect2D scissors = {}; // Dummy scissors to point to
11339 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011340
11341 VkPipelineShaderStageCreateInfo shaderStages[2];
11342 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011344 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11345 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011346 shaderStages[0] = vs.GetStageCreateInfo();
11347 shaderStages[1] = fs.GetStageCreateInfo();
11348
11349 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11350 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11351
11352 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11353 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11354 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11355
11356 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11357 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011358 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011359
11360 VkPipelineColorBlendAttachmentState att = {};
11361 att.blendEnable = VK_FALSE;
11362 att.colorWriteMask = 0xf;
11363
11364 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11365 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11366 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11367 cb_ci.logicOpEnable = VK_TRUE;
11368 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11369 cb_ci.attachmentCount = 1;
11370 cb_ci.pAttachments = &att;
11371
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011372 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11373 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11374 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11375
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011376 VkGraphicsPipelineCreateInfo gp_ci = {};
11377 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11378 gp_ci.stageCount = 2;
11379 gp_ci.pStages = shaderStages;
11380 gp_ci.pVertexInputState = &vi_ci;
11381 gp_ci.pInputAssemblyState = &ia_ci;
11382 gp_ci.pViewportState = &vp_state_ci;
11383 gp_ci.pRasterizationState = &rs_ci;
11384 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011385 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011386 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11387 gp_ci.layout = pipeline_layout;
11388 gp_ci.renderPass = renderPass();
11389
11390 VkPipelineCacheCreateInfo pc_ci = {};
11391 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11392
11393 VkPipeline pipeline;
11394 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011395 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011396 ASSERT_VK_SUCCESS(err);
11397
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011398 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011399 m_errorMonitor->VerifyFound();
11400 if (VK_SUCCESS == err) {
11401 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11402 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011403 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11404 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11405}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011406#endif // DRAW_STATE_TESTS
11407
Tobin Ehlis0788f522015-05-26 16:11:58 -060011408#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011409#if GTEST_IS_THREADSAFE
11410struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011411 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011412 VkEvent event;
11413 bool bailout;
11414};
11415
Karl Schultz6addd812016-02-02 17:17:23 -070011416extern "C" void *AddToCommandBuffer(void *arg) {
11417 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011418
Mike Stroyana6d14942016-07-13 15:10:05 -060011419 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011420 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011421 if (data->bailout) {
11422 break;
11423 }
11424 }
11425 return NULL;
11426}
11427
Karl Schultz6addd812016-02-02 17:17:23 -070011428TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011429 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011432
Mike Stroyanaccf7692015-05-12 16:00:45 -060011433 ASSERT_NO_FATAL_FAILURE(InitState());
11434 ASSERT_NO_FATAL_FAILURE(InitViewport());
11435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11436
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011437 // Calls AllocateCommandBuffers
11438 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011439
11440 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011441 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011442
11443 VkEventCreateInfo event_info;
11444 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011445 VkResult err;
11446
11447 memset(&event_info, 0, sizeof(event_info));
11448 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11449
Chia-I Wuf7458c52015-10-26 21:10:41 +080011450 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011451 ASSERT_VK_SUCCESS(err);
11452
Mike Stroyanaccf7692015-05-12 16:00:45 -060011453 err = vkResetEvent(device(), event);
11454 ASSERT_VK_SUCCESS(err);
11455
11456 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011457 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011458 data.event = event;
11459 data.bailout = false;
11460 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011461
11462 // First do some correct operations using multiple threads.
11463 // Add many entries to command buffer from another thread.
11464 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11465 // Make non-conflicting calls from this thread at the same time.
11466 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011467 uint32_t count;
11468 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011469 }
11470 test_platform_thread_join(thread, NULL);
11471
11472 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011473 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011474 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011475 // Add many entries to command buffer from this thread at the same time.
11476 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011477
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011478 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011479 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011480
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011481 m_errorMonitor->SetBailout(NULL);
11482
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011483 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011484
Chia-I Wuf7458c52015-10-26 21:10:41 +080011485 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011486}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011487#endif // GTEST_IS_THREADSAFE
11488#endif // THREADING_TESTS
11489
Chris Forbes9f7ff632015-05-25 11:13:08 +120011490#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011491TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011492 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11493 "with an impossible code size");
11494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011496
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011497 ASSERT_NO_FATAL_FAILURE(InitState());
11498 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11499
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011500 VkShaderModule module;
11501 VkShaderModuleCreateInfo moduleCreateInfo;
11502 struct icd_spv_header spv;
11503
11504 spv.magic = ICD_SPV_MAGIC;
11505 spv.version = ICD_SPV_VERSION;
11506 spv.gen_magic = 0;
11507
11508 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11509 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011510 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011511 moduleCreateInfo.codeSize = 4;
11512 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011513 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011514
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011515 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011516}
11517
Karl Schultz6addd812016-02-02 17:17:23 -070011518TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011519 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11520 "with a bad magic number");
11521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011523
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011524 ASSERT_NO_FATAL_FAILURE(InitState());
11525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11526
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011527 VkShaderModule module;
11528 VkShaderModuleCreateInfo moduleCreateInfo;
11529 struct icd_spv_header spv;
11530
11531 spv.magic = ~ICD_SPV_MAGIC;
11532 spv.version = ICD_SPV_VERSION;
11533 spv.gen_magic = 0;
11534
11535 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11536 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011537 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011538 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11539 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011540 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011541
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011542 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011543}
11544
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011545#if 0
11546// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011547TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011549 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011550
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011551 ASSERT_NO_FATAL_FAILURE(InitState());
11552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11553
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011554 VkShaderModule module;
11555 VkShaderModuleCreateInfo moduleCreateInfo;
11556 struct icd_spv_header spv;
11557
11558 spv.magic = ICD_SPV_MAGIC;
11559 spv.version = ~ICD_SPV_VERSION;
11560 spv.gen_magic = 0;
11561
11562 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11563 moduleCreateInfo.pNext = NULL;
11564
Karl Schultz6addd812016-02-02 17:17:23 -070011565 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011566 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11567 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011568 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011569
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011570 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011571}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011572#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011573
Karl Schultz6addd812016-02-02 17:17:23 -070011574TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011575 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11576 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011578
Chris Forbes9f7ff632015-05-25 11:13:08 +120011579 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011581
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011582 char const *vsSource = "#version 450\n"
11583 "\n"
11584 "layout(location=0) out float x;\n"
11585 "out gl_PerVertex {\n"
11586 " vec4 gl_Position;\n"
11587 "};\n"
11588 "void main(){\n"
11589 " gl_Position = vec4(1);\n"
11590 " x = 0;\n"
11591 "}\n";
11592 char const *fsSource = "#version 450\n"
11593 "\n"
11594 "layout(location=0) out vec4 color;\n"
11595 "void main(){\n"
11596 " color = vec4(1);\n"
11597 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011598
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011599 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11600 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011601
11602 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011603 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011604 pipe.AddShader(&vs);
11605 pipe.AddShader(&fs);
11606
Chris Forbes9f7ff632015-05-25 11:13:08 +120011607 VkDescriptorSetObj descriptorSet(m_device);
11608 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011609 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011610
Tony Barbour5781e8f2015-08-04 16:23:11 -060011611 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011612
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011613 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011614}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011615
Mark Mueller098c9cb2016-09-08 09:01:57 -060011616TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11617 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11618
11619 ASSERT_NO_FATAL_FAILURE(InitState());
11620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11621
11622 const char *bad_specialization_message =
11623 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11624
11625 char const *vsSource =
11626 "#version 450\n"
11627 "\n"
11628 "out gl_PerVertex {\n"
11629 " vec4 gl_Position;\n"
11630 "};\n"
11631 "void main(){\n"
11632 " gl_Position = vec4(1);\n"
11633 "}\n";
11634
11635 char const *fsSource =
11636 "#version 450\n"
11637 "\n"
11638 "layout (constant_id = 0) const float r = 0.0f;\n"
11639 "layout(location = 0) out vec4 uFragColor;\n"
11640 "void main(){\n"
11641 " uFragColor = vec4(r,1,0,1);\n"
11642 "}\n";
11643
11644 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11645 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11646
11647 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11648 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11649
11650 VkPipelineLayout pipeline_layout;
11651 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11652
11653 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11654 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11655 vp_state_create_info.viewportCount = 1;
11656 VkViewport viewport = {};
11657 vp_state_create_info.pViewports = &viewport;
11658 vp_state_create_info.scissorCount = 1;
11659 VkRect2D scissors = {};
11660 vp_state_create_info.pScissors = &scissors;
11661
11662 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11663
11664 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11665 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11666 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11667 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11668
11669 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11670 vs.GetStageCreateInfo(),
11671 fs.GetStageCreateInfo()
11672 };
11673
11674 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11675 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11676
11677 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11678 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11679 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11680
11681 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11682 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11683 rasterization_state_create_info.pNext = nullptr;
11684 rasterization_state_create_info.lineWidth = 1.0f;
11685 rasterization_state_create_info.rasterizerDiscardEnable = true;
11686
11687 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11688 color_blend_attachment_state.blendEnable = VK_FALSE;
11689 color_blend_attachment_state.colorWriteMask = 0xf;
11690
11691 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11692 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11693 color_blend_state_create_info.attachmentCount = 1;
11694 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11695
11696 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11697 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11698 graphicspipe_create_info.stageCount = 2;
11699 graphicspipe_create_info.pStages = shader_stage_create_info;
11700 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11701 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11702 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11703 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11704 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11705 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11706 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11707 graphicspipe_create_info.layout = pipeline_layout;
11708 graphicspipe_create_info.renderPass = renderPass();
11709
11710 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11711 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11712
11713 VkPipelineCache pipelineCache;
11714 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11715
11716 // This structure maps constant ids to data locations.
11717 const VkSpecializationMapEntry entry =
11718 // id, offset, size
11719 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11720
11721 uint32_t data = 1;
11722
11723 // Set up the info describing spec map and data
11724 const VkSpecializationInfo specialization_info = {
11725 1,
11726 &entry,
11727 1 * sizeof(float),
11728 &data,
11729 };
11730 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11731
11732 VkPipeline pipeline;
11733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11734 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11735 m_errorMonitor->VerifyFound();
11736
11737 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11738 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11739}
11740
11741TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11742 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11743
11744 ASSERT_NO_FATAL_FAILURE(InitState());
11745 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11746
11747 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11748
11749 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11750 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11751 descriptor_pool_type_count[0].descriptorCount = 1;
11752 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11753 descriptor_pool_type_count[1].descriptorCount = 1;
11754
11755 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11756 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11757 descriptor_pool_create_info.maxSets = 1;
11758 descriptor_pool_create_info.poolSizeCount = 2;
11759 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11760 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11761
11762 VkDescriptorPool descriptorset_pool;
11763 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11764
11765 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11766 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11767 descriptorset_layout_binding.descriptorCount = 1;
11768 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11769
11770 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11771 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11772 descriptorset_layout_create_info.bindingCount = 1;
11773 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11774
11775 VkDescriptorSetLayout descriptorset_layout;
11776 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11777
11778 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11779 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11780 descriptorset_allocate_info.descriptorSetCount = 1;
11781 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11782 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11783 VkDescriptorSet descriptorset;
11784 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11785
11786 // Challenge core_validation with a non uniform buffer type.
11787 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11788
Mark Mueller098c9cb2016-09-08 09:01:57 -060011789 char const *vsSource =
11790 "#version 450\n"
11791 "\n"
11792 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11793 " mat4 mvp;\n"
11794 "} ubuf;\n"
11795 "out gl_PerVertex {\n"
11796 " vec4 gl_Position;\n"
11797 "};\n"
11798 "void main(){\n"
11799 " gl_Position = ubuf.mvp * vec4(1);\n"
11800 "}\n";
11801
11802 char const *fsSource =
11803 "#version 450\n"
11804 "\n"
11805 "layout(location = 0) out vec4 uFragColor;\n"
11806 "void main(){\n"
11807 " uFragColor = vec4(0,1,0,1);\n"
11808 "}\n";
11809
11810 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11811 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11812
11813 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11814 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11815 pipeline_layout_create_info.setLayoutCount = 1;
11816 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11817
11818 VkPipelineLayout pipeline_layout;
11819 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11820
11821 VkPipelineObj pipe(m_device);
11822 pipe.AddColorAttachment();
11823 pipe.AddShader(&vs);
11824 pipe.AddShader(&fs);
11825
11826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11827 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11828 m_errorMonitor->VerifyFound();
11829
11830 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11831 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11832 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11833}
11834
11835TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11836 TEST_DESCRIPTION(
11837 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11838
11839 ASSERT_NO_FATAL_FAILURE(InitState());
11840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11841
11842 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11843
11844 VkDescriptorPoolSize descriptor_pool_type_count = {};
11845 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11846 descriptor_pool_type_count.descriptorCount = 1;
11847
11848 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11849 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11850 descriptor_pool_create_info.maxSets = 1;
11851 descriptor_pool_create_info.poolSizeCount = 1;
11852 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11853 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11854
11855 VkDescriptorPool descriptorset_pool;
11856 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11857
11858 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11859 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11860 descriptorset_layout_binding.descriptorCount = 1;
11861 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11862 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11863
11864 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11865 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11866 descriptorset_layout_create_info.bindingCount = 1;
11867 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11868
11869 VkDescriptorSetLayout descriptorset_layout;
11870 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11871 nullptr, &descriptorset_layout));
11872
11873 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11874 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11875 descriptorset_allocate_info.descriptorSetCount = 1;
11876 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11877 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11878 VkDescriptorSet descriptorset;
11879 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11880
11881 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11882
Mark Mueller098c9cb2016-09-08 09:01:57 -060011883 char const *vsSource =
11884 "#version 450\n"
11885 "\n"
11886 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11887 " mat4 mvp;\n"
11888 "} ubuf;\n"
11889 "out gl_PerVertex {\n"
11890 " vec4 gl_Position;\n"
11891 "};\n"
11892 "void main(){\n"
11893 " gl_Position = ubuf.mvp * vec4(1);\n"
11894 "}\n";
11895
11896 char const *fsSource =
11897 "#version 450\n"
11898 "\n"
11899 "layout(location = 0) out vec4 uFragColor;\n"
11900 "void main(){\n"
11901 " uFragColor = vec4(0,1,0,1);\n"
11902 "}\n";
11903
11904 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11905 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11906
11907 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11908 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11909 pipeline_layout_create_info.setLayoutCount = 1;
11910 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11911
11912 VkPipelineLayout pipeline_layout;
11913 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11914
11915 VkPipelineObj pipe(m_device);
11916 pipe.AddColorAttachment();
11917 pipe.AddShader(&vs);
11918 pipe.AddShader(&fs);
11919
11920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
11921 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11922 m_errorMonitor->VerifyFound();
11923
11924 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11925 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11926 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11927}
11928
11929TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
11930 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
11931 "accessible from the current shader stage.");
11932
11933 ASSERT_NO_FATAL_FAILURE(InitState());
11934 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11935
11936 const char *push_constant_not_accessible_message =
11937 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
11938
11939 char const *vsSource =
11940 "#version 450\n"
11941 "\n"
11942 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
11943 "out gl_PerVertex {\n"
11944 " vec4 gl_Position;\n"
11945 "};\n"
11946 "void main(){\n"
11947 " gl_Position = vec4(consts.x);\n"
11948 "}\n";
11949
11950 char const *fsSource =
11951 "#version 450\n"
11952 "\n"
11953 "layout(location = 0) out vec4 uFragColor;\n"
11954 "void main(){\n"
11955 " uFragColor = vec4(0,1,0,1);\n"
11956 "}\n";
11957
11958 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11959 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11960
11961 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11962 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11963
11964 // Set up a push constant range
11965 VkPushConstantRange push_constant_ranges = {};
11966 // Set to the wrong stage to challenge core_validation
11967 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11968 push_constant_ranges.size = 4;
11969
11970 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
11971 pipeline_layout_create_info.pushConstantRangeCount = 1;
11972
11973 VkPipelineLayout pipeline_layout;
11974 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11975
11976 VkPipelineObj pipe(m_device);
11977 pipe.AddColorAttachment();
11978 pipe.AddShader(&vs);
11979 pipe.AddShader(&fs);
11980
11981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
11982 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11983 m_errorMonitor->VerifyFound();
11984
11985 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11986}
11987
11988TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
11989 TEST_DESCRIPTION(
11990 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
11991
11992 ASSERT_NO_FATAL_FAILURE(InitState());
11993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11994
11995 const char *feature_not_enabled_message =
11996 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
11997
11998 // Some awkward steps are required to test with custom device features.
11999 std::vector<const char *> device_extension_names;
12000 auto features = m_device->phy().features();
12001 // Disable support for 64 bit floats
12002 features.shaderFloat64 = false;
12003 // The sacrificial device object
12004 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12005
12006 char const *vsSource = "#version 450\n"
12007 "\n"
12008 "out gl_PerVertex {\n"
12009 " vec4 gl_Position;\n"
12010 "};\n"
12011 "void main(){\n"
12012 " gl_Position = vec4(1);\n"
12013 "}\n";
12014 char const *fsSource = "#version 450\n"
12015 "\n"
12016 "layout(location=0) out vec4 color;\n"
12017 "void main(){\n"
12018 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12019 " color = vec4(green);\n"
12020 "}\n";
12021
12022 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12023 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12024
12025 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012026
12027 VkPipelineObj pipe(&test_device);
12028 pipe.AddColorAttachment();
12029 pipe.AddShader(&vs);
12030 pipe.AddShader(&fs);
12031
12032 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12033 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12034 VkPipelineLayout pipeline_layout;
12035 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12036
12037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12038 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12039 m_errorMonitor->VerifyFound();
12040
12041 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12042}
12043
12044TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12045 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12046
12047 ASSERT_NO_FATAL_FAILURE(InitState());
12048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12049
12050 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12051
12052 char const *vsSource = "#version 450\n"
12053 "\n"
12054 "out gl_PerVertex {\n"
12055 " vec4 gl_Position;\n"
12056 "};\n"
12057 "layout(xfb_buffer = 1) out;"
12058 "void main(){\n"
12059 " gl_Position = vec4(1);\n"
12060 "}\n";
12061 char const *fsSource = "#version 450\n"
12062 "\n"
12063 "layout(location=0) out vec4 color;\n"
12064 "void main(){\n"
12065 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12066 " color = vec4(green);\n"
12067 "}\n";
12068
12069 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12070 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12071
12072 VkPipelineObj pipe(m_device);
12073 pipe.AddColorAttachment();
12074 pipe.AddShader(&vs);
12075 pipe.AddShader(&fs);
12076
12077 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12078 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12079 VkPipelineLayout pipeline_layout;
12080 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12081
12082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12083 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12084 m_errorMonitor->VerifyFound();
12085
12086 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12087}
12088
Karl Schultz6addd812016-02-02 17:17:23 -070012089TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012090 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12091 "which is not present in the outputs of the previous stage");
12092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012094
Chris Forbes59cb88d2015-05-25 11:13:13 +120012095 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012096 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012098 char const *vsSource = "#version 450\n"
12099 "\n"
12100 "out gl_PerVertex {\n"
12101 " vec4 gl_Position;\n"
12102 "};\n"
12103 "void main(){\n"
12104 " gl_Position = vec4(1);\n"
12105 "}\n";
12106 char const *fsSource = "#version 450\n"
12107 "\n"
12108 "layout(location=0) in float x;\n"
12109 "layout(location=0) out vec4 color;\n"
12110 "void main(){\n"
12111 " color = vec4(x);\n"
12112 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012113
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012114 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12115 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012116
12117 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012118 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012119 pipe.AddShader(&vs);
12120 pipe.AddShader(&fs);
12121
Chris Forbes59cb88d2015-05-25 11:13:13 +120012122 VkDescriptorSetObj descriptorSet(m_device);
12123 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012124 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012125
Tony Barbour5781e8f2015-08-04 16:23:11 -060012126 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012127
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012128 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012129}
12130
Karl Schultz6addd812016-02-02 17:17:23 -070012131TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012132 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12133 "within an interace block, which is not present in the outputs "
12134 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012136
12137 ASSERT_NO_FATAL_FAILURE(InitState());
12138 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012140 char const *vsSource = "#version 450\n"
12141 "\n"
12142 "out gl_PerVertex {\n"
12143 " vec4 gl_Position;\n"
12144 "};\n"
12145 "void main(){\n"
12146 " gl_Position = vec4(1);\n"
12147 "}\n";
12148 char const *fsSource = "#version 450\n"
12149 "\n"
12150 "in block { layout(location=0) float x; } ins;\n"
12151 "layout(location=0) out vec4 color;\n"
12152 "void main(){\n"
12153 " color = vec4(ins.x);\n"
12154 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012155
12156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12158
12159 VkPipelineObj pipe(m_device);
12160 pipe.AddColorAttachment();
12161 pipe.AddShader(&vs);
12162 pipe.AddShader(&fs);
12163
12164 VkDescriptorSetObj descriptorSet(m_device);
12165 descriptorSet.AppendDummy();
12166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12167
12168 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12169
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012170 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012171}
12172
Karl Schultz6addd812016-02-02 17:17:23 -070012173TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012174 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012175 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12177 "output arr[2] of float32' vs 'ptr to "
12178 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012179
12180 ASSERT_NO_FATAL_FAILURE(InitState());
12181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012183 char const *vsSource = "#version 450\n"
12184 "\n"
12185 "layout(location=0) out float x[2];\n"
12186 "out gl_PerVertex {\n"
12187 " vec4 gl_Position;\n"
12188 "};\n"
12189 "void main(){\n"
12190 " x[0] = 0; x[1] = 0;\n"
12191 " gl_Position = vec4(1);\n"
12192 "}\n";
12193 char const *fsSource = "#version 450\n"
12194 "\n"
12195 "layout(location=0) in float x[3];\n"
12196 "layout(location=0) out vec4 color;\n"
12197 "void main(){\n"
12198 " color = vec4(x[0] + x[1] + x[2]);\n"
12199 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012200
12201 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12202 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12203
12204 VkPipelineObj pipe(m_device);
12205 pipe.AddColorAttachment();
12206 pipe.AddShader(&vs);
12207 pipe.AddShader(&fs);
12208
12209 VkDescriptorSetObj descriptorSet(m_device);
12210 descriptorSet.AppendDummy();
12211 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12212
12213 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12214
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012215 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012216}
12217
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012218
Karl Schultz6addd812016-02-02 17:17:23 -070012219TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012220 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012221 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012223
Chris Forbesb56af562015-05-25 11:13:17 +120012224 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012226
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012227 char const *vsSource = "#version 450\n"
12228 "\n"
12229 "layout(location=0) out int x;\n"
12230 "out gl_PerVertex {\n"
12231 " vec4 gl_Position;\n"
12232 "};\n"
12233 "void main(){\n"
12234 " x = 0;\n"
12235 " gl_Position = vec4(1);\n"
12236 "}\n";
12237 char const *fsSource = "#version 450\n"
12238 "\n"
12239 "layout(location=0) in float x;\n" /* VS writes int */
12240 "layout(location=0) out vec4 color;\n"
12241 "void main(){\n"
12242 " color = vec4(x);\n"
12243 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012244
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012245 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12246 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012247
12248 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012249 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012250 pipe.AddShader(&vs);
12251 pipe.AddShader(&fs);
12252
Chris Forbesb56af562015-05-25 11:13:17 +120012253 VkDescriptorSetObj descriptorSet(m_device);
12254 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012255 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012256
Tony Barbour5781e8f2015-08-04 16:23:11 -060012257 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012258
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012259 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012260}
12261
Karl Schultz6addd812016-02-02 17:17:23 -070012262TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012263 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012264 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012265 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012267
12268 ASSERT_NO_FATAL_FAILURE(InitState());
12269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012271 char const *vsSource = "#version 450\n"
12272 "\n"
12273 "out block { layout(location=0) int x; } outs;\n"
12274 "out gl_PerVertex {\n"
12275 " vec4 gl_Position;\n"
12276 "};\n"
12277 "void main(){\n"
12278 " outs.x = 0;\n"
12279 " gl_Position = vec4(1);\n"
12280 "}\n";
12281 char const *fsSource = "#version 450\n"
12282 "\n"
12283 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12284 "layout(location=0) out vec4 color;\n"
12285 "void main(){\n"
12286 " color = vec4(ins.x);\n"
12287 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012288
12289 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12290 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12291
12292 VkPipelineObj pipe(m_device);
12293 pipe.AddColorAttachment();
12294 pipe.AddShader(&vs);
12295 pipe.AddShader(&fs);
12296
12297 VkDescriptorSetObj descriptorSet(m_device);
12298 descriptorSet.AppendDummy();
12299 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12300
12301 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12302
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012303 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012304}
12305
12306TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012307 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012308 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012309 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012310 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 +130012311
12312 ASSERT_NO_FATAL_FAILURE(InitState());
12313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12314
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012315 char const *vsSource = "#version 450\n"
12316 "\n"
12317 "out block { layout(location=1) float x; } outs;\n"
12318 "out gl_PerVertex {\n"
12319 " vec4 gl_Position;\n"
12320 "};\n"
12321 "void main(){\n"
12322 " outs.x = 0;\n"
12323 " gl_Position = vec4(1);\n"
12324 "}\n";
12325 char const *fsSource = "#version 450\n"
12326 "\n"
12327 "in block { layout(location=0) float x; } ins;\n"
12328 "layout(location=0) out vec4 color;\n"
12329 "void main(){\n"
12330 " color = vec4(ins.x);\n"
12331 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012332
12333 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12334 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12335
12336 VkPipelineObj pipe(m_device);
12337 pipe.AddColorAttachment();
12338 pipe.AddShader(&vs);
12339 pipe.AddShader(&fs);
12340
12341 VkDescriptorSetObj descriptorSet(m_device);
12342 descriptorSet.AppendDummy();
12343 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12344
12345 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12346
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012347 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012348}
12349
12350TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012351 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012352 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012353 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012354 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 +130012355
12356 ASSERT_NO_FATAL_FAILURE(InitState());
12357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12358
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012359 char const *vsSource = "#version 450\n"
12360 "\n"
12361 "out block { layout(location=0, component=0) float x; } outs;\n"
12362 "out gl_PerVertex {\n"
12363 " vec4 gl_Position;\n"
12364 "};\n"
12365 "void main(){\n"
12366 " outs.x = 0;\n"
12367 " gl_Position = vec4(1);\n"
12368 "}\n";
12369 char const *fsSource = "#version 450\n"
12370 "\n"
12371 "in block { layout(location=0, component=1) float x; } ins;\n"
12372 "layout(location=0) out vec4 color;\n"
12373 "void main(){\n"
12374 " color = vec4(ins.x);\n"
12375 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012376
12377 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12378 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12379
12380 VkPipelineObj pipe(m_device);
12381 pipe.AddColorAttachment();
12382 pipe.AddShader(&vs);
12383 pipe.AddShader(&fs);
12384
12385 VkDescriptorSetObj descriptorSet(m_device);
12386 descriptorSet.AppendDummy();
12387 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12388
12389 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12390
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012391 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012392}
12393
Karl Schultz6addd812016-02-02 17:17:23 -070012394TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012395 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12396 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012398
Chris Forbesde136e02015-05-25 11:13:28 +120012399 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012401
12402 VkVertexInputBindingDescription input_binding;
12403 memset(&input_binding, 0, sizeof(input_binding));
12404
12405 VkVertexInputAttributeDescription input_attrib;
12406 memset(&input_attrib, 0, sizeof(input_attrib));
12407 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012409 char const *vsSource = "#version 450\n"
12410 "\n"
12411 "out gl_PerVertex {\n"
12412 " vec4 gl_Position;\n"
12413 "};\n"
12414 "void main(){\n"
12415 " gl_Position = vec4(1);\n"
12416 "}\n";
12417 char const *fsSource = "#version 450\n"
12418 "\n"
12419 "layout(location=0) out vec4 color;\n"
12420 "void main(){\n"
12421 " color = vec4(1);\n"
12422 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012423
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012424 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12425 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012426
12427 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012428 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012429 pipe.AddShader(&vs);
12430 pipe.AddShader(&fs);
12431
12432 pipe.AddVertexInputBindings(&input_binding, 1);
12433 pipe.AddVertexInputAttribs(&input_attrib, 1);
12434
Chris Forbesde136e02015-05-25 11:13:28 +120012435 VkDescriptorSetObj descriptorSet(m_device);
12436 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012437 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012438
Tony Barbour5781e8f2015-08-04 16:23:11 -060012439 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012440
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012441 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012442}
12443
Karl Schultz6addd812016-02-02 17:17:23 -070012444TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012445 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12446 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012448
12449 ASSERT_NO_FATAL_FAILURE(InitState());
12450 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12451
12452 VkVertexInputBindingDescription input_binding;
12453 memset(&input_binding, 0, sizeof(input_binding));
12454
12455 VkVertexInputAttributeDescription input_attrib;
12456 memset(&input_attrib, 0, sizeof(input_attrib));
12457 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012459 char const *vsSource = "#version 450\n"
12460 "\n"
12461 "layout(location=1) in float x;\n"
12462 "out gl_PerVertex {\n"
12463 " vec4 gl_Position;\n"
12464 "};\n"
12465 "void main(){\n"
12466 " gl_Position = vec4(x);\n"
12467 "}\n";
12468 char const *fsSource = "#version 450\n"
12469 "\n"
12470 "layout(location=0) out vec4 color;\n"
12471 "void main(){\n"
12472 " color = vec4(1);\n"
12473 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012474
12475 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12476 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12477
12478 VkPipelineObj pipe(m_device);
12479 pipe.AddColorAttachment();
12480 pipe.AddShader(&vs);
12481 pipe.AddShader(&fs);
12482
12483 pipe.AddVertexInputBindings(&input_binding, 1);
12484 pipe.AddVertexInputAttribs(&input_attrib, 1);
12485
12486 VkDescriptorSetObj descriptorSet(m_device);
12487 descriptorSet.AppendDummy();
12488 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12489
12490 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12491
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012492 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012493}
12494
Karl Schultz6addd812016-02-02 17:17:23 -070012495TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012496 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012497 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012498 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 -060012499
Chris Forbes62e8e502015-05-25 11:13:29 +120012500 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012503 char const *vsSource = "#version 450\n"
12504 "\n"
12505 "layout(location=0) in vec4 x;\n" /* not provided */
12506 "out gl_PerVertex {\n"
12507 " vec4 gl_Position;\n"
12508 "};\n"
12509 "void main(){\n"
12510 " gl_Position = x;\n"
12511 "}\n";
12512 char const *fsSource = "#version 450\n"
12513 "\n"
12514 "layout(location=0) out vec4 color;\n"
12515 "void main(){\n"
12516 " color = vec4(1);\n"
12517 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012518
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012519 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012521
12522 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012523 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012524 pipe.AddShader(&vs);
12525 pipe.AddShader(&fs);
12526
Chris Forbes62e8e502015-05-25 11:13:29 +120012527 VkDescriptorSetObj descriptorSet(m_device);
12528 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012529 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012530
Tony Barbour5781e8f2015-08-04 16:23:11 -060012531 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012532
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012533 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012534}
12535
Karl Schultz6addd812016-02-02 17:17:23 -070012536TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012537 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12538 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012539 "vertex shader input that consumes it");
12540 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 -060012541
Chris Forbesc97d98e2015-05-25 11:13:31 +120012542 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012544
12545 VkVertexInputBindingDescription input_binding;
12546 memset(&input_binding, 0, sizeof(input_binding));
12547
12548 VkVertexInputAttributeDescription input_attrib;
12549 memset(&input_attrib, 0, sizeof(input_attrib));
12550 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12551
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012552 char const *vsSource = "#version 450\n"
12553 "\n"
12554 "layout(location=0) in int x;\n" /* attrib provided float */
12555 "out gl_PerVertex {\n"
12556 " vec4 gl_Position;\n"
12557 "};\n"
12558 "void main(){\n"
12559 " gl_Position = vec4(x);\n"
12560 "}\n";
12561 char const *fsSource = "#version 450\n"
12562 "\n"
12563 "layout(location=0) out vec4 color;\n"
12564 "void main(){\n"
12565 " color = vec4(1);\n"
12566 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012567
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012568 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12569 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012570
12571 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012572 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012573 pipe.AddShader(&vs);
12574 pipe.AddShader(&fs);
12575
12576 pipe.AddVertexInputBindings(&input_binding, 1);
12577 pipe.AddVertexInputAttribs(&input_attrib, 1);
12578
Chris Forbesc97d98e2015-05-25 11:13:31 +120012579 VkDescriptorSetObj descriptorSet(m_device);
12580 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012581 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012582
Tony Barbour5781e8f2015-08-04 16:23:11 -060012583 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012584
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012585 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012586}
12587
Chris Forbesc68b43c2016-04-06 11:18:47 +120012588TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012589 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12590 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12592 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012593
12594 ASSERT_NO_FATAL_FAILURE(InitState());
12595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12596
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012597 char const *vsSource = "#version 450\n"
12598 "\n"
12599 "out gl_PerVertex {\n"
12600 " vec4 gl_Position;\n"
12601 "};\n"
12602 "void main(){\n"
12603 " gl_Position = vec4(1);\n"
12604 "}\n";
12605 char const *fsSource = "#version 450\n"
12606 "\n"
12607 "layout(location=0) out vec4 color;\n"
12608 "void main(){\n"
12609 " color = vec4(1);\n"
12610 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012611
12612 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12613 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12614
12615 VkPipelineObj pipe(m_device);
12616 pipe.AddColorAttachment();
12617 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012618 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012619 pipe.AddShader(&fs);
12620
12621 VkDescriptorSetObj descriptorSet(m_device);
12622 descriptorSet.AppendDummy();
12623 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12624
12625 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12626
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012627 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012628}
12629
Chris Forbes82ff92a2016-09-09 10:50:24 +120012630TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12632 "No entrypoint found named `foo`");
12633
12634 ASSERT_NO_FATAL_FAILURE(InitState());
12635 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12636
12637 char const *vsSource = "#version 450\n"
12638 "out gl_PerVertex {\n"
12639 " vec4 gl_Position;\n"
12640 "};\n"
12641 "void main(){\n"
12642 " gl_Position = vec4(0);\n"
12643 "}\n";
12644 char const *fsSource = "#version 450\n"
12645 "\n"
12646 "layout(location=0) out vec4 color;\n"
12647 "void main(){\n"
12648 " color = vec4(1);\n"
12649 "}\n";
12650
12651 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12653
12654 VkPipelineObj pipe(m_device);
12655 pipe.AddColorAttachment();
12656 pipe.AddShader(&vs);
12657 pipe.AddShader(&fs);
12658
12659 VkDescriptorSetObj descriptorSet(m_device);
12660 descriptorSet.AppendDummy();
12661 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12662
12663 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12664
12665 m_errorMonitor->VerifyFound();
12666}
12667
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012668TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12669 m_errorMonitor->SetDesiredFailureMsg(
12670 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12671 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12672 "uses a depth/stencil attachment");
12673
12674 ASSERT_NO_FATAL_FAILURE(InitState());
12675 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12676
12677 char const *vsSource = "#version 450\n"
12678 "void main(){ gl_Position = vec4(0); }\n";
12679 char const *fsSource = "#version 450\n"
12680 "\n"
12681 "layout(location=0) out vec4 color;\n"
12682 "void main(){\n"
12683 " color = vec4(1);\n"
12684 "}\n";
12685
12686 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12687 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12688
12689 VkPipelineObj pipe(m_device);
12690 pipe.AddColorAttachment();
12691 pipe.AddShader(&vs);
12692 pipe.AddShader(&fs);
12693
12694 VkDescriptorSetObj descriptorSet(m_device);
12695 descriptorSet.AppendDummy();
12696 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12697
12698 VkAttachmentDescription attachments[] = {
12699 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12700 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12701 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12702 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12703 },
12704 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12705 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12706 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12707 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12708 },
12709 };
12710 VkAttachmentReference refs[] = {
12711 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12712 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12713 };
12714 VkSubpassDescription subpass = {
12715 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12716 1, &refs[0], nullptr, &refs[1],
12717 0, nullptr
12718 };
12719 VkRenderPassCreateInfo rpci = {
12720 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12721 0, 2, attachments, 1, &subpass, 0, nullptr
12722 };
12723 VkRenderPass rp;
12724 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12725 ASSERT_VK_SUCCESS(err);
12726
12727 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12728
12729 m_errorMonitor->VerifyFound();
12730
12731 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12732}
12733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012734TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012735 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12736 "the TCS without the patch decoration, but consumed in the TES "
12737 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12739 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012740
12741 ASSERT_NO_FATAL_FAILURE(InitState());
12742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12743
Chris Forbesc1e852d2016-04-04 19:26:42 +120012744 if (!m_device->phy().features().tessellationShader) {
12745 printf("Device does not support tessellation shaders; skipped.\n");
12746 return;
12747 }
12748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012749 char const *vsSource = "#version 450\n"
12750 "void main(){}\n";
12751 char const *tcsSource = "#version 450\n"
12752 "layout(location=0) out int x[];\n"
12753 "layout(vertices=3) out;\n"
12754 "void main(){\n"
12755 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12756 " gl_TessLevelInner[0] = 1;\n"
12757 " x[gl_InvocationID] = gl_InvocationID;\n"
12758 "}\n";
12759 char const *tesSource = "#version 450\n"
12760 "layout(triangles, equal_spacing, cw) in;\n"
12761 "layout(location=0) patch in int x;\n"
12762 "out gl_PerVertex { vec4 gl_Position; };\n"
12763 "void main(){\n"
12764 " gl_Position.xyz = gl_TessCoord;\n"
12765 " gl_Position.w = x;\n"
12766 "}\n";
12767 char const *fsSource = "#version 450\n"
12768 "layout(location=0) out vec4 color;\n"
12769 "void main(){\n"
12770 " color = vec4(1);\n"
12771 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012772
12773 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12774 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12775 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12776 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012778 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12779 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012781 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012782
12783 VkPipelineObj pipe(m_device);
12784 pipe.SetInputAssembly(&iasci);
12785 pipe.SetTessellation(&tsci);
12786 pipe.AddColorAttachment();
12787 pipe.AddShader(&vs);
12788 pipe.AddShader(&tcs);
12789 pipe.AddShader(&tes);
12790 pipe.AddShader(&fs);
12791
12792 VkDescriptorSetObj descriptorSet(m_device);
12793 descriptorSet.AppendDummy();
12794 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12795
12796 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12797
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012798 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012799}
12800
Karl Schultz6addd812016-02-02 17:17:23 -070012801TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012802 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12803 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12805 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012806
Chris Forbes280ba2c2015-06-12 11:16:41 +120012807 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012808 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012809
12810 /* Two binding descriptions for binding 0 */
12811 VkVertexInputBindingDescription input_bindings[2];
12812 memset(input_bindings, 0, sizeof(input_bindings));
12813
12814 VkVertexInputAttributeDescription input_attrib;
12815 memset(&input_attrib, 0, sizeof(input_attrib));
12816 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012818 char const *vsSource = "#version 450\n"
12819 "\n"
12820 "layout(location=0) in float x;\n" /* attrib provided float */
12821 "out gl_PerVertex {\n"
12822 " vec4 gl_Position;\n"
12823 "};\n"
12824 "void main(){\n"
12825 " gl_Position = vec4(x);\n"
12826 "}\n";
12827 char const *fsSource = "#version 450\n"
12828 "\n"
12829 "layout(location=0) out vec4 color;\n"
12830 "void main(){\n"
12831 " color = vec4(1);\n"
12832 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012833
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012834 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12835 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012836
12837 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012838 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012839 pipe.AddShader(&vs);
12840 pipe.AddShader(&fs);
12841
12842 pipe.AddVertexInputBindings(input_bindings, 2);
12843 pipe.AddVertexInputAttribs(&input_attrib, 1);
12844
Chris Forbes280ba2c2015-06-12 11:16:41 +120012845 VkDescriptorSetObj descriptorSet(m_device);
12846 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012847 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012848
Tony Barbour5781e8f2015-08-04 16:23:11 -060012849 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012850
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012851 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012852}
Chris Forbes8f68b562015-05-25 11:13:32 +120012853
Karl Schultz6addd812016-02-02 17:17:23 -070012854TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012855 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012856 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012858
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012859 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012860
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012861 char const *vsSource = "#version 450\n"
12862 "\n"
12863 "out gl_PerVertex {\n"
12864 " vec4 gl_Position;\n"
12865 "};\n"
12866 "void main(){\n"
12867 " gl_Position = vec4(1);\n"
12868 "}\n";
12869 char const *fsSource = "#version 450\n"
12870 "\n"
12871 "void main(){\n"
12872 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012873
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012874 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12875 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012876
12877 VkPipelineObj pipe(m_device);
12878 pipe.AddShader(&vs);
12879 pipe.AddShader(&fs);
12880
Chia-I Wu08accc62015-07-07 11:50:03 +080012881 /* set up CB 0, not written */
12882 pipe.AddColorAttachment();
12883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012884
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012885 VkDescriptorSetObj descriptorSet(m_device);
12886 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012887 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012888
Tony Barbour5781e8f2015-08-04 16:23:11 -060012889 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012890
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012891 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012892}
12893
Karl Schultz6addd812016-02-02 17:17:23 -070012894TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012895 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120012896 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012898 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012899
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012900 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012901
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012902 char const *vsSource = "#version 450\n"
12903 "\n"
12904 "out gl_PerVertex {\n"
12905 " vec4 gl_Position;\n"
12906 "};\n"
12907 "void main(){\n"
12908 " gl_Position = vec4(1);\n"
12909 "}\n";
12910 char const *fsSource = "#version 450\n"
12911 "\n"
12912 "layout(location=0) out vec4 x;\n"
12913 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
12914 "void main(){\n"
12915 " x = vec4(1);\n"
12916 " y = vec4(1);\n"
12917 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012918
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012919 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12920 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012921
12922 VkPipelineObj pipe(m_device);
12923 pipe.AddShader(&vs);
12924 pipe.AddShader(&fs);
12925
Chia-I Wu08accc62015-07-07 11:50:03 +080012926 /* set up CB 0, not written */
12927 pipe.AddColorAttachment();
12928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012929 /* FS writes CB 1, but we don't configure it */
12930
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012931 VkDescriptorSetObj descriptorSet(m_device);
12932 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012933 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012934
Tony Barbour5781e8f2015-08-04 16:23:11 -060012935 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012936
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012937 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012938}
12939
Karl Schultz6addd812016-02-02 17:17:23 -070012940TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012941 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012942 "type of an fragment shader output variable, and the format of the corresponding attachment");
12943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012944
Chris Forbesa36d69e2015-05-25 11:13:44 +120012945 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012946
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012947 char const *vsSource = "#version 450\n"
12948 "\n"
12949 "out gl_PerVertex {\n"
12950 " vec4 gl_Position;\n"
12951 "};\n"
12952 "void main(){\n"
12953 " gl_Position = vec4(1);\n"
12954 "}\n";
12955 char const *fsSource = "#version 450\n"
12956 "\n"
12957 "layout(location=0) out ivec4 x;\n" /* not UNORM */
12958 "void main(){\n"
12959 " x = ivec4(1);\n"
12960 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120012961
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012962 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12963 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012964
12965 VkPipelineObj pipe(m_device);
12966 pipe.AddShader(&vs);
12967 pipe.AddShader(&fs);
12968
Chia-I Wu08accc62015-07-07 11:50:03 +080012969 /* set up CB 0; type is UNORM by default */
12970 pipe.AddColorAttachment();
12971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012972
Chris Forbesa36d69e2015-05-25 11:13:44 +120012973 VkDescriptorSetObj descriptorSet(m_device);
12974 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012975 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012976
Tony Barbour5781e8f2015-08-04 16:23:11 -060012977 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012978
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012979 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120012980}
Chris Forbes7b1b8932015-06-05 14:43:36 +120012981
Karl Schultz6addd812016-02-02 17:17:23 -070012982TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012983 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
12984 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012986
Chris Forbes556c76c2015-08-14 12:04:59 +120012987 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120012988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012989 char const *vsSource = "#version 450\n"
12990 "\n"
12991 "out gl_PerVertex {\n"
12992 " vec4 gl_Position;\n"
12993 "};\n"
12994 "void main(){\n"
12995 " gl_Position = vec4(1);\n"
12996 "}\n";
12997 char const *fsSource = "#version 450\n"
12998 "\n"
12999 "layout(location=0) out vec4 x;\n"
13000 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13001 "void main(){\n"
13002 " x = vec4(bar.y);\n"
13003 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013004
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013007
Chris Forbes556c76c2015-08-14 12:04:59 +120013008 VkPipelineObj pipe(m_device);
13009 pipe.AddShader(&vs);
13010 pipe.AddShader(&fs);
13011
13012 /* set up CB 0; type is UNORM by default */
13013 pipe.AddColorAttachment();
13014 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13015
13016 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013017 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013018
13019 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13020
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013021 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013022}
13023
Chris Forbes5c59e902016-02-26 16:56:09 +130013024TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013025 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13026 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013028
13029 ASSERT_NO_FATAL_FAILURE(InitState());
13030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013031 char const *vsSource = "#version 450\n"
13032 "\n"
13033 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13034 "out gl_PerVertex {\n"
13035 " vec4 gl_Position;\n"
13036 "};\n"
13037 "void main(){\n"
13038 " gl_Position = vec4(consts.x);\n"
13039 "}\n";
13040 char const *fsSource = "#version 450\n"
13041 "\n"
13042 "layout(location=0) out vec4 x;\n"
13043 "void main(){\n"
13044 " x = vec4(1);\n"
13045 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013046
13047 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13048 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13049
13050 VkPipelineObj pipe(m_device);
13051 pipe.AddShader(&vs);
13052 pipe.AddShader(&fs);
13053
13054 /* set up CB 0; type is UNORM by default */
13055 pipe.AddColorAttachment();
13056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13057
13058 VkDescriptorSetObj descriptorSet(m_device);
13059 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13060
13061 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13062
13063 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013064 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013065}
13066
Chris Forbes3fb17902016-08-22 14:57:55 +120013067TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13068 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13069 "which is not included in the subpass description");
13070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13071 "consumes input attachment index 0 but not provided in subpass");
13072
13073 ASSERT_NO_FATAL_FAILURE(InitState());
13074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013075 char const *vsSource = "#version 450\n"
13076 "\n"
13077 "out gl_PerVertex {\n"
13078 " vec4 gl_Position;\n"
13079 "};\n"
13080 "void main(){\n"
13081 " gl_Position = vec4(1);\n"
13082 "}\n";
13083 char const *fsSource = "#version 450\n"
13084 "\n"
13085 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13086 "layout(location=0) out vec4 color;\n"
13087 "void main() {\n"
13088 " color = subpassLoad(x);\n"
13089 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013090
13091 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13092 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13093
13094 VkPipelineObj pipe(m_device);
13095 pipe.AddShader(&vs);
13096 pipe.AddShader(&fs);
13097 pipe.AddColorAttachment();
13098 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013100 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13101 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013102 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013103 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013104 ASSERT_VK_SUCCESS(err);
13105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013106 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013107 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013108 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013109 ASSERT_VK_SUCCESS(err);
13110
13111 // error here.
13112 pipe.CreateVKPipeline(pl, renderPass());
13113
13114 m_errorMonitor->VerifyFound();
13115
13116 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13117 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13118}
13119
Chris Forbes5a9a0472016-08-22 16:02:09 +120013120TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13121 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13122 "with a format having a different fundamental type");
13123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13124 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13125
13126 ASSERT_NO_FATAL_FAILURE(InitState());
13127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013128 char const *vsSource = "#version 450\n"
13129 "\n"
13130 "out gl_PerVertex {\n"
13131 " vec4 gl_Position;\n"
13132 "};\n"
13133 "void main(){\n"
13134 " gl_Position = vec4(1);\n"
13135 "}\n";
13136 char const *fsSource = "#version 450\n"
13137 "\n"
13138 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13139 "layout(location=0) out vec4 color;\n"
13140 "void main() {\n"
13141 " color = subpassLoad(x);\n"
13142 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013143
13144 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13145 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13146
13147 VkPipelineObj pipe(m_device);
13148 pipe.AddShader(&vs);
13149 pipe.AddShader(&fs);
13150 pipe.AddColorAttachment();
13151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013153 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13154 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013155 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013156 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013157 ASSERT_VK_SUCCESS(err);
13158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013159 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013160 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013161 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013162 ASSERT_VK_SUCCESS(err);
13163
13164 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013165 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13166 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13167 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13168 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13169 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 +120013170 };
13171 VkAttachmentReference color = {
13172 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13173 };
13174 VkAttachmentReference input = {
13175 1, VK_IMAGE_LAYOUT_GENERAL,
13176 };
13177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013178 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013180 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013181 VkRenderPass rp;
13182 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13183 ASSERT_VK_SUCCESS(err);
13184
13185 // error here.
13186 pipe.CreateVKPipeline(pl, rp);
13187
13188 m_errorMonitor->VerifyFound();
13189
13190 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13191 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13192 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13193}
13194
Chris Forbes541f7b02016-08-22 15:30:27 +120013195TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13196 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13197 "which is not included in the subpass description -- array case");
13198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13199 "consumes input attachment index 1 but not provided in subpass");
13200
13201 ASSERT_NO_FATAL_FAILURE(InitState());
13202
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013203 char const *vsSource = "#version 450\n"
13204 "\n"
13205 "out gl_PerVertex {\n"
13206 " vec4 gl_Position;\n"
13207 "};\n"
13208 "void main(){\n"
13209 " gl_Position = vec4(1);\n"
13210 "}\n";
13211 char const *fsSource = "#version 450\n"
13212 "\n"
13213 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13214 "layout(location=0) out vec4 color;\n"
13215 "void main() {\n"
13216 " color = subpassLoad(xs[1]);\n"
13217 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013218
13219 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13220 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13221
13222 VkPipelineObj pipe(m_device);
13223 pipe.AddShader(&vs);
13224 pipe.AddShader(&fs);
13225 pipe.AddColorAttachment();
13226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013228 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13229 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013230 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013231 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013232 ASSERT_VK_SUCCESS(err);
13233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013234 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013235 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013236 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013237 ASSERT_VK_SUCCESS(err);
13238
13239 // error here.
13240 pipe.CreateVKPipeline(pl, renderPass());
13241
13242 m_errorMonitor->VerifyFound();
13243
13244 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13245 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13246}
13247
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013248TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013249 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13250 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013252
13253 ASSERT_NO_FATAL_FAILURE(InitState());
13254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013255 char const *csSource = "#version 450\n"
13256 "\n"
13257 "layout(local_size_x=1) in;\n"
13258 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13259 "void main(){\n"
13260 " x = vec4(1);\n"
13261 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013262
13263 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13264
13265 VkDescriptorSetObj descriptorSet(m_device);
13266 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013268 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13269 nullptr,
13270 0,
13271 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13272 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13273 descriptorSet.GetPipelineLayout(),
13274 VK_NULL_HANDLE,
13275 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013276
13277 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013278 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013279
13280 m_errorMonitor->VerifyFound();
13281
13282 if (err == VK_SUCCESS) {
13283 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13284 }
13285}
13286
Chris Forbes22a9b092016-07-19 14:34:05 +120013287TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013288 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13289 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13291 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013292
13293 ASSERT_NO_FATAL_FAILURE(InitState());
13294
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013295 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13296 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013297 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013298 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013299 ASSERT_VK_SUCCESS(err);
13300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013301 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013302 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013303 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013304 ASSERT_VK_SUCCESS(err);
13305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013306 char const *csSource = "#version 450\n"
13307 "\n"
13308 "layout(local_size_x=1) in;\n"
13309 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13310 "void main() {\n"
13311 " x.x = 1.0f;\n"
13312 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013313 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13314
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013315 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13316 nullptr,
13317 0,
13318 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13319 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13320 pl,
13321 VK_NULL_HANDLE,
13322 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013323
13324 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013325 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013326
13327 m_errorMonitor->VerifyFound();
13328
13329 if (err == VK_SUCCESS) {
13330 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13331 }
13332
13333 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13334 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13335}
13336
Chris Forbes50020592016-07-27 13:52:41 +120013337TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13338 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13339 "does not match the dimensionality declared in the shader");
13340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013341 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 +120013342
13343 ASSERT_NO_FATAL_FAILURE(InitState());
13344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013346 char const *vsSource = "#version 450\n"
13347 "\n"
13348 "out gl_PerVertex { vec4 gl_Position; };\n"
13349 "void main() { gl_Position = vec4(0); }\n";
13350 char const *fsSource = "#version 450\n"
13351 "\n"
13352 "layout(set=0, binding=0) uniform sampler3D s;\n"
13353 "layout(location=0) out vec4 color;\n"
13354 "void main() {\n"
13355 " color = texture(s, vec3(0));\n"
13356 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013357 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13358 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13359
13360 VkPipelineObj pipe(m_device);
13361 pipe.AddShader(&vs);
13362 pipe.AddShader(&fs);
13363 pipe.AddColorAttachment();
13364
13365 VkTextureObj texture(m_device, nullptr);
13366 VkSamplerObj sampler(m_device);
13367
13368 VkDescriptorSetObj descriptorSet(m_device);
13369 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13370 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13371
13372 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13373 ASSERT_VK_SUCCESS(err);
13374
13375 BeginCommandBuffer();
13376
13377 m_commandBuffer->BindPipeline(pipe);
13378 m_commandBuffer->BindDescriptorSet(descriptorSet);
13379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013380 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013381 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013382 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013383 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13384
13385 // error produced here.
13386 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13387
13388 m_errorMonitor->VerifyFound();
13389
13390 EndCommandBuffer();
13391}
13392
Chris Forbes5533bfc2016-07-27 14:12:34 +120013393TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13394 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13395 "are consumed via singlesample images types in the shader, or vice versa.");
13396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013398
13399 ASSERT_NO_FATAL_FAILURE(InitState());
13400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13401
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013402 char const *vsSource = "#version 450\n"
13403 "\n"
13404 "out gl_PerVertex { vec4 gl_Position; };\n"
13405 "void main() { gl_Position = vec4(0); }\n";
13406 char const *fsSource = "#version 450\n"
13407 "\n"
13408 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13409 "layout(location=0) out vec4 color;\n"
13410 "void main() {\n"
13411 " color = texelFetch(s, ivec2(0), 0);\n"
13412 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013413 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13414 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13415
13416 VkPipelineObj pipe(m_device);
13417 pipe.AddShader(&vs);
13418 pipe.AddShader(&fs);
13419 pipe.AddColorAttachment();
13420
13421 VkTextureObj texture(m_device, nullptr);
13422 VkSamplerObj sampler(m_device);
13423
13424 VkDescriptorSetObj descriptorSet(m_device);
13425 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13426 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13427
13428 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13429 ASSERT_VK_SUCCESS(err);
13430
13431 BeginCommandBuffer();
13432
13433 m_commandBuffer->BindPipeline(pipe);
13434 m_commandBuffer->BindDescriptorSet(descriptorSet);
13435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013436 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013437 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013438 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013439 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13440
13441 // error produced here.
13442 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13443
13444 m_errorMonitor->VerifyFound();
13445
13446 EndCommandBuffer();
13447}
13448
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013449#endif // SHADER_CHECKER_TESTS
13450
13451#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013452TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013454
13455 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013456
13457 // Create an image
13458 VkImage image;
13459
Karl Schultz6addd812016-02-02 17:17:23 -070013460 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13461 const int32_t tex_width = 32;
13462 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013463
13464 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013465 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13466 image_create_info.pNext = NULL;
13467 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13468 image_create_info.format = tex_format;
13469 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013470 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013471 image_create_info.extent.depth = 1;
13472 image_create_info.mipLevels = 1;
13473 image_create_info.arrayLayers = 1;
13474 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13475 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13476 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13477 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013478
13479 // Introduce error by sending down a bogus width extent
13480 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013481 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013482
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013483 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013484}
13485
Mark Youngc48c4c12016-04-11 14:26:49 -060013486TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13488 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013489
13490 ASSERT_NO_FATAL_FAILURE(InitState());
13491
13492 // Create an image
13493 VkImage image;
13494
13495 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13496 const int32_t tex_width = 32;
13497 const int32_t tex_height = 32;
13498
13499 VkImageCreateInfo image_create_info = {};
13500 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13501 image_create_info.pNext = NULL;
13502 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13503 image_create_info.format = tex_format;
13504 image_create_info.extent.width = tex_width;
13505 image_create_info.extent.height = tex_height;
13506 image_create_info.extent.depth = 1;
13507 image_create_info.mipLevels = 1;
13508 image_create_info.arrayLayers = 1;
13509 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13510 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13511 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13512 image_create_info.flags = 0;
13513
13514 // Introduce error by sending down a bogus width extent
13515 image_create_info.extent.width = 0;
13516 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13517
13518 m_errorMonitor->VerifyFound();
13519}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013520#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013521
Tobin Ehliscde08892015-09-22 10:11:37 -060013522#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013523TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13524 TEST_DESCRIPTION("Create a render pass with an attachment description "
13525 "format set to VK_FORMAT_UNDEFINED");
13526
13527 ASSERT_NO_FATAL_FAILURE(InitState());
13528 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13529
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013531
13532 VkAttachmentReference color_attach = {};
13533 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13534 color_attach.attachment = 0;
13535 VkSubpassDescription subpass = {};
13536 subpass.colorAttachmentCount = 1;
13537 subpass.pColorAttachments = &color_attach;
13538
13539 VkRenderPassCreateInfo rpci = {};
13540 rpci.subpassCount = 1;
13541 rpci.pSubpasses = &subpass;
13542 rpci.attachmentCount = 1;
13543 VkAttachmentDescription attach_desc = {};
13544 attach_desc.format = VK_FORMAT_UNDEFINED;
13545 rpci.pAttachments = &attach_desc;
13546 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13547 VkRenderPass rp;
13548 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13549
13550 m_errorMonitor->VerifyFound();
13551
13552 if (result == VK_SUCCESS) {
13553 vkDestroyRenderPass(m_device->device(), rp, NULL);
13554 }
13555}
13556
Karl Schultz6addd812016-02-02 17:17:23 -070013557TEST_F(VkLayerTest, InvalidImageView) {
13558 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013561
Tobin Ehliscde08892015-09-22 10:11:37 -060013562 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013563
Mike Stroyana3082432015-09-25 13:39:21 -060013564 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013565 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013566
Karl Schultz6addd812016-02-02 17:17:23 -070013567 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13568 const int32_t tex_width = 32;
13569 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013570
13571 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013572 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13573 image_create_info.pNext = NULL;
13574 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13575 image_create_info.format = tex_format;
13576 image_create_info.extent.width = tex_width;
13577 image_create_info.extent.height = tex_height;
13578 image_create_info.extent.depth = 1;
13579 image_create_info.mipLevels = 1;
13580 image_create_info.arrayLayers = 1;
13581 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13582 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13583 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13584 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013585
Chia-I Wuf7458c52015-10-26 21:10:41 +080013586 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013587 ASSERT_VK_SUCCESS(err);
13588
13589 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013590 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13591 image_view_create_info.image = image;
13592 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13593 image_view_create_info.format = tex_format;
13594 image_view_create_info.subresourceRange.layerCount = 1;
13595 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13596 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013597 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013598
13599 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013600 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013601
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013602 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013603 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013604}
Mike Stroyana3082432015-09-25 13:39:21 -060013605
Mark Youngd339ba32016-05-30 13:28:35 -060013606TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13607 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013609 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013610
13611 ASSERT_NO_FATAL_FAILURE(InitState());
13612
13613 // Create an image and try to create a view with no memory backing the image
13614 VkImage image;
13615
13616 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13617 const int32_t tex_width = 32;
13618 const int32_t tex_height = 32;
13619
13620 VkImageCreateInfo image_create_info = {};
13621 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13622 image_create_info.pNext = NULL;
13623 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13624 image_create_info.format = tex_format;
13625 image_create_info.extent.width = tex_width;
13626 image_create_info.extent.height = tex_height;
13627 image_create_info.extent.depth = 1;
13628 image_create_info.mipLevels = 1;
13629 image_create_info.arrayLayers = 1;
13630 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13631 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13632 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13633 image_create_info.flags = 0;
13634
13635 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13636 ASSERT_VK_SUCCESS(err);
13637
13638 VkImageViewCreateInfo image_view_create_info = {};
13639 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13640 image_view_create_info.image = image;
13641 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13642 image_view_create_info.format = tex_format;
13643 image_view_create_info.subresourceRange.layerCount = 1;
13644 image_view_create_info.subresourceRange.baseMipLevel = 0;
13645 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013646 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013647
13648 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013649 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013650
13651 m_errorMonitor->VerifyFound();
13652 vkDestroyImage(m_device->device(), image, NULL);
13653 // If last error is success, it still created the view, so delete it.
13654 if (err == VK_SUCCESS) {
13655 vkDestroyImageView(m_device->device(), view, NULL);
13656 }
Mark Youngd339ba32016-05-30 13:28:35 -060013657}
13658
Karl Schultz6addd812016-02-02 17:17:23 -070013659TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013660 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013662 "formats must have ONLY the "
13663 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13665 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013666
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013667 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013668
Karl Schultz6addd812016-02-02 17:17:23 -070013669 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013670 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013671 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013672 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013673
13674 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013675 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013676 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013677 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13678 image_view_create_info.format = tex_format;
13679 image_view_create_info.subresourceRange.baseMipLevel = 0;
13680 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013681 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013682 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013683 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013684
13685 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013686 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013687
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013688 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013689}
13690
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013691TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013692 VkResult err;
13693 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013694
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13696 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013697
Mike Stroyana3082432015-09-25 13:39:21 -060013698 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013699
13700 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013701 VkImage srcImage;
13702 VkImage dstImage;
13703 VkDeviceMemory srcMem;
13704 VkDeviceMemory destMem;
13705 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013706
13707 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013708 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13709 image_create_info.pNext = NULL;
13710 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13711 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13712 image_create_info.extent.width = 32;
13713 image_create_info.extent.height = 32;
13714 image_create_info.extent.depth = 1;
13715 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013716 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013717 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13718 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13719 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13720 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013721
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013722 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013723 ASSERT_VK_SUCCESS(err);
13724
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013725 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013726 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013727 ASSERT_VK_SUCCESS(err);
13728
13729 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013730 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013731 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13732 memAlloc.pNext = NULL;
13733 memAlloc.allocationSize = 0;
13734 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013735
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013736 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013737 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013738 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013739 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013740 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013741 ASSERT_VK_SUCCESS(err);
13742
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013743 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013744 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013745 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013746 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013747 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013748 ASSERT_VK_SUCCESS(err);
13749
13750 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13751 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013752 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013753 ASSERT_VK_SUCCESS(err);
13754
13755 BeginCommandBuffer();
13756 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013757 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013758 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013759 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013760 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013761 copyRegion.srcOffset.x = 0;
13762 copyRegion.srcOffset.y = 0;
13763 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013764 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013765 copyRegion.dstSubresource.mipLevel = 0;
13766 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013767 // Introduce failure by forcing the dst layerCount to differ from src
13768 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013769 copyRegion.dstOffset.x = 0;
13770 copyRegion.dstOffset.y = 0;
13771 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013772 copyRegion.extent.width = 1;
13773 copyRegion.extent.height = 1;
13774 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013775 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013776 EndCommandBuffer();
13777
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013778 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013779
Chia-I Wuf7458c52015-10-26 21:10:41 +080013780 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013781 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013782 vkFreeMemory(m_device->device(), srcMem, NULL);
13783 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013784}
13785
Tony Barbourd6673642016-05-05 14:46:39 -060013786TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13787
13788 TEST_DESCRIPTION("Creating images with unsuported formats ");
13789
13790 ASSERT_NO_FATAL_FAILURE(InitState());
13791 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13792 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013793 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 -060013794 VK_IMAGE_TILING_OPTIMAL, 0);
13795 ASSERT_TRUE(image.initialized());
13796
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013797 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13798 VkImageCreateInfo image_create_info;
13799 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13800 image_create_info.pNext = NULL;
13801 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13802 image_create_info.format = VK_FORMAT_UNDEFINED;
13803 image_create_info.extent.width = 32;
13804 image_create_info.extent.height = 32;
13805 image_create_info.extent.depth = 1;
13806 image_create_info.mipLevels = 1;
13807 image_create_info.arrayLayers = 1;
13808 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13809 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13810 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13811 image_create_info.flags = 0;
13812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13814 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013815
13816 VkImage localImage;
13817 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13818 m_errorMonitor->VerifyFound();
13819
Tony Barbourd6673642016-05-05 14:46:39 -060013820 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013821 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013822 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13823 VkFormat format = static_cast<VkFormat>(f);
13824 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013825 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013826 unsupported = format;
13827 break;
13828 }
13829 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013830
Tony Barbourd6673642016-05-05 14:46:39 -060013831 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013832 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013834
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013835 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013836 m_errorMonitor->VerifyFound();
13837 }
13838}
13839
13840TEST_F(VkLayerTest, ImageLayerViewTests) {
13841 VkResult ret;
13842 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13843
13844 ASSERT_NO_FATAL_FAILURE(InitState());
13845
13846 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013847 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 -060013848 VK_IMAGE_TILING_OPTIMAL, 0);
13849 ASSERT_TRUE(image.initialized());
13850
13851 VkImageView imgView;
13852 VkImageViewCreateInfo imgViewInfo = {};
13853 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13854 imgViewInfo.image = image.handle();
13855 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13856 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13857 imgViewInfo.subresourceRange.layerCount = 1;
13858 imgViewInfo.subresourceRange.baseMipLevel = 0;
13859 imgViewInfo.subresourceRange.levelCount = 1;
13860 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013863 // View can't have baseMipLevel >= image's mipLevels - Expect
13864 // VIEW_CREATE_ERROR
13865 imgViewInfo.subresourceRange.baseMipLevel = 1;
13866 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13867 m_errorMonitor->VerifyFound();
13868 imgViewInfo.subresourceRange.baseMipLevel = 0;
13869
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013871 // View can't have baseArrayLayer >= image's arraySize - Expect
13872 // VIEW_CREATE_ERROR
13873 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13874 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13875 m_errorMonitor->VerifyFound();
13876 imgViewInfo.subresourceRange.baseArrayLayer = 0;
13877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13879 "pCreateInfo->subresourceRange."
13880 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013881 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
13882 imgViewInfo.subresourceRange.levelCount = 0;
13883 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13884 m_errorMonitor->VerifyFound();
13885 imgViewInfo.subresourceRange.levelCount = 1;
13886
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13888 "pCreateInfo->subresourceRange."
13889 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013890 m_errorMonitor->SetDesiredFailureMsg(
13891 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13892 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060013893 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
13894 imgViewInfo.subresourceRange.layerCount = 0;
13895 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13896 m_errorMonitor->VerifyFound();
13897 imgViewInfo.subresourceRange.layerCount = 1;
13898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13901 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13902 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013903 // Can't use depth format for view into color image - Expect INVALID_FORMAT
13904 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
13905 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13906 m_errorMonitor->VerifyFound();
13907 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13910 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13911 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013912 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
13913 // VIEW_CREATE_ERROR
13914 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
13915 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13916 m_errorMonitor->VerifyFound();
13917 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
13920 "differing formats but they must be "
13921 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013922 // TODO: Update framework to easily passing mutable flag into ImageObj init
13923 // For now just allowing image for this one test to not have memory bound
13924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13925 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060013926 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
13927 // VIEW_CREATE_ERROR
13928 VkImageCreateInfo mutImgInfo = image.create_info();
13929 VkImage mutImage;
13930 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013931 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060013932 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
13933 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
13934 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
13935 ASSERT_VK_SUCCESS(ret);
13936 imgViewInfo.image = mutImage;
13937 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13938 m_errorMonitor->VerifyFound();
13939 imgViewInfo.image = image.handle();
13940 vkDestroyImage(m_device->handle(), mutImage, NULL);
13941}
13942
13943TEST_F(VkLayerTest, MiscImageLayerTests) {
13944
13945 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
13946
13947 ASSERT_NO_FATAL_FAILURE(InitState());
13948
13949 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013950 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 -060013951 VK_IMAGE_TILING_OPTIMAL, 0);
13952 ASSERT_TRUE(image.initialized());
13953
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060013955 vk_testing::Buffer buffer;
13956 VkMemoryPropertyFlags reqs = 0;
13957 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
13958 VkBufferImageCopy region = {};
13959 region.bufferRowLength = 128;
13960 region.bufferImageHeight = 128;
13961 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13962 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
13963 region.imageSubresource.layerCount = 0;
13964 region.imageExtent.height = 4;
13965 region.imageExtent.width = 4;
13966 region.imageExtent.depth = 1;
13967 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013968 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13969 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060013970 m_errorMonitor->VerifyFound();
13971 region.imageSubresource.layerCount = 1;
13972
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013973 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
13974 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
13975 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
13977 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13978 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013979 m_errorMonitor->VerifyFound();
13980
13981 // BufferOffset must be a multiple of 4
13982 // Introduce failure by setting bufferOffset to a value not divisible by 4
13983 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
13985 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13986 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013987 m_errorMonitor->VerifyFound();
13988
13989 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
13990 region.bufferOffset = 0;
13991 region.imageExtent.height = 128;
13992 region.imageExtent.width = 128;
13993 // Introduce failure by setting bufferRowLength > 0 but less than width
13994 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13996 "must be zero or greater-than-or-equal-to imageExtent.width");
13997 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13998 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013999 m_errorMonitor->VerifyFound();
14000
14001 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14002 region.bufferRowLength = 128;
14003 // Introduce failure by setting bufferRowHeight > 0 but less than height
14004 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14006 "must be zero or greater-than-or-equal-to imageExtent.height");
14007 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14008 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014009 m_errorMonitor->VerifyFound();
14010
14011 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14013 "specify only COLOR or DEPTH or "
14014 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014015 // Expect MISMATCHED_IMAGE_ASPECT
14016 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014017 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14018 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014019 m_errorMonitor->VerifyFound();
14020 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14023 "If the format of srcImage is a depth, stencil, depth stencil or "
14024 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014025 // Expect INVALID_FILTER
14026 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014027 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014028 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014029 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014030 VkImageBlit blitRegion = {};
14031 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14032 blitRegion.srcSubresource.baseArrayLayer = 0;
14033 blitRegion.srcSubresource.layerCount = 1;
14034 blitRegion.srcSubresource.mipLevel = 0;
14035 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14036 blitRegion.dstSubresource.baseArrayLayer = 0;
14037 blitRegion.dstSubresource.layerCount = 1;
14038 blitRegion.dstSubresource.mipLevel = 0;
14039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014040 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14041 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014042 m_errorMonitor->VerifyFound();
14043
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014044 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14046 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14047 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014048 m_errorMonitor->VerifyFound();
14049
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014051 VkImageMemoryBarrier img_barrier;
14052 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14053 img_barrier.pNext = NULL;
14054 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14055 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14056 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14057 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14058 img_barrier.image = image.handle();
14059 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14060 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14061 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14062 img_barrier.subresourceRange.baseArrayLayer = 0;
14063 img_barrier.subresourceRange.baseMipLevel = 0;
14064 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14065 img_barrier.subresourceRange.layerCount = 0;
14066 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014067 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14068 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014069 m_errorMonitor->VerifyFound();
14070 img_barrier.subresourceRange.layerCount = 1;
14071}
14072
14073TEST_F(VkLayerTest, ImageFormatLimits) {
14074
14075 TEST_DESCRIPTION("Exceed the limits of image format ");
14076
Cody Northropc31a84f2016-08-22 10:41:47 -060014077 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014079 VkImageCreateInfo image_create_info = {};
14080 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14081 image_create_info.pNext = NULL;
14082 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14083 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14084 image_create_info.extent.width = 32;
14085 image_create_info.extent.height = 32;
14086 image_create_info.extent.depth = 1;
14087 image_create_info.mipLevels = 1;
14088 image_create_info.arrayLayers = 1;
14089 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14090 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14091 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14092 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14093 image_create_info.flags = 0;
14094
14095 VkImage nullImg;
14096 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014097 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14098 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014099 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14100 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14101 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14102 m_errorMonitor->VerifyFound();
14103 image_create_info.extent.depth = 1;
14104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014106 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14107 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14108 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14109 m_errorMonitor->VerifyFound();
14110 image_create_info.mipLevels = 1;
14111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014113 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14114 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14115 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14116 m_errorMonitor->VerifyFound();
14117 image_create_info.arrayLayers = 1;
14118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014120 int samples = imgFmtProps.sampleCounts >> 1;
14121 image_create_info.samples = (VkSampleCountFlagBits)samples;
14122 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14123 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14124 m_errorMonitor->VerifyFound();
14125 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14126
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14128 "VK_IMAGE_LAYOUT_UNDEFINED or "
14129 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014130 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14131 // Expect INVALID_LAYOUT
14132 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14133 m_errorMonitor->VerifyFound();
14134 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14135}
14136
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014137TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14138
14139 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014141
14142 ASSERT_NO_FATAL_FAILURE(InitState());
14143
14144 VkImageObj src_image(m_device);
14145 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14146 VkImageObj dst_image(m_device);
14147 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14148
14149 BeginCommandBuffer();
14150 VkImageCopy copy_region;
14151 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14152 copy_region.srcSubresource.mipLevel = 0;
14153 copy_region.srcSubresource.baseArrayLayer = 0;
14154 copy_region.srcSubresource.layerCount = 0;
14155 copy_region.srcOffset.x = 0;
14156 copy_region.srcOffset.y = 0;
14157 copy_region.srcOffset.z = 0;
14158 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14159 copy_region.dstSubresource.mipLevel = 0;
14160 copy_region.dstSubresource.baseArrayLayer = 0;
14161 copy_region.dstSubresource.layerCount = 0;
14162 copy_region.dstOffset.x = 0;
14163 copy_region.dstOffset.y = 0;
14164 copy_region.dstOffset.z = 0;
14165 copy_region.extent.width = 64;
14166 copy_region.extent.height = 64;
14167 copy_region.extent.depth = 1;
14168 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14169 &copy_region);
14170 EndCommandBuffer();
14171
14172 m_errorMonitor->VerifyFound();
14173}
14174
14175TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14176
14177 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014179
14180 ASSERT_NO_FATAL_FAILURE(InitState());
14181
14182 VkImageObj src_image(m_device);
14183 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14184 VkImageObj dst_image(m_device);
14185 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14186
14187 BeginCommandBuffer();
14188 VkImageCopy copy_region;
14189 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14190 copy_region.srcSubresource.mipLevel = 0;
14191 copy_region.srcSubresource.baseArrayLayer = 0;
14192 copy_region.srcSubresource.layerCount = 0;
14193 copy_region.srcOffset.x = 0;
14194 copy_region.srcOffset.y = 0;
14195 copy_region.srcOffset.z = 0;
14196 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14197 copy_region.dstSubresource.mipLevel = 0;
14198 copy_region.dstSubresource.baseArrayLayer = 0;
14199 copy_region.dstSubresource.layerCount = 0;
14200 copy_region.dstOffset.x = 0;
14201 copy_region.dstOffset.y = 0;
14202 copy_region.dstOffset.z = 0;
14203 copy_region.extent.width = 64;
14204 copy_region.extent.height = 64;
14205 copy_region.extent.depth = 1;
14206 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14207 &copy_region);
14208 EndCommandBuffer();
14209
14210 m_errorMonitor->VerifyFound();
14211}
14212
Karl Schultz6addd812016-02-02 17:17:23 -070014213TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014214 VkResult err;
14215 bool pass;
14216
14217 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14219 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014220
14221 ASSERT_NO_FATAL_FAILURE(InitState());
14222
14223 // Create two images of different types and try to copy between them
14224 VkImage srcImage;
14225 VkImage dstImage;
14226 VkDeviceMemory srcMem;
14227 VkDeviceMemory destMem;
14228 VkMemoryRequirements memReqs;
14229
14230 VkImageCreateInfo image_create_info = {};
14231 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14232 image_create_info.pNext = NULL;
14233 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14234 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14235 image_create_info.extent.width = 32;
14236 image_create_info.extent.height = 32;
14237 image_create_info.extent.depth = 1;
14238 image_create_info.mipLevels = 1;
14239 image_create_info.arrayLayers = 1;
14240 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14241 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14242 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14243 image_create_info.flags = 0;
14244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014245 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014246 ASSERT_VK_SUCCESS(err);
14247
14248 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14249 // Introduce failure by creating second image with a different-sized format.
14250 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14251
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014252 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014253 ASSERT_VK_SUCCESS(err);
14254
14255 // Allocate memory
14256 VkMemoryAllocateInfo memAlloc = {};
14257 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14258 memAlloc.pNext = NULL;
14259 memAlloc.allocationSize = 0;
14260 memAlloc.memoryTypeIndex = 0;
14261
14262 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14263 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014264 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014265 ASSERT_TRUE(pass);
14266 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14267 ASSERT_VK_SUCCESS(err);
14268
14269 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14270 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014271 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014272 ASSERT_TRUE(pass);
14273 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14274 ASSERT_VK_SUCCESS(err);
14275
14276 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14277 ASSERT_VK_SUCCESS(err);
14278 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14279 ASSERT_VK_SUCCESS(err);
14280
14281 BeginCommandBuffer();
14282 VkImageCopy copyRegion;
14283 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14284 copyRegion.srcSubresource.mipLevel = 0;
14285 copyRegion.srcSubresource.baseArrayLayer = 0;
14286 copyRegion.srcSubresource.layerCount = 0;
14287 copyRegion.srcOffset.x = 0;
14288 copyRegion.srcOffset.y = 0;
14289 copyRegion.srcOffset.z = 0;
14290 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14291 copyRegion.dstSubresource.mipLevel = 0;
14292 copyRegion.dstSubresource.baseArrayLayer = 0;
14293 copyRegion.dstSubresource.layerCount = 0;
14294 copyRegion.dstOffset.x = 0;
14295 copyRegion.dstOffset.y = 0;
14296 copyRegion.dstOffset.z = 0;
14297 copyRegion.extent.width = 1;
14298 copyRegion.extent.height = 1;
14299 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014300 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014301 EndCommandBuffer();
14302
14303 m_errorMonitor->VerifyFound();
14304
14305 vkDestroyImage(m_device->device(), srcImage, NULL);
14306 vkDestroyImage(m_device->device(), dstImage, NULL);
14307 vkFreeMemory(m_device->device(), srcMem, NULL);
14308 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014309}
14310
Karl Schultz6addd812016-02-02 17:17:23 -070014311TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14312 VkResult err;
14313 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014314
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014315 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14317 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014318
Mike Stroyana3082432015-09-25 13:39:21 -060014319 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014320
14321 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014322 VkImage srcImage;
14323 VkImage dstImage;
14324 VkDeviceMemory srcMem;
14325 VkDeviceMemory destMem;
14326 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014327
14328 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014329 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14330 image_create_info.pNext = NULL;
14331 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14332 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14333 image_create_info.extent.width = 32;
14334 image_create_info.extent.height = 32;
14335 image_create_info.extent.depth = 1;
14336 image_create_info.mipLevels = 1;
14337 image_create_info.arrayLayers = 1;
14338 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14339 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14340 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14341 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014343 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014344 ASSERT_VK_SUCCESS(err);
14345
Karl Schultzbdb75952016-04-19 11:36:49 -060014346 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14347
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014348 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014349 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014350 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014351 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014353 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014354 ASSERT_VK_SUCCESS(err);
14355
14356 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014357 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014358 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14359 memAlloc.pNext = NULL;
14360 memAlloc.allocationSize = 0;
14361 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014362
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014363 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014364 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014365 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014366 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014367 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014368 ASSERT_VK_SUCCESS(err);
14369
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014370 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014371 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014372 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014373 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014374 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014375 ASSERT_VK_SUCCESS(err);
14376
14377 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14378 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014379 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014380 ASSERT_VK_SUCCESS(err);
14381
14382 BeginCommandBuffer();
14383 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014384 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014385 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014386 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014387 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014388 copyRegion.srcOffset.x = 0;
14389 copyRegion.srcOffset.y = 0;
14390 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014391 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014392 copyRegion.dstSubresource.mipLevel = 0;
14393 copyRegion.dstSubresource.baseArrayLayer = 0;
14394 copyRegion.dstSubresource.layerCount = 0;
14395 copyRegion.dstOffset.x = 0;
14396 copyRegion.dstOffset.y = 0;
14397 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014398 copyRegion.extent.width = 1;
14399 copyRegion.extent.height = 1;
14400 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014401 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014402 EndCommandBuffer();
14403
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014404 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014405
Chia-I Wuf7458c52015-10-26 21:10:41 +080014406 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014407 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014408 vkFreeMemory(m_device->device(), srcMem, NULL);
14409 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014410}
14411
Karl Schultz6addd812016-02-02 17:17:23 -070014412TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14413 VkResult err;
14414 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014415
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14417 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014418
Mike Stroyana3082432015-09-25 13:39:21 -060014419 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014420
14421 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014422 VkImage srcImage;
14423 VkImage dstImage;
14424 VkDeviceMemory srcMem;
14425 VkDeviceMemory destMem;
14426 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014427
14428 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014429 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14430 image_create_info.pNext = NULL;
14431 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14432 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14433 image_create_info.extent.width = 32;
14434 image_create_info.extent.height = 1;
14435 image_create_info.extent.depth = 1;
14436 image_create_info.mipLevels = 1;
14437 image_create_info.arrayLayers = 1;
14438 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14439 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14440 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14441 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014443 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014444 ASSERT_VK_SUCCESS(err);
14445
Karl Schultz6addd812016-02-02 17:17:23 -070014446 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014448 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014449 ASSERT_VK_SUCCESS(err);
14450
14451 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014452 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014453 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14454 memAlloc.pNext = NULL;
14455 memAlloc.allocationSize = 0;
14456 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014457
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014458 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014459 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014460 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014461 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014462 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014463 ASSERT_VK_SUCCESS(err);
14464
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014465 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014466 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014467 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014468 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014469 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014470 ASSERT_VK_SUCCESS(err);
14471
14472 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14473 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014474 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014475 ASSERT_VK_SUCCESS(err);
14476
14477 BeginCommandBuffer();
14478 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014479 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14480 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014481 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014482 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014483 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014484 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014485 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014486 resolveRegion.srcOffset.x = 0;
14487 resolveRegion.srcOffset.y = 0;
14488 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014489 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014490 resolveRegion.dstSubresource.mipLevel = 0;
14491 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014492 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014493 resolveRegion.dstOffset.x = 0;
14494 resolveRegion.dstOffset.y = 0;
14495 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014496 resolveRegion.extent.width = 1;
14497 resolveRegion.extent.height = 1;
14498 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014499 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014500 EndCommandBuffer();
14501
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014502 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014503
Chia-I Wuf7458c52015-10-26 21:10:41 +080014504 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014505 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014506 vkFreeMemory(m_device->device(), srcMem, NULL);
14507 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014508}
14509
Karl Schultz6addd812016-02-02 17:17:23 -070014510TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14511 VkResult err;
14512 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14515 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014516
Mike Stroyana3082432015-09-25 13:39:21 -060014517 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014518
Chris Forbesa7530692016-05-08 12:35:39 +120014519 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014520 VkImage srcImage;
14521 VkImage dstImage;
14522 VkDeviceMemory srcMem;
14523 VkDeviceMemory destMem;
14524 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014525
14526 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014527 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14528 image_create_info.pNext = NULL;
14529 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14530 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14531 image_create_info.extent.width = 32;
14532 image_create_info.extent.height = 1;
14533 image_create_info.extent.depth = 1;
14534 image_create_info.mipLevels = 1;
14535 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014536 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014537 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14538 // Note: Some implementations expect color attachment usage for any
14539 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014540 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014541 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014542
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014543 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014544 ASSERT_VK_SUCCESS(err);
14545
Karl Schultz6addd812016-02-02 17:17:23 -070014546 // Note: Some implementations expect color attachment usage for any
14547 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014548 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014550 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014551 ASSERT_VK_SUCCESS(err);
14552
14553 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014554 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014555 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14556 memAlloc.pNext = NULL;
14557 memAlloc.allocationSize = 0;
14558 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014559
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014560 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014561 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014562 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014563 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014564 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014565 ASSERT_VK_SUCCESS(err);
14566
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014567 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014568 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014569 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014570 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014571 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014572 ASSERT_VK_SUCCESS(err);
14573
14574 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14575 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014576 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014577 ASSERT_VK_SUCCESS(err);
14578
14579 BeginCommandBuffer();
14580 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014581 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14582 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014583 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014584 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014585 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014586 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014587 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014588 resolveRegion.srcOffset.x = 0;
14589 resolveRegion.srcOffset.y = 0;
14590 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014591 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014592 resolveRegion.dstSubresource.mipLevel = 0;
14593 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014594 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014595 resolveRegion.dstOffset.x = 0;
14596 resolveRegion.dstOffset.y = 0;
14597 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014598 resolveRegion.extent.width = 1;
14599 resolveRegion.extent.height = 1;
14600 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014601 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014602 EndCommandBuffer();
14603
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014604 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014605
Chia-I Wuf7458c52015-10-26 21:10:41 +080014606 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014607 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014608 vkFreeMemory(m_device->device(), srcMem, NULL);
14609 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014610}
14611
Karl Schultz6addd812016-02-02 17:17:23 -070014612TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14613 VkResult err;
14614 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014615
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14617 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014618
Mike Stroyana3082432015-09-25 13:39:21 -060014619 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014620
14621 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014622 VkImage srcImage;
14623 VkImage dstImage;
14624 VkDeviceMemory srcMem;
14625 VkDeviceMemory destMem;
14626 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014627
14628 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014629 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14630 image_create_info.pNext = NULL;
14631 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14632 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14633 image_create_info.extent.width = 32;
14634 image_create_info.extent.height = 1;
14635 image_create_info.extent.depth = 1;
14636 image_create_info.mipLevels = 1;
14637 image_create_info.arrayLayers = 1;
14638 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14639 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14640 // Note: Some implementations expect color attachment usage for any
14641 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014642 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014643 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014644
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014645 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014646 ASSERT_VK_SUCCESS(err);
14647
Karl Schultz6addd812016-02-02 17:17:23 -070014648 // Set format to something other than source image
14649 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14650 // Note: Some implementations expect color attachment usage for any
14651 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014652 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014653 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014654
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014655 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014656 ASSERT_VK_SUCCESS(err);
14657
14658 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014659 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014660 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14661 memAlloc.pNext = NULL;
14662 memAlloc.allocationSize = 0;
14663 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014664
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014665 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014666 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014667 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014668 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014669 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014670 ASSERT_VK_SUCCESS(err);
14671
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014672 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014673 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014674 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014675 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014676 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014677 ASSERT_VK_SUCCESS(err);
14678
14679 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14680 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014681 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014682 ASSERT_VK_SUCCESS(err);
14683
14684 BeginCommandBuffer();
14685 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014686 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14687 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014688 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014689 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014690 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014691 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014692 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014693 resolveRegion.srcOffset.x = 0;
14694 resolveRegion.srcOffset.y = 0;
14695 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014696 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014697 resolveRegion.dstSubresource.mipLevel = 0;
14698 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014699 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014700 resolveRegion.dstOffset.x = 0;
14701 resolveRegion.dstOffset.y = 0;
14702 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014703 resolveRegion.extent.width = 1;
14704 resolveRegion.extent.height = 1;
14705 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014706 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014707 EndCommandBuffer();
14708
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014709 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014710
Chia-I Wuf7458c52015-10-26 21:10:41 +080014711 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014712 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014713 vkFreeMemory(m_device->device(), srcMem, NULL);
14714 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014715}
14716
Karl Schultz6addd812016-02-02 17:17:23 -070014717TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14718 VkResult err;
14719 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14722 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014723
Mike Stroyana3082432015-09-25 13:39:21 -060014724 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014725
14726 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014727 VkImage srcImage;
14728 VkImage dstImage;
14729 VkDeviceMemory srcMem;
14730 VkDeviceMemory destMem;
14731 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014732
14733 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014734 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14735 image_create_info.pNext = NULL;
14736 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14737 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14738 image_create_info.extent.width = 32;
14739 image_create_info.extent.height = 1;
14740 image_create_info.extent.depth = 1;
14741 image_create_info.mipLevels = 1;
14742 image_create_info.arrayLayers = 1;
14743 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14744 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14745 // Note: Some implementations expect color attachment usage for any
14746 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014747 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014748 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014749
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014750 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014751 ASSERT_VK_SUCCESS(err);
14752
Karl Schultz6addd812016-02-02 17:17:23 -070014753 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14754 // Note: Some implementations expect color attachment usage for any
14755 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014756 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014757 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014759 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014760 ASSERT_VK_SUCCESS(err);
14761
14762 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014763 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014764 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14765 memAlloc.pNext = NULL;
14766 memAlloc.allocationSize = 0;
14767 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014768
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014769 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014770 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014771 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014772 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014773 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014774 ASSERT_VK_SUCCESS(err);
14775
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014776 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014777 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014778 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014779 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014780 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014781 ASSERT_VK_SUCCESS(err);
14782
14783 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14784 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014785 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014786 ASSERT_VK_SUCCESS(err);
14787
14788 BeginCommandBuffer();
14789 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014790 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14791 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014792 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014793 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014794 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014795 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014796 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014797 resolveRegion.srcOffset.x = 0;
14798 resolveRegion.srcOffset.y = 0;
14799 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014800 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014801 resolveRegion.dstSubresource.mipLevel = 0;
14802 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014803 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014804 resolveRegion.dstOffset.x = 0;
14805 resolveRegion.dstOffset.y = 0;
14806 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014807 resolveRegion.extent.width = 1;
14808 resolveRegion.extent.height = 1;
14809 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014810 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014811 EndCommandBuffer();
14812
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014813 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014814
Chia-I Wuf7458c52015-10-26 21:10:41 +080014815 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014816 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014817 vkFreeMemory(m_device->device(), srcMem, NULL);
14818 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014819}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014820
Karl Schultz6addd812016-02-02 17:17:23 -070014821TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014822 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014823 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14824 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014825 // The image format check comes 2nd in validation so we trigger it first,
14826 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014827 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14830 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014831
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014832 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014833
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014834 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014835 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14836 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014837
14838 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014839 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14840 ds_pool_ci.pNext = NULL;
14841 ds_pool_ci.maxSets = 1;
14842 ds_pool_ci.poolSizeCount = 1;
14843 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014844
14845 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014846 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014847 ASSERT_VK_SUCCESS(err);
14848
14849 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014850 dsl_binding.binding = 0;
14851 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14852 dsl_binding.descriptorCount = 1;
14853 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14854 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014855
14856 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014857 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14858 ds_layout_ci.pNext = NULL;
14859 ds_layout_ci.bindingCount = 1;
14860 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014861 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014862 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014863 ASSERT_VK_SUCCESS(err);
14864
14865 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014866 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014867 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014868 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014869 alloc_info.descriptorPool = ds_pool;
14870 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014871 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014872 ASSERT_VK_SUCCESS(err);
14873
Karl Schultz6addd812016-02-02 17:17:23 -070014874 VkImage image_bad;
14875 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014876 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060014877 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014878 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070014879 const int32_t tex_width = 32;
14880 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014881
14882 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014883 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14884 image_create_info.pNext = NULL;
14885 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14886 image_create_info.format = tex_format_bad;
14887 image_create_info.extent.width = tex_width;
14888 image_create_info.extent.height = tex_height;
14889 image_create_info.extent.depth = 1;
14890 image_create_info.mipLevels = 1;
14891 image_create_info.arrayLayers = 1;
14892 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14893 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014894 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014895 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014897 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014898 ASSERT_VK_SUCCESS(err);
14899 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014900 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14901 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014902 ASSERT_VK_SUCCESS(err);
14903
14904 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014905 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14906 image_view_create_info.image = image_bad;
14907 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14908 image_view_create_info.format = tex_format_bad;
14909 image_view_create_info.subresourceRange.baseArrayLayer = 0;
14910 image_view_create_info.subresourceRange.baseMipLevel = 0;
14911 image_view_create_info.subresourceRange.layerCount = 1;
14912 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014913 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014914
14915 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014916 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014917
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014918 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014919
Chia-I Wuf7458c52015-10-26 21:10:41 +080014920 vkDestroyImage(m_device->device(), image_bad, NULL);
14921 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014922 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
14923 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014924}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014925
14926TEST_F(VkLayerTest, ClearImageErrors) {
14927 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
14928 "ClearDepthStencilImage with a color image.");
14929
14930 ASSERT_NO_FATAL_FAILURE(InitState());
14931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14932
14933 // Renderpass is started here so end it as Clear cmds can't be in renderpass
14934 BeginCommandBuffer();
14935 m_commandBuffer->EndRenderPass();
14936
14937 // Color image
14938 VkClearColorValue clear_color;
14939 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
14940 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
14941 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
14942 const int32_t img_width = 32;
14943 const int32_t img_height = 32;
14944 VkImageCreateInfo image_create_info = {};
14945 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14946 image_create_info.pNext = NULL;
14947 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14948 image_create_info.format = color_format;
14949 image_create_info.extent.width = img_width;
14950 image_create_info.extent.height = img_height;
14951 image_create_info.extent.depth = 1;
14952 image_create_info.mipLevels = 1;
14953 image_create_info.arrayLayers = 1;
14954 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14955 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14956 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14957
14958 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014959 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014961 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014962
14963 // Depth/Stencil image
14964 VkClearDepthStencilValue clear_value = {0};
14965 reqs = 0; // don't need HOST_VISIBLE DS image
14966 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
14967 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
14968 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
14969 ds_image_create_info.extent.width = 64;
14970 ds_image_create_info.extent.height = 64;
14971 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14972 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
14973
14974 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014975 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014976
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014977 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 -060014978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014980
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014981 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014982 &color_range);
14983
14984 m_errorMonitor->VerifyFound();
14985
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
14987 "image created without "
14988 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060014989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014990 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060014991 &color_range);
14992
14993 m_errorMonitor->VerifyFound();
14994
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014995 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14997 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014998
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014999 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15000 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015001
15002 m_errorMonitor->VerifyFound();
15003}
Tobin Ehliscde08892015-09-22 10:11:37 -060015004#endif // IMAGE_TESTS
15005
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015006
15007// WSI Enabled Tests
15008//
15009TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15010
15011#if defined(VK_USE_PLATFORM_XCB_KHR)
15012 VkSurfaceKHR surface = VK_NULL_HANDLE;
15013
15014 VkResult err;
15015 bool pass;
15016 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15017 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15018 // uint32_t swapchain_image_count = 0;
15019 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15020 // uint32_t image_index = 0;
15021 // VkPresentInfoKHR present_info = {};
15022
15023 ASSERT_NO_FATAL_FAILURE(InitState());
15024
15025 // Use the create function from one of the VK_KHR_*_surface extension in
15026 // order to create a surface, testing all known errors in the process,
15027 // before successfully creating a surface:
15028 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15030 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15031 pass = (err != VK_SUCCESS);
15032 ASSERT_TRUE(pass);
15033 m_errorMonitor->VerifyFound();
15034
15035 // Next, try to create a surface with the wrong
15036 // VkXcbSurfaceCreateInfoKHR::sType:
15037 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15038 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15040 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15041 pass = (err != VK_SUCCESS);
15042 ASSERT_TRUE(pass);
15043 m_errorMonitor->VerifyFound();
15044
15045 // Create a native window, and then correctly create a surface:
15046 xcb_connection_t *connection;
15047 xcb_screen_t *screen;
15048 xcb_window_t xcb_window;
15049 xcb_intern_atom_reply_t *atom_wm_delete_window;
15050
15051 const xcb_setup_t *setup;
15052 xcb_screen_iterator_t iter;
15053 int scr;
15054 uint32_t value_mask, value_list[32];
15055 int width = 1;
15056 int height = 1;
15057
15058 connection = xcb_connect(NULL, &scr);
15059 ASSERT_TRUE(connection != NULL);
15060 setup = xcb_get_setup(connection);
15061 iter = xcb_setup_roots_iterator(setup);
15062 while (scr-- > 0)
15063 xcb_screen_next(&iter);
15064 screen = iter.data;
15065
15066 xcb_window = xcb_generate_id(connection);
15067
15068 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15069 value_list[0] = screen->black_pixel;
15070 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15071
15072 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15073 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15074
15075 /* Magic code that will send notification when window is destroyed */
15076 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15077 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15078
15079 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15080 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15081 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15082 free(reply);
15083
15084 xcb_map_window(connection, xcb_window);
15085
15086 // Force the x/y coordinates to 100,100 results are identical in consecutive
15087 // runs
15088 const uint32_t coords[] = { 100, 100 };
15089 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15090
15091 // Finally, try to correctly create a surface:
15092 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15093 xcb_create_info.pNext = NULL;
15094 xcb_create_info.flags = 0;
15095 xcb_create_info.connection = connection;
15096 xcb_create_info.window = xcb_window;
15097 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15098 pass = (err == VK_SUCCESS);
15099 ASSERT_TRUE(pass);
15100
15101 // Check if surface supports presentation:
15102
15103 // 1st, do so without having queried the queue families:
15104 VkBool32 supported = false;
15105 // TODO: Get the following error to come out:
15106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15107 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15108 "function");
15109 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15110 pass = (err != VK_SUCCESS);
15111 // ASSERT_TRUE(pass);
15112 // m_errorMonitor->VerifyFound();
15113
15114 // Next, query a queue family index that's too large:
15115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15116 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15117 pass = (err != VK_SUCCESS);
15118 ASSERT_TRUE(pass);
15119 m_errorMonitor->VerifyFound();
15120
15121 // Finally, do so correctly:
15122 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15123 // SUPPORTED
15124 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15125 pass = (err == VK_SUCCESS);
15126 ASSERT_TRUE(pass);
15127
15128 // Before proceeding, try to create a swapchain without having called
15129 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15130 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15131 swapchain_create_info.pNext = NULL;
15132 swapchain_create_info.flags = 0;
15133 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15134 swapchain_create_info.surface = surface;
15135 swapchain_create_info.imageArrayLayers = 1;
15136 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15137 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15139 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15140 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15141 pass = (err != VK_SUCCESS);
15142 ASSERT_TRUE(pass);
15143 m_errorMonitor->VerifyFound();
15144
15145 // Get the surface capabilities:
15146 VkSurfaceCapabilitiesKHR surface_capabilities;
15147
15148 // Do so correctly (only error logged by this entrypoint is if the
15149 // extension isn't enabled):
15150 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15151 pass = (err == VK_SUCCESS);
15152 ASSERT_TRUE(pass);
15153
15154 // Get the surface formats:
15155 uint32_t surface_format_count;
15156
15157 // First, try without a pointer to surface_format_count:
15158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15159 "specified as NULL");
15160 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15161 pass = (err == VK_SUCCESS);
15162 ASSERT_TRUE(pass);
15163 m_errorMonitor->VerifyFound();
15164
15165 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15166 // correctly done a 1st try (to get the count):
15167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15168 surface_format_count = 0;
15169 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15170 pass = (err == VK_SUCCESS);
15171 ASSERT_TRUE(pass);
15172 m_errorMonitor->VerifyFound();
15173
15174 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15175 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15176 pass = (err == VK_SUCCESS);
15177 ASSERT_TRUE(pass);
15178
15179 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15180 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15181
15182 // Next, do a 2nd try with surface_format_count being set too high:
15183 surface_format_count += 5;
15184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15185 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15186 pass = (err == VK_SUCCESS);
15187 ASSERT_TRUE(pass);
15188 m_errorMonitor->VerifyFound();
15189
15190 // Finally, do a correct 1st and 2nd try:
15191 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15192 pass = (err == VK_SUCCESS);
15193 ASSERT_TRUE(pass);
15194 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15195 pass = (err == VK_SUCCESS);
15196 ASSERT_TRUE(pass);
15197
15198 // Get the surface present modes:
15199 uint32_t surface_present_mode_count;
15200
15201 // First, try without a pointer to surface_format_count:
15202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15203 "specified as NULL");
15204
15205 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15206 pass = (err == VK_SUCCESS);
15207 ASSERT_TRUE(pass);
15208 m_errorMonitor->VerifyFound();
15209
15210 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15211 // correctly done a 1st try (to get the count):
15212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15213 surface_present_mode_count = 0;
15214 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15215 (VkPresentModeKHR *)&surface_present_mode_count);
15216 pass = (err == VK_SUCCESS);
15217 ASSERT_TRUE(pass);
15218 m_errorMonitor->VerifyFound();
15219
15220 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15221 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15222 pass = (err == VK_SUCCESS);
15223 ASSERT_TRUE(pass);
15224
15225 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15226 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15227
15228 // Next, do a 2nd try with surface_format_count being set too high:
15229 surface_present_mode_count += 5;
15230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15231 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15232 pass = (err == VK_SUCCESS);
15233 ASSERT_TRUE(pass);
15234 m_errorMonitor->VerifyFound();
15235
15236 // Finally, do a correct 1st and 2nd try:
15237 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15238 pass = (err == VK_SUCCESS);
15239 ASSERT_TRUE(pass);
15240 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15241 pass = (err == VK_SUCCESS);
15242 ASSERT_TRUE(pass);
15243
15244 // Create a swapchain:
15245
15246 // First, try without a pointer to swapchain_create_info:
15247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15248 "specified as NULL");
15249
15250 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15251 pass = (err != VK_SUCCESS);
15252 ASSERT_TRUE(pass);
15253 m_errorMonitor->VerifyFound();
15254
15255 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15256 // sType:
15257 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15259
15260 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15261 pass = (err != VK_SUCCESS);
15262 ASSERT_TRUE(pass);
15263 m_errorMonitor->VerifyFound();
15264
15265 // Next, call with a NULL swapchain pointer:
15266 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15267 swapchain_create_info.pNext = NULL;
15268 swapchain_create_info.flags = 0;
15269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15270 "specified as NULL");
15271
15272 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15273 pass = (err != VK_SUCCESS);
15274 ASSERT_TRUE(pass);
15275 m_errorMonitor->VerifyFound();
15276
15277 // TODO: Enhance swapchain layer so that
15278 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15279
15280 // Next, call with a queue family index that's too large:
15281 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15282 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15283 swapchain_create_info.queueFamilyIndexCount = 2;
15284 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15286 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15287 pass = (err != VK_SUCCESS);
15288 ASSERT_TRUE(pass);
15289 m_errorMonitor->VerifyFound();
15290
15291 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15292 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15293 swapchain_create_info.queueFamilyIndexCount = 1;
15294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15295 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15296 "pCreateInfo->pQueueFamilyIndices).");
15297 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15298 pass = (err != VK_SUCCESS);
15299 ASSERT_TRUE(pass);
15300 m_errorMonitor->VerifyFound();
15301
15302 // Next, call with an invalid imageSharingMode:
15303 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15304 swapchain_create_info.queueFamilyIndexCount = 1;
15305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15306 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15307 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15308 pass = (err != VK_SUCCESS);
15309 ASSERT_TRUE(pass);
15310 m_errorMonitor->VerifyFound();
15311 // Fix for the future:
15312 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15313 // SUPPORTED
15314 swapchain_create_info.queueFamilyIndexCount = 0;
15315 queueFamilyIndex[0] = 0;
15316 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15317
15318 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15319 // Get the images from a swapchain:
15320 // Acquire an image from a swapchain:
15321 // Present an image to a swapchain:
15322 // Destroy the swapchain:
15323
15324 // TODOs:
15325 //
15326 // - Try destroying the device without first destroying the swapchain
15327 //
15328 // - Try destroying the device without first destroying the surface
15329 //
15330 // - Try destroying the surface without first destroying the swapchain
15331
15332 // Destroy the surface:
15333 vkDestroySurfaceKHR(instance(), surface, NULL);
15334
15335 // Tear down the window:
15336 xcb_destroy_window(connection, xcb_window);
15337 xcb_disconnect(connection);
15338
15339#else // VK_USE_PLATFORM_XCB_KHR
15340 return;
15341#endif // VK_USE_PLATFORM_XCB_KHR
15342}
15343
15344//
15345// POSITIVE VALIDATION TESTS
15346//
15347// These tests do not expect to encounter ANY validation errors pass only if this is true
15348
15349// This is a positive test. No failures are expected.
15350TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15351 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15352 "is ignoring VkWriteDescriptorSet members that are not "
15353 "related to the descriptor type specified by "
15354 "VkWriteDescriptorSet::descriptorType. Correct "
15355 "validation behavior will result in the test running to "
15356 "completion without validation errors.");
15357
15358 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15359
15360 ASSERT_NO_FATAL_FAILURE(InitState());
15361
15362 // Image Case
15363 {
15364 m_errorMonitor->ExpectSuccess();
15365
15366 VkImage image;
15367 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15368 const int32_t tex_width = 32;
15369 const int32_t tex_height = 32;
15370 VkImageCreateInfo image_create_info = {};
15371 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15372 image_create_info.pNext = NULL;
15373 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15374 image_create_info.format = tex_format;
15375 image_create_info.extent.width = tex_width;
15376 image_create_info.extent.height = tex_height;
15377 image_create_info.extent.depth = 1;
15378 image_create_info.mipLevels = 1;
15379 image_create_info.arrayLayers = 1;
15380 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15381 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15382 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15383 image_create_info.flags = 0;
15384 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15385 ASSERT_VK_SUCCESS(err);
15386
15387 VkMemoryRequirements memory_reqs;
15388 VkDeviceMemory image_memory;
15389 bool pass;
15390 VkMemoryAllocateInfo memory_info = {};
15391 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15392 memory_info.pNext = NULL;
15393 memory_info.allocationSize = 0;
15394 memory_info.memoryTypeIndex = 0;
15395 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15396 memory_info.allocationSize = memory_reqs.size;
15397 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15398 ASSERT_TRUE(pass);
15399 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15400 ASSERT_VK_SUCCESS(err);
15401 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15402 ASSERT_VK_SUCCESS(err);
15403
15404 VkImageViewCreateInfo image_view_create_info = {};
15405 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15406 image_view_create_info.image = image;
15407 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15408 image_view_create_info.format = tex_format;
15409 image_view_create_info.subresourceRange.layerCount = 1;
15410 image_view_create_info.subresourceRange.baseMipLevel = 0;
15411 image_view_create_info.subresourceRange.levelCount = 1;
15412 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15413
15414 VkImageView view;
15415 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15416 ASSERT_VK_SUCCESS(err);
15417
15418 VkDescriptorPoolSize ds_type_count = {};
15419 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15420 ds_type_count.descriptorCount = 1;
15421
15422 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15423 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15424 ds_pool_ci.pNext = NULL;
15425 ds_pool_ci.maxSets = 1;
15426 ds_pool_ci.poolSizeCount = 1;
15427 ds_pool_ci.pPoolSizes = &ds_type_count;
15428
15429 VkDescriptorPool ds_pool;
15430 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15431 ASSERT_VK_SUCCESS(err);
15432
15433 VkDescriptorSetLayoutBinding dsl_binding = {};
15434 dsl_binding.binding = 0;
15435 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15436 dsl_binding.descriptorCount = 1;
15437 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15438 dsl_binding.pImmutableSamplers = NULL;
15439
15440 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15441 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15442 ds_layout_ci.pNext = NULL;
15443 ds_layout_ci.bindingCount = 1;
15444 ds_layout_ci.pBindings = &dsl_binding;
15445 VkDescriptorSetLayout ds_layout;
15446 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15447 ASSERT_VK_SUCCESS(err);
15448
15449 VkDescriptorSet descriptor_set;
15450 VkDescriptorSetAllocateInfo alloc_info = {};
15451 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15452 alloc_info.descriptorSetCount = 1;
15453 alloc_info.descriptorPool = ds_pool;
15454 alloc_info.pSetLayouts = &ds_layout;
15455 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15456 ASSERT_VK_SUCCESS(err);
15457
15458 VkDescriptorImageInfo image_info = {};
15459 image_info.imageView = view;
15460 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15461
15462 VkWriteDescriptorSet descriptor_write;
15463 memset(&descriptor_write, 0, sizeof(descriptor_write));
15464 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15465 descriptor_write.dstSet = descriptor_set;
15466 descriptor_write.dstBinding = 0;
15467 descriptor_write.descriptorCount = 1;
15468 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15469 descriptor_write.pImageInfo = &image_info;
15470
15471 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15472 // be
15473 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15474 // This will most likely produce a crash if the parameter_validation
15475 // layer
15476 // does not correctly ignore pBufferInfo.
15477 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15478 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15479
15480 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15481
15482 m_errorMonitor->VerifyNotFound();
15483
15484 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15485 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15486 vkDestroyImageView(m_device->device(), view, NULL);
15487 vkDestroyImage(m_device->device(), image, NULL);
15488 vkFreeMemory(m_device->device(), image_memory, NULL);
15489 }
15490
15491 // Buffer Case
15492 {
15493 m_errorMonitor->ExpectSuccess();
15494
15495 VkBuffer buffer;
15496 uint32_t queue_family_index = 0;
15497 VkBufferCreateInfo buffer_create_info = {};
15498 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15499 buffer_create_info.size = 1024;
15500 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15501 buffer_create_info.queueFamilyIndexCount = 1;
15502 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15503
15504 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15505 ASSERT_VK_SUCCESS(err);
15506
15507 VkMemoryRequirements memory_reqs;
15508 VkDeviceMemory buffer_memory;
15509 bool pass;
15510 VkMemoryAllocateInfo memory_info = {};
15511 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15512 memory_info.pNext = NULL;
15513 memory_info.allocationSize = 0;
15514 memory_info.memoryTypeIndex = 0;
15515
15516 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15517 memory_info.allocationSize = memory_reqs.size;
15518 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15519 ASSERT_TRUE(pass);
15520
15521 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15522 ASSERT_VK_SUCCESS(err);
15523 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15524 ASSERT_VK_SUCCESS(err);
15525
15526 VkDescriptorPoolSize ds_type_count = {};
15527 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15528 ds_type_count.descriptorCount = 1;
15529
15530 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15531 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15532 ds_pool_ci.pNext = NULL;
15533 ds_pool_ci.maxSets = 1;
15534 ds_pool_ci.poolSizeCount = 1;
15535 ds_pool_ci.pPoolSizes = &ds_type_count;
15536
15537 VkDescriptorPool ds_pool;
15538 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15539 ASSERT_VK_SUCCESS(err);
15540
15541 VkDescriptorSetLayoutBinding dsl_binding = {};
15542 dsl_binding.binding = 0;
15543 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15544 dsl_binding.descriptorCount = 1;
15545 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15546 dsl_binding.pImmutableSamplers = NULL;
15547
15548 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15549 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15550 ds_layout_ci.pNext = NULL;
15551 ds_layout_ci.bindingCount = 1;
15552 ds_layout_ci.pBindings = &dsl_binding;
15553 VkDescriptorSetLayout ds_layout;
15554 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15555 ASSERT_VK_SUCCESS(err);
15556
15557 VkDescriptorSet descriptor_set;
15558 VkDescriptorSetAllocateInfo alloc_info = {};
15559 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15560 alloc_info.descriptorSetCount = 1;
15561 alloc_info.descriptorPool = ds_pool;
15562 alloc_info.pSetLayouts = &ds_layout;
15563 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15564 ASSERT_VK_SUCCESS(err);
15565
15566 VkDescriptorBufferInfo buffer_info = {};
15567 buffer_info.buffer = buffer;
15568 buffer_info.offset = 0;
15569 buffer_info.range = 1024;
15570
15571 VkWriteDescriptorSet descriptor_write;
15572 memset(&descriptor_write, 0, sizeof(descriptor_write));
15573 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15574 descriptor_write.dstSet = descriptor_set;
15575 descriptor_write.dstBinding = 0;
15576 descriptor_write.descriptorCount = 1;
15577 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15578 descriptor_write.pBufferInfo = &buffer_info;
15579
15580 // Set pImageInfo and pTexelBufferView to invalid values, which should
15581 // be
15582 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15583 // This will most likely produce a crash if the parameter_validation
15584 // layer
15585 // does not correctly ignore pImageInfo.
15586 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15587 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15588
15589 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15590
15591 m_errorMonitor->VerifyNotFound();
15592
15593 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15594 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15595 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15596 vkDestroyBuffer(m_device->device(), buffer, NULL);
15597 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15598 }
15599
15600 // Texel Buffer Case
15601 {
15602 m_errorMonitor->ExpectSuccess();
15603
15604 VkBuffer buffer;
15605 uint32_t queue_family_index = 0;
15606 VkBufferCreateInfo buffer_create_info = {};
15607 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15608 buffer_create_info.size = 1024;
15609 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15610 buffer_create_info.queueFamilyIndexCount = 1;
15611 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15612
15613 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15614 ASSERT_VK_SUCCESS(err);
15615
15616 VkMemoryRequirements memory_reqs;
15617 VkDeviceMemory buffer_memory;
15618 bool pass;
15619 VkMemoryAllocateInfo memory_info = {};
15620 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15621 memory_info.pNext = NULL;
15622 memory_info.allocationSize = 0;
15623 memory_info.memoryTypeIndex = 0;
15624
15625 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15626 memory_info.allocationSize = memory_reqs.size;
15627 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15628 ASSERT_TRUE(pass);
15629
15630 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15631 ASSERT_VK_SUCCESS(err);
15632 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15633 ASSERT_VK_SUCCESS(err);
15634
15635 VkBufferViewCreateInfo buff_view_ci = {};
15636 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15637 buff_view_ci.buffer = buffer;
15638 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15639 buff_view_ci.range = VK_WHOLE_SIZE;
15640 VkBufferView buffer_view;
15641 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15642
15643 VkDescriptorPoolSize ds_type_count = {};
15644 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15645 ds_type_count.descriptorCount = 1;
15646
15647 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15648 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15649 ds_pool_ci.pNext = NULL;
15650 ds_pool_ci.maxSets = 1;
15651 ds_pool_ci.poolSizeCount = 1;
15652 ds_pool_ci.pPoolSizes = &ds_type_count;
15653
15654 VkDescriptorPool ds_pool;
15655 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15656 ASSERT_VK_SUCCESS(err);
15657
15658 VkDescriptorSetLayoutBinding dsl_binding = {};
15659 dsl_binding.binding = 0;
15660 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15661 dsl_binding.descriptorCount = 1;
15662 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15663 dsl_binding.pImmutableSamplers = NULL;
15664
15665 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15666 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15667 ds_layout_ci.pNext = NULL;
15668 ds_layout_ci.bindingCount = 1;
15669 ds_layout_ci.pBindings = &dsl_binding;
15670 VkDescriptorSetLayout ds_layout;
15671 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15672 ASSERT_VK_SUCCESS(err);
15673
15674 VkDescriptorSet descriptor_set;
15675 VkDescriptorSetAllocateInfo alloc_info = {};
15676 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15677 alloc_info.descriptorSetCount = 1;
15678 alloc_info.descriptorPool = ds_pool;
15679 alloc_info.pSetLayouts = &ds_layout;
15680 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15681 ASSERT_VK_SUCCESS(err);
15682
15683 VkWriteDescriptorSet descriptor_write;
15684 memset(&descriptor_write, 0, sizeof(descriptor_write));
15685 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15686 descriptor_write.dstSet = descriptor_set;
15687 descriptor_write.dstBinding = 0;
15688 descriptor_write.descriptorCount = 1;
15689 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15690 descriptor_write.pTexelBufferView = &buffer_view;
15691
15692 // Set pImageInfo and pBufferInfo to invalid values, which should be
15693 // ignored for descriptorType ==
15694 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15695 // This will most likely produce a crash if the parameter_validation
15696 // layer
15697 // does not correctly ignore pImageInfo and pBufferInfo.
15698 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15699 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15700
15701 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15702
15703 m_errorMonitor->VerifyNotFound();
15704
15705 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15706 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15707 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15708 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15709 vkDestroyBuffer(m_device->device(), buffer, NULL);
15710 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15711 }
15712}
15713
Tobin Ehlisf7428442016-10-25 07:58:24 -060015714TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15715 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15716
15717 ASSERT_NO_FATAL_FAILURE(InitState());
15718 // Create layout where two binding #s are "1"
15719 static const uint32_t NUM_BINDINGS = 3;
15720 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15721 dsl_binding[0].binding = 1;
15722 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15723 dsl_binding[0].descriptorCount = 1;
15724 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15725 dsl_binding[0].pImmutableSamplers = NULL;
15726 dsl_binding[1].binding = 0;
15727 dsl_binding[1].descriptorCount = 1;
15728 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15729 dsl_binding[1].descriptorCount = 1;
15730 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15731 dsl_binding[1].pImmutableSamplers = NULL;
15732 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15733 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15734 dsl_binding[2].descriptorCount = 1;
15735 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15736 dsl_binding[2].pImmutableSamplers = NULL;
15737
15738 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15739 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15740 ds_layout_ci.pNext = NULL;
15741 ds_layout_ci.bindingCount = NUM_BINDINGS;
15742 ds_layout_ci.pBindings = dsl_binding;
15743 VkDescriptorSetLayout ds_layout;
15744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15745 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15746 m_errorMonitor->VerifyFound();
15747}
15748
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015749TEST_F(VkLayerTest, ViewportBoundsChecking) {
15750 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
15751
15752 ASSERT_NO_FATAL_FAILURE(InitState());
15753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15754
15755 char const *vsSource = "#version 450\n"
15756 "void main() { gl_Position = vec4(1); }\n";
15757 char const *fsSource = "#version 450\n"
15758 "layout(location=0) out vec4 color;\n"
15759 "void main() { color = vec4(1); }\n";
15760
15761 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15762 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15763
15764 VkPipelineObj pipe(m_device);
15765 pipe.AddShader(&vs);
15766 pipe.AddShader(&fs);
15767 pipe.AddColorAttachment();
15768
15769 VkDescriptorSetObj descriptorSet(m_device);
15770 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15771 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15772 ASSERT_VK_SUCCESS(err);
15773
15774 BeginCommandBuffer();
15775 m_commandBuffer->BindPipeline(pipe);
15776
15777 VkViewport viewport = {0, 0, 16, 16, 0, 1};
15778 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15779
15780 {
15781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15782 VkRect2D scissor = {{-1, 0}, {16, 16}};
15783 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15784 m_errorMonitor->VerifyFound();
15785 }
15786
15787 {
15788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15789 VkRect2D scissor = {{0, -2}, {16, 16}};
15790 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15791 m_errorMonitor->VerifyFound();
15792 }
15793
15794 {
15795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
15796 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
15797 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15798 m_errorMonitor->VerifyFound();
15799 }
15800
15801 {
15802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
15803 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
15804 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15805 m_errorMonitor->VerifyFound();
15806 }
15807
15808 EndCommandBuffer();
15809}
15810
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015811// This is a positive test. No failures are expected.
15812TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
15813 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
15814 VkResult err;
15815
15816 ASSERT_NO_FATAL_FAILURE(InitState());
15817 m_errorMonitor->ExpectSuccess();
15818 VkDescriptorPoolSize ds_type_count = {};
15819 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15820 ds_type_count.descriptorCount = 2;
15821
15822 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15823 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15824 ds_pool_ci.pNext = NULL;
15825 ds_pool_ci.maxSets = 1;
15826 ds_pool_ci.poolSizeCount = 1;
15827 ds_pool_ci.pPoolSizes = &ds_type_count;
15828
15829 VkDescriptorPool ds_pool;
15830 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15831 ASSERT_VK_SUCCESS(err);
15832
15833 // Create layout with two uniform buffer descriptors w/ empty binding between them
15834 static const uint32_t NUM_BINDINGS = 3;
15835 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15836 dsl_binding[0].binding = 0;
15837 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15838 dsl_binding[0].descriptorCount = 1;
15839 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
15840 dsl_binding[0].pImmutableSamplers = NULL;
15841 dsl_binding[1].binding = 1;
15842 dsl_binding[1].descriptorCount = 0; // empty binding
15843 dsl_binding[2].binding = 2;
15844 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15845 dsl_binding[2].descriptorCount = 1;
15846 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
15847 dsl_binding[2].pImmutableSamplers = NULL;
15848
15849 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15850 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15851 ds_layout_ci.pNext = NULL;
15852 ds_layout_ci.bindingCount = NUM_BINDINGS;
15853 ds_layout_ci.pBindings = dsl_binding;
15854 VkDescriptorSetLayout ds_layout;
15855 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15856 ASSERT_VK_SUCCESS(err);
15857
15858 VkDescriptorSet descriptor_set = {};
15859 VkDescriptorSetAllocateInfo alloc_info = {};
15860 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15861 alloc_info.descriptorSetCount = 1;
15862 alloc_info.descriptorPool = ds_pool;
15863 alloc_info.pSetLayouts = &ds_layout;
15864 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15865 ASSERT_VK_SUCCESS(err);
15866
15867 // Create a buffer to be used for update
15868 VkBufferCreateInfo buff_ci = {};
15869 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15870 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15871 buff_ci.size = 256;
15872 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15873 VkBuffer buffer;
15874 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
15875 ASSERT_VK_SUCCESS(err);
15876 // Have to bind memory to buffer before descriptor update
15877 VkMemoryAllocateInfo mem_alloc = {};
15878 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15879 mem_alloc.pNext = NULL;
15880 mem_alloc.allocationSize = 512; // one allocation for both buffers
15881 mem_alloc.memoryTypeIndex = 0;
15882
15883 VkMemoryRequirements mem_reqs;
15884 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15885 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
15886 if (!pass) {
15887 vkDestroyBuffer(m_device->device(), buffer, NULL);
15888 return;
15889 }
15890
15891 VkDeviceMemory mem;
15892 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
15893 ASSERT_VK_SUCCESS(err);
15894 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
15895 ASSERT_VK_SUCCESS(err);
15896
15897 // Only update the descriptor at binding 2
15898 VkDescriptorBufferInfo buff_info = {};
15899 buff_info.buffer = buffer;
15900 buff_info.offset = 0;
15901 buff_info.range = VK_WHOLE_SIZE;
15902 VkWriteDescriptorSet descriptor_write = {};
15903 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15904 descriptor_write.dstBinding = 2;
15905 descriptor_write.descriptorCount = 1;
15906 descriptor_write.pTexelBufferView = nullptr;
15907 descriptor_write.pBufferInfo = &buff_info;
15908 descriptor_write.pImageInfo = nullptr;
15909 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15910 descriptor_write.dstSet = descriptor_set;
15911
15912 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15913
15914 m_errorMonitor->VerifyNotFound();
15915 // Cleanup
15916 vkFreeMemory(m_device->device(), mem, NULL);
15917 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15918 vkDestroyBuffer(m_device->device(), buffer, NULL);
15919 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15920}
15921
15922// This is a positive test. No failures are expected.
15923TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
15924 VkResult err;
15925 bool pass;
15926
15927 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
15928 "the buffer, create an image, and bind the same memory to "
15929 "it");
15930
15931 m_errorMonitor->ExpectSuccess();
15932
15933 ASSERT_NO_FATAL_FAILURE(InitState());
15934
15935 VkBuffer buffer;
15936 VkImage image;
15937 VkDeviceMemory mem;
15938 VkMemoryRequirements mem_reqs;
15939
15940 VkBufferCreateInfo buf_info = {};
15941 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15942 buf_info.pNext = NULL;
15943 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15944 buf_info.size = 256;
15945 buf_info.queueFamilyIndexCount = 0;
15946 buf_info.pQueueFamilyIndices = NULL;
15947 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15948 buf_info.flags = 0;
15949 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
15950 ASSERT_VK_SUCCESS(err);
15951
15952 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15953
15954 VkMemoryAllocateInfo alloc_info = {};
15955 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15956 alloc_info.pNext = NULL;
15957 alloc_info.memoryTypeIndex = 0;
15958
15959 // Ensure memory is big enough for both bindings
15960 alloc_info.allocationSize = 0x10000;
15961
15962 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
15963 if (!pass) {
15964 vkDestroyBuffer(m_device->device(), buffer, NULL);
15965 return;
15966 }
15967
15968 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
15969 ASSERT_VK_SUCCESS(err);
15970
15971 uint8_t *pData;
15972 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
15973 ASSERT_VK_SUCCESS(err);
15974
15975 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
15976
15977 vkUnmapMemory(m_device->device(), mem);
15978
15979 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
15980 ASSERT_VK_SUCCESS(err);
15981
15982 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
15983 // memory. In fact, it was never used by the GPU.
15984 // Just be be sure, wait for idle.
15985 vkDestroyBuffer(m_device->device(), buffer, NULL);
15986 vkDeviceWaitIdle(m_device->device());
15987
15988 VkImageCreateInfo image_create_info = {};
15989 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15990 image_create_info.pNext = NULL;
15991 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15992 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
15993 image_create_info.extent.width = 64;
15994 image_create_info.extent.height = 64;
15995 image_create_info.extent.depth = 1;
15996 image_create_info.mipLevels = 1;
15997 image_create_info.arrayLayers = 1;
15998 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15999 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16000 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16001 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16002 image_create_info.queueFamilyIndexCount = 0;
16003 image_create_info.pQueueFamilyIndices = NULL;
16004 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16005 image_create_info.flags = 0;
16006
16007 VkMemoryAllocateInfo mem_alloc = {};
16008 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16009 mem_alloc.pNext = NULL;
16010 mem_alloc.allocationSize = 0;
16011 mem_alloc.memoryTypeIndex = 0;
16012
16013 /* Create a mappable image. It will be the texture if linear images are ok
16014 * to be textures or it will be the staging image if they are not.
16015 */
16016 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16017 ASSERT_VK_SUCCESS(err);
16018
16019 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16020
16021 mem_alloc.allocationSize = mem_reqs.size;
16022
16023 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16024 if (!pass) {
16025 vkDestroyImage(m_device->device(), image, NULL);
16026 return;
16027 }
16028
16029 // VALIDATION FAILURE:
16030 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16031 ASSERT_VK_SUCCESS(err);
16032
16033 m_errorMonitor->VerifyNotFound();
16034
16035 vkFreeMemory(m_device->device(), mem, NULL);
16036 vkDestroyBuffer(m_device->device(), buffer, NULL);
16037 vkDestroyImage(m_device->device(), image, NULL);
16038}
16039
16040TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16041
16042 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16043 "mapping while using VK_WHOLE_SIZE does not cause access "
16044 "violations");
16045 VkResult err;
16046 uint8_t *pData;
16047 ASSERT_NO_FATAL_FAILURE(InitState());
16048
16049 VkDeviceMemory mem;
16050 VkMemoryRequirements mem_reqs;
16051 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16052 VkMemoryAllocateInfo alloc_info = {};
16053 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16054 alloc_info.pNext = NULL;
16055 alloc_info.memoryTypeIndex = 0;
16056
16057 static const VkDeviceSize allocation_size = 0x1000;
16058 alloc_info.allocationSize = allocation_size;
16059
16060 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16061 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16062 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16063 if (!pass) {
16064 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16065 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16066 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16067 if (!pass) {
16068 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16069 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16070 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16071 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16072 if (!pass) {
16073 return;
16074 }
16075 }
16076 }
16077
16078 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16079 ASSERT_VK_SUCCESS(err);
16080
16081 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16082 // mapped range
16083 m_errorMonitor->ExpectSuccess();
16084 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16085 ASSERT_VK_SUCCESS(err);
16086 VkMappedMemoryRange mmr = {};
16087 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16088 mmr.memory = mem;
16089 mmr.offset = 0;
16090 mmr.size = VK_WHOLE_SIZE;
16091 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16092 ASSERT_VK_SUCCESS(err);
16093 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16094 ASSERT_VK_SUCCESS(err);
16095 m_errorMonitor->VerifyNotFound();
16096 vkUnmapMemory(m_device->device(), mem);
16097
16098 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16099 // mapped range
16100 m_errorMonitor->ExpectSuccess();
16101 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16102 ASSERT_VK_SUCCESS(err);
16103 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16104 mmr.memory = mem;
16105 mmr.offset = 13;
16106 mmr.size = VK_WHOLE_SIZE;
16107 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16108 ASSERT_VK_SUCCESS(err);
16109 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16110 ASSERT_VK_SUCCESS(err);
16111 m_errorMonitor->VerifyNotFound();
16112 vkUnmapMemory(m_device->device(), mem);
16113
16114 // Map with prime offset and size
16115 // Flush/Invalidate subrange of mapped area with prime offset and size
16116 m_errorMonitor->ExpectSuccess();
16117 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16118 ASSERT_VK_SUCCESS(err);
16119 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16120 mmr.memory = mem;
16121 mmr.offset = allocation_size - 107;
16122 mmr.size = 61;
16123 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16124 ASSERT_VK_SUCCESS(err);
16125 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16126 ASSERT_VK_SUCCESS(err);
16127 m_errorMonitor->VerifyNotFound();
16128 vkUnmapMemory(m_device->device(), mem);
16129
16130 // Map without offset and flush WHOLE_SIZE with two separate offsets
16131 m_errorMonitor->ExpectSuccess();
16132 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16133 ASSERT_VK_SUCCESS(err);
16134 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16135 mmr.memory = mem;
16136 mmr.offset = allocation_size - 100;
16137 mmr.size = VK_WHOLE_SIZE;
16138 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16139 ASSERT_VK_SUCCESS(err);
16140 mmr.offset = allocation_size - 200;
16141 mmr.size = VK_WHOLE_SIZE;
16142 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16143 ASSERT_VK_SUCCESS(err);
16144 m_errorMonitor->VerifyNotFound();
16145 vkUnmapMemory(m_device->device(), mem);
16146
16147 vkFreeMemory(m_device->device(), mem, NULL);
16148}
16149
16150// This is a positive test. We used to expect error in this case but spec now allows it
16151TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16152 m_errorMonitor->ExpectSuccess();
16153 vk_testing::Fence testFence;
16154 VkFenceCreateInfo fenceInfo = {};
16155 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16156 fenceInfo.pNext = NULL;
16157
16158 ASSERT_NO_FATAL_FAILURE(InitState());
16159 testFence.init(*m_device, fenceInfo);
16160 VkFence fences[1] = { testFence.handle() };
16161 VkResult result = vkResetFences(m_device->device(), 1, fences);
16162 ASSERT_VK_SUCCESS(result);
16163
16164 m_errorMonitor->VerifyNotFound();
16165}
16166
16167TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16168 m_errorMonitor->ExpectSuccess();
16169
16170 ASSERT_NO_FATAL_FAILURE(InitState());
16171 VkResult err;
16172
16173 // Record (empty!) command buffer that can be submitted multiple times
16174 // simultaneously.
16175 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16176 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16177 m_commandBuffer->BeginCommandBuffer(&cbbi);
16178 m_commandBuffer->EndCommandBuffer();
16179
16180 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16181 VkFence fence;
16182 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16183 ASSERT_VK_SUCCESS(err);
16184
16185 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16186 VkSemaphore s1, s2;
16187 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16188 ASSERT_VK_SUCCESS(err);
16189 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16190 ASSERT_VK_SUCCESS(err);
16191
16192 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16193 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16194 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16195 ASSERT_VK_SUCCESS(err);
16196
16197 // Submit CB again, signaling s2.
16198 si.pSignalSemaphores = &s2;
16199 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16200 ASSERT_VK_SUCCESS(err);
16201
16202 // Wait for fence.
16203 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16204 ASSERT_VK_SUCCESS(err);
16205
16206 // CB is still in flight from second submission, but semaphore s1 is no
16207 // longer in flight. delete it.
16208 vkDestroySemaphore(m_device->device(), s1, nullptr);
16209
16210 m_errorMonitor->VerifyNotFound();
16211
16212 // Force device idle and clean up remaining objects
16213 vkDeviceWaitIdle(m_device->device());
16214 vkDestroySemaphore(m_device->device(), s2, nullptr);
16215 vkDestroyFence(m_device->device(), fence, nullptr);
16216}
16217
16218TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16219 m_errorMonitor->ExpectSuccess();
16220
16221 ASSERT_NO_FATAL_FAILURE(InitState());
16222 VkResult err;
16223
16224 // A fence created signaled
16225 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16226 VkFence f1;
16227 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16228 ASSERT_VK_SUCCESS(err);
16229
16230 // A fence created not
16231 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16232 VkFence f2;
16233 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16234 ASSERT_VK_SUCCESS(err);
16235
16236 // Submit the unsignaled fence
16237 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16238 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16239
16240 // Wait on both fences, with signaled first.
16241 VkFence fences[] = { f1, f2 };
16242 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16243
16244 // Should have both retired!
16245 vkDestroyFence(m_device->device(), f1, nullptr);
16246 vkDestroyFence(m_device->device(), f2, nullptr);
16247
16248 m_errorMonitor->VerifyNotFound();
16249}
16250
16251TEST_F(VkPositiveLayerTest, ValidUsage) {
16252 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16253 "doesn't generate validation errors");
16254
16255 ASSERT_NO_FATAL_FAILURE(InitState());
16256
16257 m_errorMonitor->ExpectSuccess();
16258 // Verify that we can create a view with usage INPUT_ATTACHMENT
16259 VkImageObj image(m_device);
16260 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16261 ASSERT_TRUE(image.initialized());
16262 VkImageView imageView;
16263 VkImageViewCreateInfo ivci = {};
16264 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16265 ivci.image = image.handle();
16266 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16267 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16268 ivci.subresourceRange.layerCount = 1;
16269 ivci.subresourceRange.baseMipLevel = 0;
16270 ivci.subresourceRange.levelCount = 1;
16271 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16272
16273 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16274 m_errorMonitor->VerifyNotFound();
16275 vkDestroyImageView(m_device->device(), imageView, NULL);
16276}
16277
16278// This is a positive test. No failures are expected.
16279TEST_F(VkPositiveLayerTest, BindSparse) {
16280 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16281 "and then free the memory");
16282
16283 ASSERT_NO_FATAL_FAILURE(InitState());
16284
16285 auto index = m_device->graphics_queue_node_index_;
16286 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16287 return;
16288
16289 m_errorMonitor->ExpectSuccess();
16290
16291 VkImage image;
16292 VkImageCreateInfo image_create_info = {};
16293 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16294 image_create_info.pNext = NULL;
16295 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16296 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16297 image_create_info.extent.width = 64;
16298 image_create_info.extent.height = 64;
16299 image_create_info.extent.depth = 1;
16300 image_create_info.mipLevels = 1;
16301 image_create_info.arrayLayers = 1;
16302 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16303 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16304 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16305 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16306 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16307 ASSERT_VK_SUCCESS(err);
16308
16309 VkMemoryRequirements memory_reqs;
16310 VkDeviceMemory memory_one, memory_two;
16311 bool pass;
16312 VkMemoryAllocateInfo memory_info = {};
16313 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16314 memory_info.pNext = NULL;
16315 memory_info.allocationSize = 0;
16316 memory_info.memoryTypeIndex = 0;
16317 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16318 // Find an image big enough to allow sparse mapping of 2 memory regions
16319 // Increase the image size until it is at least twice the
16320 // size of the required alignment, to ensure we can bind both
16321 // allocated memory blocks to the image on aligned offsets.
16322 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16323 vkDestroyImage(m_device->device(), image, nullptr);
16324 image_create_info.extent.width *= 2;
16325 image_create_info.extent.height *= 2;
16326 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16327 ASSERT_VK_SUCCESS(err);
16328 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16329 }
16330 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16331 // at the end of the first
16332 memory_info.allocationSize = memory_reqs.alignment;
16333 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16334 ASSERT_TRUE(pass);
16335 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16336 ASSERT_VK_SUCCESS(err);
16337 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16338 ASSERT_VK_SUCCESS(err);
16339 VkSparseMemoryBind binds[2];
16340 binds[0].flags = 0;
16341 binds[0].memory = memory_one;
16342 binds[0].memoryOffset = 0;
16343 binds[0].resourceOffset = 0;
16344 binds[0].size = memory_info.allocationSize;
16345 binds[1].flags = 0;
16346 binds[1].memory = memory_two;
16347 binds[1].memoryOffset = 0;
16348 binds[1].resourceOffset = memory_info.allocationSize;
16349 binds[1].size = memory_info.allocationSize;
16350
16351 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16352 opaqueBindInfo.image = image;
16353 opaqueBindInfo.bindCount = 2;
16354 opaqueBindInfo.pBinds = binds;
16355
16356 VkFence fence = VK_NULL_HANDLE;
16357 VkBindSparseInfo bindSparseInfo = {};
16358 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16359 bindSparseInfo.imageOpaqueBindCount = 1;
16360 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16361
16362 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16363 vkQueueWaitIdle(m_device->m_queue);
16364 vkDestroyImage(m_device->device(), image, NULL);
16365 vkFreeMemory(m_device->device(), memory_one, NULL);
16366 vkFreeMemory(m_device->device(), memory_two, NULL);
16367 m_errorMonitor->VerifyNotFound();
16368}
16369
16370TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16371 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16372 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16373 "the command buffer has prior knowledge of that "
16374 "attachment's layout.");
16375
16376 m_errorMonitor->ExpectSuccess();
16377
16378 ASSERT_NO_FATAL_FAILURE(InitState());
16379
16380 // A renderpass with one color attachment.
16381 VkAttachmentDescription attachment = { 0,
16382 VK_FORMAT_R8G8B8A8_UNORM,
16383 VK_SAMPLE_COUNT_1_BIT,
16384 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16385 VK_ATTACHMENT_STORE_OP_STORE,
16386 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16387 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16388 VK_IMAGE_LAYOUT_UNDEFINED,
16389 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16390
16391 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16392
16393 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16394
16395 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16396
16397 VkRenderPass rp;
16398 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16399 ASSERT_VK_SUCCESS(err);
16400
16401 // A compatible framebuffer.
16402 VkImageObj image(m_device);
16403 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16404 ASSERT_TRUE(image.initialized());
16405
16406 VkImageViewCreateInfo ivci = {
16407 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16408 nullptr,
16409 0,
16410 image.handle(),
16411 VK_IMAGE_VIEW_TYPE_2D,
16412 VK_FORMAT_R8G8B8A8_UNORM,
16413 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16414 VK_COMPONENT_SWIZZLE_IDENTITY },
16415 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16416 };
16417 VkImageView view;
16418 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16419 ASSERT_VK_SUCCESS(err);
16420
16421 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16422 VkFramebuffer fb;
16423 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16424 ASSERT_VK_SUCCESS(err);
16425
16426 // Record a single command buffer which uses this renderpass twice. The
16427 // bug is triggered at the beginning of the second renderpass, when the
16428 // command buffer already has a layout recorded for the attachment.
16429 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16430 BeginCommandBuffer();
16431 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16432 vkCmdEndRenderPass(m_commandBuffer->handle());
16433 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16434
16435 m_errorMonitor->VerifyNotFound();
16436
16437 vkCmdEndRenderPass(m_commandBuffer->handle());
16438 EndCommandBuffer();
16439
16440 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16441 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16442 vkDestroyImageView(m_device->device(), view, nullptr);
16443}
16444
16445TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16446 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16447 "command buffer, bind them together, then destroy "
16448 "command pool and framebuffer and verify there are no "
16449 "errors.");
16450
16451 m_errorMonitor->ExpectSuccess();
16452
16453 ASSERT_NO_FATAL_FAILURE(InitState());
16454
16455 // A renderpass with one color attachment.
16456 VkAttachmentDescription attachment = { 0,
16457 VK_FORMAT_R8G8B8A8_UNORM,
16458 VK_SAMPLE_COUNT_1_BIT,
16459 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16460 VK_ATTACHMENT_STORE_OP_STORE,
16461 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16462 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16463 VK_IMAGE_LAYOUT_UNDEFINED,
16464 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16465
16466 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16467
16468 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16469
16470 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16471
16472 VkRenderPass rp;
16473 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16474 ASSERT_VK_SUCCESS(err);
16475
16476 // A compatible framebuffer.
16477 VkImageObj image(m_device);
16478 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16479 ASSERT_TRUE(image.initialized());
16480
16481 VkImageViewCreateInfo ivci = {
16482 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16483 nullptr,
16484 0,
16485 image.handle(),
16486 VK_IMAGE_VIEW_TYPE_2D,
16487 VK_FORMAT_R8G8B8A8_UNORM,
16488 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16489 VK_COMPONENT_SWIZZLE_IDENTITY },
16490 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16491 };
16492 VkImageView view;
16493 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16494 ASSERT_VK_SUCCESS(err);
16495
16496 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16497 VkFramebuffer fb;
16498 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16499 ASSERT_VK_SUCCESS(err);
16500
16501 // Explicitly create a command buffer to bind the FB to so that we can then
16502 // destroy the command pool in order to implicitly free command buffer
16503 VkCommandPool command_pool;
16504 VkCommandPoolCreateInfo pool_create_info{};
16505 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16506 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16507 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16508 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16509
16510 VkCommandBuffer command_buffer;
16511 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16512 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16513 command_buffer_allocate_info.commandPool = command_pool;
16514 command_buffer_allocate_info.commandBufferCount = 1;
16515 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16516 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16517
16518 // Begin our cmd buffer with renderpass using our framebuffer
16519 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16520 VkCommandBufferBeginInfo begin_info{};
16521 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16522 vkBeginCommandBuffer(command_buffer, &begin_info);
16523
16524 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16525 vkCmdEndRenderPass(command_buffer);
16526 vkEndCommandBuffer(command_buffer);
16527 vkDestroyImageView(m_device->device(), view, nullptr);
16528 // Destroy command pool to implicitly free command buffer
16529 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16530 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16531 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16532 m_errorMonitor->VerifyNotFound();
16533}
16534
16535TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16536 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16537 "transitions for the first subpass");
16538
16539 m_errorMonitor->ExpectSuccess();
16540
16541 ASSERT_NO_FATAL_FAILURE(InitState());
16542
16543 // A renderpass with one color attachment.
16544 VkAttachmentDescription attachment = { 0,
16545 VK_FORMAT_R8G8B8A8_UNORM,
16546 VK_SAMPLE_COUNT_1_BIT,
16547 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16548 VK_ATTACHMENT_STORE_OP_STORE,
16549 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16550 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16551 VK_IMAGE_LAYOUT_UNDEFINED,
16552 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16553
16554 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16555
16556 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16557
16558 VkSubpassDependency dep = { 0,
16559 0,
16560 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16561 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16562 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16563 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16564 VK_DEPENDENCY_BY_REGION_BIT };
16565
16566 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16567
16568 VkResult err;
16569 VkRenderPass rp;
16570 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16571 ASSERT_VK_SUCCESS(err);
16572
16573 // A compatible framebuffer.
16574 VkImageObj image(m_device);
16575 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16576 ASSERT_TRUE(image.initialized());
16577
16578 VkImageViewCreateInfo ivci = {
16579 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16580 nullptr,
16581 0,
16582 image.handle(),
16583 VK_IMAGE_VIEW_TYPE_2D,
16584 VK_FORMAT_R8G8B8A8_UNORM,
16585 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16586 VK_COMPONENT_SWIZZLE_IDENTITY },
16587 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16588 };
16589 VkImageView view;
16590 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16591 ASSERT_VK_SUCCESS(err);
16592
16593 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16594 VkFramebuffer fb;
16595 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16596 ASSERT_VK_SUCCESS(err);
16597
16598 // Record a single command buffer which issues a pipeline barrier w/
16599 // image memory barrier for the attachment. This detects the previously
16600 // missing tracking of the subpass layout by throwing a validation error
16601 // if it doesn't occur.
16602 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16603 BeginCommandBuffer();
16604 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16605
16606 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
16607 nullptr,
16608 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16609 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16610 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16611 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16612 VK_QUEUE_FAMILY_IGNORED,
16613 VK_QUEUE_FAMILY_IGNORED,
16614 image.handle(),
16615 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
16616 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16617 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16618 &imb);
16619
16620 vkCmdEndRenderPass(m_commandBuffer->handle());
16621 m_errorMonitor->VerifyNotFound();
16622 EndCommandBuffer();
16623
16624 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16625 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16626 vkDestroyImageView(m_device->device(), view, nullptr);
16627}
16628
16629TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
16630 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
16631 "is used as a depth/stencil framebuffer attachment, the "
16632 "aspectMask is ignored and both depth and stencil image "
16633 "subresources are used.");
16634
16635 VkFormatProperties format_properties;
16636 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
16637 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
16638 return;
16639 }
16640
16641 m_errorMonitor->ExpectSuccess();
16642
16643 ASSERT_NO_FATAL_FAILURE(InitState());
16644
16645 VkAttachmentDescription attachment = { 0,
16646 VK_FORMAT_D32_SFLOAT_S8_UINT,
16647 VK_SAMPLE_COUNT_1_BIT,
16648 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16649 VK_ATTACHMENT_STORE_OP_STORE,
16650 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16651 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16652 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
16653 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16654
16655 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16656
16657 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
16658
16659 VkSubpassDependency dep = { 0,
16660 0,
16661 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16662 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16663 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16664 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16665 VK_DEPENDENCY_BY_REGION_BIT};
16666
16667 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16668
16669 VkResult err;
16670 VkRenderPass rp;
16671 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16672 ASSERT_VK_SUCCESS(err);
16673
16674 VkImageObj image(m_device);
16675 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
16676 0x26, // usage
16677 VK_IMAGE_TILING_OPTIMAL, 0);
16678 ASSERT_TRUE(image.initialized());
16679 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
16680
16681 VkImageViewCreateInfo ivci = {
16682 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16683 nullptr,
16684 0,
16685 image.handle(),
16686 VK_IMAGE_VIEW_TYPE_2D,
16687 VK_FORMAT_D32_SFLOAT_S8_UINT,
16688 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
16689 { 0x2, 0, 1, 0, 1 },
16690 };
16691 VkImageView view;
16692 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16693 ASSERT_VK_SUCCESS(err);
16694
16695 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16696 VkFramebuffer fb;
16697 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16698 ASSERT_VK_SUCCESS(err);
16699
16700 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16701 BeginCommandBuffer();
16702 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16703
16704 VkImageMemoryBarrier imb = {};
16705 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16706 imb.pNext = nullptr;
16707 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16708 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16709 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16710 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16711 imb.srcQueueFamilyIndex = 0;
16712 imb.dstQueueFamilyIndex = 0;
16713 imb.image = image.handle();
16714 imb.subresourceRange.aspectMask = 0x6;
16715 imb.subresourceRange.baseMipLevel = 0;
16716 imb.subresourceRange.levelCount = 0x1;
16717 imb.subresourceRange.baseArrayLayer = 0;
16718 imb.subresourceRange.layerCount = 0x1;
16719
16720 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16721 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16722 &imb);
16723
16724 vkCmdEndRenderPass(m_commandBuffer->handle());
16725 EndCommandBuffer();
16726 QueueCommandBuffer(false);
16727 m_errorMonitor->VerifyNotFound();
16728
16729 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16730 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16731 vkDestroyImageView(m_device->device(), view, nullptr);
16732}
16733
16734TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
16735 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
16736 "errors, when an attachment reference is "
16737 "VK_ATTACHMENT_UNUSED");
16738
16739 m_errorMonitor->ExpectSuccess();
16740
16741 ASSERT_NO_FATAL_FAILURE(InitState());
16742
16743 // A renderpass with no attachments
16744 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16745
16746 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16747
16748 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
16749
16750 VkRenderPass rp;
16751 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16752 ASSERT_VK_SUCCESS(err);
16753
16754 // A compatible framebuffer.
16755 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
16756 VkFramebuffer fb;
16757 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16758 ASSERT_VK_SUCCESS(err);
16759
16760 // Record a command buffer which just begins and ends the renderpass. The
16761 // bug manifests in BeginRenderPass.
16762 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16763 BeginCommandBuffer();
16764 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16765 vkCmdEndRenderPass(m_commandBuffer->handle());
16766 m_errorMonitor->VerifyNotFound();
16767 EndCommandBuffer();
16768
16769 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16770 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16771}
16772
16773// This is a positive test. No errors are expected.
16774TEST_F(VkPositiveLayerTest, StencilLoadOp) {
16775 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
16776 "CLEAR. stencil[Load|Store]Op used to be ignored.");
16777 VkResult result = VK_SUCCESS;
16778 VkImageFormatProperties formatProps;
16779 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
16780 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
16781 &formatProps);
16782 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
16783 return;
16784 }
16785
16786 ASSERT_NO_FATAL_FAILURE(InitState());
16787 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
16788 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
16789 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
16790 VkAttachmentDescription att = {};
16791 VkAttachmentReference ref = {};
16792 att.format = depth_stencil_fmt;
16793 att.samples = VK_SAMPLE_COUNT_1_BIT;
16794 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
16795 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
16796 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
16797 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
16798 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16799 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16800
16801 VkClearValue clear;
16802 clear.depthStencil.depth = 1.0;
16803 clear.depthStencil.stencil = 0;
16804 ref.attachment = 0;
16805 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16806
16807 VkSubpassDescription subpass = {};
16808 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
16809 subpass.flags = 0;
16810 subpass.inputAttachmentCount = 0;
16811 subpass.pInputAttachments = NULL;
16812 subpass.colorAttachmentCount = 0;
16813 subpass.pColorAttachments = NULL;
16814 subpass.pResolveAttachments = NULL;
16815 subpass.pDepthStencilAttachment = &ref;
16816 subpass.preserveAttachmentCount = 0;
16817 subpass.pPreserveAttachments = NULL;
16818
16819 VkRenderPass rp;
16820 VkRenderPassCreateInfo rp_info = {};
16821 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16822 rp_info.attachmentCount = 1;
16823 rp_info.pAttachments = &att;
16824 rp_info.subpassCount = 1;
16825 rp_info.pSubpasses = &subpass;
16826 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
16827 ASSERT_VK_SUCCESS(result);
16828
16829 VkImageView *depthView = m_depthStencil->BindInfo();
16830 VkFramebufferCreateInfo fb_info = {};
16831 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
16832 fb_info.pNext = NULL;
16833 fb_info.renderPass = rp;
16834 fb_info.attachmentCount = 1;
16835 fb_info.pAttachments = depthView;
16836 fb_info.width = 100;
16837 fb_info.height = 100;
16838 fb_info.layers = 1;
16839 VkFramebuffer fb;
16840 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
16841 ASSERT_VK_SUCCESS(result);
16842
16843 VkRenderPassBeginInfo rpbinfo = {};
16844 rpbinfo.clearValueCount = 1;
16845 rpbinfo.pClearValues = &clear;
16846 rpbinfo.pNext = NULL;
16847 rpbinfo.renderPass = rp;
16848 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
16849 rpbinfo.renderArea.extent.width = 100;
16850 rpbinfo.renderArea.extent.height = 100;
16851 rpbinfo.renderArea.offset.x = 0;
16852 rpbinfo.renderArea.offset.y = 0;
16853 rpbinfo.framebuffer = fb;
16854
16855 VkFence fence = {};
16856 VkFenceCreateInfo fence_ci = {};
16857 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16858 fence_ci.pNext = nullptr;
16859 fence_ci.flags = 0;
16860 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
16861 ASSERT_VK_SUCCESS(result);
16862
16863 m_commandBuffer->BeginCommandBuffer();
16864 m_commandBuffer->BeginRenderPass(rpbinfo);
16865 m_commandBuffer->EndRenderPass();
16866 m_commandBuffer->EndCommandBuffer();
16867 m_commandBuffer->QueueCommandBuffer(fence);
16868
16869 VkImageObj destImage(m_device);
16870 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16871 VK_IMAGE_TILING_OPTIMAL, 0);
16872 VkImageMemoryBarrier barrier = {};
16873 VkImageSubresourceRange range;
16874 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16875 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16876 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
16877 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16878 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
16879 barrier.image = m_depthStencil->handle();
16880 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16881 range.baseMipLevel = 0;
16882 range.levelCount = 1;
16883 range.baseArrayLayer = 0;
16884 range.layerCount = 1;
16885 barrier.subresourceRange = range;
16886 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16887 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
16888 cmdbuf.BeginCommandBuffer();
16889 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
16890 &barrier);
16891 barrier.srcAccessMask = 0;
16892 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16893 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
16894 barrier.image = destImage.handle();
16895 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16896 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
16897 &barrier);
16898 VkImageCopy cregion;
16899 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16900 cregion.srcSubresource.mipLevel = 0;
16901 cregion.srcSubresource.baseArrayLayer = 0;
16902 cregion.srcSubresource.layerCount = 1;
16903 cregion.srcOffset.x = 0;
16904 cregion.srcOffset.y = 0;
16905 cregion.srcOffset.z = 0;
16906 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16907 cregion.dstSubresource.mipLevel = 0;
16908 cregion.dstSubresource.baseArrayLayer = 0;
16909 cregion.dstSubresource.layerCount = 1;
16910 cregion.dstOffset.x = 0;
16911 cregion.dstOffset.y = 0;
16912 cregion.dstOffset.z = 0;
16913 cregion.extent.width = 100;
16914 cregion.extent.height = 100;
16915 cregion.extent.depth = 1;
16916 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
16917 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
16918 cmdbuf.EndCommandBuffer();
16919
16920 VkSubmitInfo submit_info;
16921 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16922 submit_info.pNext = NULL;
16923 submit_info.waitSemaphoreCount = 0;
16924 submit_info.pWaitSemaphores = NULL;
16925 submit_info.pWaitDstStageMask = NULL;
16926 submit_info.commandBufferCount = 1;
16927 submit_info.pCommandBuffers = &cmdbuf.handle();
16928 submit_info.signalSemaphoreCount = 0;
16929 submit_info.pSignalSemaphores = NULL;
16930
16931 m_errorMonitor->ExpectSuccess();
16932 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16933 m_errorMonitor->VerifyNotFound();
16934
16935 vkQueueWaitIdle(m_device->m_queue);
16936 vkDestroyFence(m_device->device(), fence, nullptr);
16937 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16938 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16939}
16940
16941// This is a positive test. No errors should be generated.
16942TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
16943 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
16944
16945 m_errorMonitor->ExpectSuccess();
16946 ASSERT_NO_FATAL_FAILURE(InitState());
16947
16948 VkEvent event;
16949 VkEventCreateInfo event_create_info{};
16950 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
16951 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
16952
16953 VkCommandPool command_pool;
16954 VkCommandPoolCreateInfo pool_create_info{};
16955 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16956 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16957 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16958 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16959
16960 VkCommandBuffer command_buffer;
16961 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16962 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16963 command_buffer_allocate_info.commandPool = command_pool;
16964 command_buffer_allocate_info.commandBufferCount = 1;
16965 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16966 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16967
16968 VkQueue queue = VK_NULL_HANDLE;
16969 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
16970
16971 {
16972 VkCommandBufferBeginInfo begin_info{};
16973 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16974 vkBeginCommandBuffer(command_buffer, &begin_info);
16975
16976 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
16977 nullptr, 0, nullptr);
16978 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
16979 vkEndCommandBuffer(command_buffer);
16980 }
16981 {
16982 VkSubmitInfo submit_info{};
16983 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16984 submit_info.commandBufferCount = 1;
16985 submit_info.pCommandBuffers = &command_buffer;
16986 submit_info.signalSemaphoreCount = 0;
16987 submit_info.pSignalSemaphores = nullptr;
16988 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
16989 }
16990 { vkSetEvent(m_device->device(), event); }
16991
16992 vkQueueWaitIdle(queue);
16993
16994 vkDestroyEvent(m_device->device(), event, nullptr);
16995 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
16996 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16997
16998 m_errorMonitor->VerifyNotFound();
16999}
17000// This is a positive test. No errors should be generated.
17001TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17002 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17003
17004 ASSERT_NO_FATAL_FAILURE(InitState());
17005 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17006 return;
17007
17008 m_errorMonitor->ExpectSuccess();
17009
17010 VkQueryPool query_pool;
17011 VkQueryPoolCreateInfo query_pool_create_info{};
17012 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17013 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17014 query_pool_create_info.queryCount = 1;
17015 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17016
17017 VkCommandPool command_pool;
17018 VkCommandPoolCreateInfo pool_create_info{};
17019 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17020 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17021 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17022 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17023
17024 VkCommandBuffer command_buffer;
17025 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17026 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17027 command_buffer_allocate_info.commandPool = command_pool;
17028 command_buffer_allocate_info.commandBufferCount = 1;
17029 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17030 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17031
17032 VkCommandBuffer secondary_command_buffer;
17033 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17034 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17035
17036 VkQueue queue = VK_NULL_HANDLE;
17037 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17038
17039 uint32_t qfi = 0;
17040 VkBufferCreateInfo buff_create_info = {};
17041 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17042 buff_create_info.size = 1024;
17043 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17044 buff_create_info.queueFamilyIndexCount = 1;
17045 buff_create_info.pQueueFamilyIndices = &qfi;
17046
17047 VkResult err;
17048 VkBuffer buffer;
17049 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17050 ASSERT_VK_SUCCESS(err);
17051 VkMemoryAllocateInfo mem_alloc = {};
17052 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17053 mem_alloc.pNext = NULL;
17054 mem_alloc.allocationSize = 1024;
17055 mem_alloc.memoryTypeIndex = 0;
17056
17057 VkMemoryRequirements memReqs;
17058 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17059 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17060 if (!pass) {
17061 vkDestroyBuffer(m_device->device(), buffer, NULL);
17062 return;
17063 }
17064
17065 VkDeviceMemory mem;
17066 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17067 ASSERT_VK_SUCCESS(err);
17068 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17069 ASSERT_VK_SUCCESS(err);
17070
17071 VkCommandBufferInheritanceInfo hinfo = {};
17072 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17073 hinfo.renderPass = VK_NULL_HANDLE;
17074 hinfo.subpass = 0;
17075 hinfo.framebuffer = VK_NULL_HANDLE;
17076 hinfo.occlusionQueryEnable = VK_FALSE;
17077 hinfo.queryFlags = 0;
17078 hinfo.pipelineStatistics = 0;
17079
17080 {
17081 VkCommandBufferBeginInfo begin_info{};
17082 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17083 begin_info.pInheritanceInfo = &hinfo;
17084 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17085
17086 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17087 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17088
17089 vkEndCommandBuffer(secondary_command_buffer);
17090
17091 begin_info.pInheritanceInfo = nullptr;
17092 vkBeginCommandBuffer(command_buffer, &begin_info);
17093
17094 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17095 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17096
17097 vkEndCommandBuffer(command_buffer);
17098 }
17099 {
17100 VkSubmitInfo submit_info{};
17101 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17102 submit_info.commandBufferCount = 1;
17103 submit_info.pCommandBuffers = &command_buffer;
17104 submit_info.signalSemaphoreCount = 0;
17105 submit_info.pSignalSemaphores = nullptr;
17106 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17107 }
17108
17109 vkQueueWaitIdle(queue);
17110
17111 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17112 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17113 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17114 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17115 vkDestroyBuffer(m_device->device(), buffer, NULL);
17116 vkFreeMemory(m_device->device(), mem, NULL);
17117
17118 m_errorMonitor->VerifyNotFound();
17119}
17120
17121// This is a positive test. No errors should be generated.
17122TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17123 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17124
17125 ASSERT_NO_FATAL_FAILURE(InitState());
17126 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17127 return;
17128
17129 m_errorMonitor->ExpectSuccess();
17130
17131 VkQueryPool query_pool;
17132 VkQueryPoolCreateInfo query_pool_create_info{};
17133 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17134 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17135 query_pool_create_info.queryCount = 1;
17136 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17137
17138 VkCommandPool command_pool;
17139 VkCommandPoolCreateInfo pool_create_info{};
17140 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17141 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17142 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17143 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17144
17145 VkCommandBuffer command_buffer[2];
17146 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17147 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17148 command_buffer_allocate_info.commandPool = command_pool;
17149 command_buffer_allocate_info.commandBufferCount = 2;
17150 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17151 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17152
17153 VkQueue queue = VK_NULL_HANDLE;
17154 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17155
17156 uint32_t qfi = 0;
17157 VkBufferCreateInfo buff_create_info = {};
17158 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17159 buff_create_info.size = 1024;
17160 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17161 buff_create_info.queueFamilyIndexCount = 1;
17162 buff_create_info.pQueueFamilyIndices = &qfi;
17163
17164 VkResult err;
17165 VkBuffer buffer;
17166 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17167 ASSERT_VK_SUCCESS(err);
17168 VkMemoryAllocateInfo mem_alloc = {};
17169 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17170 mem_alloc.pNext = NULL;
17171 mem_alloc.allocationSize = 1024;
17172 mem_alloc.memoryTypeIndex = 0;
17173
17174 VkMemoryRequirements memReqs;
17175 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17176 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17177 if (!pass) {
17178 vkDestroyBuffer(m_device->device(), buffer, NULL);
17179 return;
17180 }
17181
17182 VkDeviceMemory mem;
17183 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17184 ASSERT_VK_SUCCESS(err);
17185 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17186 ASSERT_VK_SUCCESS(err);
17187
17188 {
17189 VkCommandBufferBeginInfo begin_info{};
17190 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17191 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17192
17193 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17194 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17195
17196 vkEndCommandBuffer(command_buffer[0]);
17197
17198 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17199
17200 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17201
17202 vkEndCommandBuffer(command_buffer[1]);
17203 }
17204 {
17205 VkSubmitInfo submit_info{};
17206 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17207 submit_info.commandBufferCount = 2;
17208 submit_info.pCommandBuffers = command_buffer;
17209 submit_info.signalSemaphoreCount = 0;
17210 submit_info.pSignalSemaphores = nullptr;
17211 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17212 }
17213
17214 vkQueueWaitIdle(queue);
17215
17216 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17217 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17218 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17219 vkDestroyBuffer(m_device->device(), buffer, NULL);
17220 vkFreeMemory(m_device->device(), mem, NULL);
17221
17222 m_errorMonitor->VerifyNotFound();
17223}
17224
17225TEST_F(VkPositiveLayerTest, ResetEventThenSet) {
17226 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17227
17228 m_errorMonitor->ExpectSuccess();
17229
17230 ASSERT_NO_FATAL_FAILURE(InitState());
17231 VkEvent event;
17232 VkEventCreateInfo event_create_info{};
17233 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17234 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17235
17236 VkCommandPool command_pool;
17237 VkCommandPoolCreateInfo pool_create_info{};
17238 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17239 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17240 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17241 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17242
17243 VkCommandBuffer command_buffer;
17244 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17245 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17246 command_buffer_allocate_info.commandPool = command_pool;
17247 command_buffer_allocate_info.commandBufferCount = 1;
17248 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17249 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17250
17251 VkQueue queue = VK_NULL_HANDLE;
17252 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17253
17254 {
17255 VkCommandBufferBeginInfo begin_info{};
17256 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17257 vkBeginCommandBuffer(command_buffer, &begin_info);
17258
17259 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17260 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
17261 nullptr, 0, nullptr, 0, nullptr);
17262 vkEndCommandBuffer(command_buffer);
17263 }
17264 {
17265 VkSubmitInfo submit_info{};
17266 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17267 submit_info.commandBufferCount = 1;
17268 submit_info.pCommandBuffers = &command_buffer;
17269 submit_info.signalSemaphoreCount = 0;
17270 submit_info.pSignalSemaphores = nullptr;
17271 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17272 }
17273 {
17274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17275 "command buffer.");
17276 vkSetEvent(m_device->device(), event);
17277 m_errorMonitor->VerifyFound();
17278 }
17279
17280 vkQueueWaitIdle(queue);
17281
17282 vkDestroyEvent(m_device->device(), event, nullptr);
17283 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17284 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17285}
17286
17287// This is a positive test. No errors should be generated.
17288TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17289 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17290 "run through a Submit & WaitForFences cycle 3 times. This "
17291 "previously revealed a bug so running this positive test "
17292 "to prevent a regression.");
17293 m_errorMonitor->ExpectSuccess();
17294
17295 ASSERT_NO_FATAL_FAILURE(InitState());
17296 VkQueue queue = VK_NULL_HANDLE;
17297 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17298
17299 static const uint32_t NUM_OBJECTS = 2;
17300 static const uint32_t NUM_FRAMES = 3;
17301 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17302 VkFence fences[NUM_OBJECTS] = {};
17303
17304 VkCommandPool cmd_pool;
17305 VkCommandPoolCreateInfo cmd_pool_ci = {};
17306 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17307 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17308 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17309 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17310 ASSERT_VK_SUCCESS(err);
17311
17312 VkCommandBufferAllocateInfo cmd_buf_info = {};
17313 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17314 cmd_buf_info.commandPool = cmd_pool;
17315 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17316 cmd_buf_info.commandBufferCount = 1;
17317
17318 VkFenceCreateInfo fence_ci = {};
17319 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17320 fence_ci.pNext = nullptr;
17321 fence_ci.flags = 0;
17322
17323 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17324 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17325 ASSERT_VK_SUCCESS(err);
17326 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17327 ASSERT_VK_SUCCESS(err);
17328 }
17329
17330 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17331 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17332 // Create empty cmd buffer
17333 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17334 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17335
17336 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17337 ASSERT_VK_SUCCESS(err);
17338 err = vkEndCommandBuffer(cmd_buffers[obj]);
17339 ASSERT_VK_SUCCESS(err);
17340
17341 VkSubmitInfo submit_info = {};
17342 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17343 submit_info.commandBufferCount = 1;
17344 submit_info.pCommandBuffers = &cmd_buffers[obj];
17345 // Submit cmd buffer and wait for fence
17346 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17347 ASSERT_VK_SUCCESS(err);
17348 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17349 ASSERT_VK_SUCCESS(err);
17350 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17351 ASSERT_VK_SUCCESS(err);
17352 }
17353 }
17354 m_errorMonitor->VerifyNotFound();
17355 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17356 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17357 vkDestroyFence(m_device->device(), fences[i], nullptr);
17358 }
17359}
17360// This is a positive test. No errors should be generated.
17361TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17362
17363 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17364 "submitted on separate queues followed by a QueueWaitIdle.");
17365
17366 ASSERT_NO_FATAL_FAILURE(InitState());
17367 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17368 return;
17369
17370 m_errorMonitor->ExpectSuccess();
17371
17372 VkSemaphore semaphore;
17373 VkSemaphoreCreateInfo semaphore_create_info{};
17374 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17375 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17376
17377 VkCommandPool command_pool;
17378 VkCommandPoolCreateInfo pool_create_info{};
17379 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17380 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17381 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17382 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17383
17384 VkCommandBuffer command_buffer[2];
17385 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17386 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17387 command_buffer_allocate_info.commandPool = command_pool;
17388 command_buffer_allocate_info.commandBufferCount = 2;
17389 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17390 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17391
17392 VkQueue queue = VK_NULL_HANDLE;
17393 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17394
17395 {
17396 VkCommandBufferBeginInfo begin_info{};
17397 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17398 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17399
17400 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17401 nullptr, 0, nullptr, 0, nullptr);
17402
17403 VkViewport viewport{};
17404 viewport.maxDepth = 1.0f;
17405 viewport.minDepth = 0.0f;
17406 viewport.width = 512;
17407 viewport.height = 512;
17408 viewport.x = 0;
17409 viewport.y = 0;
17410 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17411 vkEndCommandBuffer(command_buffer[0]);
17412 }
17413 {
17414 VkCommandBufferBeginInfo begin_info{};
17415 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17416 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17417
17418 VkViewport viewport{};
17419 viewport.maxDepth = 1.0f;
17420 viewport.minDepth = 0.0f;
17421 viewport.width = 512;
17422 viewport.height = 512;
17423 viewport.x = 0;
17424 viewport.y = 0;
17425 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17426 vkEndCommandBuffer(command_buffer[1]);
17427 }
17428 {
17429 VkSubmitInfo submit_info{};
17430 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17431 submit_info.commandBufferCount = 1;
17432 submit_info.pCommandBuffers = &command_buffer[0];
17433 submit_info.signalSemaphoreCount = 1;
17434 submit_info.pSignalSemaphores = &semaphore;
17435 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17436 }
17437 {
17438 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17439 VkSubmitInfo submit_info{};
17440 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17441 submit_info.commandBufferCount = 1;
17442 submit_info.pCommandBuffers = &command_buffer[1];
17443 submit_info.waitSemaphoreCount = 1;
17444 submit_info.pWaitSemaphores = &semaphore;
17445 submit_info.pWaitDstStageMask = flags;
17446 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17447 }
17448
17449 vkQueueWaitIdle(m_device->m_queue);
17450
17451 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17452 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17453 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17454
17455 m_errorMonitor->VerifyNotFound();
17456}
17457
17458// This is a positive test. No errors should be generated.
17459TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17460
17461 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17462 "submitted on separate queues, the second having a fence"
17463 "followed by a QueueWaitIdle.");
17464
17465 ASSERT_NO_FATAL_FAILURE(InitState());
17466 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17467 return;
17468
17469 m_errorMonitor->ExpectSuccess();
17470
17471 VkFence fence;
17472 VkFenceCreateInfo fence_create_info{};
17473 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17474 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17475
17476 VkSemaphore semaphore;
17477 VkSemaphoreCreateInfo semaphore_create_info{};
17478 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17479 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17480
17481 VkCommandPool command_pool;
17482 VkCommandPoolCreateInfo pool_create_info{};
17483 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17484 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17485 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17486 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17487
17488 VkCommandBuffer command_buffer[2];
17489 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17490 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17491 command_buffer_allocate_info.commandPool = command_pool;
17492 command_buffer_allocate_info.commandBufferCount = 2;
17493 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17494 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17495
17496 VkQueue queue = VK_NULL_HANDLE;
17497 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17498
17499 {
17500 VkCommandBufferBeginInfo begin_info{};
17501 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17502 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17503
17504 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17505 nullptr, 0, nullptr, 0, nullptr);
17506
17507 VkViewport viewport{};
17508 viewport.maxDepth = 1.0f;
17509 viewport.minDepth = 0.0f;
17510 viewport.width = 512;
17511 viewport.height = 512;
17512 viewport.x = 0;
17513 viewport.y = 0;
17514 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17515 vkEndCommandBuffer(command_buffer[0]);
17516 }
17517 {
17518 VkCommandBufferBeginInfo begin_info{};
17519 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17520 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17521
17522 VkViewport viewport{};
17523 viewport.maxDepth = 1.0f;
17524 viewport.minDepth = 0.0f;
17525 viewport.width = 512;
17526 viewport.height = 512;
17527 viewport.x = 0;
17528 viewport.y = 0;
17529 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17530 vkEndCommandBuffer(command_buffer[1]);
17531 }
17532 {
17533 VkSubmitInfo submit_info{};
17534 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17535 submit_info.commandBufferCount = 1;
17536 submit_info.pCommandBuffers = &command_buffer[0];
17537 submit_info.signalSemaphoreCount = 1;
17538 submit_info.pSignalSemaphores = &semaphore;
17539 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17540 }
17541 {
17542 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17543 VkSubmitInfo submit_info{};
17544 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17545 submit_info.commandBufferCount = 1;
17546 submit_info.pCommandBuffers = &command_buffer[1];
17547 submit_info.waitSemaphoreCount = 1;
17548 submit_info.pWaitSemaphores = &semaphore;
17549 submit_info.pWaitDstStageMask = flags;
17550 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17551 }
17552
17553 vkQueueWaitIdle(m_device->m_queue);
17554
17555 vkDestroyFence(m_device->device(), fence, nullptr);
17556 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17557 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17558 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17559
17560 m_errorMonitor->VerifyNotFound();
17561}
17562
17563// This is a positive test. No errors should be generated.
17564TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17565
17566 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17567 "submitted on separate queues, the second having a fence"
17568 "followed by two consecutive WaitForFences calls on the same fence.");
17569
17570 ASSERT_NO_FATAL_FAILURE(InitState());
17571 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17572 return;
17573
17574 m_errorMonitor->ExpectSuccess();
17575
17576 VkFence fence;
17577 VkFenceCreateInfo fence_create_info{};
17578 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17579 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17580
17581 VkSemaphore semaphore;
17582 VkSemaphoreCreateInfo semaphore_create_info{};
17583 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17584 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17585
17586 VkCommandPool command_pool;
17587 VkCommandPoolCreateInfo pool_create_info{};
17588 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17589 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17590 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17591 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17592
17593 VkCommandBuffer command_buffer[2];
17594 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17595 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17596 command_buffer_allocate_info.commandPool = command_pool;
17597 command_buffer_allocate_info.commandBufferCount = 2;
17598 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17599 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17600
17601 VkQueue queue = VK_NULL_HANDLE;
17602 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17603
17604 {
17605 VkCommandBufferBeginInfo begin_info{};
17606 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17607 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17608
17609 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17610 nullptr, 0, nullptr, 0, nullptr);
17611
17612 VkViewport viewport{};
17613 viewport.maxDepth = 1.0f;
17614 viewport.minDepth = 0.0f;
17615 viewport.width = 512;
17616 viewport.height = 512;
17617 viewport.x = 0;
17618 viewport.y = 0;
17619 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17620 vkEndCommandBuffer(command_buffer[0]);
17621 }
17622 {
17623 VkCommandBufferBeginInfo begin_info{};
17624 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17625 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17626
17627 VkViewport viewport{};
17628 viewport.maxDepth = 1.0f;
17629 viewport.minDepth = 0.0f;
17630 viewport.width = 512;
17631 viewport.height = 512;
17632 viewport.x = 0;
17633 viewport.y = 0;
17634 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17635 vkEndCommandBuffer(command_buffer[1]);
17636 }
17637 {
17638 VkSubmitInfo submit_info{};
17639 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17640 submit_info.commandBufferCount = 1;
17641 submit_info.pCommandBuffers = &command_buffer[0];
17642 submit_info.signalSemaphoreCount = 1;
17643 submit_info.pSignalSemaphores = &semaphore;
17644 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17645 }
17646 {
17647 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17648 VkSubmitInfo submit_info{};
17649 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17650 submit_info.commandBufferCount = 1;
17651 submit_info.pCommandBuffers = &command_buffer[1];
17652 submit_info.waitSemaphoreCount = 1;
17653 submit_info.pWaitSemaphores = &semaphore;
17654 submit_info.pWaitDstStageMask = flags;
17655 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17656 }
17657
17658 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17659 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17660
17661 vkDestroyFence(m_device->device(), fence, nullptr);
17662 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17663 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17664 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17665
17666 m_errorMonitor->VerifyNotFound();
17667}
17668
17669TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
17670
17671 ASSERT_NO_FATAL_FAILURE(InitState());
17672 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
17673 printf("Test requires two queues, skipping\n");
17674 return;
17675 }
17676
17677 VkResult err;
17678
17679 m_errorMonitor->ExpectSuccess();
17680
17681 VkQueue q0 = m_device->m_queue;
17682 VkQueue q1 = nullptr;
17683 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
17684 ASSERT_NE(q1, nullptr);
17685
17686 // An (empty) command buffer. We must have work in the first submission --
17687 // the layer treats unfenced work differently from fenced work.
17688 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
17689 VkCommandPool pool;
17690 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
17691 ASSERT_VK_SUCCESS(err);
17692 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
17693 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
17694 VkCommandBuffer cb;
17695 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
17696 ASSERT_VK_SUCCESS(err);
17697 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
17698 err = vkBeginCommandBuffer(cb, &cbbi);
17699 ASSERT_VK_SUCCESS(err);
17700 err = vkEndCommandBuffer(cb);
17701 ASSERT_VK_SUCCESS(err);
17702
17703 // A semaphore
17704 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17705 VkSemaphore s;
17706 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
17707 ASSERT_VK_SUCCESS(err);
17708
17709 // First submission, to q0
17710 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
17711
17712 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
17713 ASSERT_VK_SUCCESS(err);
17714
17715 // Second submission, to q1, waiting on s
17716 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
17717 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
17718
17719 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
17720 ASSERT_VK_SUCCESS(err);
17721
17722 // Wait for q0 idle
17723 err = vkQueueWaitIdle(q0);
17724 ASSERT_VK_SUCCESS(err);
17725
17726 // Command buffer should have been completed (it was on q0); reset the pool.
17727 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
17728
17729 m_errorMonitor->VerifyNotFound();
17730
17731 // Force device completely idle and clean up resources
17732 vkDeviceWaitIdle(m_device->device());
17733 vkDestroyCommandPool(m_device->device(), pool, nullptr);
17734 vkDestroySemaphore(m_device->device(), s, nullptr);
17735}
17736
17737// This is a positive test. No errors should be generated.
17738TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
17739
17740 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17741 "submitted on separate queues, the second having a fence, "
17742 "followed by a WaitForFences call.");
17743
17744 ASSERT_NO_FATAL_FAILURE(InitState());
17745 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17746 return;
17747
17748 m_errorMonitor->ExpectSuccess();
17749
17750 ASSERT_NO_FATAL_FAILURE(InitState());
17751 VkFence fence;
17752 VkFenceCreateInfo fence_create_info{};
17753 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17754 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17755
17756 VkSemaphore semaphore;
17757 VkSemaphoreCreateInfo semaphore_create_info{};
17758 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17759 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17760
17761 VkCommandPool command_pool;
17762 VkCommandPoolCreateInfo pool_create_info{};
17763 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17764 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17765 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17766 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17767
17768 VkCommandBuffer command_buffer[2];
17769 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17770 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17771 command_buffer_allocate_info.commandPool = command_pool;
17772 command_buffer_allocate_info.commandBufferCount = 2;
17773 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17774 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17775
17776 VkQueue queue = VK_NULL_HANDLE;
17777 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17778
17779 {
17780 VkCommandBufferBeginInfo begin_info{};
17781 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17782 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17783
17784 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17785 nullptr, 0, nullptr, 0, nullptr);
17786
17787 VkViewport viewport{};
17788 viewport.maxDepth = 1.0f;
17789 viewport.minDepth = 0.0f;
17790 viewport.width = 512;
17791 viewport.height = 512;
17792 viewport.x = 0;
17793 viewport.y = 0;
17794 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17795 vkEndCommandBuffer(command_buffer[0]);
17796 }
17797 {
17798 VkCommandBufferBeginInfo begin_info{};
17799 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17800 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17801
17802 VkViewport viewport{};
17803 viewport.maxDepth = 1.0f;
17804 viewport.minDepth = 0.0f;
17805 viewport.width = 512;
17806 viewport.height = 512;
17807 viewport.x = 0;
17808 viewport.y = 0;
17809 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17810 vkEndCommandBuffer(command_buffer[1]);
17811 }
17812 {
17813 VkSubmitInfo submit_info{};
17814 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17815 submit_info.commandBufferCount = 1;
17816 submit_info.pCommandBuffers = &command_buffer[0];
17817 submit_info.signalSemaphoreCount = 1;
17818 submit_info.pSignalSemaphores = &semaphore;
17819 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17820 }
17821 {
17822 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17823 VkSubmitInfo submit_info{};
17824 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17825 submit_info.commandBufferCount = 1;
17826 submit_info.pCommandBuffers = &command_buffer[1];
17827 submit_info.waitSemaphoreCount = 1;
17828 submit_info.pWaitSemaphores = &semaphore;
17829 submit_info.pWaitDstStageMask = flags;
17830 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17831 }
17832
17833 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17834
17835 vkDestroyFence(m_device->device(), fence, nullptr);
17836 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17837 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17838 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17839
17840 m_errorMonitor->VerifyNotFound();
17841}
17842
17843// This is a positive test. No errors should be generated.
17844TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
17845
17846 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17847 "on the same queue, sharing a signal/wait semaphore, the "
17848 "second having a fence, "
17849 "followed by a WaitForFences call.");
17850
17851 m_errorMonitor->ExpectSuccess();
17852
17853 ASSERT_NO_FATAL_FAILURE(InitState());
17854 VkFence fence;
17855 VkFenceCreateInfo fence_create_info{};
17856 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17857 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17858
17859 VkSemaphore semaphore;
17860 VkSemaphoreCreateInfo semaphore_create_info{};
17861 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17862 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17863
17864 VkCommandPool command_pool;
17865 VkCommandPoolCreateInfo pool_create_info{};
17866 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17867 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17868 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17869 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17870
17871 VkCommandBuffer command_buffer[2];
17872 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17873 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17874 command_buffer_allocate_info.commandPool = command_pool;
17875 command_buffer_allocate_info.commandBufferCount = 2;
17876 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17877 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17878
17879 {
17880 VkCommandBufferBeginInfo begin_info{};
17881 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17882 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17883
17884 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17885 nullptr, 0, nullptr, 0, nullptr);
17886
17887 VkViewport viewport{};
17888 viewport.maxDepth = 1.0f;
17889 viewport.minDepth = 0.0f;
17890 viewport.width = 512;
17891 viewport.height = 512;
17892 viewport.x = 0;
17893 viewport.y = 0;
17894 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17895 vkEndCommandBuffer(command_buffer[0]);
17896 }
17897 {
17898 VkCommandBufferBeginInfo begin_info{};
17899 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17900 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17901
17902 VkViewport viewport{};
17903 viewport.maxDepth = 1.0f;
17904 viewport.minDepth = 0.0f;
17905 viewport.width = 512;
17906 viewport.height = 512;
17907 viewport.x = 0;
17908 viewport.y = 0;
17909 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17910 vkEndCommandBuffer(command_buffer[1]);
17911 }
17912 {
17913 VkSubmitInfo submit_info{};
17914 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17915 submit_info.commandBufferCount = 1;
17916 submit_info.pCommandBuffers = &command_buffer[0];
17917 submit_info.signalSemaphoreCount = 1;
17918 submit_info.pSignalSemaphores = &semaphore;
17919 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17920 }
17921 {
17922 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17923 VkSubmitInfo submit_info{};
17924 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17925 submit_info.commandBufferCount = 1;
17926 submit_info.pCommandBuffers = &command_buffer[1];
17927 submit_info.waitSemaphoreCount = 1;
17928 submit_info.pWaitSemaphores = &semaphore;
17929 submit_info.pWaitDstStageMask = flags;
17930 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17931 }
17932
17933 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17934
17935 vkDestroyFence(m_device->device(), fence, nullptr);
17936 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17937 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17938 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17939
17940 m_errorMonitor->VerifyNotFound();
17941}
17942
17943// This is a positive test. No errors should be generated.
17944TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
17945
17946 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17947 "on the same queue, no fences, followed by a third QueueSubmit with NO "
17948 "SubmitInfos but with a fence, followed by a WaitForFences call.");
17949
17950 m_errorMonitor->ExpectSuccess();
17951
17952 ASSERT_NO_FATAL_FAILURE(InitState());
17953 VkFence fence;
17954 VkFenceCreateInfo fence_create_info{};
17955 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17956 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17957
17958 VkCommandPool command_pool;
17959 VkCommandPoolCreateInfo pool_create_info{};
17960 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17961 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17962 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17963 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17964
17965 VkCommandBuffer command_buffer[2];
17966 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17967 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17968 command_buffer_allocate_info.commandPool = command_pool;
17969 command_buffer_allocate_info.commandBufferCount = 2;
17970 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17971 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17972
17973 {
17974 VkCommandBufferBeginInfo begin_info{};
17975 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17976 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17977
17978 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17979 nullptr, 0, nullptr, 0, nullptr);
17980
17981 VkViewport viewport{};
17982 viewport.maxDepth = 1.0f;
17983 viewport.minDepth = 0.0f;
17984 viewport.width = 512;
17985 viewport.height = 512;
17986 viewport.x = 0;
17987 viewport.y = 0;
17988 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17989 vkEndCommandBuffer(command_buffer[0]);
17990 }
17991 {
17992 VkCommandBufferBeginInfo begin_info{};
17993 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17994 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17995
17996 VkViewport viewport{};
17997 viewport.maxDepth = 1.0f;
17998 viewport.minDepth = 0.0f;
17999 viewport.width = 512;
18000 viewport.height = 512;
18001 viewport.x = 0;
18002 viewport.y = 0;
18003 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18004 vkEndCommandBuffer(command_buffer[1]);
18005 }
18006 {
18007 VkSubmitInfo submit_info{};
18008 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18009 submit_info.commandBufferCount = 1;
18010 submit_info.pCommandBuffers = &command_buffer[0];
18011 submit_info.signalSemaphoreCount = 0;
18012 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18013 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18014 }
18015 {
18016 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18017 VkSubmitInfo submit_info{};
18018 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18019 submit_info.commandBufferCount = 1;
18020 submit_info.pCommandBuffers = &command_buffer[1];
18021 submit_info.waitSemaphoreCount = 0;
18022 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18023 submit_info.pWaitDstStageMask = flags;
18024 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18025 }
18026
18027 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18028
18029 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18030 ASSERT_VK_SUCCESS(err);
18031
18032 vkDestroyFence(m_device->device(), fence, nullptr);
18033 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18034 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18035
18036 m_errorMonitor->VerifyNotFound();
18037}
18038
18039// This is a positive test. No errors should be generated.
18040TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18041
18042 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18043 "on the same queue, the second having a fence, followed "
18044 "by a WaitForFences call.");
18045
18046 m_errorMonitor->ExpectSuccess();
18047
18048 ASSERT_NO_FATAL_FAILURE(InitState());
18049 VkFence fence;
18050 VkFenceCreateInfo fence_create_info{};
18051 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18052 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18053
18054 VkCommandPool command_pool;
18055 VkCommandPoolCreateInfo pool_create_info{};
18056 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18057 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18058 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18059 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18060
18061 VkCommandBuffer command_buffer[2];
18062 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18063 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18064 command_buffer_allocate_info.commandPool = command_pool;
18065 command_buffer_allocate_info.commandBufferCount = 2;
18066 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18067 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18068
18069 {
18070 VkCommandBufferBeginInfo begin_info{};
18071 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18072 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18073
18074 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18075 nullptr, 0, nullptr, 0, nullptr);
18076
18077 VkViewport viewport{};
18078 viewport.maxDepth = 1.0f;
18079 viewport.minDepth = 0.0f;
18080 viewport.width = 512;
18081 viewport.height = 512;
18082 viewport.x = 0;
18083 viewport.y = 0;
18084 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18085 vkEndCommandBuffer(command_buffer[0]);
18086 }
18087 {
18088 VkCommandBufferBeginInfo begin_info{};
18089 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18090 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18091
18092 VkViewport viewport{};
18093 viewport.maxDepth = 1.0f;
18094 viewport.minDepth = 0.0f;
18095 viewport.width = 512;
18096 viewport.height = 512;
18097 viewport.x = 0;
18098 viewport.y = 0;
18099 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18100 vkEndCommandBuffer(command_buffer[1]);
18101 }
18102 {
18103 VkSubmitInfo submit_info{};
18104 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18105 submit_info.commandBufferCount = 1;
18106 submit_info.pCommandBuffers = &command_buffer[0];
18107 submit_info.signalSemaphoreCount = 0;
18108 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18109 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18110 }
18111 {
18112 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18113 VkSubmitInfo submit_info{};
18114 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18115 submit_info.commandBufferCount = 1;
18116 submit_info.pCommandBuffers = &command_buffer[1];
18117 submit_info.waitSemaphoreCount = 0;
18118 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18119 submit_info.pWaitDstStageMask = flags;
18120 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18121 }
18122
18123 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18124
18125 vkDestroyFence(m_device->device(), fence, nullptr);
18126 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18127 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18128
18129 m_errorMonitor->VerifyNotFound();
18130}
18131
18132// This is a positive test. No errors should be generated.
18133TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18134
18135 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18136 "QueueSubmit call followed by a WaitForFences call.");
18137 ASSERT_NO_FATAL_FAILURE(InitState());
18138
18139 m_errorMonitor->ExpectSuccess();
18140
18141 VkFence fence;
18142 VkFenceCreateInfo fence_create_info{};
18143 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18144 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18145
18146 VkSemaphore semaphore;
18147 VkSemaphoreCreateInfo semaphore_create_info{};
18148 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18149 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18150
18151 VkCommandPool command_pool;
18152 VkCommandPoolCreateInfo pool_create_info{};
18153 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18154 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18155 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18156 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18157
18158 VkCommandBuffer command_buffer[2];
18159 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18160 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18161 command_buffer_allocate_info.commandPool = command_pool;
18162 command_buffer_allocate_info.commandBufferCount = 2;
18163 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18164 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18165
18166 {
18167 VkCommandBufferBeginInfo begin_info{};
18168 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18169 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18170
18171 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18172 nullptr, 0, nullptr, 0, nullptr);
18173
18174 VkViewport viewport{};
18175 viewport.maxDepth = 1.0f;
18176 viewport.minDepth = 0.0f;
18177 viewport.width = 512;
18178 viewport.height = 512;
18179 viewport.x = 0;
18180 viewport.y = 0;
18181 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18182 vkEndCommandBuffer(command_buffer[0]);
18183 }
18184 {
18185 VkCommandBufferBeginInfo begin_info{};
18186 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18187 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18188
18189 VkViewport viewport{};
18190 viewport.maxDepth = 1.0f;
18191 viewport.minDepth = 0.0f;
18192 viewport.width = 512;
18193 viewport.height = 512;
18194 viewport.x = 0;
18195 viewport.y = 0;
18196 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18197 vkEndCommandBuffer(command_buffer[1]);
18198 }
18199 {
18200 VkSubmitInfo submit_info[2];
18201 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18202
18203 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18204 submit_info[0].pNext = NULL;
18205 submit_info[0].commandBufferCount = 1;
18206 submit_info[0].pCommandBuffers = &command_buffer[0];
18207 submit_info[0].signalSemaphoreCount = 1;
18208 submit_info[0].pSignalSemaphores = &semaphore;
18209 submit_info[0].waitSemaphoreCount = 0;
18210 submit_info[0].pWaitSemaphores = NULL;
18211 submit_info[0].pWaitDstStageMask = 0;
18212
18213 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18214 submit_info[1].pNext = NULL;
18215 submit_info[1].commandBufferCount = 1;
18216 submit_info[1].pCommandBuffers = &command_buffer[1];
18217 submit_info[1].waitSemaphoreCount = 1;
18218 submit_info[1].pWaitSemaphores = &semaphore;
18219 submit_info[1].pWaitDstStageMask = flags;
18220 submit_info[1].signalSemaphoreCount = 0;
18221 submit_info[1].pSignalSemaphores = NULL;
18222 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18223 }
18224
18225 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18226
18227 vkDestroyFence(m_device->device(), fence, nullptr);
18228 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18229 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18230 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18231
18232 m_errorMonitor->VerifyNotFound();
18233}
18234
18235TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18236 m_errorMonitor->ExpectSuccess();
18237
18238 ASSERT_NO_FATAL_FAILURE(InitState());
18239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18240
18241 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18242 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18243
18244 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18245 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18246 m_errorMonitor->VerifyNotFound();
18247 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18248 m_errorMonitor->VerifyNotFound();
18249 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18250 m_errorMonitor->VerifyNotFound();
18251
18252 m_commandBuffer->EndCommandBuffer();
18253 m_errorMonitor->VerifyNotFound();
18254}
18255
18256TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18257 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18258 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18259 "has a valid layout, and a second subpass then uses a "
18260 "valid *READ_ONLY* layout.");
18261 m_errorMonitor->ExpectSuccess();
18262 ASSERT_NO_FATAL_FAILURE(InitState());
18263
18264 VkAttachmentReference attach[2] = {};
18265 attach[0].attachment = 0;
18266 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18267 attach[1].attachment = 0;
18268 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18269 VkSubpassDescription subpasses[2] = {};
18270 // First subpass clears DS attach on load
18271 subpasses[0].pDepthStencilAttachment = &attach[0];
18272 // 2nd subpass reads in DS as input attachment
18273 subpasses[1].inputAttachmentCount = 1;
18274 subpasses[1].pInputAttachments = &attach[1];
18275 VkAttachmentDescription attach_desc = {};
18276 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18277 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18278 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18279 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18280 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18281 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18282 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18283 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18284 VkRenderPassCreateInfo rpci = {};
18285 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18286 rpci.attachmentCount = 1;
18287 rpci.pAttachments = &attach_desc;
18288 rpci.subpassCount = 2;
18289 rpci.pSubpasses = subpasses;
18290
18291 // Now create RenderPass and verify no errors
18292 VkRenderPass rp;
18293 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18294 m_errorMonitor->VerifyNotFound();
18295
18296 vkDestroyRenderPass(m_device->device(), rp, NULL);
18297}
18298
18299TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18300 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18301 "as vertex attributes");
18302 m_errorMonitor->ExpectSuccess();
18303
18304 ASSERT_NO_FATAL_FAILURE(InitState());
18305 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18306
18307 VkVertexInputBindingDescription input_binding;
18308 memset(&input_binding, 0, sizeof(input_binding));
18309
18310 VkVertexInputAttributeDescription input_attribs[2];
18311 memset(input_attribs, 0, sizeof(input_attribs));
18312
18313 for (int i = 0; i < 2; i++) {
18314 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18315 input_attribs[i].location = i;
18316 }
18317
18318 char const *vsSource = "#version 450\n"
18319 "\n"
18320 "layout(location=0) in mat2x4 x;\n"
18321 "out gl_PerVertex {\n"
18322 " vec4 gl_Position;\n"
18323 "};\n"
18324 "void main(){\n"
18325 " gl_Position = x[0] + x[1];\n"
18326 "}\n";
18327 char const *fsSource = "#version 450\n"
18328 "\n"
18329 "layout(location=0) out vec4 color;\n"
18330 "void main(){\n"
18331 " color = vec4(1);\n"
18332 "}\n";
18333
18334 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18335 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18336
18337 VkPipelineObj pipe(m_device);
18338 pipe.AddColorAttachment();
18339 pipe.AddShader(&vs);
18340 pipe.AddShader(&fs);
18341
18342 pipe.AddVertexInputBindings(&input_binding, 1);
18343 pipe.AddVertexInputAttribs(input_attribs, 2);
18344
18345 VkDescriptorSetObj descriptorSet(m_device);
18346 descriptorSet.AppendDummy();
18347 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18348
18349 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18350
18351 /* expect success */
18352 m_errorMonitor->VerifyNotFound();
18353}
18354
18355TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18356 m_errorMonitor->ExpectSuccess();
18357
18358 ASSERT_NO_FATAL_FAILURE(InitState());
18359 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18360
18361 VkVertexInputBindingDescription input_binding;
18362 memset(&input_binding, 0, sizeof(input_binding));
18363
18364 VkVertexInputAttributeDescription input_attribs[2];
18365 memset(input_attribs, 0, sizeof(input_attribs));
18366
18367 for (int i = 0; i < 2; i++) {
18368 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18369 input_attribs[i].location = i;
18370 }
18371
18372 char const *vsSource = "#version 450\n"
18373 "\n"
18374 "layout(location=0) in vec4 x[2];\n"
18375 "out gl_PerVertex {\n"
18376 " vec4 gl_Position;\n"
18377 "};\n"
18378 "void main(){\n"
18379 " gl_Position = x[0] + x[1];\n"
18380 "}\n";
18381 char const *fsSource = "#version 450\n"
18382 "\n"
18383 "layout(location=0) out vec4 color;\n"
18384 "void main(){\n"
18385 " color = vec4(1);\n"
18386 "}\n";
18387
18388 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18389 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18390
18391 VkPipelineObj pipe(m_device);
18392 pipe.AddColorAttachment();
18393 pipe.AddShader(&vs);
18394 pipe.AddShader(&fs);
18395
18396 pipe.AddVertexInputBindings(&input_binding, 1);
18397 pipe.AddVertexInputAttribs(input_attribs, 2);
18398
18399 VkDescriptorSetObj descriptorSet(m_device);
18400 descriptorSet.AppendDummy();
18401 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18402
18403 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18404
18405 m_errorMonitor->VerifyNotFound();
18406}
18407
18408TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18409 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18410 "through multiple vertex shader inputs, each consuming a different "
18411 "subset of the components.");
18412 m_errorMonitor->ExpectSuccess();
18413
18414 ASSERT_NO_FATAL_FAILURE(InitState());
18415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18416
18417 VkVertexInputBindingDescription input_binding;
18418 memset(&input_binding, 0, sizeof(input_binding));
18419
18420 VkVertexInputAttributeDescription input_attribs[3];
18421 memset(input_attribs, 0, sizeof(input_attribs));
18422
18423 for (int i = 0; i < 3; i++) {
18424 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18425 input_attribs[i].location = i;
18426 }
18427
18428 char const *vsSource = "#version 450\n"
18429 "\n"
18430 "layout(location=0) in vec4 x;\n"
18431 "layout(location=1) in vec3 y1;\n"
18432 "layout(location=1, component=3) in float y2;\n"
18433 "layout(location=2) in vec4 z;\n"
18434 "out gl_PerVertex {\n"
18435 " vec4 gl_Position;\n"
18436 "};\n"
18437 "void main(){\n"
18438 " gl_Position = x + vec4(y1, y2) + z;\n"
18439 "}\n";
18440 char const *fsSource = "#version 450\n"
18441 "\n"
18442 "layout(location=0) out vec4 color;\n"
18443 "void main(){\n"
18444 " color = vec4(1);\n"
18445 "}\n";
18446
18447 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18448 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18449
18450 VkPipelineObj pipe(m_device);
18451 pipe.AddColorAttachment();
18452 pipe.AddShader(&vs);
18453 pipe.AddShader(&fs);
18454
18455 pipe.AddVertexInputBindings(&input_binding, 1);
18456 pipe.AddVertexInputAttribs(input_attribs, 3);
18457
18458 VkDescriptorSetObj descriptorSet(m_device);
18459 descriptorSet.AppendDummy();
18460 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18461
18462 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18463
18464 m_errorMonitor->VerifyNotFound();
18465}
18466
18467TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18468 m_errorMonitor->ExpectSuccess();
18469
18470 ASSERT_NO_FATAL_FAILURE(InitState());
18471 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18472
18473 char const *vsSource = "#version 450\n"
18474 "out gl_PerVertex {\n"
18475 " vec4 gl_Position;\n"
18476 "};\n"
18477 "void main(){\n"
18478 " gl_Position = vec4(0);\n"
18479 "}\n";
18480 char const *fsSource = "#version 450\n"
18481 "\n"
18482 "layout(location=0) out vec4 color;\n"
18483 "void main(){\n"
18484 " color = vec4(1);\n"
18485 "}\n";
18486
18487 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18488 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18489
18490 VkPipelineObj pipe(m_device);
18491 pipe.AddColorAttachment();
18492 pipe.AddShader(&vs);
18493 pipe.AddShader(&fs);
18494
18495 VkDescriptorSetObj descriptorSet(m_device);
18496 descriptorSet.AppendDummy();
18497 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18498
18499 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18500
18501 m_errorMonitor->VerifyNotFound();
18502}
18503
18504TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18505 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18506 "set out in 14.1.3: fundamental type must match, and producer side must "
18507 "have at least as many components");
18508 m_errorMonitor->ExpectSuccess();
18509
18510 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18511
18512 ASSERT_NO_FATAL_FAILURE(InitState());
18513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18514
18515 char const *vsSource = "#version 450\n"
18516 "out gl_PerVertex {\n"
18517 " vec4 gl_Position;\n"
18518 "};\n"
18519 "layout(location=0) out vec3 x;\n"
18520 "layout(location=1) out ivec3 y;\n"
18521 "layout(location=2) out vec3 z;\n"
18522 "void main(){\n"
18523 " gl_Position = vec4(0);\n"
18524 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18525 "}\n";
18526 char const *fsSource = "#version 450\n"
18527 "\n"
18528 "layout(location=0) out vec4 color;\n"
18529 "layout(location=0) in float x;\n"
18530 "layout(location=1) flat in int y;\n"
18531 "layout(location=2) in vec2 z;\n"
18532 "void main(){\n"
18533 " color = vec4(1 + x + y + z.x);\n"
18534 "}\n";
18535
18536 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18537 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18538
18539 VkPipelineObj pipe(m_device);
18540 pipe.AddColorAttachment();
18541 pipe.AddShader(&vs);
18542 pipe.AddShader(&fs);
18543
18544 VkDescriptorSetObj descriptorSet(m_device);
18545 descriptorSet.AppendDummy();
18546 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18547
18548 VkResult err = VK_SUCCESS;
18549 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18550 ASSERT_VK_SUCCESS(err);
18551
18552 m_errorMonitor->VerifyNotFound();
18553}
18554
18555TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18556 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18557 "passed between the TCS and TES stages");
18558 m_errorMonitor->ExpectSuccess();
18559
18560 ASSERT_NO_FATAL_FAILURE(InitState());
18561 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18562
18563 if (!m_device->phy().features().tessellationShader) {
18564 printf("Device does not support tessellation shaders; skipped.\n");
18565 return;
18566 }
18567
18568 char const *vsSource = "#version 450\n"
18569 "void main(){}\n";
18570 char const *tcsSource = "#version 450\n"
18571 "layout(location=0) out int x[];\n"
18572 "layout(vertices=3) out;\n"
18573 "void main(){\n"
18574 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18575 " gl_TessLevelInner[0] = 1;\n"
18576 " x[gl_InvocationID] = gl_InvocationID;\n"
18577 "}\n";
18578 char const *tesSource = "#version 450\n"
18579 "layout(triangles, equal_spacing, cw) in;\n"
18580 "layout(location=0) in int x[];\n"
18581 "out gl_PerVertex { vec4 gl_Position; };\n"
18582 "void main(){\n"
18583 " gl_Position.xyz = gl_TessCoord;\n"
18584 " gl_Position.w = x[0] + x[1] + x[2];\n"
18585 "}\n";
18586 char const *fsSource = "#version 450\n"
18587 "layout(location=0) out vec4 color;\n"
18588 "void main(){\n"
18589 " color = vec4(1);\n"
18590 "}\n";
18591
18592 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18593 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
18594 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
18595 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18596
18597 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
18598 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
18599
18600 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
18601
18602 VkPipelineObj pipe(m_device);
18603 pipe.SetInputAssembly(&iasci);
18604 pipe.SetTessellation(&tsci);
18605 pipe.AddColorAttachment();
18606 pipe.AddShader(&vs);
18607 pipe.AddShader(&tcs);
18608 pipe.AddShader(&tes);
18609 pipe.AddShader(&fs);
18610
18611 VkDescriptorSetObj descriptorSet(m_device);
18612 descriptorSet.AppendDummy();
18613 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18614
18615 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18616
18617 m_errorMonitor->VerifyNotFound();
18618}
18619
18620TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
18621 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
18622 "interface block passed into the geometry shader. This "
18623 "is interesting because the 'extra' array level is not "
18624 "present on the member type, but on the block instance.");
18625 m_errorMonitor->ExpectSuccess();
18626
18627 ASSERT_NO_FATAL_FAILURE(InitState());
18628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18629
18630 if (!m_device->phy().features().geometryShader) {
18631 printf("Device does not support geometry shaders; skipped.\n");
18632 return;
18633 }
18634
18635 char const *vsSource = "#version 450\n"
18636 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
18637 "void main(){\n"
18638 " vs_out.x = vec4(1);\n"
18639 "}\n";
18640 char const *gsSource = "#version 450\n"
18641 "layout(triangles) in;\n"
18642 "layout(triangle_strip, max_vertices=3) out;\n"
18643 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
18644 "out gl_PerVertex { vec4 gl_Position; };\n"
18645 "void main() {\n"
18646 " gl_Position = gs_in[0].x;\n"
18647 " EmitVertex();\n"
18648 "}\n";
18649 char const *fsSource = "#version 450\n"
18650 "layout(location=0) out vec4 color;\n"
18651 "void main(){\n"
18652 " color = vec4(1);\n"
18653 "}\n";
18654
18655 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18656 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
18657 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18658
18659 VkPipelineObj pipe(m_device);
18660 pipe.AddColorAttachment();
18661 pipe.AddShader(&vs);
18662 pipe.AddShader(&gs);
18663 pipe.AddShader(&fs);
18664
18665 VkDescriptorSetObj descriptorSet(m_device);
18666 descriptorSet.AppendDummy();
18667 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18668
18669 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18670
18671 m_errorMonitor->VerifyNotFound();
18672}
18673
18674TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
18675 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
18676 "attributes. This is interesting because they consume multiple "
18677 "locations.");
18678 m_errorMonitor->ExpectSuccess();
18679
18680 ASSERT_NO_FATAL_FAILURE(InitState());
18681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18682
18683 if (!m_device->phy().features().shaderFloat64) {
18684 printf("Device does not support 64bit vertex attributes; skipped.\n");
18685 return;
18686 }
18687
18688 VkVertexInputBindingDescription input_bindings[1];
18689 memset(input_bindings, 0, sizeof(input_bindings));
18690
18691 VkVertexInputAttributeDescription input_attribs[4];
18692 memset(input_attribs, 0, sizeof(input_attribs));
18693 input_attribs[0].location = 0;
18694 input_attribs[0].offset = 0;
18695 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18696 input_attribs[1].location = 2;
18697 input_attribs[1].offset = 32;
18698 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18699 input_attribs[2].location = 4;
18700 input_attribs[2].offset = 64;
18701 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18702 input_attribs[3].location = 6;
18703 input_attribs[3].offset = 96;
18704 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18705
18706 char const *vsSource = "#version 450\n"
18707 "\n"
18708 "layout(location=0) in dmat4 x;\n"
18709 "out gl_PerVertex {\n"
18710 " vec4 gl_Position;\n"
18711 "};\n"
18712 "void main(){\n"
18713 " gl_Position = vec4(x[0][0]);\n"
18714 "}\n";
18715 char const *fsSource = "#version 450\n"
18716 "\n"
18717 "layout(location=0) out vec4 color;\n"
18718 "void main(){\n"
18719 " color = vec4(1);\n"
18720 "}\n";
18721
18722 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18723 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18724
18725 VkPipelineObj pipe(m_device);
18726 pipe.AddColorAttachment();
18727 pipe.AddShader(&vs);
18728 pipe.AddShader(&fs);
18729
18730 pipe.AddVertexInputBindings(input_bindings, 1);
18731 pipe.AddVertexInputAttribs(input_attribs, 4);
18732
18733 VkDescriptorSetObj descriptorSet(m_device);
18734 descriptorSet.AppendDummy();
18735 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18736
18737 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18738
18739 m_errorMonitor->VerifyNotFound();
18740}
18741
18742TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
18743 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
18744 m_errorMonitor->ExpectSuccess();
18745
18746 ASSERT_NO_FATAL_FAILURE(InitState());
18747
18748 char const *vsSource = "#version 450\n"
18749 "\n"
18750 "out gl_PerVertex {\n"
18751 " vec4 gl_Position;\n"
18752 "};\n"
18753 "void main(){\n"
18754 " gl_Position = vec4(1);\n"
18755 "}\n";
18756 char const *fsSource = "#version 450\n"
18757 "\n"
18758 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
18759 "layout(location=0) out vec4 color;\n"
18760 "void main() {\n"
18761 " color = subpassLoad(x);\n"
18762 "}\n";
18763
18764 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18765 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18766
18767 VkPipelineObj pipe(m_device);
18768 pipe.AddShader(&vs);
18769 pipe.AddShader(&fs);
18770 pipe.AddColorAttachment();
18771 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18772
18773 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
18774 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
18775 VkDescriptorSetLayout dsl;
18776 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18777 ASSERT_VK_SUCCESS(err);
18778
18779 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18780 VkPipelineLayout pl;
18781 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18782 ASSERT_VK_SUCCESS(err);
18783
18784 VkAttachmentDescription descs[2] = {
18785 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18786 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18787 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
18788 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18789 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
18790 };
18791 VkAttachmentReference color = {
18792 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18793 };
18794 VkAttachmentReference input = {
18795 1, VK_IMAGE_LAYOUT_GENERAL,
18796 };
18797
18798 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
18799
18800 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
18801 VkRenderPass rp;
18802 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18803 ASSERT_VK_SUCCESS(err);
18804
18805 // should be OK. would go wrong here if it's going to...
18806 pipe.CreateVKPipeline(pl, rp);
18807
18808 m_errorMonitor->VerifyNotFound();
18809
18810 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18811 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18812 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18813}
18814
18815TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
18816 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
18817 "descriptor-backed resource which is not provided, but the shader does not "
18818 "statically use it. This is interesting because it requires compute pipelines "
18819 "to have a proper descriptor use walk, which they didn't for some time.");
18820 m_errorMonitor->ExpectSuccess();
18821
18822 ASSERT_NO_FATAL_FAILURE(InitState());
18823
18824 char const *csSource = "#version 450\n"
18825 "\n"
18826 "layout(local_size_x=1) in;\n"
18827 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
18828 "void main(){\n"
18829 " // x is not used.\n"
18830 "}\n";
18831
18832 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18833
18834 VkDescriptorSetObj descriptorSet(m_device);
18835 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18836
18837 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18838 nullptr,
18839 0,
18840 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18841 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18842 descriptorSet.GetPipelineLayout(),
18843 VK_NULL_HANDLE,
18844 -1 };
18845
18846 VkPipeline pipe;
18847 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18848
18849 m_errorMonitor->VerifyNotFound();
18850
18851 if (err == VK_SUCCESS) {
18852 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18853 }
18854}
18855
18856TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
18857 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18858 "sampler portion of a combined image + sampler");
18859 m_errorMonitor->ExpectSuccess();
18860
18861 ASSERT_NO_FATAL_FAILURE(InitState());
18862
18863 VkDescriptorSetLayoutBinding bindings[] = {
18864 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18865 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18866 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18867 };
18868 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18869 VkDescriptorSetLayout dsl;
18870 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18871 ASSERT_VK_SUCCESS(err);
18872
18873 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18874 VkPipelineLayout pl;
18875 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18876 ASSERT_VK_SUCCESS(err);
18877
18878 char const *csSource = "#version 450\n"
18879 "\n"
18880 "layout(local_size_x=1) in;\n"
18881 "layout(set=0, binding=0) uniform sampler s;\n"
18882 "layout(set=0, binding=1) uniform texture2D t;\n"
18883 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18884 "void main() {\n"
18885 " x = texture(sampler2D(t, s), vec2(0));\n"
18886 "}\n";
18887 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18888
18889 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18890 nullptr,
18891 0,
18892 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18893 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18894 pl,
18895 VK_NULL_HANDLE,
18896 -1 };
18897
18898 VkPipeline pipe;
18899 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18900
18901 m_errorMonitor->VerifyNotFound();
18902
18903 if (err == VK_SUCCESS) {
18904 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18905 }
18906
18907 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18908 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18909}
18910
18911TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
18912 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18913 "image portion of a combined image + sampler");
18914 m_errorMonitor->ExpectSuccess();
18915
18916 ASSERT_NO_FATAL_FAILURE(InitState());
18917
18918 VkDescriptorSetLayoutBinding bindings[] = {
18919 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18920 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18921 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18922 };
18923 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18924 VkDescriptorSetLayout dsl;
18925 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18926 ASSERT_VK_SUCCESS(err);
18927
18928 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18929 VkPipelineLayout pl;
18930 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18931 ASSERT_VK_SUCCESS(err);
18932
18933 char const *csSource = "#version 450\n"
18934 "\n"
18935 "layout(local_size_x=1) in;\n"
18936 "layout(set=0, binding=0) uniform texture2D t;\n"
18937 "layout(set=0, binding=1) uniform sampler s;\n"
18938 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18939 "void main() {\n"
18940 " x = texture(sampler2D(t, s), vec2(0));\n"
18941 "}\n";
18942 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18943
18944 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18945 nullptr,
18946 0,
18947 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18948 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18949 pl,
18950 VK_NULL_HANDLE,
18951 -1 };
18952
18953 VkPipeline pipe;
18954 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18955
18956 m_errorMonitor->VerifyNotFound();
18957
18958 if (err == VK_SUCCESS) {
18959 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18960 }
18961
18962 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18963 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18964}
18965
18966TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
18967 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
18968 "both the sampler and the image of a combined image+sampler "
18969 "but via separate variables");
18970 m_errorMonitor->ExpectSuccess();
18971
18972 ASSERT_NO_FATAL_FAILURE(InitState());
18973
18974 VkDescriptorSetLayoutBinding bindings[] = {
18975 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18976 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18977 };
18978 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
18979 VkDescriptorSetLayout dsl;
18980 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18981 ASSERT_VK_SUCCESS(err);
18982
18983 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18984 VkPipelineLayout pl;
18985 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18986 ASSERT_VK_SUCCESS(err);
18987
18988 char const *csSource = "#version 450\n"
18989 "\n"
18990 "layout(local_size_x=1) in;\n"
18991 "layout(set=0, binding=0) uniform texture2D t;\n"
18992 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
18993 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
18994 "void main() {\n"
18995 " x = texture(sampler2D(t, s), vec2(0));\n"
18996 "}\n";
18997 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18998
18999 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19000 nullptr,
19001 0,
19002 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19003 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19004 pl,
19005 VK_NULL_HANDLE,
19006 -1 };
19007
19008 VkPipeline pipe;
19009 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19010
19011 m_errorMonitor->VerifyNotFound();
19012
19013 if (err == VK_SUCCESS) {
19014 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19015 }
19016
19017 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19018 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19019}
19020
19021TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19022 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19023
19024 ASSERT_NO_FATAL_FAILURE(InitState());
19025
19026 // Positive test to check parameter_validation and unique_objects support
19027 // for NV_dedicated_allocation
19028 uint32_t extension_count = 0;
19029 bool supports_nv_dedicated_allocation = false;
19030 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19031 ASSERT_VK_SUCCESS(err);
19032
19033 if (extension_count > 0) {
19034 std::vector<VkExtensionProperties> available_extensions(extension_count);
19035
19036 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19037 ASSERT_VK_SUCCESS(err);
19038
19039 for (const auto &extension_props : available_extensions) {
19040 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19041 supports_nv_dedicated_allocation = true;
19042 }
19043 }
19044 }
19045
19046 if (supports_nv_dedicated_allocation) {
19047 m_errorMonitor->ExpectSuccess();
19048
19049 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19050 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19051 dedicated_buffer_create_info.pNext = nullptr;
19052 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19053
19054 uint32_t queue_family_index = 0;
19055 VkBufferCreateInfo buffer_create_info = {};
19056 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19057 buffer_create_info.pNext = &dedicated_buffer_create_info;
19058 buffer_create_info.size = 1024;
19059 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19060 buffer_create_info.queueFamilyIndexCount = 1;
19061 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19062
19063 VkBuffer buffer;
19064 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19065 ASSERT_VK_SUCCESS(err);
19066
19067 VkMemoryRequirements memory_reqs;
19068 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19069
19070 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19071 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19072 dedicated_memory_info.pNext = nullptr;
19073 dedicated_memory_info.buffer = buffer;
19074 dedicated_memory_info.image = VK_NULL_HANDLE;
19075
19076 VkMemoryAllocateInfo memory_info = {};
19077 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19078 memory_info.pNext = &dedicated_memory_info;
19079 memory_info.allocationSize = memory_reqs.size;
19080
19081 bool pass;
19082 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19083 ASSERT_TRUE(pass);
19084
19085 VkDeviceMemory buffer_memory;
19086 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19087 ASSERT_VK_SUCCESS(err);
19088
19089 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19090 ASSERT_VK_SUCCESS(err);
19091
19092 vkDestroyBuffer(m_device->device(), buffer, NULL);
19093 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19094
19095 m_errorMonitor->VerifyNotFound();
19096 }
19097}
19098
19099TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19100 VkResult err;
19101
19102 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19103
19104 ASSERT_NO_FATAL_FAILURE(InitState());
19105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19106
19107 std::vector<const char *> device_extension_names;
19108 auto features = m_device->phy().features();
19109 // Artificially disable support for non-solid fill modes
19110 features.fillModeNonSolid = false;
19111 // The sacrificial device object
19112 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19113
19114 VkRenderpassObj render_pass(&test_device);
19115
19116 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19117 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19118 pipeline_layout_ci.setLayoutCount = 0;
19119 pipeline_layout_ci.pSetLayouts = NULL;
19120
19121 VkPipelineLayout pipeline_layout;
19122 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19123 ASSERT_VK_SUCCESS(err);
19124
19125 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19126 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19127 rs_ci.pNext = nullptr;
19128 rs_ci.lineWidth = 1.0f;
19129 rs_ci.rasterizerDiscardEnable = true;
19130
19131 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19132 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19133
19134 // Set polygonMode=FILL. No error is expected
19135 m_errorMonitor->ExpectSuccess();
19136 {
19137 VkPipelineObj pipe(&test_device);
19138 pipe.AddShader(&vs);
19139 pipe.AddShader(&fs);
19140 pipe.AddColorAttachment();
19141 // Set polygonMode to a good value
19142 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19143 pipe.SetRasterization(&rs_ci);
19144 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19145 }
19146 m_errorMonitor->VerifyNotFound();
19147
19148 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19149}
19150
19151TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19152 VkResult err;
19153 ASSERT_NO_FATAL_FAILURE(InitState());
19154 ASSERT_NO_FATAL_FAILURE(InitViewport());
19155 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19156
19157 VkPipelineLayout pipeline_layout;
19158 VkPushConstantRange pc_range = {};
19159 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19160 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19161 pipeline_layout_ci.pushConstantRangeCount = 1;
19162 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19163
19164 //
19165 // Check for invalid push constant ranges in pipeline layouts.
19166 //
19167 struct PipelineLayoutTestCase {
19168 VkPushConstantRange const range;
19169 char const *msg;
19170 };
19171
19172 // Check for overlapping ranges
19173 const uint32_t ranges_per_test = 5;
19174 struct OverlappingRangeTestCase {
19175 VkPushConstantRange const ranges[ranges_per_test];
19176 char const *msg;
19177 };
19178
19179 // Run some positive tests to make sure overlap checking in the layer is OK
19180 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19181 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19182 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19183 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19184 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19185 "" },
19186 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19187 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19188 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19189 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19190 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19191 "" } } };
19192 for (const auto &iter : overlapping_range_tests_pos) {
19193 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19194 m_errorMonitor->ExpectSuccess();
19195 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19196 m_errorMonitor->VerifyNotFound();
19197 if (VK_SUCCESS == err) {
19198 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19199 }
19200 }
19201
19202 //
19203 // CmdPushConstants tests
19204 //
19205 const uint8_t dummy_values[100] = {};
19206
19207 BeginCommandBuffer();
19208
19209 // positive overlapping range tests with cmd
19210 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19211 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19212 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19213 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19214 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19215 } };
19216
19217 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19218 const VkPushConstantRange pc_range4[] = {
19219 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19220 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19221 };
19222
19223 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19224 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19225 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19226 ASSERT_VK_SUCCESS(err);
19227 for (const auto &iter : cmd_overlap_tests_pos) {
19228 m_errorMonitor->ExpectSuccess();
19229 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19230 iter.range.size, dummy_values);
19231 m_errorMonitor->VerifyNotFound();
19232 }
19233 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19234
19235 EndCommandBuffer();
19236}
19237
19238
19239
19240
19241
19242
19243
19244#if 0 // A few devices have issues with this test so disabling for now
19245TEST_F(VkPositiveLayerTest, LongFenceChain)
19246{
19247 m_errorMonitor->ExpectSuccess();
19248
19249 ASSERT_NO_FATAL_FAILURE(InitState());
19250 VkResult err;
19251
19252 std::vector<VkFence> fences;
19253
19254 const int chainLength = 32768;
19255
19256 for (int i = 0; i < chainLength; i++) {
19257 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19258 VkFence fence;
19259 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19260 ASSERT_VK_SUCCESS(err);
19261
19262 fences.push_back(fence);
19263
19264 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19265 0, nullptr, 0, nullptr };
19266 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19267 ASSERT_VK_SUCCESS(err);
19268
19269 }
19270
19271 // BOOM, stack overflow.
19272 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19273
19274 for (auto fence : fences)
19275 vkDestroyFence(m_device->device(), fence, nullptr);
19276
19277 m_errorMonitor->VerifyNotFound();
19278}
19279#endif
19280
19281
Cody Northrop1242dfd2016-07-13 17:24:59 -060019282#if defined(ANDROID) && defined(VALIDATION_APK)
19283static bool initialized = false;
19284static bool active = false;
19285
19286// Convert Intents to argv
19287// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019288std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019289 std::vector<std::string> args;
19290 JavaVM &vm = *app.activity->vm;
19291 JNIEnv *p_env;
19292 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19293 return args;
19294
19295 JNIEnv &env = *p_env;
19296 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019297 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019298 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019299 jmethodID get_string_extra_method =
19300 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019301 jvalue get_string_extra_args;
19302 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019303 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019304
19305 std::string args_str;
19306 if (extra_str) {
19307 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19308 args_str = extra_utf;
19309 env.ReleaseStringUTFChars(extra_str, extra_utf);
19310 env.DeleteLocalRef(extra_str);
19311 }
19312
19313 env.DeleteLocalRef(get_string_extra_args.l);
19314 env.DeleteLocalRef(intent);
19315 vm.DetachCurrentThread();
19316
19317 // split args_str
19318 std::stringstream ss(args_str);
19319 std::string arg;
19320 while (std::getline(ss, arg, ' ')) {
19321 if (!arg.empty())
19322 args.push_back(arg);
19323 }
19324
19325 return args;
19326}
19327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019328static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019330static void processCommand(struct android_app *app, int32_t cmd) {
19331 switch (cmd) {
19332 case APP_CMD_INIT_WINDOW: {
19333 if (app->window) {
19334 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019335 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019336 break;
19337 }
19338 case APP_CMD_GAINED_FOCUS: {
19339 active = true;
19340 break;
19341 }
19342 case APP_CMD_LOST_FOCUS: {
19343 active = false;
19344 break;
19345 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019346 }
19347}
19348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019349void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019350 app_dummy();
19351
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019352 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019353
19354 int vulkanSupport = InitVulkan();
19355 if (vulkanSupport == 0) {
19356 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19357 return;
19358 }
19359
19360 app->onAppCmd = processCommand;
19361 app->onInputEvent = processInput;
19362
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019363 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019364 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019365 struct android_poll_source *source;
19366 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019367 if (source) {
19368 source->process(app, source);
19369 }
19370
19371 if (app->destroyRequested != 0) {
19372 VkTestFramework::Finish();
19373 return;
19374 }
19375 }
19376
19377 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019378 // Use the following key to send arguments to gtest, i.e.
19379 // --es args "--gtest_filter=-VkLayerTest.foo"
19380 const char key[] = "args";
19381 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019383 std::string filter = "";
19384 if (args.size() > 0) {
19385 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19386 filter += args[0];
19387 } else {
19388 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19389 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019391 int argc = 2;
19392 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19393 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019395 // Route output to files until we can override the gtest output
19396 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19397 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019399 ::testing::InitGoogleTest(&argc, argv);
19400 VkTestFramework::InitArgs(&argc, argv);
19401 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019403 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019405 if (result != 0) {
19406 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19407 } else {
19408 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19409 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019410
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019411 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019412
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019413 fclose(stdout);
19414 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019415
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019416 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019418 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019419 }
19420 }
19421}
19422#endif
19423
Tony Barbour300a6082015-04-07 13:44:53 -060019424int main(int argc, char **argv) {
19425 int result;
19426
Cody Northrop8e54a402016-03-08 22:25:52 -070019427#ifdef ANDROID
19428 int vulkanSupport = InitVulkan();
19429 if (vulkanSupport == 0)
19430 return 1;
19431#endif
19432
Tony Barbour300a6082015-04-07 13:44:53 -060019433 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019434 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019435
19436 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19437
19438 result = RUN_ALL_TESTS();
19439
Tony Barbour6918cd52015-04-09 12:58:51 -060019440 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019441 return result;
19442}