blob: fdeadb02cf3ebf00eaeb8e9ee0813af280651f31 [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();
Tony Barbour59b42282016-11-03 13:31:28 -0600225 if (otherMsgs.size()) {
226 cout << "Other error messages logged for this test were:" << endl;
227 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
228 cout << " " << *iter << endl;
229 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600230 }
231 }
232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200234
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
236 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
237 m_msgFlags = message_flag_mask;
238 // Match ANY message matching specified type
239 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200240 }
241
242 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600243 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244 if (!DesiredMsgFound()) {
245 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600246 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600247 FAIL() << "Did not receive expected error '" << desired_msg << "'";
248 }
Tony Barbour59b42282016-11-03 13:31:28 -0600249 for (auto desired_id : m_desired_message_ids) {
250 FAIL() << "Did not receive expected error '" << desired_id << "'";
251 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 }
253 }
254
255 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 if (DesiredMsgFound()) {
258 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600259 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600260 FAIL() << "Expected to succeed but got error: " << msg;
261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
263 }
264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 private:
266 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600267 std::unordered_set<uint32_t>m_desired_message_ids;
268 std::unordered_set<string> m_desired_message_strings;
269 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700270 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600271 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700272 bool *m_bailout;
273 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600274};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500275
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600276static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
277 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
278 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
280 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600281 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600282 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600283 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600284}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500285
Karl Schultz6addd812016-02-02 17:17:23 -0700286class VkLayerTest : public VkRenderFramework {
287 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
289 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
291 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700292 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
294 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700295 }
Tony Barbour300a6082015-04-07 13:44:53 -0600296
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
301 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700302 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
308 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
309 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700310 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
311 }
312 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
313 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
314 }
315
316 protected:
317 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600318 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
320 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600321 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600322 std::vector<const char *> instance_extension_names;
323 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600324
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600326 /*
327 * Since CreateDbgMsgCallback is an instance level extension call
328 * any extension / layer that utilizes that feature also needs
329 * to be enabled at create instance time.
330 */
Karl Schultz6addd812016-02-02 17:17:23 -0700331 // Use Threading layer first to protect others from
332 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600334 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700336 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800337 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600338 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700339 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600340
Ian Elliott2c1daf52016-05-12 09:41:46 -0600341 if (m_enableWSI) {
342 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
343 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
344#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
345#if defined(VK_USE_PLATFORM_ANDROID_KHR)
346 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_ANDROID_KHR
348#if defined(VK_USE_PLATFORM_MIR_KHR)
349 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_MIR_KHR
351#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
352 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_WAYLAND_KHR
354#if defined(VK_USE_PLATFORM_WIN32_KHR)
355 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WIN32_KHR
357#endif // NEED_TO_TEST_THIS_ON_PLATFORM
358#if defined(VK_USE_PLATFORM_XCB_KHR)
359 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
360#elif defined(VK_USE_PLATFORM_XLIB_KHR)
361 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
362#endif // VK_USE_PLATFORM_XLIB_KHR
363 }
364
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600366 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800367 this->app_info.pApplicationName = "layer_tests";
368 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pEngineName = "unittest";
370 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600371 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600372
Tony Barbour15524c32015-04-29 17:34:29 -0600373 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
376
377 virtual void TearDown() {
378 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600379 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600380 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600381 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600382
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600384};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385
Karl Schultz6addd812016-02-02 17:17:23 -0700386VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600390
391 /*
392 * For render test all drawing happens in a single render pass
393 * on a single command buffer.
394 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200395 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600397 }
398
399 return result;
400}
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600404
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200405 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200407 }
Tony Barbour300a6082015-04-07 13:44:53 -0600408
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600410
411 return result;
412}
413
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600414void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500415 // Create identity matrix
416 int i;
417 struct vktriangle_vs_uniform data;
418
419 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700420 glm::mat4 View = glm::mat4(1.0f);
421 glm::mat4 Model = glm::mat4(1.0f);
422 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700424 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425
426 memcpy(&data.mvp, &MVP[0][0], matrixSize);
427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 {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 -0500430 };
431
Karl Schultz6addd812016-02-02 17:17:23 -0700432 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 data.position[i][0] = tri_data[i].posX;
434 data.position[i][1] = tri_data[i].posY;
435 data.position[i][2] = tri_data[i].posZ;
436 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700437 data.color[i][0] = tri_data[i].r;
438 data.color[i][1] = tri_data[i].g;
439 data.color[i][2] = tri_data[i].b;
440 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441 }
442
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 ASSERT_NO_FATAL_FAILURE(InitViewport());
444
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200445 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
446 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Karl Schultz6addd812016-02-02 17:17:23 -0700448 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600449 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800452 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 pipelineobj.AddShader(&vs);
454 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 if (failMask & BsoFailLineWidth) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600458 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
460 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBias) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600464 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600466 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600467 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 }
Karl Schultz6addd812016-02-02 17:17:23 -0700470 // Viewport and scissors must stay in synch or other errors will occur than
471 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 if (failMask & BsoFailViewport) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
474 }
475 if (failMask & BsoFailScissor) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
477 }
478 if (failMask & BsoFailBlend) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 VkPipelineColorBlendAttachmentState att_state = {};
481 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
482 att_state.blendEnable = VK_TRUE;
483 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 }
485 if (failMask & BsoFailDepthBounds) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
487 }
488 if (failMask & BsoFailStencilReadMask) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
490 }
491 if (failMask & BsoFailStencilWriteMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
493 }
494 if (failMask & BsoFailStencilReference) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
496 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
498 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600502 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Tony Barbourfe3351b2015-07-28 10:17:20 -0600504 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505
506 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600507 if (failMask & BsoFailIndexBuffer) {
508 // Use DrawIndexed w/o an index buffer bound
509 DrawIndexed(3, 1, 0, 0, 0);
510 } else {
511 Draw(3, 1, 0, 0);
512 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mark Muellerd4914412016-06-13 17:52:06 -0600514 if (failMask & BsoFailCmdClearAttachments) {
515 VkClearAttachment color_attachment = {};
516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
517 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
518 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
519
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600521 }
522
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Tony Barbourfe3351b2015-07-28 10:17:20 -0600526 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527}
528
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
530 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700538 // Make sure depthWriteEnable is set so that Depth fail test will work
539 // correctly
540 // Make sure stencilTestEnable is set so that Stencil fail test will work
541 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600542 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800543 stencil.failOp = VK_STENCIL_OP_KEEP;
544 stencil.passOp = VK_STENCIL_OP_KEEP;
545 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
546 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600547
548 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
549 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.pNext = NULL;
551 ds_ci.depthTestEnable = VK_FALSE;
552 ds_ci.depthWriteEnable = VK_TRUE;
553 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
554 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600555 if (failMask & BsoFailDepthBounds) {
556 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600557 ds_ci.maxDepthBounds = 0.0f;
558 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600559 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600560 ds_ci.stencilTestEnable = VK_TRUE;
561 ds_ci.front = stencil;
562 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600563
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600564 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600565 pipelineobj.SetViewport(m_viewports);
566 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800567 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 commandBuffer->BindPipeline(pipelineobj);
571 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500572}
573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600574class VkPositiveLayerTest : public VkLayerTest {
575 public:
576 protected:
577};
578
Ian Elliott2c1daf52016-05-12 09:41:46 -0600579class VkWsiEnabledLayerTest : public VkLayerTest {
580 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 protected:
582 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600583};
584
Mark Muellerdfe37552016-07-07 14:47:42 -0600585class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600587 enum eTestEnFlags {
588 eDoubleDelete,
589 eInvalidDeviceOffset,
590 eInvalidMemoryOffset,
591 eBindNullBuffer,
592 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600593 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 };
595
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
599 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 return true;
601 }
602 VkDeviceSize offset_limit = 0;
603 if (eInvalidMemoryOffset == aTestFlag) {
604 VkBuffer vulkanBuffer;
605 VkBufferCreateInfo buffer_create_info = {};
606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
607 buffer_create_info.size = 32;
608 buffer_create_info.usage = aBufferUsage;
609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600611 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
615 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
617 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600618 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 }
623 if (eOffsetAlignment < offset_limit) {
624 return true;
625 }
626 return false;
627 }
628
629 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
631 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 if (eBindNullBuffer == aTestFlag) {
634 VulkanMemory = 0;
635 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
636 } else {
637 VkBufferCreateInfo buffer_create_info = {};
638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 buffer_create_info.size = 32;
640 buffer_create_info.usage = aBufferUsage;
641
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 CreateCurrent = true;
645
646 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648
649 VkMemoryAllocateInfo memory_allocate_info = {};
650 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
651 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
653 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 if (!pass) {
655 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
656 return;
657 }
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 AllocateCurrent = true;
661 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
663 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 BoundCurrent = true;
665
666 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
667 }
668 }
669
670 ~VkBufferTest() {
671 if (CreateCurrent) {
672 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
673 }
674 if (AllocateCurrent) {
675 if (InvalidDeleteEn) {
676 union {
677 VkDeviceMemory device_memory;
678 unsigned long long index_access;
679 } bad_index;
680
681 bad_index.device_memory = VulkanMemory;
682 bad_index.index_access++;
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 }
686 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
687 }
688 }
689
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600690 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600693
694 void TestDoubleDestroy() {
695 // Destroy the buffer but leave the flag set, which will cause
696 // the buffer to be destroyed again in the destructor.
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600701 bool AllocateCurrent;
702 bool BoundCurrent;
703 bool CreateCurrent;
704 bool InvalidDeleteEn;
705
706 VkBuffer VulkanBuffer;
707 VkDevice VulkanDevice;
708 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709};
710
711class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 public:
713 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
718 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BindIdGenerator++; // NB: This can wrap w/misuse
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
722 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
725 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
726 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
727 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
728 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729
730 unsigned i = 0;
731 do {
732 VertexInputAttributeDescription[i].binding = BindId;
733 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
735 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (AttributeCount < i);
738
739 i = 0;
740 do {
741 VertexInputBindingDescription[i].binding = BindId;
742 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 i++;
745 } while (BindingCount < i);
746 }
747
748 ~VkVerticesObj() {
749 if (VertexInputAttributeDescription) {
750 delete[] VertexInputAttributeDescription;
751 }
752 if (VertexInputBindingDescription) {
753 delete[] VertexInputBindingDescription;
754 }
755 }
756
757 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
759 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 return true;
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 VkDeviceSize *offsetList;
765 unsigned offsetCount;
766
767 if (aOffsetCount) {
768 offsetList = aOffsetList;
769 offsetCount = aOffsetCount;
770 } else {
771 offsetList = new VkDeviceSize[1]();
772 offsetCount = 1;
773 }
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 BoundCurrent = true;
777
778 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600780 }
781 }
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600784 static uint32_t BindIdGenerator;
785
786 bool BoundCurrent;
787 unsigned AttributeCount;
788 unsigned BindingCount;
789 uint32_t BindId;
790
791 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
792 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
793 VkVertexInputBindingDescription *VertexInputBindingDescription;
794 VkConstantBufferObj VulkanMemoryBuffer;
795};
796
797uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500798// ********************************************************************************************************************
799// ********************************************************************************************************************
800// ********************************************************************************************************************
801// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802#if PARAMETER_VALIDATION_TESTS
803TEST_F(VkLayerTest, RequiredParameter) {
804 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
805 "pointer, array, and array count parameters");
806
807 ASSERT_NO_FATAL_FAILURE(InitState());
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600810 // Specify NULL for a pointer to a handle
811 // Expected to trigger an error with
812 // parameter_validation::validate_required_pointer
813 vkGetPhysicalDeviceFeatures(gpu(), NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
817 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify NULL for pointer to array count
819 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600820 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify 0 for a required array count
825 // Expected to trigger an error with parameter_validation::validate_array
826 VkViewport view_port = {};
827 m_commandBuffer->SetViewport(0, 0, &view_port);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for a required array
832 // Expected to trigger an error with parameter_validation::validate_array
833 m_commandBuffer->SetViewport(0, 1, NULL);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify VK_NULL_HANDLE for a required handle
838 // Expected to trigger an error with
839 // parameter_validation::validate_required_handle
840 vkUnmapMemory(device(), VK_NULL_HANDLE);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify VK_NULL_HANDLE for a required handle array entry
846 // Expected to trigger an error with
847 // parameter_validation::validate_required_handle_array
848 VkFence fence = VK_NULL_HANDLE;
849 vkResetFences(device(), 1, &fence);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600853 // Specify NULL for a required struct pointer
854 // Expected to trigger an error with
855 // parameter_validation::validate_struct_type
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), NULL, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required VkFlags parameter
862 // Expected to trigger an error with parameter_validation::validate_flags
863 m_commandBuffer->SetStencilReference(0, 0);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 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 -0600867 // Specify 0 for a required VkFlags array entry
868 // Expected to trigger an error with
869 // parameter_validation::validate_flags_array
870 VkSemaphore semaphore = VK_NULL_HANDLE;
871 VkPipelineStageFlags stageFlags = 0;
872 VkSubmitInfo submitInfo = {};
873 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
874 submitInfo.waitSemaphoreCount = 1;
875 submitInfo.pWaitSemaphores = &semaphore;
876 submitInfo.pWaitDstStageMask = &stageFlags;
877 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600880
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881TEST_F(VkLayerTest, ReservedParameter) {
882 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600887 // Specify 0 for a reserved VkFlags parameter
888 // Expected to trigger an error with
889 // parameter_validation::validate_reserved_flags
890 VkEvent event_handle = VK_NULL_HANDLE;
891 VkEventCreateInfo event_info = {};
892 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
893 event_info.flags = 1;
894 vkCreateEvent(device(), &event_info, NULL, &event_handle);
895 m_errorMonitor->VerifyFound();
896}
897
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600898TEST_F(VkLayerTest, InvalidStructSType) {
899 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
900 "structure's sType field");
901
902 ASSERT_NO_FATAL_FAILURE(InitState());
903
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600905 // Zero struct memory, effectively setting sType to
906 // VK_STRUCTURE_TYPE_APPLICATION_INFO
907 // Expected to trigger an error with
908 // parameter_validation::validate_struct_type
909 VkMemoryAllocateInfo alloc_info = {};
910 VkDeviceMemory memory = VK_NULL_HANDLE;
911 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
912 m_errorMonitor->VerifyFound();
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915 // Zero struct memory, effectively setting sType to
916 // VK_STRUCTURE_TYPE_APPLICATION_INFO
917 // Expected to trigger an error with
918 // parameter_validation::validate_struct_type_array
919 VkSubmitInfo submit_info = {};
920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
921 m_errorMonitor->VerifyFound();
922}
923
924TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600925 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600931 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600932 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600933 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600934 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600935 // Zero-initialization will provide the correct sType
936 VkApplicationInfo app_info = {};
937 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
938 event_alloc_info.pNext = &app_info;
939 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
943 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
945 // a function that has allowed pNext structure types and specify
946 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600949 VkMemoryAllocateInfo memory_alloc_info = {};
950 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
951 memory_alloc_info.pNext = &app_info;
952 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600954}
Dustin Graves5d33d532016-05-09 16:21:12 -0600955
956TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959 ASSERT_NO_FATAL_FAILURE(InitState());
960
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
962 "range of the core VkFormat "
963 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 // Specify an invalid VkFormat value
965 // Expected to trigger an error with
966 // parameter_validation::validate_ranged_enum
967 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600968 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 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 -0600972 // Specify an invalid VkFlags bitmask value
973 // Expected to trigger an error with parameter_validation::validate_flags
974 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
976 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 m_errorMonitor->VerifyFound();
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 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 -0600980 // Specify an invalid VkFlags array entry
981 // Expected to trigger an error with
982 // parameter_validation::validate_flags_array
983 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 VkSubmitInfo submit_info = {};
986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
987 submit_info.waitSemaphoreCount = 1;
988 submit_info.pWaitSemaphores = &semaphore;
989 submit_info.pWaitDstStageMask = &stage_flags;
990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkBool32 value
995 // Expected to trigger a warning with
996 // parameter_validation::validate_bool32
997 VkSampler sampler = VK_NULL_HANDLE;
998 VkSamplerCreateInfo sampler_info = {};
999 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1000 sampler_info.pNext = NULL;
1001 sampler_info.magFilter = VK_FILTER_NEAREST;
1002 sampler_info.minFilter = VK_FILTER_NEAREST;
1003 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1004 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1005 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1006 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1007 sampler_info.mipLodBias = 1.0;
1008 sampler_info.maxAnisotropy = 1;
1009 sampler_info.compareEnable = VK_FALSE;
1010 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1011 sampler_info.minLod = 1.0;
1012 sampler_info.maxLod = 1.0;
1013 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1014 sampler_info.unnormalizedCoordinates = VK_FALSE;
1015 // Not VK_TRUE or VK_FALSE
1016 sampler_info.anisotropyEnable = 3;
1017 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1018 m_errorMonitor->VerifyFound();
1019}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001020
1021TEST_F(VkLayerTest, FailedReturnValue) {
1022 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 // Find an unsupported image format
1027 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1028 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1029 VkFormat format = static_cast<VkFormat>(f);
1030 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001031 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 unsupported = format;
1033 break;
1034 }
1035 }
1036
1037 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1039 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Specify an unsupported VkFormat value to generate a
1041 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1042 // Expected to trigger a warning from
1043 // parameter_validation::validate_result
1044 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1046 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1048 m_errorMonitor->VerifyFound();
1049 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001051
1052TEST_F(VkLayerTest, UpdateBufferAlignment) {
1053 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055
1056 ASSERT_NO_FATAL_FAILURE(InitState());
1057
1058 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1059 vk_testing::Buffer buffer;
1060 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1061
1062 BeginCommandBuffer();
1063 // Introduce failure by using dstOffset 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(), 1, 4, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is < 0
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 // Introduce failure by using dataSize that is > 65536
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1083 m_errorMonitor->VerifyFound();
1084
1085 EndCommandBuffer();
1086}
1087
1088TEST_F(VkLayerTest, FillBufferAlignment) {
1089 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1090
1091 ASSERT_NO_FATAL_FAILURE(InitState());
1092
1093 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1094 vk_testing::Buffer buffer;
1095 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1096
1097 BeginCommandBuffer();
1098
1099 // Introduce failure by using dstOffset 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(), 1, 4, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1112 m_errorMonitor->VerifyFound();
1113
1114 EndCommandBuffer();
1115}
Dustin Graves40f35822016-06-23 11:12:53 -06001116
Cortd889ff92016-07-27 09:51:27 -07001117TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1118 VkResult err;
1119
1120 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1125
1126 std::vector<const char *> device_extension_names;
1127 auto features = m_device->phy().features();
1128 // Artificially disable support for non-solid fill modes
1129 features.fillModeNonSolid = false;
1130 // The sacrificial device object
1131 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1132
1133 VkRenderpassObj render_pass(&test_device);
1134
1135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1137 pipeline_layout_ci.setLayoutCount = 0;
1138 pipeline_layout_ci.pSetLayouts = NULL;
1139
1140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001141 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001142 ASSERT_VK_SUCCESS(err);
1143
1144 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1145 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1146 rs_ci.pNext = nullptr;
1147 rs_ci.lineWidth = 1.0f;
1148 rs_ci.rasterizerDiscardEnable = true;
1149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1151 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001152
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001153 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1155 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001156 {
1157 VkPipelineObj pipe(&test_device);
1158 pipe.AddShader(&vs);
1159 pipe.AddShader(&fs);
1160 pipe.AddColorAttachment();
1161 // Introduce failure by setting unsupported polygon mode
1162 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1163 pipe.SetRasterization(&rs_ci);
1164 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1165 }
1166 m_errorMonitor->VerifyFound();
1167
1168 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1170 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001171 {
1172 VkPipelineObj pipe(&test_device);
1173 pipe.AddShader(&vs);
1174 pipe.AddShader(&fs);
1175 pipe.AddColorAttachment();
1176 // Introduce failure by setting unsupported polygon mode
1177 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1178 pipe.SetRasterization(&rs_ci);
1179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1180 }
1181 m_errorMonitor->VerifyFound();
1182
Cortd889ff92016-07-27 09:51:27 -07001183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1184}
1185
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001186#endif // PARAMETER_VALIDATION_TESTS
1187
Tobin Ehlis0788f522015-05-26 16:11:58 -06001188#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001191{
1192 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193 VkFenceCreateInfo fenceInfo = {};
1194 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195 fenceInfo.pNext = NULL;
1196 fenceInfo.flags = 0;
1197
Mike Weiblencce7ec72016-10-17 19:33:05 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001201
1202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1203 vk_testing::Buffer buffer;
1204 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
Tony Barbourfe3351b2015-07-28 10:17:20 -06001206 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001207 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001208 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209
1210 testFence.init(*m_device, fenceInfo);
1211
1212 // Bypass framework since it does the waits automatically
1213 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1216 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001219 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001222 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001223 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001224
1225 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226 ASSERT_VK_SUCCESS( err );
1227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001231 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232}
1233
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235{
1236 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237 VkFenceCreateInfo fenceInfo = {};
1238 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1239 fenceInfo.pNext = NULL;
1240 fenceInfo.flags = 0;
1241
Mike Weiblencce7ec72016-10-17 19:33:05 -06001242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 ASSERT_NO_FATAL_FAILURE(InitViewport());
1246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251
1252 testFence.init(*m_device, fenceInfo);
1253
1254 // Bypass framework since it does the waits automatically
1255 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1258 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001261 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001264 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001265 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001266
1267 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268 ASSERT_VK_SUCCESS( err );
1269
Jon Ashburnf19916e2016-01-11 13:12:43 -07001270 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271 VkCommandBufferBeginInfo info = {};
1272 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1273 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274 info.renderPass = VK_NULL_HANDLE;
1275 info.subpass = 0;
1276 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001277 info.occlusionQueryEnable = VK_FALSE;
1278 info.queryFlags = 0;
1279 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280
1281 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001284 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001286#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287
Tobin Ehlisf11be982016-05-11 13:52:53 -06001288TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1289 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1290 "buffer and image to memory such that they will alias.");
1291 VkResult err;
1292 bool pass;
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001297 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001298 VkDeviceMemory mem; // buffer will be bound first
1299 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001300 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301
1302 VkBufferCreateInfo buf_info = {};
1303 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1304 buf_info.pNext = NULL;
1305 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1306 buf_info.size = 256;
1307 buf_info.queueFamilyIndexCount = 0;
1308 buf_info.pQueueFamilyIndices = NULL;
1309 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1310 buf_info.flags = 0;
1311 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001315
1316 VkImageCreateInfo image_create_info = {};
1317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1318 image_create_info.pNext = NULL;
1319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1320 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1321 image_create_info.extent.width = 64;
1322 image_create_info.extent.height = 64;
1323 image_create_info.extent.depth = 1;
1324 image_create_info.mipLevels = 1;
1325 image_create_info.arrayLayers = 1;
1326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001327 // Image tiling must be optimal to trigger error when aliasing linear buffer
1328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001329 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1331 image_create_info.queueFamilyIndexCount = 0;
1332 image_create_info.pQueueFamilyIndices = NULL;
1333 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 image_create_info.flags = 0;
1335
Tobin Ehlisf11be982016-05-11 13:52:53 -06001336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1337 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1339 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1342
1343 VkMemoryAllocateInfo alloc_info = {};
1344 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1345 alloc_info.pNext = NULL;
1346 alloc_info.memoryTypeIndex = 0;
1347 // Ensure memory is big enough for both bindings
1348 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1350 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001352 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 vkDestroyImage(m_device->device(), image, NULL);
1354 return;
1355 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1357 ASSERT_VK_SUCCESS(err);
1358 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1359 ASSERT_VK_SUCCESS(err);
1360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1364 m_errorMonitor->VerifyFound();
1365
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 // aliasing buffer2
1368 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1369 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001372 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001375 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 m_errorMonitor->VerifyFound();
1377
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001381 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 vkFreeMemory(m_device->device(), mem, NULL);
1383 vkFreeMemory(m_device->device(), mem_img, NULL);
1384}
1385
Tobin Ehlis35372522016-05-12 08:32:31 -06001386TEST_F(VkLayerTest, InvalidMemoryMapping) {
1387 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1388 VkResult err;
1389 bool pass;
1390 ASSERT_NO_FATAL_FAILURE(InitState());
1391
1392 VkBuffer buffer;
1393 VkDeviceMemory mem;
1394 VkMemoryRequirements mem_reqs;
1395
1396 VkBufferCreateInfo buf_info = {};
1397 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1398 buf_info.pNext = NULL;
1399 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1400 buf_info.size = 256;
1401 buf_info.queueFamilyIndexCount = 0;
1402 buf_info.pQueueFamilyIndices = NULL;
1403 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1404 buf_info.flags = 0;
1405 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1406 ASSERT_VK_SUCCESS(err);
1407
1408 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1409 VkMemoryAllocateInfo alloc_info = {};
1410 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1411 alloc_info.pNext = NULL;
1412 alloc_info.memoryTypeIndex = 0;
1413
1414 // Ensure memory is big enough for both bindings
1415 static const VkDeviceSize allocation_size = 0x10000;
1416 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001417 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 -06001418 if (!pass) {
1419 vkDestroyBuffer(m_device->device(), buffer, NULL);
1420 return;
1421 }
1422 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1423 ASSERT_VK_SUCCESS(err);
1424
1425 uint8_t *pData;
1426 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001427 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 -06001428 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1429 m_errorMonitor->VerifyFound();
1430 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001431 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001432 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1434 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1435 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001436 m_errorMonitor->VerifyFound();
1437
1438 // Unmap the memory to avoid re-map error
1439 vkUnmapMemory(m_device->device(), mem);
1440 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1442 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1443 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001444 m_errorMonitor->VerifyFound();
1445 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1447 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001448 m_errorMonitor->VerifyFound();
1449 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001451 vkUnmapMemory(m_device->device(), mem);
1452 m_errorMonitor->VerifyFound();
1453 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001454 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001455 ASSERT_VK_SUCCESS(err);
1456 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001457 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 mmr.memory = mem;
1459 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1462 m_errorMonitor->VerifyFound();
1463 // Now flush range that oversteps mapped range
1464 vkUnmapMemory(m_device->device(), mem);
1465 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1466 ASSERT_VK_SUCCESS(err);
1467 mmr.offset = 16;
1468 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1471 m_errorMonitor->VerifyFound();
1472
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001473 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1474 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001475 if (!pass) {
1476 vkFreeMemory(m_device->device(), mem, NULL);
1477 vkDestroyBuffer(m_device->device(), buffer, NULL);
1478 return;
1479 }
1480 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1481 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1482
1483 vkDestroyBuffer(m_device->device(), buffer, NULL);
1484 vkFreeMemory(m_device->device(), mem, NULL);
1485}
1486
Ian Elliott1c32c772016-04-28 14:47:13 -06001487TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1488 VkResult err;
1489 bool pass;
1490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001491 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1492 // following declaration (which is temporarily being moved below):
1493 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001494 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001495 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001496 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001497 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001498 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001499 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001500
1501 ASSERT_NO_FATAL_FAILURE(InitState());
1502
Ian Elliott3f06ce52016-04-29 14:46:21 -06001503#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1504#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1505 // Use the functions from the VK_KHR_android_surface extension without
1506 // enabling that extension:
1507
1508 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001509 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1511 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001512 pass = (err != VK_SUCCESS);
1513 ASSERT_TRUE(pass);
1514 m_errorMonitor->VerifyFound();
1515#endif // VK_USE_PLATFORM_ANDROID_KHR
1516
Ian Elliott3f06ce52016-04-29 14:46:21 -06001517#if defined(VK_USE_PLATFORM_MIR_KHR)
1518 // Use the functions from the VK_KHR_mir_surface extension without enabling
1519 // that extension:
1520
1521 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001522 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001524 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1525 pass = (err != VK_SUCCESS);
1526 ASSERT_TRUE(pass);
1527 m_errorMonitor->VerifyFound();
1528
1529 // Tell whether an mir_connection supports presentation:
1530 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1532 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001533 m_errorMonitor->VerifyFound();
1534#endif // VK_USE_PLATFORM_MIR_KHR
1535
Ian Elliott3f06ce52016-04-29 14:46:21 -06001536#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1537 // Use the functions from the VK_KHR_wayland_surface extension without
1538 // enabling that extension:
1539
1540 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001541 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1543 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001544 pass = (err != VK_SUCCESS);
1545 ASSERT_TRUE(pass);
1546 m_errorMonitor->VerifyFound();
1547
1548 // Tell whether an wayland_display supports presentation:
1549 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1551 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001552 m_errorMonitor->VerifyFound();
1553#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001554#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555
Ian Elliott3f06ce52016-04-29 14:46:21 -06001556#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001557 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1558 // TO NON-LINUX PLATFORMS:
1559 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001560 // Use the functions from the VK_KHR_win32_surface extension without
1561 // enabling that extension:
1562
1563 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001564 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1566 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001567 pass = (err != VK_SUCCESS);
1568 ASSERT_TRUE(pass);
1569 m_errorMonitor->VerifyFound();
1570
1571 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001573 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001575// Set this (for now, until all platforms are supported and tested):
1576#define NEED_TO_TEST_THIS_ON_PLATFORM
1577#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001578#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001579 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1580 // TO NON-LINUX PLATFORMS:
1581 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001582#endif
1583#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001584 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1585 // that extension:
1586
1587 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001588 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001590 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1591 pass = (err != VK_SUCCESS);
1592 ASSERT_TRUE(pass);
1593 m_errorMonitor->VerifyFound();
1594
1595 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001596 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001597 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1599 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001600 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001601// Set this (for now, until all platforms are supported and tested):
1602#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001603#endif // VK_USE_PLATFORM_XCB_KHR
1604
Ian Elliott12630812016-04-29 14:35:43 -06001605#if defined(VK_USE_PLATFORM_XLIB_KHR)
1606 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1607 // that extension:
1608
1609 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001610 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001612 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1613 pass = (err != VK_SUCCESS);
1614 ASSERT_TRUE(pass);
1615 m_errorMonitor->VerifyFound();
1616
1617 // Tell whether an Xlib VisualID supports presentation:
1618 Display *dpy = NULL;
1619 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001621 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1622 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001623// Set this (for now, until all platforms are supported and tested):
1624#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001625#endif // VK_USE_PLATFORM_XLIB_KHR
1626
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001627// Use the functions from the VK_KHR_surface extension without enabling
1628// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001629
Ian Elliott489eec02016-05-05 14:12:44 -06001630#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001631 // Destroy a surface:
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 vkDestroySurfaceKHR(instance(), surface, NULL);
1634 m_errorMonitor->VerifyFound();
1635
1636 // Check if surface supports presentation:
1637 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001639 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1640 pass = (err != VK_SUCCESS);
1641 ASSERT_TRUE(pass);
1642 m_errorMonitor->VerifyFound();
1643
1644 // Check surface capabilities:
1645 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1647 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001648 pass = (err != VK_SUCCESS);
1649 ASSERT_TRUE(pass);
1650 m_errorMonitor->VerifyFound();
1651
1652 // Check surface formats:
1653 uint32_t format_count = 0;
1654 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1656 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001657 pass = (err != VK_SUCCESS);
1658 ASSERT_TRUE(pass);
1659 m_errorMonitor->VerifyFound();
1660
1661 // Check surface present modes:
1662 uint32_t present_mode_count = 0;
1663 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1665 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001666 pass = (err != VK_SUCCESS);
1667 ASSERT_TRUE(pass);
1668 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001669#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001670
Ian Elliott1c32c772016-04-28 14:47:13 -06001671 // Use the functions from the VK_KHR_swapchain extension without enabling
1672 // that extension:
1673
1674 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001676 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1677 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001678 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001679 pass = (err != VK_SUCCESS);
1680 ASSERT_TRUE(pass);
1681 m_errorMonitor->VerifyFound();
1682
1683 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1685 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 pass = (err != VK_SUCCESS);
1687 ASSERT_TRUE(pass);
1688 m_errorMonitor->VerifyFound();
1689
Chris Forbeseb7d5502016-09-13 18:19:21 +12001690 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1691 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1692 VkFence fence;
1693 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1694
Ian Elliott1c32c772016-04-28 14:47:13 -06001695 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001697 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001698 pass = (err != VK_SUCCESS);
1699 ASSERT_TRUE(pass);
1700 m_errorMonitor->VerifyFound();
1701
Chris Forbeseb7d5502016-09-13 18:19:21 +12001702 vkDestroyFence(m_device->device(), fence, nullptr);
1703
Ian Elliott1c32c772016-04-28 14:47:13 -06001704 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001705 //
1706 // NOTE: Currently can't test this because a real swapchain is needed (as
1707 // opposed to the fake one we created) in order for the layer to lookup the
1708 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001709
1710 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001712 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1713 m_errorMonitor->VerifyFound();
1714}
1715
Karl Schultz6addd812016-02-02 17:17:23 -07001716TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1717 VkResult err;
1718 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1721 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001722
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001723 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001724
1725 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001726 VkImage image;
1727 VkDeviceMemory mem;
1728 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001729
Karl Schultz6addd812016-02-02 17:17:23 -07001730 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1731 const int32_t tex_width = 32;
1732 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001733
Tony Barboureb254902015-07-15 12:50:33 -06001734 VkImageCreateInfo image_create_info = {};
1735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001736 image_create_info.pNext = NULL;
1737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1738 image_create_info.format = tex_format;
1739 image_create_info.extent.width = tex_width;
1740 image_create_info.extent.height = tex_height;
1741 image_create_info.extent.depth = 1;
1742 image_create_info.mipLevels = 1;
1743 image_create_info.arrayLayers = 1;
1744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1745 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1746 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1747 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001748 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001749
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001750 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001751 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001752 mem_alloc.pNext = NULL;
1753 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001754
Chia-I Wuf7458c52015-10-26 21:10:41 +08001755 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001756 ASSERT_VK_SUCCESS(err);
1757
Karl Schultz6addd812016-02-02 17:17:23 -07001758 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001759
Mark Lobodzinski23065352015-05-29 09:32:35 -05001760 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001761
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001762 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 -07001763 if (!pass) { // If we can't find any unmappable memory this test doesn't
1764 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001765 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001766 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001767 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001768
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001769 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001770 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001771 ASSERT_VK_SUCCESS(err);
1772
1773 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001774 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001775 ASSERT_VK_SUCCESS(err);
1776
1777 // Map memory as if to initialize the image
1778 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001779 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001781 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001782
Chia-I Wuf7458c52015-10-26 21:10:41 +08001783 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001784 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001785}
1786
Karl Schultz6addd812016-02-02 17:17:23 -07001787TEST_F(VkLayerTest, RebindMemory) {
1788 VkResult err;
1789 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001790
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001792
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001793 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001794
1795 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001796 VkImage image;
1797 VkDeviceMemory mem1;
1798 VkDeviceMemory mem2;
1799 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001800
Karl Schultz6addd812016-02-02 17:17:23 -07001801 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1802 const int32_t tex_width = 32;
1803 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001804
Tony Barboureb254902015-07-15 12:50:33 -06001805 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001806 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1807 image_create_info.pNext = NULL;
1808 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1809 image_create_info.format = tex_format;
1810 image_create_info.extent.width = tex_width;
1811 image_create_info.extent.height = tex_height;
1812 image_create_info.extent.depth = 1;
1813 image_create_info.mipLevels = 1;
1814 image_create_info.arrayLayers = 1;
1815 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1816 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1817 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1818 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001819
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001820 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001821 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1822 mem_alloc.pNext = NULL;
1823 mem_alloc.allocationSize = 0;
1824 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001825
Karl Schultz6addd812016-02-02 17:17:23 -07001826 // Introduce failure, do NOT set memProps to
1827 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001828 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001829 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001830 ASSERT_VK_SUCCESS(err);
1831
Karl Schultz6addd812016-02-02 17:17:23 -07001832 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001833
1834 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001835 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001836 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001837
1838 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001839 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001840 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001841 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001842 ASSERT_VK_SUCCESS(err);
1843
1844 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001845 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001846 ASSERT_VK_SUCCESS(err);
1847
Karl Schultz6addd812016-02-02 17:17:23 -07001848 // Introduce validation failure, try to bind a different memory object to
1849 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001850 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001851
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001852 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001853
Chia-I Wuf7458c52015-10-26 21:10:41 +08001854 vkDestroyImage(m_device->device(), image, NULL);
1855 vkFreeMemory(m_device->device(), mem1, NULL);
1856 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001857}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001858
Karl Schultz6addd812016-02-02 17:17:23 -07001859TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001860 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1863 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001864
1865 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001866 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1867 fenceInfo.pNext = NULL;
1868 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001869
Tony Barbour300a6082015-04-07 13:44:53 -06001870 ASSERT_NO_FATAL_FAILURE(InitState());
1871 ASSERT_NO_FATAL_FAILURE(InitViewport());
1872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1873
Tony Barbourfe3351b2015-07-28 10:17:20 -06001874 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001875 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001876 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001877
1878 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001879
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001880 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001881 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1882 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001883 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001884 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001885 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001886 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001887 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001888 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001889 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001890
1891 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001892 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001893
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001894 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001895}
Chris Forbes4e44c912016-06-16 10:20:00 +12001896
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001897TEST_F(VkLayerTest, InvalidUsageBits) {
1898 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1899 "Initialize buffer with wrong usage then perform copy expecting errors "
1900 "from both the image and the buffer (2 calls)");
1901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001902
1903 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001904 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001905 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001906 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 -06001907 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001908
Tony Barbourf92621a2016-05-02 14:28:12 -06001909 VkImageView dsv;
1910 VkImageViewCreateInfo dsvci = {};
1911 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1912 dsvci.image = image.handle();
1913 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1914 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1915 dsvci.subresourceRange.layerCount = 1;
1916 dsvci.subresourceRange.baseMipLevel = 0;
1917 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001918 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001919
Tony Barbourf92621a2016-05-02 14:28:12 -06001920 // Create a view with depth / stencil aspect for image with different usage
1921 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001922
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001923 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001924
1925 // Initialize buffer with TRANSFER_DST usage
1926 vk_testing::Buffer buffer;
1927 VkMemoryPropertyFlags reqs = 0;
1928 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1929 VkBufferImageCopy region = {};
1930 region.bufferRowLength = 128;
1931 region.bufferImageHeight = 128;
1932 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1933 region.imageSubresource.layerCount = 1;
1934 region.imageExtent.height = 16;
1935 region.imageExtent.width = 16;
1936 region.imageExtent.depth = 1;
1937
Tony Barbourf92621a2016-05-02 14:28:12 -06001938 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1939 // TRANSFER_DST
1940 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001941
Chris Forbesda581202016-10-06 18:25:26 +13001942 // two separate errors from this call:
1943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1945
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001946 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1947 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001948 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001949}
Tony Barbour75d79f02016-08-30 09:39:07 -06001950
Tony Barbour75d79f02016-08-30 09:39:07 -06001951
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001952#endif // MEM_TRACKER_TESTS
1953
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001954#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001955
1956TEST_F(VkLayerTest, LeakAnObject) {
1957 VkResult err;
1958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001959 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001960
1961 // Note that we have to create a new device since destroying the
1962 // framework's device causes Teardown() to fail and just calling Teardown
1963 // will destroy the errorMonitor.
1964
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001966
1967 ASSERT_NO_FATAL_FAILURE(InitState());
1968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001970 std::vector<VkDeviceQueueCreateInfo> queue_info;
1971 queue_info.reserve(queue_props.size());
1972 std::vector<std::vector<float>> queue_priorities;
1973 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
1974 VkDeviceQueueCreateInfo qi = {};
1975 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
1976 qi.pNext = NULL;
1977 qi.queueFamilyIndex = i;
1978 qi.queueCount = queue_props[i].queueCount;
1979 queue_priorities.emplace_back(qi.queueCount, 0.0f);
1980 qi.pQueuePriorities = queue_priorities[i].data();
1981 queue_info.push_back(qi);
1982 }
1983
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001984 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001985
1986 // The sacrificial device object
1987 VkDevice testDevice;
1988 VkDeviceCreateInfo device_create_info = {};
1989 auto features = m_device->phy().features();
1990 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
1991 device_create_info.pNext = NULL;
1992 device_create_info.queueCreateInfoCount = queue_info.size();
1993 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06001994 device_create_info.enabledLayerCount = 0;
1995 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001996 device_create_info.pEnabledFeatures = &features;
1997 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
1998 ASSERT_VK_SUCCESS(err);
1999
2000 VkFence fence;
2001 VkFenceCreateInfo fence_create_info = {};
2002 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2003 fence_create_info.pNext = NULL;
2004 fence_create_info.flags = 0;
2005 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2006 ASSERT_VK_SUCCESS(err);
2007
2008 // Induce failure by not calling vkDestroyFence
2009 vkDestroyDevice(testDevice, NULL);
2010 m_errorMonitor->VerifyFound();
2011}
2012
2013TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2014
2015 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2016 "attempt to delete them from another.");
2017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002019
Cody Northropc31a84f2016-08-22 10:41:47 -06002020 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002021 VkCommandPool command_pool_one;
2022 VkCommandPool command_pool_two;
2023
2024 VkCommandPoolCreateInfo pool_create_info{};
2025 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2026 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2027 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002029 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002030
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002031 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002032
2033 VkCommandBuffer command_buffer[9];
2034 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002035 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002036 command_buffer_allocate_info.commandPool = command_pool_one;
2037 command_buffer_allocate_info.commandBufferCount = 9;
2038 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002039 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002040
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002041 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002042
2043 m_errorMonitor->VerifyFound();
2044
2045 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2046 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2047}
2048
2049TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2050 VkResult err;
2051
2052 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002053 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002056
2057 ASSERT_NO_FATAL_FAILURE(InitState());
2058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2059
2060 VkDescriptorPoolSize ds_type_count = {};
2061 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2062 ds_type_count.descriptorCount = 1;
2063
2064 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2065 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2066 ds_pool_ci.pNext = NULL;
2067 ds_pool_ci.flags = 0;
2068 ds_pool_ci.maxSets = 1;
2069 ds_pool_ci.poolSizeCount = 1;
2070 ds_pool_ci.pPoolSizes = &ds_type_count;
2071
2072 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002073 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002074 ASSERT_VK_SUCCESS(err);
2075
2076 // Create a second descriptor pool
2077 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079 ASSERT_VK_SUCCESS(err);
2080
2081 VkDescriptorSetLayoutBinding dsl_binding = {};
2082 dsl_binding.binding = 0;
2083 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2084 dsl_binding.descriptorCount = 1;
2085 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2086 dsl_binding.pImmutableSamplers = NULL;
2087
2088 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2089 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2090 ds_layout_ci.pNext = NULL;
2091 ds_layout_ci.bindingCount = 1;
2092 ds_layout_ci.pBindings = &dsl_binding;
2093
2094 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002095 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002096 ASSERT_VK_SUCCESS(err);
2097
2098 VkDescriptorSet descriptorSet;
2099 VkDescriptorSetAllocateInfo alloc_info = {};
2100 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2101 alloc_info.descriptorSetCount = 1;
2102 alloc_info.descriptorPool = ds_pool_one;
2103 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002104 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002105 ASSERT_VK_SUCCESS(err);
2106
2107 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2108
2109 m_errorMonitor->VerifyFound();
2110
2111 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2112 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2113 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2114}
2115
2116TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002119 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002120
2121 ASSERT_NO_FATAL_FAILURE(InitState());
2122
2123 // Pass bogus handle into GetImageMemoryRequirements
2124 VkMemoryRequirements mem_reqs;
2125 uint64_t fakeImageHandle = 0xCADECADE;
2126 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2127
2128 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2129
2130 m_errorMonitor->VerifyFound();
2131}
2132
Karl Schultz6addd812016-02-02 17:17:23 -07002133TEST_F(VkLayerTest, PipelineNotBound) {
2134 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002135
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002136 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002137
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002139
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002140 ASSERT_NO_FATAL_FAILURE(InitState());
2141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002142
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002143 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002144 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2145 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002146
2147 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002148 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2149 ds_pool_ci.pNext = NULL;
2150 ds_pool_ci.maxSets = 1;
2151 ds_pool_ci.poolSizeCount = 1;
2152 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002153
2154 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002155 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002156 ASSERT_VK_SUCCESS(err);
2157
2158 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002159 dsl_binding.binding = 0;
2160 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2161 dsl_binding.descriptorCount = 1;
2162 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2163 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002164
2165 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002166 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2167 ds_layout_ci.pNext = NULL;
2168 ds_layout_ci.bindingCount = 1;
2169 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002170
2171 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002173 ASSERT_VK_SUCCESS(err);
2174
2175 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002176 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002177 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002178 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002179 alloc_info.descriptorPool = ds_pool;
2180 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002181 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002182 ASSERT_VK_SUCCESS(err);
2183
2184 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002185 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2186 pipeline_layout_ci.pNext = NULL;
2187 pipeline_layout_ci.setLayoutCount = 1;
2188 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002189
2190 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002191 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002192 ASSERT_VK_SUCCESS(err);
2193
Mark Youngad779052016-01-06 14:26:04 -07002194 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002195
2196 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002198
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002199 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002200
Chia-I Wuf7458c52015-10-26 21:10:41 +08002201 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2202 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2203 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002204}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002205
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002206TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2207 VkResult err;
2208
2209 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2210 "during bind[Buffer|Image]Memory time");
2211
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002212 ASSERT_NO_FATAL_FAILURE(InitState());
2213
2214 // Create an image, allocate memory, set a bad typeIndex and then try to
2215 // bind it
2216 VkImage image;
2217 VkDeviceMemory mem;
2218 VkMemoryRequirements mem_reqs;
2219 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2220 const int32_t tex_width = 32;
2221 const int32_t tex_height = 32;
2222
2223 VkImageCreateInfo image_create_info = {};
2224 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2225 image_create_info.pNext = NULL;
2226 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2227 image_create_info.format = tex_format;
2228 image_create_info.extent.width = tex_width;
2229 image_create_info.extent.height = tex_height;
2230 image_create_info.extent.depth = 1;
2231 image_create_info.mipLevels = 1;
2232 image_create_info.arrayLayers = 1;
2233 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2234 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2235 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2236 image_create_info.flags = 0;
2237
2238 VkMemoryAllocateInfo mem_alloc = {};
2239 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2240 mem_alloc.pNext = NULL;
2241 mem_alloc.allocationSize = 0;
2242 mem_alloc.memoryTypeIndex = 0;
2243
2244 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2245 ASSERT_VK_SUCCESS(err);
2246
2247 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2248 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002249
2250 // Introduce Failure, select invalid TypeIndex
2251 VkPhysicalDeviceMemoryProperties memory_info;
2252
2253 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2254 unsigned int i;
2255 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2256 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2257 mem_alloc.memoryTypeIndex = i;
2258 break;
2259 }
2260 }
2261 if (i >= memory_info.memoryTypeCount) {
2262 printf("No invalid memory type index could be found; skipped.\n");
2263 vkDestroyImage(m_device->device(), image, NULL);
2264 return;
2265 }
2266
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002267 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 -06002268
2269 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2270 ASSERT_VK_SUCCESS(err);
2271
2272 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2273 (void)err;
2274
2275 m_errorMonitor->VerifyFound();
2276
2277 vkDestroyImage(m_device->device(), image, NULL);
2278 vkFreeMemory(m_device->device(), mem, NULL);
2279}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002280
Karl Schultz6addd812016-02-02 17:17:23 -07002281TEST_F(VkLayerTest, BindInvalidMemory) {
2282 VkResult err;
2283 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002286
Tobin Ehlisec598302015-09-15 15:02:17 -06002287 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002288
2289 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002290 VkImage image;
2291 VkDeviceMemory mem;
2292 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002293
Karl Schultz6addd812016-02-02 17:17:23 -07002294 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2295 const int32_t tex_width = 32;
2296 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002297
2298 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002299 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2300 image_create_info.pNext = NULL;
2301 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2302 image_create_info.format = tex_format;
2303 image_create_info.extent.width = tex_width;
2304 image_create_info.extent.height = tex_height;
2305 image_create_info.extent.depth = 1;
2306 image_create_info.mipLevels = 1;
2307 image_create_info.arrayLayers = 1;
2308 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2309 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2310 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2311 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002312
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002313 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002314 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2315 mem_alloc.pNext = NULL;
2316 mem_alloc.allocationSize = 0;
2317 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002318
Chia-I Wuf7458c52015-10-26 21:10:41 +08002319 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002320 ASSERT_VK_SUCCESS(err);
2321
Karl Schultz6addd812016-02-02 17:17:23 -07002322 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002323
2324 mem_alloc.allocationSize = mem_reqs.size;
2325
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002326 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002327 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002328
2329 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002330 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002331 ASSERT_VK_SUCCESS(err);
2332
2333 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002334 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002335
2336 // Try to bind free memory that has been freed
2337 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2338 // This may very well return an error.
2339 (void)err;
2340
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002341 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002342
Chia-I Wuf7458c52015-10-26 21:10:41 +08002343 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002344}
2345
Karl Schultz6addd812016-02-02 17:17:23 -07002346TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2347 VkResult err;
2348 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002349
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002351
Tobin Ehlisec598302015-09-15 15:02:17 -06002352 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002353
Karl Schultz6addd812016-02-02 17:17:23 -07002354 // Create an image object, allocate memory, destroy the object and then try
2355 // to bind it
2356 VkImage image;
2357 VkDeviceMemory mem;
2358 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002359
Karl Schultz6addd812016-02-02 17:17:23 -07002360 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2361 const int32_t tex_width = 32;
2362 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002363
2364 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002365 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2366 image_create_info.pNext = NULL;
2367 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2368 image_create_info.format = tex_format;
2369 image_create_info.extent.width = tex_width;
2370 image_create_info.extent.height = tex_height;
2371 image_create_info.extent.depth = 1;
2372 image_create_info.mipLevels = 1;
2373 image_create_info.arrayLayers = 1;
2374 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2375 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2376 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2377 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002378
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002379 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002380 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2381 mem_alloc.pNext = NULL;
2382 mem_alloc.allocationSize = 0;
2383 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002384
Chia-I Wuf7458c52015-10-26 21:10:41 +08002385 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002386 ASSERT_VK_SUCCESS(err);
2387
Karl Schultz6addd812016-02-02 17:17:23 -07002388 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002389
2390 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002391 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002392 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002393
2394 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002395 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002396 ASSERT_VK_SUCCESS(err);
2397
2398 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002399 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002400 ASSERT_VK_SUCCESS(err);
2401
2402 // Now Try to bind memory to this destroyed object
2403 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2404 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002405 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002406
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002407 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002408
Chia-I Wuf7458c52015-10-26 21:10:41 +08002409 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002410}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002411
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002412#endif // OBJ_TRACKER_TESTS
2413
Tobin Ehlis0788f522015-05-26 16:11:58 -06002414#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002415
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002416TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2417 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2418
2419 ASSERT_NO_FATAL_FAILURE(InitState());
2420 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2421
2422 VkVertexInputBindingDescription input_binding;
2423 memset(&input_binding, 0, sizeof(input_binding));
2424
2425 VkVertexInputAttributeDescription input_attribs;
2426 memset(&input_attribs, 0, sizeof(input_attribs));
2427
2428 // Pick a really bad format for this purpose and make sure it should fail
2429 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2430 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2431 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2432 printf("Format unsuitable for test; skipped.\n");
2433 return;
2434 }
2435
2436 input_attribs.location = 0;
2437 char const *vsSource = "#version 450\n"
2438 "\n"
2439 "out gl_PerVertex {\n"
2440 " vec4 gl_Position;\n"
2441 "};\n"
2442 "void main(){\n"
2443 " gl_Position = vec4(1);\n"
2444 "}\n";
2445 char const *fsSource = "#version 450\n"
2446 "\n"
2447 "layout(location=0) out vec4 color;\n"
2448 "void main(){\n"
2449 " color = vec4(1);\n"
2450 "}\n";
2451
2452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2453 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2454 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2455
2456 VkPipelineObj pipe(m_device);
2457 pipe.AddColorAttachment();
2458 pipe.AddShader(&vs);
2459 pipe.AddShader(&fs);
2460
2461 pipe.AddVertexInputBindings(&input_binding, 1);
2462 pipe.AddVertexInputAttribs(&input_attribs, 1);
2463
2464 VkDescriptorSetObj descriptorSet(m_device);
2465 descriptorSet.AppendDummy();
2466 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2467
2468 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2469
2470 m_errorMonitor->VerifyFound();
2471}
2472
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002473TEST_F(VkLayerTest, ImageSampleCounts) {
2474
2475 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2476 "validation errors.");
2477 ASSERT_NO_FATAL_FAILURE(InitState());
2478
2479 VkMemoryPropertyFlags reqs = 0;
2480 VkImageCreateInfo image_create_info = {};
2481 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2482 image_create_info.pNext = NULL;
2483 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2484 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2485 image_create_info.extent.width = 256;
2486 image_create_info.extent.height = 256;
2487 image_create_info.extent.depth = 1;
2488 image_create_info.mipLevels = 1;
2489 image_create_info.arrayLayers = 1;
2490 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2491 image_create_info.flags = 0;
2492
2493 VkImageBlit blit_region = {};
2494 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2495 blit_region.srcSubresource.baseArrayLayer = 0;
2496 blit_region.srcSubresource.layerCount = 1;
2497 blit_region.srcSubresource.mipLevel = 0;
2498 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2499 blit_region.dstSubresource.baseArrayLayer = 0;
2500 blit_region.dstSubresource.layerCount = 1;
2501 blit_region.dstSubresource.mipLevel = 0;
2502
2503 // Create two images, the source with sampleCount = 2, and attempt to blit
2504 // between them
2505 {
2506 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002507 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002508 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002509 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002510 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002511 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002512 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002513 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002514 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2516 "of VK_SAMPLE_COUNT_2_BIT but "
2517 "must be VK_SAMPLE_COUNT_1_BIT");
2518 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2519 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002520 m_errorMonitor->VerifyFound();
2521 m_commandBuffer->EndCommandBuffer();
2522 }
2523
2524 // Create two images, the dest with sampleCount = 4, and attempt to blit
2525 // between them
2526 {
2527 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002528 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002529 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002530 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002531 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002532 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002533 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002534 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002535 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2537 "of VK_SAMPLE_COUNT_4_BIT but "
2538 "must be VK_SAMPLE_COUNT_1_BIT");
2539 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2540 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002541 m_errorMonitor->VerifyFound();
2542 m_commandBuffer->EndCommandBuffer();
2543 }
2544
2545 VkBufferImageCopy copy_region = {};
2546 copy_region.bufferRowLength = 128;
2547 copy_region.bufferImageHeight = 128;
2548 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2549 copy_region.imageSubresource.layerCount = 1;
2550 copy_region.imageExtent.height = 64;
2551 copy_region.imageExtent.width = 64;
2552 copy_region.imageExtent.depth = 1;
2553
2554 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2555 // buffer to image
2556 {
2557 vk_testing::Buffer src_buffer;
2558 VkMemoryPropertyFlags reqs = 0;
2559 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2560 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002561 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002562 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002563 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002564 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2566 "of VK_SAMPLE_COUNT_8_BIT but "
2567 "must be VK_SAMPLE_COUNT_1_BIT");
2568 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2569 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002570 m_errorMonitor->VerifyFound();
2571 m_commandBuffer->EndCommandBuffer();
2572 }
2573
2574 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2575 // image to buffer
2576 {
2577 vk_testing::Buffer dst_buffer;
2578 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2579 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002580 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002581 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002582 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002583 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2585 "of VK_SAMPLE_COUNT_2_BIT but "
2586 "must be VK_SAMPLE_COUNT_1_BIT");
2587 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002588 dst_buffer.handle(), 1, &copy_region);
2589 m_errorMonitor->VerifyFound();
2590 m_commandBuffer->EndCommandBuffer();
2591 }
2592}
2593
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002594TEST_F(VkLayerTest, BlitImageFormats) {
2595
2596 // Image blit with mismatched formats
2597 const char * expected_message =
2598 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2599 " the other one must also have signed/unsigned integer format";
2600
2601 ASSERT_NO_FATAL_FAILURE(InitState());
2602
2603 VkImageObj src_image(m_device);
2604 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2605 VkImageObj dst_image(m_device);
2606 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2607 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002608 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 -06002609
2610 VkImageBlit blitRegion = {};
2611 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2612 blitRegion.srcSubresource.baseArrayLayer = 0;
2613 blitRegion.srcSubresource.layerCount = 1;
2614 blitRegion.srcSubresource.mipLevel = 0;
2615 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2616 blitRegion.dstSubresource.baseArrayLayer = 0;
2617 blitRegion.dstSubresource.layerCount = 1;
2618 blitRegion.dstSubresource.mipLevel = 0;
2619
2620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2621
2622 // Unsigned int vs not an int
2623 BeginCommandBuffer();
2624 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2625 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2626
2627 m_errorMonitor->VerifyFound();
2628
2629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2630
2631 // Unsigned int vs signed int
2632 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2633 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2634
2635 m_errorMonitor->VerifyFound();
2636
2637 EndCommandBuffer();
2638}
2639
2640
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002641TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2642 VkResult err;
2643 bool pass;
2644
2645 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2646 ASSERT_NO_FATAL_FAILURE(InitState());
2647
2648 // If w/d/h granularity is 1, test is not meaningful
2649 // TODO: When virtual device limits are available, create a set of limits for this test that
2650 // will always have a granularity of > 1 for w, h, and d
2651 auto index = m_device->graphics_queue_node_index_;
2652 auto queue_family_properties = m_device->phy().queue_properties();
2653
2654 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2655 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2656 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2657 return;
2658 }
2659
2660 // Create two images of different types and try to copy between them
2661 VkImage srcImage;
2662 VkImage dstImage;
2663 VkDeviceMemory srcMem;
2664 VkDeviceMemory destMem;
2665 VkMemoryRequirements memReqs;
2666
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002667 VkImageCreateInfo image_create_info = {};
2668 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2669 image_create_info.pNext = NULL;
2670 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2671 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2672 image_create_info.extent.width = 32;
2673 image_create_info.extent.height = 32;
2674 image_create_info.extent.depth = 1;
2675 image_create_info.mipLevels = 1;
2676 image_create_info.arrayLayers = 4;
2677 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2678 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2679 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2680 image_create_info.flags = 0;
2681
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002682 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002683 ASSERT_VK_SUCCESS(err);
2684
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002685 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002686 ASSERT_VK_SUCCESS(err);
2687
2688 // Allocate memory
2689 VkMemoryAllocateInfo memAlloc = {};
2690 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2691 memAlloc.pNext = NULL;
2692 memAlloc.allocationSize = 0;
2693 memAlloc.memoryTypeIndex = 0;
2694
2695 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2696 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002697 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002698 ASSERT_TRUE(pass);
2699 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2700 ASSERT_VK_SUCCESS(err);
2701
2702 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2703 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002704 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002705 ASSERT_VK_SUCCESS(err);
2706 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2707 ASSERT_VK_SUCCESS(err);
2708
2709 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2710 ASSERT_VK_SUCCESS(err);
2711 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2712 ASSERT_VK_SUCCESS(err);
2713
2714 BeginCommandBuffer();
2715 VkImageCopy copyRegion;
2716 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2717 copyRegion.srcSubresource.mipLevel = 0;
2718 copyRegion.srcSubresource.baseArrayLayer = 0;
2719 copyRegion.srcSubresource.layerCount = 1;
2720 copyRegion.srcOffset.x = 0;
2721 copyRegion.srcOffset.y = 0;
2722 copyRegion.srcOffset.z = 0;
2723 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2724 copyRegion.dstSubresource.mipLevel = 0;
2725 copyRegion.dstSubresource.baseArrayLayer = 0;
2726 copyRegion.dstSubresource.layerCount = 1;
2727 copyRegion.dstOffset.x = 0;
2728 copyRegion.dstOffset.y = 0;
2729 copyRegion.dstOffset.z = 0;
2730 copyRegion.extent.width = 1;
2731 copyRegion.extent.height = 1;
2732 copyRegion.extent.depth = 1;
2733
2734 // Introduce failure by setting srcOffset to a bad granularity value
2735 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2737 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002738 m_errorMonitor->VerifyFound();
2739
2740 // Introduce failure by setting extent to a bad granularity value
2741 copyRegion.srcOffset.y = 0;
2742 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2744 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002745 m_errorMonitor->VerifyFound();
2746
2747 // Now do some buffer/image copies
2748 vk_testing::Buffer buffer;
2749 VkMemoryPropertyFlags reqs = 0;
2750 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2751 VkBufferImageCopy region = {};
2752 region.bufferOffset = 0;
2753 region.bufferRowLength = 3;
2754 region.bufferImageHeight = 128;
2755 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2756 region.imageSubresource.layerCount = 1;
2757 region.imageExtent.height = 16;
2758 region.imageExtent.width = 16;
2759 region.imageExtent.depth = 1;
2760 region.imageOffset.x = 0;
2761 region.imageOffset.y = 0;
2762 region.imageOffset.z = 0;
2763
2764 // Introduce failure by setting bufferRowLength to a bad granularity value
2765 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2767 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2768 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002769 m_errorMonitor->VerifyFound();
2770 region.bufferRowLength = 128;
2771
2772 // Introduce failure by setting bufferOffset to a bad granularity value
2773 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2775 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2776 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002777 m_errorMonitor->VerifyFound();
2778 region.bufferOffset = 0;
2779
2780 // Introduce failure by setting bufferImageHeight to a bad granularity value
2781 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2783 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2784 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002785 m_errorMonitor->VerifyFound();
2786 region.bufferImageHeight = 128;
2787
2788 // Introduce failure by setting imageExtent to a bad granularity value
2789 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2791 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2792 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002793 m_errorMonitor->VerifyFound();
2794 region.imageExtent.width = 16;
2795
2796 // Introduce failure by setting imageOffset to a bad granularity value
2797 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2799 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2800 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002801 m_errorMonitor->VerifyFound();
2802
2803 EndCommandBuffer();
2804
2805 vkDestroyImage(m_device->device(), srcImage, NULL);
2806 vkDestroyImage(m_device->device(), dstImage, NULL);
2807 vkFreeMemory(m_device->device(), srcMem, NULL);
2808 vkFreeMemory(m_device->device(), destMem, NULL);
2809}
2810
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002811TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002812 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2813 "attempt to submit them on a queue created in a different "
2814 "queue family.");
2815
Cody Northropc31a84f2016-08-22 10:41:47 -06002816 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002817 // This test is meaningless unless we have multiple queue families
2818 auto queue_family_properties = m_device->phy().queue_properties();
2819 if (queue_family_properties.size() < 2) {
2820 return;
2821 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002823 // Get safe index of another queue family
2824 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2825 ASSERT_NO_FATAL_FAILURE(InitState());
2826 // Create a second queue using a different queue family
2827 VkQueue other_queue;
2828 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2829
2830 // Record an empty cmd buffer
2831 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2832 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2833 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2834 vkEndCommandBuffer(m_commandBuffer->handle());
2835
2836 // And submit on the wrong queue
2837 VkSubmitInfo submit_info = {};
2838 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2839 submit_info.commandBufferCount = 1;
2840 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002841 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002842
2843 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002844}
2845
Chris Forbesa58c4522016-09-28 15:19:39 +13002846TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2847 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2848 ASSERT_NO_FATAL_FAILURE(InitState());
2849
2850 // A renderpass with two subpasses, both writing the same attachment.
2851 VkAttachmentDescription attach[] = {
2852 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2853 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2854 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2855 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2856 },
2857 };
2858 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2859 VkSubpassDescription subpasses[] = {
2860 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2861 1, &ref, nullptr, nullptr, 0, nullptr },
2862 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2863 1, &ref, nullptr, nullptr, 0, nullptr },
2864 };
2865 VkSubpassDependency dep = {
2866 0, 1,
2867 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2868 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2869 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2870 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2871 VK_DEPENDENCY_BY_REGION_BIT
2872 };
2873 VkRenderPassCreateInfo rpci = {
2874 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2875 0, 1, attach, 2, subpasses, 1, &dep
2876 };
2877 VkRenderPass rp;
2878 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2879 ASSERT_VK_SUCCESS(err);
2880
2881 VkImageObj image(m_device);
2882 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2883 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2884 VK_IMAGE_TILING_OPTIMAL, 0);
2885 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2886
2887 VkFramebufferCreateInfo fbci = {
2888 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2889 0, rp, 1, &imageView, 32, 32, 1
2890 };
2891 VkFramebuffer fb;
2892 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2893 ASSERT_VK_SUCCESS(err);
2894
2895 char const *vsSource =
2896 "#version 450\n"
2897 "void main() { gl_Position = vec4(1); }\n";
2898 char const *fsSource =
2899 "#version 450\n"
2900 "layout(location=0) out vec4 color;\n"
2901 "void main() { color = vec4(1); }\n";
2902
2903 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2904 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2905 VkPipelineObj pipe(m_device);
2906 pipe.AddColorAttachment();
2907 pipe.AddShader(&vs);
2908 pipe.AddShader(&fs);
2909 VkViewport view_port = {};
2910 m_viewports.push_back(view_port);
2911 pipe.SetViewport(m_viewports);
2912 VkRect2D rect = {};
2913 m_scissors.push_back(rect);
2914 pipe.SetScissor(m_scissors);
2915
2916 VkPipelineLayoutCreateInfo plci = {
2917 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2918 0, 0, nullptr, 0, nullptr
2919 };
2920 VkPipelineLayout pl;
2921 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2922 ASSERT_VK_SUCCESS(err);
2923 pipe.CreateVKPipeline(pl, rp);
2924
2925 BeginCommandBuffer();
2926
2927 VkRenderPassBeginInfo rpbi = {
2928 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2929 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2930 };
2931
2932 // subtest 1: bind in the wrong subpass
2933 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2934 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2936 "built for subpass 0 but used in subpass 1");
2937 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2938 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2939 m_errorMonitor->VerifyFound();
2940
2941 vkCmdEndRenderPass(m_commandBuffer->handle());
2942
2943 // subtest 2: bind in correct subpass, then transition to next subpass
2944 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2945 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2946 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2948 "built for subpass 0 but used in subpass 1");
2949 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2950 m_errorMonitor->VerifyFound();
2951
2952 vkCmdEndRenderPass(m_commandBuffer->handle());
2953
2954 EndCommandBuffer();
2955
2956 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
2957 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2958 vkDestroyRenderPass(m_device->device(), rp, nullptr);
2959}
2960
Tony Barbour4e919972016-08-09 13:27:40 -06002961TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
2962 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
2963 "with extent outside of framebuffer");
2964 ASSERT_NO_FATAL_FAILURE(InitState());
2965 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2966
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
2968 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06002969
2970 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
2971 m_renderPassBeginInfo.renderArea.extent.width = 257;
2972 m_renderPassBeginInfo.renderArea.extent.height = 257;
2973 BeginCommandBuffer();
2974 m_errorMonitor->VerifyFound();
2975}
2976
2977TEST_F(VkLayerTest, DisabledIndependentBlend) {
2978 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
2979 "blend and then specifying different blend states for two "
2980 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06002981 VkPhysicalDeviceFeatures features = {};
2982 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06002983 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06002984
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2986 "Invalid Pipeline CreateInfo: If independent blend feature not "
2987 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06002988
Cody Northropc31a84f2016-08-22 10:41:47 -06002989 VkDescriptorSetObj descriptorSet(m_device);
2990 descriptorSet.AppendDummy();
2991 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06002992
Cody Northropc31a84f2016-08-22 10:41:47 -06002993 VkPipelineObj pipeline(m_device);
2994 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002995 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06002996 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06002997
Cody Northropc31a84f2016-08-22 10:41:47 -06002998 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
2999 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3000 att_state1.blendEnable = VK_TRUE;
3001 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3002 att_state2.blendEnable = VK_FALSE;
3003 pipeline.AddColorAttachment(0, &att_state1);
3004 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003005 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003006 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003007}
3008
3009TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3010 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3011 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003012 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003013
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3015 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003016
3017 // Create a renderPass with a single color attachment
3018 VkAttachmentReference attach = {};
3019 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3020 VkSubpassDescription subpass = {};
3021 VkRenderPassCreateInfo rpci = {};
3022 rpci.subpassCount = 1;
3023 rpci.pSubpasses = &subpass;
3024 rpci.attachmentCount = 1;
3025 VkAttachmentDescription attach_desc = {};
3026 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3027 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3028 rpci.pAttachments = &attach_desc;
3029 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3030 VkRenderPass rp;
3031 subpass.pDepthStencilAttachment = &attach;
3032 subpass.pColorAttachments = NULL;
3033 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3034 m_errorMonitor->VerifyFound();
3035}
3036
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003037TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3038 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3039 "attachment reference of VK_ATTACHMENT_UNUSED");
3040
3041 ASSERT_NO_FATAL_FAILURE(InitState());
3042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003045
3046 VkAttachmentReference color_attach = {};
3047 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3048 color_attach.attachment = 0;
3049 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3050 VkSubpassDescription subpass = {};
3051 subpass.colorAttachmentCount = 1;
3052 subpass.pColorAttachments = &color_attach;
3053 subpass.preserveAttachmentCount = 1;
3054 subpass.pPreserveAttachments = &preserve_attachment;
3055
3056 VkRenderPassCreateInfo rpci = {};
3057 rpci.subpassCount = 1;
3058 rpci.pSubpasses = &subpass;
3059 rpci.attachmentCount = 1;
3060 VkAttachmentDescription attach_desc = {};
3061 attach_desc.format = VK_FORMAT_UNDEFINED;
3062 rpci.pAttachments = &attach_desc;
3063 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3064 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003065 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003066
3067 m_errorMonitor->VerifyFound();
3068
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003069 if (result == VK_SUCCESS) {
3070 vkDestroyRenderPass(m_device->device(), rp, NULL);
3071 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003072}
3073
Chris Forbesc5389742016-06-29 11:49:23 +12003074TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003075 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3076 "when the source of a subpass multisample resolve "
3077 "does not have multiple samples.");
3078
Chris Forbesc5389742016-06-29 11:49:23 +12003079 ASSERT_NO_FATAL_FAILURE(InitState());
3080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3082 "Subpass 0 requests multisample resolve from attachment 0 which has "
3083 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003084
3085 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003086 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3087 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3088 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3089 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3090 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3091 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003092 };
3093
3094 VkAttachmentReference color = {
3095 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3096 };
3097
3098 VkAttachmentReference resolve = {
3099 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3100 };
3101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003102 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003103
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003104 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003105
3106 VkRenderPass rp;
3107 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3108
3109 m_errorMonitor->VerifyFound();
3110
3111 if (err == VK_SUCCESS)
3112 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3113}
3114
3115TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003116 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3117 "when a subpass multisample resolve operation is "
3118 "requested, and the destination of that resolve has "
3119 "multiple samples.");
3120
Chris Forbesc5389742016-06-29 11:49:23 +12003121 ASSERT_NO_FATAL_FAILURE(InitState());
3122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3124 "Subpass 0 requests multisample resolve into attachment 1, which "
3125 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003126
3127 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003128 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3129 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3130 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3131 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3132 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3133 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003134 };
3135
3136 VkAttachmentReference color = {
3137 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3138 };
3139
3140 VkAttachmentReference resolve = {
3141 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3142 };
3143
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003144 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003146 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003147
3148 VkRenderPass rp;
3149 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3150
3151 m_errorMonitor->VerifyFound();
3152
3153 if (err == VK_SUCCESS)
3154 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3155}
3156
Chris Forbes3f128ef2016-06-29 14:58:53 +12003157TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003158 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3159 "when the color and depth attachments used by a subpass "
3160 "have inconsistent sample counts");
3161
Chris Forbes3f128ef2016-06-29 14:58:53 +12003162 ASSERT_NO_FATAL_FAILURE(InitState());
3163
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3165 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003166
3167 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003168 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3169 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3170 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3171 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3172 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3173 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003174 };
3175
3176 VkAttachmentReference color[] = {
3177 {
3178 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3179 },
3180 {
3181 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3182 },
3183 };
3184
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003185 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003186
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003187 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003188
3189 VkRenderPass rp;
3190 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3191
3192 m_errorMonitor->VerifyFound();
3193
3194 if (err == VK_SUCCESS)
3195 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3196}
3197
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003198TEST_F(VkLayerTest, FramebufferCreateErrors) {
3199 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003200 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003201 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003202 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3203 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3204 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3205 " 6. Framebuffer attachment where dimensions don't match\n"
3206 " 7. Framebuffer attachment w/o identity swizzle\n"
3207 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003208
3209 ASSERT_NO_FATAL_FAILURE(InitState());
3210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3211
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3213 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3214 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003215
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003216 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003217 VkAttachmentReference attach = {};
3218 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3219 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003220 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003221 VkRenderPassCreateInfo rpci = {};
3222 rpci.subpassCount = 1;
3223 rpci.pSubpasses = &subpass;
3224 rpci.attachmentCount = 1;
3225 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003226 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003227 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003228 rpci.pAttachments = &attach_desc;
3229 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3230 VkRenderPass rp;
3231 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3232 ASSERT_VK_SUCCESS(err);
3233
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003234 VkImageView ivs[2];
3235 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3236 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003237 VkFramebufferCreateInfo fb_info = {};
3238 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3239 fb_info.pNext = NULL;
3240 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003241 // Set mis-matching attachmentCount
3242 fb_info.attachmentCount = 2;
3243 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003244 fb_info.width = 100;
3245 fb_info.height = 100;
3246 fb_info.layers = 1;
3247
3248 VkFramebuffer fb;
3249 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3250
3251 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003252 if (err == VK_SUCCESS) {
3253 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3254 }
3255 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003256
3257 // Create a renderPass with a depth-stencil attachment created with
3258 // IMAGE_USAGE_COLOR_ATTACHMENT
3259 // Add our color attachment to pDepthStencilAttachment
3260 subpass.pDepthStencilAttachment = &attach;
3261 subpass.pColorAttachments = NULL;
3262 VkRenderPass rp_ds;
3263 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3264 ASSERT_VK_SUCCESS(err);
3265 // Set correct attachment count, but attachment has COLOR usage bit set
3266 fb_info.attachmentCount = 1;
3267 fb_info.renderPass = rp_ds;
3268
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003270 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3271
3272 m_errorMonitor->VerifyFound();
3273 if (err == VK_SUCCESS) {
3274 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3275 }
3276 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003277
3278 // Create new renderpass with alternate attachment format from fb
3279 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3280 subpass.pDepthStencilAttachment = NULL;
3281 subpass.pColorAttachments = &attach;
3282 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3283 ASSERT_VK_SUCCESS(err);
3284
3285 // Cause error due to mis-matched formats between rp & fb
3286 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3287 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3289 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003290 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3291
3292 m_errorMonitor->VerifyFound();
3293 if (err == VK_SUCCESS) {
3294 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3295 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003296 vkDestroyRenderPass(m_device->device(), rp, NULL);
3297
3298 // Create new renderpass with alternate sample count from fb
3299 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3300 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3301 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3302 ASSERT_VK_SUCCESS(err);
3303
3304 // Cause error due to mis-matched sample count between rp & fb
3305 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3307 "that do not match the "
3308 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003309 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3310
3311 m_errorMonitor->VerifyFound();
3312 if (err == VK_SUCCESS) {
3313 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3314 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003315
3316 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003317
3318 // Create a custom imageView with non-1 mip levels
3319 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003320 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 -06003321 ASSERT_TRUE(image.initialized());
3322
3323 VkImageView view;
3324 VkImageViewCreateInfo ivci = {};
3325 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3326 ivci.image = image.handle();
3327 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3328 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3329 ivci.subresourceRange.layerCount = 1;
3330 ivci.subresourceRange.baseMipLevel = 0;
3331 // Set level count 2 (only 1 is allowed for FB attachment)
3332 ivci.subresourceRange.levelCount = 2;
3333 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3334 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3335 ASSERT_VK_SUCCESS(err);
3336 // Re-create renderpass to have matching sample count
3337 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3338 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3339 ASSERT_VK_SUCCESS(err);
3340
3341 fb_info.renderPass = rp;
3342 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003344 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3345
3346 m_errorMonitor->VerifyFound();
3347 if (err == VK_SUCCESS) {
3348 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3349 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003350 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003351 // Update view to original color buffer and grow FB dimensions too big
3352 fb_info.pAttachments = ivs;
3353 fb_info.height = 1024;
3354 fb_info.width = 1024;
3355 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3357 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003358 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3359
3360 m_errorMonitor->VerifyFound();
3361 if (err == VK_SUCCESS) {
3362 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3363 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003364 // Create view attachment with non-identity swizzle
3365 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3366 ivci.image = image.handle();
3367 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3368 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3369 ivci.subresourceRange.layerCount = 1;
3370 ivci.subresourceRange.baseMipLevel = 0;
3371 ivci.subresourceRange.levelCount = 1;
3372 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3373 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3374 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3375 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3376 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3377 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3378 ASSERT_VK_SUCCESS(err);
3379
3380 fb_info.pAttachments = &view;
3381 fb_info.height = 100;
3382 fb_info.width = 100;
3383 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3385 "framebuffer attachments must have "
3386 "been created with the identity "
3387 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003388 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3389
3390 m_errorMonitor->VerifyFound();
3391 if (err == VK_SUCCESS) {
3392 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3393 }
3394 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003395 // Request fb that exceeds max dimensions
3396 // reset attachment to color attachment
3397 fb_info.pAttachments = ivs;
3398 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3399 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3400 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3402 "dimensions exceed physical device "
3403 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003404 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3405
3406 m_errorMonitor->VerifyFound();
3407 if (err == VK_SUCCESS) {
3408 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3409 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003410
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003411 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003412}
3413
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003414TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003415 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3416 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003417
Cody Northropc31a84f2016-08-22 10:41:47 -06003418 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003419 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3421 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003422 m_errorMonitor->VerifyFound();
3423}
3424
3425TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003426 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3427 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003428
Cody Northropc31a84f2016-08-22 10:41:47 -06003429 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003430 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3432 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003433 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003434}
3435
3436TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003437 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3438 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003439
Cody Northropc31a84f2016-08-22 10:41:47 -06003440 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003441 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003442 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 -06003443 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003444 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003445}
3446
3447TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003448 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3449 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003450
Cody Northropc31a84f2016-08-22 10:41:47 -06003451 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003452 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003453 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 -06003454 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003455 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003456}
3457
Cortd713fe82016-07-27 09:51:27 -07003458TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003459 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3460 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003461
3462 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003463 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3465 "Dynamic blend constants state not set for this command buffer");
3466 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003467 m_errorMonitor->VerifyFound();
3468}
3469
3470TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003471 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3472 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003473
3474 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003475 if (!m_device->phy().features().depthBounds) {
3476 printf("Device does not support depthBounds test; skipped.\n");
3477 return;
3478 }
3479 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3481 "Dynamic depth bounds state not set for this command buffer");
3482 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003483 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003484}
3485
3486TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003487 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3488 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003489
3490 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003491 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3493 "Dynamic stencil read mask state not set for this command buffer");
3494 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003495 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003496}
3497
3498TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003499 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3500 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003501
3502 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003503 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3505 "Dynamic stencil write mask state not set for this command buffer");
3506 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003507 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003508}
3509
3510TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003511 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3512 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003513
3514 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003515 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3517 "Dynamic stencil reference state not set for this command buffer");
3518 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003519 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003520}
3521
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003522TEST_F(VkLayerTest, IndexBufferNotBound) {
3523 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003524
3525 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3527 "Index buffer object not bound to this command buffer when Indexed ");
3528 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003529 m_errorMonitor->VerifyFound();
3530}
3531
Karl Schultz6addd812016-02-02 17:17:23 -07003532TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3534 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3535 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003536
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003537 ASSERT_NO_FATAL_FAILURE(InitState());
3538 ASSERT_NO_FATAL_FAILURE(InitViewport());
3539 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3540
Karl Schultz6addd812016-02-02 17:17:23 -07003541 // We luck out b/c by default the framework creates CB w/ the
3542 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003543 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003544 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003545 EndCommandBuffer();
3546
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003547 // Bypass framework since it does the waits automatically
3548 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003549 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003550 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3551 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003552 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003553 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003554 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003555 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003556 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003557 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003558 submit_info.pSignalSemaphores = NULL;
3559
Chris Forbes40028e22016-06-13 09:59:34 +12003560 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003561 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003562 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003563
Karl Schultz6addd812016-02-02 17:17:23 -07003564 // Cause validation error by re-submitting cmd buffer that should only be
3565 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003566 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003567 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003568
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003569 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003570}
3571
Karl Schultz6addd812016-02-02 17:17:23 -07003572TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003573 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003574 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003575
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3577 "type "
3578 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003579
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003580 ASSERT_NO_FATAL_FAILURE(InitState());
3581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003582
Karl Schultz6addd812016-02-02 17:17:23 -07003583 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3584 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003585 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003586 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3587 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003588
3589 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003590 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3591 ds_pool_ci.pNext = NULL;
3592 ds_pool_ci.flags = 0;
3593 ds_pool_ci.maxSets = 1;
3594 ds_pool_ci.poolSizeCount = 1;
3595 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003596
3597 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003598 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003599 ASSERT_VK_SUCCESS(err);
3600
3601 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003602 dsl_binding.binding = 0;
3603 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3604 dsl_binding.descriptorCount = 1;
3605 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3606 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003607
3608 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003609 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3610 ds_layout_ci.pNext = NULL;
3611 ds_layout_ci.bindingCount = 1;
3612 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003613
3614 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003616 ASSERT_VK_SUCCESS(err);
3617
3618 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003619 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003620 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003621 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003622 alloc_info.descriptorPool = ds_pool;
3623 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003625
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003626 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003627
Chia-I Wuf7458c52015-10-26 21:10:41 +08003628 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3629 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003630}
3631
Karl Schultz6addd812016-02-02 17:17:23 -07003632TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3633 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003634
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3636 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3637 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003638
Tobin Ehlise735c692015-10-08 13:13:50 -06003639 ASSERT_NO_FATAL_FAILURE(InitState());
3640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003641
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003642 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003643 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3644 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003645
3646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3648 ds_pool_ci.pNext = NULL;
3649 ds_pool_ci.maxSets = 1;
3650 ds_pool_ci.poolSizeCount = 1;
3651 ds_pool_ci.flags = 0;
3652 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3653 // app can only call vkResetDescriptorPool on this pool.;
3654 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003655
3656 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003657 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003658 ASSERT_VK_SUCCESS(err);
3659
3660 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003661 dsl_binding.binding = 0;
3662 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3663 dsl_binding.descriptorCount = 1;
3664 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3665 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003666
3667 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003668 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3669 ds_layout_ci.pNext = NULL;
3670 ds_layout_ci.bindingCount = 1;
3671 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003672
3673 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003674 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003675 ASSERT_VK_SUCCESS(err);
3676
3677 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003678 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003679 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003680 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003681 alloc_info.descriptorPool = ds_pool;
3682 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003683 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003684 ASSERT_VK_SUCCESS(err);
3685
3686 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003687 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003688
Chia-I Wuf7458c52015-10-26 21:10:41 +08003689 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3690 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003691}
3692
Karl Schultz6addd812016-02-02 17:17:23 -07003693TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003694 // Attempt to clear Descriptor Pool with bad object.
3695 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003696
3697 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003699 uint64_t fake_pool_handle = 0xbaad6001;
3700 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3701 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003702 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003703}
3704
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003705TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003706 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3707 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003708 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003709 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003710
3711 uint64_t fake_set_handle = 0xbaad6001;
3712 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003713 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003715
3716 ASSERT_NO_FATAL_FAILURE(InitState());
3717
3718 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3719 layout_bindings[0].binding = 0;
3720 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3721 layout_bindings[0].descriptorCount = 1;
3722 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3723 layout_bindings[0].pImmutableSamplers = NULL;
3724
3725 VkDescriptorSetLayout descriptor_set_layout;
3726 VkDescriptorSetLayoutCreateInfo dslci = {};
3727 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3728 dslci.pNext = NULL;
3729 dslci.bindingCount = 1;
3730 dslci.pBindings = layout_bindings;
3731 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003732 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003733
3734 VkPipelineLayout pipeline_layout;
3735 VkPipelineLayoutCreateInfo plci = {};
3736 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3737 plci.pNext = NULL;
3738 plci.setLayoutCount = 1;
3739 plci.pSetLayouts = &descriptor_set_layout;
3740 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003741 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003742
3743 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003744 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3745 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003746 m_errorMonitor->VerifyFound();
3747 EndCommandBuffer();
3748 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3749 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003750}
3751
Karl Schultz6addd812016-02-02 17:17:23 -07003752TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003753 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3754 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003755 uint64_t fake_layout_handle = 0xbaad6001;
3756 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003758 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003759 VkPipelineLayout pipeline_layout;
3760 VkPipelineLayoutCreateInfo plci = {};
3761 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3762 plci.pNext = NULL;
3763 plci.setLayoutCount = 1;
3764 plci.pSetLayouts = &bad_layout;
3765 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3766
3767 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003768}
3769
Mark Muellerd4914412016-06-13 17:52:06 -06003770TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3771 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3772 "1) A uniform buffer update must have a valid buffer index."
3773 "2) When using an array of descriptors in a single WriteDescriptor,"
3774 " the descriptor types and stageflags must all be the same."
3775 "3) Immutable Sampler state must match across descriptors");
3776
3777 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003778 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3779 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3780 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3781 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3782 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003783
Mark Muellerd4914412016-06-13 17:52:06 -06003784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3785
3786 ASSERT_NO_FATAL_FAILURE(InitState());
3787 VkDescriptorPoolSize ds_type_count[4] = {};
3788 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3789 ds_type_count[0].descriptorCount = 1;
3790 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3791 ds_type_count[1].descriptorCount = 1;
3792 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3793 ds_type_count[2].descriptorCount = 1;
3794 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3795 ds_type_count[3].descriptorCount = 1;
3796
3797 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3798 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3799 ds_pool_ci.maxSets = 1;
3800 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3801 ds_pool_ci.pPoolSizes = ds_type_count;
3802
3803 VkDescriptorPool ds_pool;
3804 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3805 ASSERT_VK_SUCCESS(err);
3806
Mark Muellerb9896722016-06-16 09:54:29 -06003807 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003808 layout_binding[0].binding = 0;
3809 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3810 layout_binding[0].descriptorCount = 1;
3811 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3812 layout_binding[0].pImmutableSamplers = NULL;
3813
3814 layout_binding[1].binding = 1;
3815 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3816 layout_binding[1].descriptorCount = 1;
3817 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3818 layout_binding[1].pImmutableSamplers = NULL;
3819
3820 VkSamplerCreateInfo sampler_ci = {};
3821 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3822 sampler_ci.pNext = NULL;
3823 sampler_ci.magFilter = VK_FILTER_NEAREST;
3824 sampler_ci.minFilter = VK_FILTER_NEAREST;
3825 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3826 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3827 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3828 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3829 sampler_ci.mipLodBias = 1.0;
3830 sampler_ci.anisotropyEnable = VK_FALSE;
3831 sampler_ci.maxAnisotropy = 1;
3832 sampler_ci.compareEnable = VK_FALSE;
3833 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3834 sampler_ci.minLod = 1.0;
3835 sampler_ci.maxLod = 1.0;
3836 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3837 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3838 VkSampler sampler;
3839
3840 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3841 ASSERT_VK_SUCCESS(err);
3842
3843 layout_binding[2].binding = 2;
3844 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3845 layout_binding[2].descriptorCount = 1;
3846 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3847 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3848
Mark Muellerd4914412016-06-13 17:52:06 -06003849 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3850 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3851 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3852 ds_layout_ci.pBindings = layout_binding;
3853 VkDescriptorSetLayout ds_layout;
3854 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3855 ASSERT_VK_SUCCESS(err);
3856
3857 VkDescriptorSetAllocateInfo alloc_info = {};
3858 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3859 alloc_info.descriptorSetCount = 1;
3860 alloc_info.descriptorPool = ds_pool;
3861 alloc_info.pSetLayouts = &ds_layout;
3862 VkDescriptorSet descriptorSet;
3863 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3864 ASSERT_VK_SUCCESS(err);
3865
3866 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3867 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3868 pipeline_layout_ci.pNext = NULL;
3869 pipeline_layout_ci.setLayoutCount = 1;
3870 pipeline_layout_ci.pSetLayouts = &ds_layout;
3871
3872 VkPipelineLayout pipeline_layout;
3873 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3874 ASSERT_VK_SUCCESS(err);
3875
Mark Mueller5c838ce2016-06-16 09:54:29 -06003876 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003877 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3878 descriptor_write.dstSet = descriptorSet;
3879 descriptor_write.dstBinding = 0;
3880 descriptor_write.descriptorCount = 1;
3881 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3882
Mark Mueller5c838ce2016-06-16 09:54:29 -06003883 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003884 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3885 m_errorMonitor->VerifyFound();
3886
3887 // Create a buffer to update the descriptor with
3888 uint32_t qfi = 0;
3889 VkBufferCreateInfo buffCI = {};
3890 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3891 buffCI.size = 1024;
3892 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3893 buffCI.queueFamilyIndexCount = 1;
3894 buffCI.pQueueFamilyIndices = &qfi;
3895
3896 VkBuffer dyub;
3897 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3898 ASSERT_VK_SUCCESS(err);
3899 VkDescriptorBufferInfo buffInfo = {};
3900 buffInfo.buffer = dyub;
3901 buffInfo.offset = 0;
3902 buffInfo.range = 1024;
3903
3904 descriptor_write.pBufferInfo = &buffInfo;
3905 descriptor_write.descriptorCount = 2;
3906
Mark Mueller5c838ce2016-06-16 09:54:29 -06003907 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3909 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3910 m_errorMonitor->VerifyFound();
3911
Mark Mueller5c838ce2016-06-16 09:54:29 -06003912 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3913 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003914 descriptor_write.dstBinding = 1;
3915 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003916
Mark Mueller5c838ce2016-06-16 09:54:29 -06003917 // Make pImageInfo index non-null to avoid complaints of it missing
3918 VkDescriptorImageInfo imageInfo = {};
3919 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3920 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3922 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3923 m_errorMonitor->VerifyFound();
3924
Mark Muellerd4914412016-06-13 17:52:06 -06003925 vkDestroyBuffer(m_device->device(), dyub, NULL);
3926 vkDestroySampler(m_device->device(), sampler, NULL);
3927 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3928 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3929 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3930}
3931
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003932TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3933 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3934 "due to a buffer dependency being destroyed.");
3935 ASSERT_NO_FATAL_FAILURE(InitState());
3936
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003937 VkBuffer buffer;
3938 VkDeviceMemory mem;
3939 VkMemoryRequirements mem_reqs;
3940
3941 VkBufferCreateInfo buf_info = {};
3942 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12003943 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003944 buf_info.size = 256;
3945 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3946 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
3947 ASSERT_VK_SUCCESS(err);
3948
3949 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
3950
3951 VkMemoryAllocateInfo alloc_info = {};
3952 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3953 alloc_info.allocationSize = 256;
3954 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003955 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 -06003956 if (!pass) {
3957 vkDestroyBuffer(m_device->device(), buffer, NULL);
3958 return;
3959 }
3960 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
3961 ASSERT_VK_SUCCESS(err);
3962
3963 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3964 ASSERT_VK_SUCCESS(err);
3965
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003966 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12003967 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003968 m_commandBuffer->EndCommandBuffer();
3969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003971 // Destroy buffer dependency prior to submit to cause ERROR
3972 vkDestroyBuffer(m_device->device(), buffer, NULL);
3973
3974 VkSubmitInfo submit_info = {};
3975 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3976 submit_info.commandBufferCount = 1;
3977 submit_info.pCommandBuffers = &m_commandBuffer->handle();
3978 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3979
3980 m_errorMonitor->VerifyFound();
3981 vkFreeMemory(m_device->handle(), mem, NULL);
3982}
3983
Tobin Ehlisea413442016-09-28 10:23:59 -06003984TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
3985 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
3986
3987 ASSERT_NO_FATAL_FAILURE(InitState());
3988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3989
3990 VkDescriptorPoolSize ds_type_count;
3991 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3992 ds_type_count.descriptorCount = 1;
3993
3994 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3995 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3996 ds_pool_ci.maxSets = 1;
3997 ds_pool_ci.poolSizeCount = 1;
3998 ds_pool_ci.pPoolSizes = &ds_type_count;
3999
4000 VkDescriptorPool ds_pool;
4001 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4002 ASSERT_VK_SUCCESS(err);
4003
4004 VkDescriptorSetLayoutBinding layout_binding;
4005 layout_binding.binding = 0;
4006 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4007 layout_binding.descriptorCount = 1;
4008 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4009 layout_binding.pImmutableSamplers = NULL;
4010
4011 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4012 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4013 ds_layout_ci.bindingCount = 1;
4014 ds_layout_ci.pBindings = &layout_binding;
4015 VkDescriptorSetLayout ds_layout;
4016 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4017 ASSERT_VK_SUCCESS(err);
4018
4019 VkDescriptorSetAllocateInfo alloc_info = {};
4020 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4021 alloc_info.descriptorSetCount = 1;
4022 alloc_info.descriptorPool = ds_pool;
4023 alloc_info.pSetLayouts = &ds_layout;
4024 VkDescriptorSet descriptor_set;
4025 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4026 ASSERT_VK_SUCCESS(err);
4027
4028 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4029 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4030 pipeline_layout_ci.pNext = NULL;
4031 pipeline_layout_ci.setLayoutCount = 1;
4032 pipeline_layout_ci.pSetLayouts = &ds_layout;
4033
4034 VkPipelineLayout pipeline_layout;
4035 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4036 ASSERT_VK_SUCCESS(err);
4037
4038 VkBuffer buffer;
4039 uint32_t queue_family_index = 0;
4040 VkBufferCreateInfo buffer_create_info = {};
4041 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4042 buffer_create_info.size = 1024;
4043 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4044 buffer_create_info.queueFamilyIndexCount = 1;
4045 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4046
4047 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4048 ASSERT_VK_SUCCESS(err);
4049
4050 VkMemoryRequirements memory_reqs;
4051 VkDeviceMemory buffer_memory;
4052
4053 VkMemoryAllocateInfo memory_info = {};
4054 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4055 memory_info.allocationSize = 0;
4056 memory_info.memoryTypeIndex = 0;
4057
4058 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4059 memory_info.allocationSize = memory_reqs.size;
4060 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4061 ASSERT_TRUE(pass);
4062
4063 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4064 ASSERT_VK_SUCCESS(err);
4065 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4066 ASSERT_VK_SUCCESS(err);
4067
4068 VkBufferView view;
4069 VkBufferViewCreateInfo bvci = {};
4070 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4071 bvci.buffer = buffer;
4072 bvci.format = VK_FORMAT_R8_UNORM;
4073 bvci.range = VK_WHOLE_SIZE;
4074
4075 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4076 ASSERT_VK_SUCCESS(err);
4077
4078 VkWriteDescriptorSet descriptor_write = {};
4079 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4080 descriptor_write.dstSet = descriptor_set;
4081 descriptor_write.dstBinding = 0;
4082 descriptor_write.descriptorCount = 1;
4083 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4084 descriptor_write.pTexelBufferView = &view;
4085
4086 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4087
4088 char const *vsSource = "#version 450\n"
4089 "\n"
4090 "out gl_PerVertex { \n"
4091 " vec4 gl_Position;\n"
4092 "};\n"
4093 "void main(){\n"
4094 " gl_Position = vec4(1);\n"
4095 "}\n";
4096 char const *fsSource = "#version 450\n"
4097 "\n"
4098 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4099 "layout(location=0) out vec4 x;\n"
4100 "void main(){\n"
4101 " x = imageLoad(s, 0);\n"
4102 "}\n";
4103 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4104 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4105 VkPipelineObj pipe(m_device);
4106 pipe.AddShader(&vs);
4107 pipe.AddShader(&fs);
4108 pipe.AddColorAttachment();
4109 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4110
4111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4113
4114 BeginCommandBuffer();
4115 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4116 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4117 VkRect2D scissor = {{0, 0}, {16, 16}};
4118 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4119 // Bind pipeline to cmd buffer
4120 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4121 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4122 &descriptor_set, 0, nullptr);
4123 Draw(1, 0, 0, 0);
4124 EndCommandBuffer();
4125
4126 // Delete BufferView in order to invalidate cmd buffer
4127 vkDestroyBufferView(m_device->device(), view, NULL);
4128 // Now attempt submit of cmd buffer
4129 VkSubmitInfo submit_info = {};
4130 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4131 submit_info.commandBufferCount = 1;
4132 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4133 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4134 m_errorMonitor->VerifyFound();
4135
4136 // Clean-up
4137 vkDestroyBuffer(m_device->device(), buffer, NULL);
4138 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4139 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4140 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4141 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4142}
4143
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004144TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4145 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4146 "due to an image dependency being destroyed.");
4147 ASSERT_NO_FATAL_FAILURE(InitState());
4148
4149 VkImage image;
4150 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4151 VkImageCreateInfo image_create_info = {};
4152 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4153 image_create_info.pNext = NULL;
4154 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4155 image_create_info.format = tex_format;
4156 image_create_info.extent.width = 32;
4157 image_create_info.extent.height = 32;
4158 image_create_info.extent.depth = 1;
4159 image_create_info.mipLevels = 1;
4160 image_create_info.arrayLayers = 1;
4161 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4162 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004163 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004164 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004165 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004166 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004167 // Have to bind memory to image before recording cmd in cmd buffer using it
4168 VkMemoryRequirements mem_reqs;
4169 VkDeviceMemory image_mem;
4170 bool pass;
4171 VkMemoryAllocateInfo mem_alloc = {};
4172 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4173 mem_alloc.pNext = NULL;
4174 mem_alloc.memoryTypeIndex = 0;
4175 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4176 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004177 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004178 ASSERT_TRUE(pass);
4179 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4180 ASSERT_VK_SUCCESS(err);
4181 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4182 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004183
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004184 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004185 VkClearColorValue ccv;
4186 ccv.float32[0] = 1.0f;
4187 ccv.float32[1] = 1.0f;
4188 ccv.float32[2] = 1.0f;
4189 ccv.float32[3] = 1.0f;
4190 VkImageSubresourceRange isr = {};
4191 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004192 isr.baseArrayLayer = 0;
4193 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004194 isr.layerCount = 1;
4195 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004196 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004197 m_commandBuffer->EndCommandBuffer();
4198
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004200 // Destroy image dependency prior to submit to cause ERROR
4201 vkDestroyImage(m_device->device(), image, NULL);
4202
4203 VkSubmitInfo submit_info = {};
4204 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4205 submit_info.commandBufferCount = 1;
4206 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4207 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4208
4209 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004210 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004211}
4212
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004213TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4214 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4215 "due to a framebuffer image dependency being destroyed.");
4216 VkFormatProperties format_properties;
4217 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004218 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4219 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004220 return;
4221 }
4222
4223 ASSERT_NO_FATAL_FAILURE(InitState());
4224 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4225
4226 VkImageCreateInfo image_ci = {};
4227 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4228 image_ci.pNext = NULL;
4229 image_ci.imageType = VK_IMAGE_TYPE_2D;
4230 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4231 image_ci.extent.width = 32;
4232 image_ci.extent.height = 32;
4233 image_ci.extent.depth = 1;
4234 image_ci.mipLevels = 1;
4235 image_ci.arrayLayers = 1;
4236 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4237 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004238 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004239 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4240 image_ci.flags = 0;
4241 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004242 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004243
4244 VkMemoryRequirements memory_reqs;
4245 VkDeviceMemory image_memory;
4246 bool pass;
4247 VkMemoryAllocateInfo memory_info = {};
4248 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4249 memory_info.pNext = NULL;
4250 memory_info.allocationSize = 0;
4251 memory_info.memoryTypeIndex = 0;
4252 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4253 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004254 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004255 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004256 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004257 ASSERT_VK_SUCCESS(err);
4258 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4259 ASSERT_VK_SUCCESS(err);
4260
4261 VkImageViewCreateInfo ivci = {
4262 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4263 nullptr,
4264 0,
4265 image,
4266 VK_IMAGE_VIEW_TYPE_2D,
4267 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004268 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004269 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4270 };
4271 VkImageView view;
4272 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4273 ASSERT_VK_SUCCESS(err);
4274
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004275 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004276 VkFramebuffer fb;
4277 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4278 ASSERT_VK_SUCCESS(err);
4279
4280 // Just use default renderpass with our framebuffer
4281 m_renderPassBeginInfo.framebuffer = fb;
4282 // Create Null cmd buffer for submit
4283 BeginCommandBuffer();
4284 EndCommandBuffer();
4285 // Destroy image attached to framebuffer to invalidate cmd buffer
4286 vkDestroyImage(m_device->device(), image, NULL);
4287 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004289 QueueCommandBuffer(false);
4290 m_errorMonitor->VerifyFound();
4291
4292 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4293 vkDestroyImageView(m_device->device(), view, nullptr);
4294 vkFreeMemory(m_device->device(), image_memory, nullptr);
4295}
4296
Tobin Ehlisb329f992016-10-12 13:20:29 -06004297TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4298 TEST_DESCRIPTION("Delete in-use framebuffer.");
4299 VkFormatProperties format_properties;
4300 VkResult err = VK_SUCCESS;
4301 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4302
4303 ASSERT_NO_FATAL_FAILURE(InitState());
4304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4305
4306 VkImageObj image(m_device);
4307 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4308 ASSERT_TRUE(image.initialized());
4309 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4310
4311 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4312 VkFramebuffer fb;
4313 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4314 ASSERT_VK_SUCCESS(err);
4315
4316 // Just use default renderpass with our framebuffer
4317 m_renderPassBeginInfo.framebuffer = fb;
4318 // Create Null cmd buffer for submit
4319 BeginCommandBuffer();
4320 EndCommandBuffer();
4321 // Submit cmd buffer to put it in-flight
4322 VkSubmitInfo submit_info = {};
4323 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4324 submit_info.commandBufferCount = 1;
4325 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4326 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4327 // Destroy framebuffer while in-flight
4328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4329 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4330 m_errorMonitor->VerifyFound();
4331 // Wait for queue to complete so we can safely destroy everything
4332 vkQueueWaitIdle(m_device->m_queue);
4333 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4334}
4335
Tobin Ehlis88becd72016-09-21 14:33:41 -06004336TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4337 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4338 VkFormatProperties format_properties;
4339 VkResult err = VK_SUCCESS;
4340 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004341
4342 ASSERT_NO_FATAL_FAILURE(InitState());
4343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4344
4345 VkImageCreateInfo image_ci = {};
4346 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4347 image_ci.pNext = NULL;
4348 image_ci.imageType = VK_IMAGE_TYPE_2D;
4349 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4350 image_ci.extent.width = 256;
4351 image_ci.extent.height = 256;
4352 image_ci.extent.depth = 1;
4353 image_ci.mipLevels = 1;
4354 image_ci.arrayLayers = 1;
4355 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4356 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004357 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004358 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4359 image_ci.flags = 0;
4360 VkImage image;
4361 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4362
4363 VkMemoryRequirements memory_reqs;
4364 VkDeviceMemory image_memory;
4365 bool pass;
4366 VkMemoryAllocateInfo memory_info = {};
4367 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4368 memory_info.pNext = NULL;
4369 memory_info.allocationSize = 0;
4370 memory_info.memoryTypeIndex = 0;
4371 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4372 memory_info.allocationSize = memory_reqs.size;
4373 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4374 ASSERT_TRUE(pass);
4375 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4376 ASSERT_VK_SUCCESS(err);
4377 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4378 ASSERT_VK_SUCCESS(err);
4379
4380 VkImageViewCreateInfo ivci = {
4381 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4382 nullptr,
4383 0,
4384 image,
4385 VK_IMAGE_VIEW_TYPE_2D,
4386 VK_FORMAT_B8G8R8A8_UNORM,
4387 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4388 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4389 };
4390 VkImageView view;
4391 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4392 ASSERT_VK_SUCCESS(err);
4393
4394 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4395 VkFramebuffer fb;
4396 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4397 ASSERT_VK_SUCCESS(err);
4398
4399 // Just use default renderpass with our framebuffer
4400 m_renderPassBeginInfo.framebuffer = fb;
4401 // Create Null cmd buffer for submit
4402 BeginCommandBuffer();
4403 EndCommandBuffer();
4404 // Submit cmd buffer to put it (and attached imageView) in-flight
4405 VkSubmitInfo submit_info = {};
4406 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4407 submit_info.commandBufferCount = 1;
4408 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4409 // Submit cmd buffer to put framebuffer and children in-flight
4410 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4411 // Destroy image attached to framebuffer while in-flight
4412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4413 vkDestroyImage(m_device->device(), image, NULL);
4414 m_errorMonitor->VerifyFound();
4415 // Wait for queue to complete so we can safely destroy image and other objects
4416 vkQueueWaitIdle(m_device->m_queue);
4417 vkDestroyImage(m_device->device(), image, NULL);
4418 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4419 vkDestroyImageView(m_device->device(), view, nullptr);
4420 vkFreeMemory(m_device->device(), image_memory, nullptr);
4421}
4422
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004423TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4424 TEST_DESCRIPTION("Delete in-use renderPass.");
4425
4426 ASSERT_NO_FATAL_FAILURE(InitState());
4427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4428
4429 // Create simple renderpass
4430 VkAttachmentReference attach = {};
4431 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4432 VkSubpassDescription subpass = {};
4433 subpass.pColorAttachments = &attach;
4434 VkRenderPassCreateInfo rpci = {};
4435 rpci.subpassCount = 1;
4436 rpci.pSubpasses = &subpass;
4437 rpci.attachmentCount = 1;
4438 VkAttachmentDescription attach_desc = {};
4439 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4440 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4441 rpci.pAttachments = &attach_desc;
4442 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4443 VkRenderPass rp;
4444 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4445 ASSERT_VK_SUCCESS(err);
4446
4447 // Create a pipeline that uses the given renderpass
4448 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4449 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4450
4451 VkPipelineLayout pipeline_layout;
4452 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4453 ASSERT_VK_SUCCESS(err);
4454
4455 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4456 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4457 vp_state_ci.viewportCount = 1;
4458 VkViewport vp = {}; // Just need dummy vp to point to
4459 vp_state_ci.pViewports = &vp;
4460 vp_state_ci.scissorCount = 1;
4461 VkRect2D scissors = {}; // Dummy scissors to point to
4462 vp_state_ci.pScissors = &scissors;
4463
4464 VkPipelineShaderStageCreateInfo shaderStages[2];
4465 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4466
4467 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4468 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4469 // but add it to be able to run on more devices
4470 shaderStages[0] = vs.GetStageCreateInfo();
4471 shaderStages[1] = fs.GetStageCreateInfo();
4472
4473 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4474 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4475
4476 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4477 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4478 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4479
4480 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4481 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4482 rs_ci.rasterizerDiscardEnable = true;
4483 rs_ci.lineWidth = 1.0f;
4484
4485 VkPipelineColorBlendAttachmentState att = {};
4486 att.blendEnable = VK_FALSE;
4487 att.colorWriteMask = 0xf;
4488
4489 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4490 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4491 cb_ci.attachmentCount = 1;
4492 cb_ci.pAttachments = &att;
4493
4494 VkGraphicsPipelineCreateInfo gp_ci = {};
4495 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4496 gp_ci.stageCount = 2;
4497 gp_ci.pStages = shaderStages;
4498 gp_ci.pVertexInputState = &vi_ci;
4499 gp_ci.pInputAssemblyState = &ia_ci;
4500 gp_ci.pViewportState = &vp_state_ci;
4501 gp_ci.pRasterizationState = &rs_ci;
4502 gp_ci.pColorBlendState = &cb_ci;
4503 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4504 gp_ci.layout = pipeline_layout;
4505 gp_ci.renderPass = rp;
4506
4507 VkPipelineCacheCreateInfo pc_ci = {};
4508 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4509
4510 VkPipeline pipeline;
4511 VkPipelineCache pipe_cache;
4512 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4513 ASSERT_VK_SUCCESS(err);
4514
4515 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4516 ASSERT_VK_SUCCESS(err);
4517 // Bind pipeline to cmd buffer, will also bind renderpass
4518 m_commandBuffer->BeginCommandBuffer();
4519 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4520 m_commandBuffer->EndCommandBuffer();
4521
4522 VkSubmitInfo submit_info = {};
4523 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4524 submit_info.commandBufferCount = 1;
4525 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4526 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4527
4528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4529 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4530 m_errorMonitor->VerifyFound();
4531
4532 // Wait for queue to complete so we can safely destroy everything
4533 vkQueueWaitIdle(m_device->m_queue);
4534 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4535 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4536 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4537 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4538}
4539
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004540TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004541 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004542 ASSERT_NO_FATAL_FAILURE(InitState());
4543
4544 VkImage image;
4545 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4546 VkImageCreateInfo image_create_info = {};
4547 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4548 image_create_info.pNext = NULL;
4549 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4550 image_create_info.format = tex_format;
4551 image_create_info.extent.width = 32;
4552 image_create_info.extent.height = 32;
4553 image_create_info.extent.depth = 1;
4554 image_create_info.mipLevels = 1;
4555 image_create_info.arrayLayers = 1;
4556 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4557 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004558 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004559 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004560 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004561 ASSERT_VK_SUCCESS(err);
4562 // Have to bind memory to image before recording cmd in cmd buffer using it
4563 VkMemoryRequirements mem_reqs;
4564 VkDeviceMemory image_mem;
4565 bool pass;
4566 VkMemoryAllocateInfo mem_alloc = {};
4567 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4568 mem_alloc.pNext = NULL;
4569 mem_alloc.memoryTypeIndex = 0;
4570 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4571 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004572 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004573 ASSERT_TRUE(pass);
4574 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4575 ASSERT_VK_SUCCESS(err);
4576
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004577 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004579 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004580
4581 m_commandBuffer->BeginCommandBuffer();
4582 VkClearColorValue ccv;
4583 ccv.float32[0] = 1.0f;
4584 ccv.float32[1] = 1.0f;
4585 ccv.float32[2] = 1.0f;
4586 ccv.float32[3] = 1.0f;
4587 VkImageSubresourceRange isr = {};
4588 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4589 isr.baseArrayLayer = 0;
4590 isr.baseMipLevel = 0;
4591 isr.layerCount = 1;
4592 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004593 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004594 m_commandBuffer->EndCommandBuffer();
4595
4596 m_errorMonitor->VerifyFound();
4597 vkDestroyImage(m_device->device(), image, NULL);
4598 vkFreeMemory(m_device->device(), image_mem, nullptr);
4599}
4600
4601TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004602 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004603 ASSERT_NO_FATAL_FAILURE(InitState());
4604
4605 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004606 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 -06004607 VK_IMAGE_TILING_OPTIMAL, 0);
4608 ASSERT_TRUE(image.initialized());
4609
4610 VkBuffer buffer;
4611 VkDeviceMemory mem;
4612 VkMemoryRequirements mem_reqs;
4613
4614 VkBufferCreateInfo buf_info = {};
4615 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004616 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004617 buf_info.size = 256;
4618 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4619 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4620 ASSERT_VK_SUCCESS(err);
4621
4622 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4623
4624 VkMemoryAllocateInfo alloc_info = {};
4625 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4626 alloc_info.allocationSize = 256;
4627 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004628 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 -06004629 if (!pass) {
4630 vkDestroyBuffer(m_device->device(), buffer, NULL);
4631 return;
4632 }
4633 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4634 ASSERT_VK_SUCCESS(err);
4635
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004636 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004638 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004639 VkBufferImageCopy region = {};
4640 region.bufferRowLength = 128;
4641 region.bufferImageHeight = 128;
4642 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4643
4644 region.imageSubresource.layerCount = 1;
4645 region.imageExtent.height = 4;
4646 region.imageExtent.width = 4;
4647 region.imageExtent.depth = 1;
4648 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004649 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4650 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004651 m_commandBuffer->EndCommandBuffer();
4652
4653 m_errorMonitor->VerifyFound();
4654
4655 vkDestroyBuffer(m_device->device(), buffer, NULL);
4656 vkFreeMemory(m_device->handle(), mem, NULL);
4657}
4658
Tobin Ehlis85940f52016-07-07 16:57:21 -06004659TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4660 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4661 "due to an event dependency being destroyed.");
4662 ASSERT_NO_FATAL_FAILURE(InitState());
4663
4664 VkEvent event;
4665 VkEventCreateInfo evci = {};
4666 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4667 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4668 ASSERT_VK_SUCCESS(result);
4669
4670 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004671 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004672 m_commandBuffer->EndCommandBuffer();
4673
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004675 // Destroy event dependency prior to submit to cause ERROR
4676 vkDestroyEvent(m_device->device(), event, NULL);
4677
4678 VkSubmitInfo submit_info = {};
4679 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4680 submit_info.commandBufferCount = 1;
4681 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4682 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4683
4684 m_errorMonitor->VerifyFound();
4685}
4686
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004687TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4688 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4689 "due to a query pool dependency being destroyed.");
4690 ASSERT_NO_FATAL_FAILURE(InitState());
4691
4692 VkQueryPool query_pool;
4693 VkQueryPoolCreateInfo qpci{};
4694 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4695 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4696 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004697 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004698 ASSERT_VK_SUCCESS(result);
4699
4700 m_commandBuffer->BeginCommandBuffer();
4701 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4702 m_commandBuffer->EndCommandBuffer();
4703
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004705 // Destroy query pool dependency prior to submit to cause ERROR
4706 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4707
4708 VkSubmitInfo submit_info = {};
4709 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4710 submit_info.commandBufferCount = 1;
4711 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4712 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4713
4714 m_errorMonitor->VerifyFound();
4715}
4716
Tobin Ehlis24130d92016-07-08 15:50:53 -06004717TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4718 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4719 "due to a pipeline dependency being destroyed.");
4720 ASSERT_NO_FATAL_FAILURE(InitState());
4721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4722
4723 VkResult err;
4724
4725 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4726 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4727
4728 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004729 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004730 ASSERT_VK_SUCCESS(err);
4731
4732 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4733 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4734 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004735 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004736 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004737 vp_state_ci.scissorCount = 1;
4738 VkRect2D scissors = {}; // Dummy scissors to point to
4739 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004740
4741 VkPipelineShaderStageCreateInfo shaderStages[2];
4742 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004744 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4745 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4746 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004747 shaderStages[0] = vs.GetStageCreateInfo();
4748 shaderStages[1] = fs.GetStageCreateInfo();
4749
4750 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4751 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4752
4753 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4754 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4755 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4756
4757 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4758 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004759 rs_ci.rasterizerDiscardEnable = true;
4760 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004761
4762 VkPipelineColorBlendAttachmentState att = {};
4763 att.blendEnable = VK_FALSE;
4764 att.colorWriteMask = 0xf;
4765
4766 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4767 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4768 cb_ci.attachmentCount = 1;
4769 cb_ci.pAttachments = &att;
4770
4771 VkGraphicsPipelineCreateInfo gp_ci = {};
4772 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4773 gp_ci.stageCount = 2;
4774 gp_ci.pStages = shaderStages;
4775 gp_ci.pVertexInputState = &vi_ci;
4776 gp_ci.pInputAssemblyState = &ia_ci;
4777 gp_ci.pViewportState = &vp_state_ci;
4778 gp_ci.pRasterizationState = &rs_ci;
4779 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004780 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4781 gp_ci.layout = pipeline_layout;
4782 gp_ci.renderPass = renderPass();
4783
4784 VkPipelineCacheCreateInfo pc_ci = {};
4785 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4786
4787 VkPipeline pipeline;
4788 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004789 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004790 ASSERT_VK_SUCCESS(err);
4791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004792 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004793 ASSERT_VK_SUCCESS(err);
4794
4795 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004796 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004797 m_commandBuffer->EndCommandBuffer();
4798 // Now destroy pipeline in order to cause error when submitting
4799 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004802
4803 VkSubmitInfo submit_info = {};
4804 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4805 submit_info.commandBufferCount = 1;
4806 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4807 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4808
4809 m_errorMonitor->VerifyFound();
4810 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4811 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4812}
4813
Tobin Ehlis31289162016-08-17 14:57:58 -06004814TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4815 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4816 "due to a bound descriptor set with a buffer dependency "
4817 "being destroyed.");
4818 ASSERT_NO_FATAL_FAILURE(InitState());
4819 ASSERT_NO_FATAL_FAILURE(InitViewport());
4820 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4821
4822 VkDescriptorPoolSize ds_type_count = {};
4823 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4824 ds_type_count.descriptorCount = 1;
4825
4826 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4827 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4828 ds_pool_ci.pNext = NULL;
4829 ds_pool_ci.maxSets = 1;
4830 ds_pool_ci.poolSizeCount = 1;
4831 ds_pool_ci.pPoolSizes = &ds_type_count;
4832
4833 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004834 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004835 ASSERT_VK_SUCCESS(err);
4836
4837 VkDescriptorSetLayoutBinding dsl_binding = {};
4838 dsl_binding.binding = 0;
4839 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4840 dsl_binding.descriptorCount = 1;
4841 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4842 dsl_binding.pImmutableSamplers = NULL;
4843
4844 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4845 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4846 ds_layout_ci.pNext = NULL;
4847 ds_layout_ci.bindingCount = 1;
4848 ds_layout_ci.pBindings = &dsl_binding;
4849 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004850 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004851 ASSERT_VK_SUCCESS(err);
4852
4853 VkDescriptorSet descriptorSet;
4854 VkDescriptorSetAllocateInfo alloc_info = {};
4855 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4856 alloc_info.descriptorSetCount = 1;
4857 alloc_info.descriptorPool = ds_pool;
4858 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004859 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004860 ASSERT_VK_SUCCESS(err);
4861
4862 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4863 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4864 pipeline_layout_ci.pNext = NULL;
4865 pipeline_layout_ci.setLayoutCount = 1;
4866 pipeline_layout_ci.pSetLayouts = &ds_layout;
4867
4868 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004869 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004870 ASSERT_VK_SUCCESS(err);
4871
4872 // Create a buffer to update the descriptor with
4873 uint32_t qfi = 0;
4874 VkBufferCreateInfo buffCI = {};
4875 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4876 buffCI.size = 1024;
4877 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4878 buffCI.queueFamilyIndexCount = 1;
4879 buffCI.pQueueFamilyIndices = &qfi;
4880
4881 VkBuffer buffer;
4882 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4883 ASSERT_VK_SUCCESS(err);
4884 // Allocate memory and bind to buffer so we can make it to the appropriate
4885 // error
4886 VkMemoryAllocateInfo mem_alloc = {};
4887 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4888 mem_alloc.pNext = NULL;
4889 mem_alloc.allocationSize = 1024;
4890 mem_alloc.memoryTypeIndex = 0;
4891
4892 VkMemoryRequirements memReqs;
4893 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004894 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004895 if (!pass) {
4896 vkDestroyBuffer(m_device->device(), buffer, NULL);
4897 return;
4898 }
4899
4900 VkDeviceMemory mem;
4901 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4902 ASSERT_VK_SUCCESS(err);
4903 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4904 ASSERT_VK_SUCCESS(err);
4905 // Correctly update descriptor to avoid "NOT_UPDATED" error
4906 VkDescriptorBufferInfo buffInfo = {};
4907 buffInfo.buffer = buffer;
4908 buffInfo.offset = 0;
4909 buffInfo.range = 1024;
4910
4911 VkWriteDescriptorSet descriptor_write;
4912 memset(&descriptor_write, 0, sizeof(descriptor_write));
4913 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4914 descriptor_write.dstSet = descriptorSet;
4915 descriptor_write.dstBinding = 0;
4916 descriptor_write.descriptorCount = 1;
4917 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4918 descriptor_write.pBufferInfo = &buffInfo;
4919
4920 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4921
4922 // Create PSO to be used for draw-time errors below
4923 char const *vsSource = "#version 450\n"
4924 "\n"
4925 "out gl_PerVertex { \n"
4926 " vec4 gl_Position;\n"
4927 "};\n"
4928 "void main(){\n"
4929 " gl_Position = vec4(1);\n"
4930 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004931 char const *fsSource = "#version 450\n"
4932 "\n"
4933 "layout(location=0) out vec4 x;\n"
4934 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4935 "void main(){\n"
4936 " x = vec4(bar.y);\n"
4937 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004938 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4939 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4940 VkPipelineObj pipe(m_device);
4941 pipe.AddShader(&vs);
4942 pipe.AddShader(&fs);
4943 pipe.AddColorAttachment();
4944 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4945
4946 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004947 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4948 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4949 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06004950 Draw(1, 0, 0, 0);
4951 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06004953 // Destroy buffer should invalidate the cmd buffer, causing error on submit
4954 vkDestroyBuffer(m_device->device(), buffer, NULL);
4955 // Attempt to submit cmd buffer
4956 VkSubmitInfo submit_info = {};
4957 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4958 submit_info.commandBufferCount = 1;
4959 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4960 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4961 m_errorMonitor->VerifyFound();
4962 // Cleanup
4963 vkFreeMemory(m_device->device(), mem, NULL);
4964
4965 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4966 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4967 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4968}
4969
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004970TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
4971 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4972 "due to a bound descriptor sets with a combined image "
4973 "sampler having their image, sampler, and descriptor set "
4974 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06004975 "submit associated cmd buffers. Attempt to destroy a "
4976 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004977 ASSERT_NO_FATAL_FAILURE(InitState());
4978 ASSERT_NO_FATAL_FAILURE(InitViewport());
4979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4980
4981 VkDescriptorPoolSize ds_type_count = {};
4982 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4983 ds_type_count.descriptorCount = 1;
4984
4985 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4986 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4987 ds_pool_ci.pNext = NULL;
4988 ds_pool_ci.maxSets = 1;
4989 ds_pool_ci.poolSizeCount = 1;
4990 ds_pool_ci.pPoolSizes = &ds_type_count;
4991
4992 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004993 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004994 ASSERT_VK_SUCCESS(err);
4995
4996 VkDescriptorSetLayoutBinding dsl_binding = {};
4997 dsl_binding.binding = 0;
4998 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4999 dsl_binding.descriptorCount = 1;
5000 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5001 dsl_binding.pImmutableSamplers = NULL;
5002
5003 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5004 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5005 ds_layout_ci.pNext = NULL;
5006 ds_layout_ci.bindingCount = 1;
5007 ds_layout_ci.pBindings = &dsl_binding;
5008 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005009 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005010 ASSERT_VK_SUCCESS(err);
5011
5012 VkDescriptorSet descriptorSet;
5013 VkDescriptorSetAllocateInfo alloc_info = {};
5014 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5015 alloc_info.descriptorSetCount = 1;
5016 alloc_info.descriptorPool = ds_pool;
5017 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005018 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005019 ASSERT_VK_SUCCESS(err);
5020
5021 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5022 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5023 pipeline_layout_ci.pNext = NULL;
5024 pipeline_layout_ci.setLayoutCount = 1;
5025 pipeline_layout_ci.pSetLayouts = &ds_layout;
5026
5027 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005028 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005029 ASSERT_VK_SUCCESS(err);
5030
5031 // Create images to update the descriptor with
5032 VkImage image;
5033 VkImage image2;
5034 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5035 const int32_t tex_width = 32;
5036 const int32_t tex_height = 32;
5037 VkImageCreateInfo image_create_info = {};
5038 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5039 image_create_info.pNext = NULL;
5040 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5041 image_create_info.format = tex_format;
5042 image_create_info.extent.width = tex_width;
5043 image_create_info.extent.height = tex_height;
5044 image_create_info.extent.depth = 1;
5045 image_create_info.mipLevels = 1;
5046 image_create_info.arrayLayers = 1;
5047 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5048 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5049 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5050 image_create_info.flags = 0;
5051 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5052 ASSERT_VK_SUCCESS(err);
5053 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5054 ASSERT_VK_SUCCESS(err);
5055
5056 VkMemoryRequirements memory_reqs;
5057 VkDeviceMemory image_memory;
5058 bool pass;
5059 VkMemoryAllocateInfo memory_info = {};
5060 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5061 memory_info.pNext = NULL;
5062 memory_info.allocationSize = 0;
5063 memory_info.memoryTypeIndex = 0;
5064 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5065 // Allocate enough memory for both images
5066 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005067 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005068 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005069 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005070 ASSERT_VK_SUCCESS(err);
5071 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5072 ASSERT_VK_SUCCESS(err);
5073 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005074 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005075 ASSERT_VK_SUCCESS(err);
5076
5077 VkImageViewCreateInfo image_view_create_info = {};
5078 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5079 image_view_create_info.image = image;
5080 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5081 image_view_create_info.format = tex_format;
5082 image_view_create_info.subresourceRange.layerCount = 1;
5083 image_view_create_info.subresourceRange.baseMipLevel = 0;
5084 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005085 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005086
5087 VkImageView view;
5088 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005089 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005090 ASSERT_VK_SUCCESS(err);
5091 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005092 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005093 ASSERT_VK_SUCCESS(err);
5094 // Create Samplers
5095 VkSamplerCreateInfo sampler_ci = {};
5096 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5097 sampler_ci.pNext = NULL;
5098 sampler_ci.magFilter = VK_FILTER_NEAREST;
5099 sampler_ci.minFilter = VK_FILTER_NEAREST;
5100 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5101 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5102 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5103 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5104 sampler_ci.mipLodBias = 1.0;
5105 sampler_ci.anisotropyEnable = VK_FALSE;
5106 sampler_ci.maxAnisotropy = 1;
5107 sampler_ci.compareEnable = VK_FALSE;
5108 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5109 sampler_ci.minLod = 1.0;
5110 sampler_ci.maxLod = 1.0;
5111 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5112 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5113 VkSampler sampler;
5114 VkSampler sampler2;
5115 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5116 ASSERT_VK_SUCCESS(err);
5117 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5118 ASSERT_VK_SUCCESS(err);
5119 // Update descriptor with image and sampler
5120 VkDescriptorImageInfo img_info = {};
5121 img_info.sampler = sampler;
5122 img_info.imageView = view;
5123 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5124
5125 VkWriteDescriptorSet descriptor_write;
5126 memset(&descriptor_write, 0, sizeof(descriptor_write));
5127 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5128 descriptor_write.dstSet = descriptorSet;
5129 descriptor_write.dstBinding = 0;
5130 descriptor_write.descriptorCount = 1;
5131 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5132 descriptor_write.pImageInfo = &img_info;
5133
5134 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5135
5136 // Create PSO to be used for draw-time errors below
5137 char const *vsSource = "#version 450\n"
5138 "\n"
5139 "out gl_PerVertex { \n"
5140 " vec4 gl_Position;\n"
5141 "};\n"
5142 "void main(){\n"
5143 " gl_Position = vec4(1);\n"
5144 "}\n";
5145 char const *fsSource = "#version 450\n"
5146 "\n"
5147 "layout(set=0, binding=0) uniform sampler2D s;\n"
5148 "layout(location=0) out vec4 x;\n"
5149 "void main(){\n"
5150 " x = texture(s, vec2(1));\n"
5151 "}\n";
5152 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5153 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5154 VkPipelineObj pipe(m_device);
5155 pipe.AddShader(&vs);
5156 pipe.AddShader(&fs);
5157 pipe.AddColorAttachment();
5158 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5159
5160 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005162 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005163 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5164 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5165 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005166 Draw(1, 0, 0, 0);
5167 EndCommandBuffer();
5168 // Destroy sampler invalidates the cmd buffer, causing error on submit
5169 vkDestroySampler(m_device->device(), sampler, NULL);
5170 // Attempt to submit cmd buffer
5171 VkSubmitInfo submit_info = {};
5172 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5173 submit_info.commandBufferCount = 1;
5174 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5175 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5176 m_errorMonitor->VerifyFound();
5177 // Now re-update descriptor with valid sampler and delete image
5178 img_info.sampler = sampler2;
5179 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005181 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005182 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5183 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5184 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005185 Draw(1, 0, 0, 0);
5186 EndCommandBuffer();
5187 // Destroy image invalidates the cmd buffer, causing error on submit
5188 vkDestroyImage(m_device->device(), image, NULL);
5189 // Attempt to submit cmd buffer
5190 submit_info = {};
5191 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5192 submit_info.commandBufferCount = 1;
5193 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5194 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5195 m_errorMonitor->VerifyFound();
5196 // Now update descriptor to be valid, but then free descriptor
5197 img_info.imageView = view2;
5198 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005200 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005201 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5202 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5203 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005204 Draw(1, 0, 0, 0);
5205 EndCommandBuffer();
5206 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005208 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005209 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005210 // Attempt to submit cmd buffer
5211 submit_info = {};
5212 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5213 submit_info.commandBufferCount = 1;
5214 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5215 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5216 m_errorMonitor->VerifyFound();
5217 // Cleanup
5218 vkFreeMemory(m_device->device(), image_memory, NULL);
5219 vkDestroySampler(m_device->device(), sampler2, NULL);
5220 vkDestroyImage(m_device->device(), image2, NULL);
5221 vkDestroyImageView(m_device->device(), view, NULL);
5222 vkDestroyImageView(m_device->device(), view2, NULL);
5223 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5224 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5225 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5226}
5227
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005228TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5229 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5230 ASSERT_NO_FATAL_FAILURE(InitState());
5231 ASSERT_NO_FATAL_FAILURE(InitViewport());
5232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5233
5234 VkDescriptorPoolSize ds_type_count = {};
5235 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5236 ds_type_count.descriptorCount = 1;
5237
5238 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5239 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5240 ds_pool_ci.pNext = NULL;
5241 ds_pool_ci.maxSets = 1;
5242 ds_pool_ci.poolSizeCount = 1;
5243 ds_pool_ci.pPoolSizes = &ds_type_count;
5244
5245 VkDescriptorPool ds_pool;
5246 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5247 ASSERT_VK_SUCCESS(err);
5248
5249 VkDescriptorSetLayoutBinding dsl_binding = {};
5250 dsl_binding.binding = 0;
5251 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5252 dsl_binding.descriptorCount = 1;
5253 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5254 dsl_binding.pImmutableSamplers = NULL;
5255
5256 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5257 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5258 ds_layout_ci.pNext = NULL;
5259 ds_layout_ci.bindingCount = 1;
5260 ds_layout_ci.pBindings = &dsl_binding;
5261 VkDescriptorSetLayout ds_layout;
5262 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5263 ASSERT_VK_SUCCESS(err);
5264
5265 VkDescriptorSet descriptor_set;
5266 VkDescriptorSetAllocateInfo alloc_info = {};
5267 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5268 alloc_info.descriptorSetCount = 1;
5269 alloc_info.descriptorPool = ds_pool;
5270 alloc_info.pSetLayouts = &ds_layout;
5271 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5272 ASSERT_VK_SUCCESS(err);
5273
5274 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5275 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5276 pipeline_layout_ci.pNext = NULL;
5277 pipeline_layout_ci.setLayoutCount = 1;
5278 pipeline_layout_ci.pSetLayouts = &ds_layout;
5279
5280 VkPipelineLayout pipeline_layout;
5281 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5282 ASSERT_VK_SUCCESS(err);
5283
5284 // Create image to update the descriptor with
5285 VkImageObj image(m_device);
5286 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5287 ASSERT_TRUE(image.initialized());
5288
5289 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5290 // Create Sampler
5291 VkSamplerCreateInfo sampler_ci = {};
5292 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5293 sampler_ci.pNext = NULL;
5294 sampler_ci.magFilter = VK_FILTER_NEAREST;
5295 sampler_ci.minFilter = VK_FILTER_NEAREST;
5296 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5297 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5298 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5299 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5300 sampler_ci.mipLodBias = 1.0;
5301 sampler_ci.anisotropyEnable = VK_FALSE;
5302 sampler_ci.maxAnisotropy = 1;
5303 sampler_ci.compareEnable = VK_FALSE;
5304 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5305 sampler_ci.minLod = 1.0;
5306 sampler_ci.maxLod = 1.0;
5307 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5308 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5309 VkSampler sampler;
5310 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5311 ASSERT_VK_SUCCESS(err);
5312 // Update descriptor with image and sampler
5313 VkDescriptorImageInfo img_info = {};
5314 img_info.sampler = sampler;
5315 img_info.imageView = view;
5316 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5317
5318 VkWriteDescriptorSet descriptor_write;
5319 memset(&descriptor_write, 0, sizeof(descriptor_write));
5320 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5321 descriptor_write.dstSet = descriptor_set;
5322 descriptor_write.dstBinding = 0;
5323 descriptor_write.descriptorCount = 1;
5324 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5325 descriptor_write.pImageInfo = &img_info;
5326
5327 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5328
5329 // Create PSO to be used for draw-time errors below
5330 char const *vsSource = "#version 450\n"
5331 "\n"
5332 "out gl_PerVertex { \n"
5333 " vec4 gl_Position;\n"
5334 "};\n"
5335 "void main(){\n"
5336 " gl_Position = vec4(1);\n"
5337 "}\n";
5338 char const *fsSource = "#version 450\n"
5339 "\n"
5340 "layout(set=0, binding=0) uniform sampler2D s;\n"
5341 "layout(location=0) out vec4 x;\n"
5342 "void main(){\n"
5343 " x = texture(s, vec2(1));\n"
5344 "}\n";
5345 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5346 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5347 VkPipelineObj pipe(m_device);
5348 pipe.AddShader(&vs);
5349 pipe.AddShader(&fs);
5350 pipe.AddColorAttachment();
5351 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5352
5353 BeginCommandBuffer();
5354 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5355 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5356 &descriptor_set, 0, NULL);
5357 Draw(1, 0, 0, 0);
5358 EndCommandBuffer();
5359 // Submit cmd buffer to put pool in-flight
5360 VkSubmitInfo submit_info = {};
5361 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5362 submit_info.commandBufferCount = 1;
5363 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5364 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5365 // Destroy pool while in-flight, causing error
5366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5367 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5368 m_errorMonitor->VerifyFound();
5369 vkQueueWaitIdle(m_device->m_queue);
5370 // Cleanup
5371 vkDestroySampler(m_device->device(), sampler, NULL);
5372 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5373 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5374 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5375}
5376
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005377TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5378 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5379 ASSERT_NO_FATAL_FAILURE(InitState());
5380 ASSERT_NO_FATAL_FAILURE(InitViewport());
5381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5382
5383 VkDescriptorPoolSize ds_type_count = {};
5384 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5385 ds_type_count.descriptorCount = 1;
5386
5387 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5388 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5389 ds_pool_ci.pNext = NULL;
5390 ds_pool_ci.maxSets = 1;
5391 ds_pool_ci.poolSizeCount = 1;
5392 ds_pool_ci.pPoolSizes = &ds_type_count;
5393
5394 VkDescriptorPool ds_pool;
5395 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5396 ASSERT_VK_SUCCESS(err);
5397
5398 VkDescriptorSetLayoutBinding dsl_binding = {};
5399 dsl_binding.binding = 0;
5400 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5401 dsl_binding.descriptorCount = 1;
5402 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5403 dsl_binding.pImmutableSamplers = NULL;
5404
5405 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5406 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5407 ds_layout_ci.pNext = NULL;
5408 ds_layout_ci.bindingCount = 1;
5409 ds_layout_ci.pBindings = &dsl_binding;
5410 VkDescriptorSetLayout ds_layout;
5411 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5412 ASSERT_VK_SUCCESS(err);
5413
5414 VkDescriptorSet descriptorSet;
5415 VkDescriptorSetAllocateInfo alloc_info = {};
5416 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5417 alloc_info.descriptorSetCount = 1;
5418 alloc_info.descriptorPool = ds_pool;
5419 alloc_info.pSetLayouts = &ds_layout;
5420 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5421 ASSERT_VK_SUCCESS(err);
5422
5423 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5424 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5425 pipeline_layout_ci.pNext = NULL;
5426 pipeline_layout_ci.setLayoutCount = 1;
5427 pipeline_layout_ci.pSetLayouts = &ds_layout;
5428
5429 VkPipelineLayout pipeline_layout;
5430 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5431 ASSERT_VK_SUCCESS(err);
5432
5433 // Create images to update the descriptor with
5434 VkImage image;
5435 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5436 const int32_t tex_width = 32;
5437 const int32_t tex_height = 32;
5438 VkImageCreateInfo image_create_info = {};
5439 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5440 image_create_info.pNext = NULL;
5441 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5442 image_create_info.format = tex_format;
5443 image_create_info.extent.width = tex_width;
5444 image_create_info.extent.height = tex_height;
5445 image_create_info.extent.depth = 1;
5446 image_create_info.mipLevels = 1;
5447 image_create_info.arrayLayers = 1;
5448 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5449 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5450 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5451 image_create_info.flags = 0;
5452 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5453 ASSERT_VK_SUCCESS(err);
5454 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5455 VkMemoryRequirements memory_reqs;
5456 VkDeviceMemory image_memory;
5457 bool pass;
5458 VkMemoryAllocateInfo memory_info = {};
5459 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5460 memory_info.pNext = NULL;
5461 memory_info.allocationSize = 0;
5462 memory_info.memoryTypeIndex = 0;
5463 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5464 // Allocate enough memory for image
5465 memory_info.allocationSize = memory_reqs.size;
5466 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5467 ASSERT_TRUE(pass);
5468 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5469 ASSERT_VK_SUCCESS(err);
5470 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5471 ASSERT_VK_SUCCESS(err);
5472
5473 VkImageViewCreateInfo image_view_create_info = {};
5474 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5475 image_view_create_info.image = image;
5476 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5477 image_view_create_info.format = tex_format;
5478 image_view_create_info.subresourceRange.layerCount = 1;
5479 image_view_create_info.subresourceRange.baseMipLevel = 0;
5480 image_view_create_info.subresourceRange.levelCount = 1;
5481 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5482
5483 VkImageView view;
5484 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5485 ASSERT_VK_SUCCESS(err);
5486 // Create Samplers
5487 VkSamplerCreateInfo sampler_ci = {};
5488 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5489 sampler_ci.pNext = NULL;
5490 sampler_ci.magFilter = VK_FILTER_NEAREST;
5491 sampler_ci.minFilter = VK_FILTER_NEAREST;
5492 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5493 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5494 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5495 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5496 sampler_ci.mipLodBias = 1.0;
5497 sampler_ci.anisotropyEnable = VK_FALSE;
5498 sampler_ci.maxAnisotropy = 1;
5499 sampler_ci.compareEnable = VK_FALSE;
5500 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5501 sampler_ci.minLod = 1.0;
5502 sampler_ci.maxLod = 1.0;
5503 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5504 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5505 VkSampler sampler;
5506 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5507 ASSERT_VK_SUCCESS(err);
5508 // Update descriptor with image and sampler
5509 VkDescriptorImageInfo img_info = {};
5510 img_info.sampler = sampler;
5511 img_info.imageView = view;
5512 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5513
5514 VkWriteDescriptorSet descriptor_write;
5515 memset(&descriptor_write, 0, sizeof(descriptor_write));
5516 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5517 descriptor_write.dstSet = descriptorSet;
5518 descriptor_write.dstBinding = 0;
5519 descriptor_write.descriptorCount = 1;
5520 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5521 descriptor_write.pImageInfo = &img_info;
5522 // Break memory binding and attempt update
5523 vkFreeMemory(m_device->device(), image_memory, nullptr);
5524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005525 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5527 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5528 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5529 m_errorMonitor->VerifyFound();
5530 // Cleanup
5531 vkDestroyImage(m_device->device(), image, NULL);
5532 vkDestroySampler(m_device->device(), sampler, NULL);
5533 vkDestroyImageView(m_device->device(), view, NULL);
5534 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5535 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5536 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5537}
5538
Karl Schultz6addd812016-02-02 17:17:23 -07005539TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005540 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5541 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005542 // Create a valid cmd buffer
5543 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005544 uint64_t fake_pipeline_handle = 0xbaad6001;
5545 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005546 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005547 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5548
5549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005550 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005551 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005552 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005553
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005554 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005555 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 -06005556 Draw(1, 0, 0, 0);
5557 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005558
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005559 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005560 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 +12005561 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005562 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5563 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005564}
5565
Karl Schultz6addd812016-02-02 17:17:23 -07005566TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005567 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005568 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005569
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005571
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005572 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005573 ASSERT_NO_FATAL_FAILURE(InitViewport());
5574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005575 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005576 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5577 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005578
5579 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005580 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5581 ds_pool_ci.pNext = NULL;
5582 ds_pool_ci.maxSets = 1;
5583 ds_pool_ci.poolSizeCount = 1;
5584 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005585
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005586 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005587 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005588 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005589
Tony Barboureb254902015-07-15 12:50:33 -06005590 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005591 dsl_binding.binding = 0;
5592 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5593 dsl_binding.descriptorCount = 1;
5594 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5595 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005596
Tony Barboureb254902015-07-15 12:50:33 -06005597 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005598 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5599 ds_layout_ci.pNext = NULL;
5600 ds_layout_ci.bindingCount = 1;
5601 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005602 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005603 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005604 ASSERT_VK_SUCCESS(err);
5605
5606 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005607 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005608 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005609 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005610 alloc_info.descriptorPool = ds_pool;
5611 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005612 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005613 ASSERT_VK_SUCCESS(err);
5614
Tony Barboureb254902015-07-15 12:50:33 -06005615 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005616 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5617 pipeline_layout_ci.pNext = NULL;
5618 pipeline_layout_ci.setLayoutCount = 1;
5619 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005620
5621 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005622 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005623 ASSERT_VK_SUCCESS(err);
5624
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005625 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005626 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005627 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005628 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005629
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005630 VkPipelineObj pipe(m_device);
5631 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005632 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005633 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005634 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005635
5636 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005637 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5638 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5639 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005640
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005641 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005642
Chia-I Wuf7458c52015-10-26 21:10:41 +08005643 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5644 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5645 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005646}
5647
Karl Schultz6addd812016-02-02 17:17:23 -07005648TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005649 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005650 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005651
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5653 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005654
5655 ASSERT_NO_FATAL_FAILURE(InitState());
5656 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005657 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5658 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005659
5660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5662 ds_pool_ci.pNext = NULL;
5663 ds_pool_ci.maxSets = 1;
5664 ds_pool_ci.poolSizeCount = 1;
5665 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005666
5667 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005668 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005669 ASSERT_VK_SUCCESS(err);
5670
5671 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005672 dsl_binding.binding = 0;
5673 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5674 dsl_binding.descriptorCount = 1;
5675 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5676 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005677
5678 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005679 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5680 ds_layout_ci.pNext = NULL;
5681 ds_layout_ci.bindingCount = 1;
5682 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005683 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005684 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005685 ASSERT_VK_SUCCESS(err);
5686
5687 VkDescriptorSet descriptorSet;
5688 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005689 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005690 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005691 alloc_info.descriptorPool = ds_pool;
5692 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005693 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005694 ASSERT_VK_SUCCESS(err);
5695
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005696 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005697 VkWriteDescriptorSet descriptor_write;
5698 memset(&descriptor_write, 0, sizeof(descriptor_write));
5699 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5700 descriptor_write.dstSet = descriptorSet;
5701 descriptor_write.dstBinding = 0;
5702 descriptor_write.descriptorCount = 1;
5703 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5704 descriptor_write.pTexelBufferView = &view;
5705
5706 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005708 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005709
5710 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5711 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5712}
5713
Mark Youngd339ba32016-05-30 13:28:35 -06005714TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005715 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 -06005716
5717 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005719 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005720
5721 ASSERT_NO_FATAL_FAILURE(InitState());
5722
5723 // Create a buffer with no bound memory and then attempt to create
5724 // a buffer view.
5725 VkBufferCreateInfo buff_ci = {};
5726 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005727 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005728 buff_ci.size = 256;
5729 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5730 VkBuffer buffer;
5731 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5732 ASSERT_VK_SUCCESS(err);
5733
5734 VkBufferViewCreateInfo buff_view_ci = {};
5735 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5736 buff_view_ci.buffer = buffer;
5737 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5738 buff_view_ci.range = VK_WHOLE_SIZE;
5739 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005740 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005741
5742 m_errorMonitor->VerifyFound();
5743 vkDestroyBuffer(m_device->device(), buffer, NULL);
5744 // If last error is success, it still created the view, so delete it.
5745 if (err == VK_SUCCESS) {
5746 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5747 }
5748}
5749
Karl Schultz6addd812016-02-02 17:17:23 -07005750TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5751 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5752 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005753 // 1. No dynamicOffset supplied
5754 // 2. Too many dynamicOffsets supplied
5755 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005756 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5758 "0 dynamicOffsets are left in "
5759 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005760
5761 ASSERT_NO_FATAL_FAILURE(InitState());
5762 ASSERT_NO_FATAL_FAILURE(InitViewport());
5763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5764
5765 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005766 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5767 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005768
5769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5771 ds_pool_ci.pNext = NULL;
5772 ds_pool_ci.maxSets = 1;
5773 ds_pool_ci.poolSizeCount = 1;
5774 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005775
5776 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005777 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005778 ASSERT_VK_SUCCESS(err);
5779
5780 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005781 dsl_binding.binding = 0;
5782 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5783 dsl_binding.descriptorCount = 1;
5784 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5785 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005786
5787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5789 ds_layout_ci.pNext = NULL;
5790 ds_layout_ci.bindingCount = 1;
5791 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005792 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005794 ASSERT_VK_SUCCESS(err);
5795
5796 VkDescriptorSet descriptorSet;
5797 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005799 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005800 alloc_info.descriptorPool = ds_pool;
5801 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005802 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005803 ASSERT_VK_SUCCESS(err);
5804
5805 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005806 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5807 pipeline_layout_ci.pNext = NULL;
5808 pipeline_layout_ci.setLayoutCount = 1;
5809 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005810
5811 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005812 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005813 ASSERT_VK_SUCCESS(err);
5814
5815 // Create a buffer to update the descriptor with
5816 uint32_t qfi = 0;
5817 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005818 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5819 buffCI.size = 1024;
5820 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5821 buffCI.queueFamilyIndexCount = 1;
5822 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005823
5824 VkBuffer dyub;
5825 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5826 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005827 // Allocate memory and bind to buffer so we can make it to the appropriate
5828 // error
5829 VkMemoryAllocateInfo mem_alloc = {};
5830 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5831 mem_alloc.pNext = NULL;
5832 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005833 mem_alloc.memoryTypeIndex = 0;
5834
5835 VkMemoryRequirements memReqs;
5836 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005837 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005838 if (!pass) {
5839 vkDestroyBuffer(m_device->device(), dyub, NULL);
5840 return;
5841 }
5842
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005843 VkDeviceMemory mem;
5844 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5845 ASSERT_VK_SUCCESS(err);
5846 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5847 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005848 // Correctly update descriptor to avoid "NOT_UPDATED" error
5849 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005850 buffInfo.buffer = dyub;
5851 buffInfo.offset = 0;
5852 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005853
5854 VkWriteDescriptorSet descriptor_write;
5855 memset(&descriptor_write, 0, sizeof(descriptor_write));
5856 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5857 descriptor_write.dstSet = descriptorSet;
5858 descriptor_write.dstBinding = 0;
5859 descriptor_write.descriptorCount = 1;
5860 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5861 descriptor_write.pBufferInfo = &buffInfo;
5862
5863 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5864
5865 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5867 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005868 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005869 uint32_t pDynOff[2] = {512, 756};
5870 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5872 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5873 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5874 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005875 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005876 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5878 "offset 0 and range 1024 that "
5879 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005880 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005881 char const *vsSource = "#version 450\n"
5882 "\n"
5883 "out gl_PerVertex { \n"
5884 " vec4 gl_Position;\n"
5885 "};\n"
5886 "void main(){\n"
5887 " gl_Position = vec4(1);\n"
5888 "}\n";
5889 char const *fsSource = "#version 450\n"
5890 "\n"
5891 "layout(location=0) out vec4 x;\n"
5892 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5893 "void main(){\n"
5894 " x = vec4(bar.y);\n"
5895 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005896 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5897 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5898 VkPipelineObj pipe(m_device);
5899 pipe.AddShader(&vs);
5900 pipe.AddShader(&fs);
5901 pipe.AddColorAttachment();
5902 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5903
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005904 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005905 // This update should succeed, but offset size of 512 will overstep buffer
5906 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005907 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5908 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005909 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005910 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005911
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005912 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005913 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005914
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005915 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005916 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005917 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5918}
5919
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005920TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5921 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5922 "that doesn't have memory bound");
5923 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005925 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5927 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005928
5929 ASSERT_NO_FATAL_FAILURE(InitState());
5930 ASSERT_NO_FATAL_FAILURE(InitViewport());
5931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5932
5933 VkDescriptorPoolSize ds_type_count = {};
5934 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5935 ds_type_count.descriptorCount = 1;
5936
5937 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5938 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5939 ds_pool_ci.pNext = NULL;
5940 ds_pool_ci.maxSets = 1;
5941 ds_pool_ci.poolSizeCount = 1;
5942 ds_pool_ci.pPoolSizes = &ds_type_count;
5943
5944 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005945 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005946 ASSERT_VK_SUCCESS(err);
5947
5948 VkDescriptorSetLayoutBinding dsl_binding = {};
5949 dsl_binding.binding = 0;
5950 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5951 dsl_binding.descriptorCount = 1;
5952 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5953 dsl_binding.pImmutableSamplers = NULL;
5954
5955 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5956 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5957 ds_layout_ci.pNext = NULL;
5958 ds_layout_ci.bindingCount = 1;
5959 ds_layout_ci.pBindings = &dsl_binding;
5960 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005961 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005962 ASSERT_VK_SUCCESS(err);
5963
5964 VkDescriptorSet descriptorSet;
5965 VkDescriptorSetAllocateInfo alloc_info = {};
5966 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5967 alloc_info.descriptorSetCount = 1;
5968 alloc_info.descriptorPool = ds_pool;
5969 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005970 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005971 ASSERT_VK_SUCCESS(err);
5972
5973 // Create a buffer to update the descriptor with
5974 uint32_t qfi = 0;
5975 VkBufferCreateInfo buffCI = {};
5976 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5977 buffCI.size = 1024;
5978 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5979 buffCI.queueFamilyIndexCount = 1;
5980 buffCI.pQueueFamilyIndices = &qfi;
5981
5982 VkBuffer dyub;
5983 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5984 ASSERT_VK_SUCCESS(err);
5985
5986 // Attempt to update descriptor without binding memory to it
5987 VkDescriptorBufferInfo buffInfo = {};
5988 buffInfo.buffer = dyub;
5989 buffInfo.offset = 0;
5990 buffInfo.range = 1024;
5991
5992 VkWriteDescriptorSet descriptor_write;
5993 memset(&descriptor_write, 0, sizeof(descriptor_write));
5994 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5995 descriptor_write.dstSet = descriptorSet;
5996 descriptor_write.dstBinding = 0;
5997 descriptor_write.descriptorCount = 1;
5998 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5999 descriptor_write.pBufferInfo = &buffInfo;
6000
6001 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6002 m_errorMonitor->VerifyFound();
6003
6004 vkDestroyBuffer(m_device->device(), dyub, NULL);
6005 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6006 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6007}
6008
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006009TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006010 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006011 ASSERT_NO_FATAL_FAILURE(InitState());
6012 ASSERT_NO_FATAL_FAILURE(InitViewport());
6013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6014
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006015 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006016 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006017 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6018 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6019 pipeline_layout_ci.pushConstantRangeCount = 1;
6020 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6021
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006022 //
6023 // Check for invalid push constant ranges in pipeline layouts.
6024 //
6025 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006026 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006027 char const *msg;
6028 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006029
Karl Schultzc81037d2016-05-12 08:11:23 -06006030 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6031 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6032 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6033 "vkCreatePipelineLayout() call has push constants index 0 with "
6034 "size 0."},
6035 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6036 "vkCreatePipelineLayout() call has push constants index 0 with "
6037 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006038 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006039 "vkCreatePipelineLayout() call has push constants index 0 with "
6040 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006041 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006042 "vkCreatePipelineLayout() call has push constants index 0 with "
6043 "size 0."},
6044 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6045 "vkCreatePipelineLayout() call has push constants index 0 with "
6046 "offset 1. Offset must"},
6047 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6048 "vkCreatePipelineLayout() call has push constants index 0 "
6049 "with offset "},
6050 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6051 "vkCreatePipelineLayout() call has push constants "
6052 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006053 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006054 "vkCreatePipelineLayout() call has push constants index 0 "
6055 "with offset "},
6056 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6057 "vkCreatePipelineLayout() call has push "
6058 "constants index 0 with offset "},
6059 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6060 "vkCreatePipelineLayout() call has push "
6061 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006062 }};
6063
6064 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006065 for (const auto &iter : range_tests) {
6066 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6068 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006069 m_errorMonitor->VerifyFound();
6070 if (VK_SUCCESS == err) {
6071 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6072 }
6073 }
6074
6075 // Check for invalid stage flag
6076 pc_range.offset = 0;
6077 pc_range.size = 16;
6078 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006079 m_errorMonitor->SetDesiredFailureMsg(
6080 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6081 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006082 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006083 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006084 if (VK_SUCCESS == err) {
6085 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6086 }
6087
6088 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006089 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006090 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006091 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006092 char const *msg;
6093 };
6094
Karl Schultzc81037d2016-05-12 08:11:23 -06006095 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006096 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6097 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6098 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6099 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6100 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006101 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006102 {
6103 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6104 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6105 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6106 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6107 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006108 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006109 },
6110 {
6111 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6112 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6113 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6114 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6115 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006116 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006117 },
6118 {
6119 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6120 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6121 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6122 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6123 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006124 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006125 },
6126 {
6127 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6128 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6129 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6130 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6131 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006132 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006133 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006134
Karl Schultzc81037d2016-05-12 08:11:23 -06006135 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006136 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006137 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6139 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006140 m_errorMonitor->VerifyFound();
6141 if (VK_SUCCESS == err) {
6142 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6143 }
6144 }
6145
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006146 //
6147 // CmdPushConstants tests
6148 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006149 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006150
6151 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006152 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6153 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006154 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6155 "vkCmdPushConstants() call has push constants with size 1. Size "
6156 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006157 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006158 "vkCmdPushConstants() call has push constants with size 1. Size "
6159 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006160 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006161 "vkCmdPushConstants() call has push constants with offset 1. "
6162 "Offset must be a multiple of 4."},
6163 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6164 "vkCmdPushConstants() call has push constants with offset 1. "
6165 "Offset must be a multiple of 4."},
6166 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6167 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6168 "0x1 not within flag-matching ranges in pipeline layout"},
6169 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6170 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6171 "0x1 not within flag-matching ranges in pipeline layout"},
6172 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6173 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6174 "0x1 not within flag-matching ranges in pipeline layout"},
6175 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6176 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6177 "0x1 not within flag-matching ranges in pipeline layout"},
6178 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6179 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6180 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006181 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006182 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6183 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006184 }};
6185
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006186 BeginCommandBuffer();
6187
6188 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006189 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006190 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006191 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006192 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006193 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006194 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006195 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006196 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6198 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006199 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006200 m_errorMonitor->VerifyFound();
6201 }
6202
6203 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006205 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006206 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006207 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006208
Karl Schultzc81037d2016-05-12 08:11:23 -06006209 // overlapping range tests with cmd
6210 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6211 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6212 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6213 "0x1 not within flag-matching ranges in pipeline layout"},
6214 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6215 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6216 "0x1 not within flag-matching ranges in pipeline layout"},
6217 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6218 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6219 "0x1 not within flag-matching ranges in pipeline layout"},
6220 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006221 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006222 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006223 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6224 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006225 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006226 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006227 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006229 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006230 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6232 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006233 iter.range.size, dummy_values);
6234 m_errorMonitor->VerifyFound();
6235 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006236 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6237
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006238 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006239}
6240
Karl Schultz6addd812016-02-02 17:17:23 -07006241TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006242 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006243 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006244
6245 ASSERT_NO_FATAL_FAILURE(InitState());
6246 ASSERT_NO_FATAL_FAILURE(InitViewport());
6247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6248
Mike Stroyanb8a61002016-06-20 16:00:28 -06006249 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6250 VkImageTiling tiling;
6251 VkFormatProperties format_properties;
6252 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006253 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006254 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006255 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006256 tiling = VK_IMAGE_TILING_OPTIMAL;
6257 } else {
6258 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6259 "skipped.\n");
6260 return;
6261 }
6262
Tobin Ehlis559c6382015-11-05 09:52:49 -07006263 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6264 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006265 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6266 ds_type_count[0].descriptorCount = 10;
6267 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6268 ds_type_count[1].descriptorCount = 2;
6269 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6270 ds_type_count[2].descriptorCount = 2;
6271 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6272 ds_type_count[3].descriptorCount = 5;
6273 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6274 // type
6275 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6276 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6277 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006278
6279 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006280 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6281 ds_pool_ci.pNext = NULL;
6282 ds_pool_ci.maxSets = 5;
6283 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6284 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006285
6286 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006287 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006288 ASSERT_VK_SUCCESS(err);
6289
6290 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6291 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006292 dsl_binding[0].binding = 0;
6293 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6294 dsl_binding[0].descriptorCount = 5;
6295 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6296 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006297
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006298 // Create layout identical to set0 layout but w/ different stageFlags
6299 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006300 dsl_fs_stage_only.binding = 0;
6301 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6302 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006303 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6304 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006305 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006306 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006307 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6308 ds_layout_ci.pNext = NULL;
6309 ds_layout_ci.bindingCount = 1;
6310 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006311 static const uint32_t NUM_LAYOUTS = 4;
6312 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006313 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006314 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6315 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006316 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006317 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006318 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006319 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006320 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006321 dsl_binding[0].binding = 0;
6322 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006323 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006324 dsl_binding[1].binding = 1;
6325 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6326 dsl_binding[1].descriptorCount = 2;
6327 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6328 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006329 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006330 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006331 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006332 ASSERT_VK_SUCCESS(err);
6333 dsl_binding[0].binding = 0;
6334 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006335 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006336 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006337 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006338 ASSERT_VK_SUCCESS(err);
6339 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006340 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006341 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006342 ASSERT_VK_SUCCESS(err);
6343
6344 static const uint32_t NUM_SETS = 4;
6345 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6346 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006347 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006348 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006349 alloc_info.descriptorPool = ds_pool;
6350 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006351 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006352 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006353 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006354 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006355 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006356 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006357 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006358
6359 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006360 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6361 pipeline_layout_ci.pNext = NULL;
6362 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6363 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006364
6365 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006366 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006367 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006368 // Create pipelineLayout with only one setLayout
6369 pipeline_layout_ci.setLayoutCount = 1;
6370 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006371 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006372 ASSERT_VK_SUCCESS(err);
6373 // Create pipelineLayout with 2 descriptor setLayout at index 0
6374 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6375 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006376 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006377 ASSERT_VK_SUCCESS(err);
6378 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6379 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6380 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006381 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006382 ASSERT_VK_SUCCESS(err);
6383 // Create pipelineLayout with UB type, but stageFlags for FS only
6384 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6385 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006387 ASSERT_VK_SUCCESS(err);
6388 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6389 VkDescriptorSetLayout pl_bad_s0[2] = {};
6390 pl_bad_s0[0] = ds_layout_fs_only;
6391 pl_bad_s0[1] = ds_layout[1];
6392 pipeline_layout_ci.setLayoutCount = 2;
6393 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6394 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006396 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006397
6398 // Create a buffer to update the descriptor with
6399 uint32_t qfi = 0;
6400 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006401 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6402 buffCI.size = 1024;
6403 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6404 buffCI.queueFamilyIndexCount = 1;
6405 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006406
6407 VkBuffer dyub;
6408 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6409 ASSERT_VK_SUCCESS(err);
6410 // Correctly update descriptor to avoid "NOT_UPDATED" error
6411 static const uint32_t NUM_BUFFS = 5;
6412 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006413 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006414 buffInfo[i].buffer = dyub;
6415 buffInfo[i].offset = 0;
6416 buffInfo[i].range = 1024;
6417 }
Karl Schultz6addd812016-02-02 17:17:23 -07006418 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006419 const int32_t tex_width = 32;
6420 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006421 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006422 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6423 image_create_info.pNext = NULL;
6424 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6425 image_create_info.format = tex_format;
6426 image_create_info.extent.width = tex_width;
6427 image_create_info.extent.height = tex_height;
6428 image_create_info.extent.depth = 1;
6429 image_create_info.mipLevels = 1;
6430 image_create_info.arrayLayers = 1;
6431 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006432 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006434 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006435 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6436 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006437
Karl Schultz6addd812016-02-02 17:17:23 -07006438 VkMemoryRequirements memReqs;
6439 VkDeviceMemory imageMem;
6440 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006441 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006442 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6443 memAlloc.pNext = NULL;
6444 memAlloc.allocationSize = 0;
6445 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006446 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6447 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006448 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006449 ASSERT_TRUE(pass);
6450 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6451 ASSERT_VK_SUCCESS(err);
6452 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6453 ASSERT_VK_SUCCESS(err);
6454
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006455 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006456 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6457 image_view_create_info.image = image;
6458 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6459 image_view_create_info.format = tex_format;
6460 image_view_create_info.subresourceRange.layerCount = 1;
6461 image_view_create_info.subresourceRange.baseMipLevel = 0;
6462 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006463 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006464
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006465 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006466 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006467 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006468 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006469 imageInfo[0].imageView = view;
6470 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6471 imageInfo[1].imageView = view;
6472 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006473 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006474 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006475 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006476 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006477
6478 static const uint32_t NUM_SET_UPDATES = 3;
6479 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6480 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6481 descriptor_write[0].dstSet = descriptorSet[0];
6482 descriptor_write[0].dstBinding = 0;
6483 descriptor_write[0].descriptorCount = 5;
6484 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6485 descriptor_write[0].pBufferInfo = buffInfo;
6486 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6487 descriptor_write[1].dstSet = descriptorSet[1];
6488 descriptor_write[1].dstBinding = 0;
6489 descriptor_write[1].descriptorCount = 2;
6490 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6491 descriptor_write[1].pImageInfo = imageInfo;
6492 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6493 descriptor_write[2].dstSet = descriptorSet[1];
6494 descriptor_write[2].dstBinding = 1;
6495 descriptor_write[2].descriptorCount = 2;
6496 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006497 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006498
6499 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006500
Tobin Ehlis88452832015-12-03 09:40:56 -07006501 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006502 char const *vsSource = "#version 450\n"
6503 "\n"
6504 "out gl_PerVertex {\n"
6505 " vec4 gl_Position;\n"
6506 "};\n"
6507 "void main(){\n"
6508 " gl_Position = vec4(1);\n"
6509 "}\n";
6510 char const *fsSource = "#version 450\n"
6511 "\n"
6512 "layout(location=0) out vec4 x;\n"
6513 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6514 "void main(){\n"
6515 " x = vec4(bar.y);\n"
6516 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006517 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6518 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006519 VkPipelineObj pipe(m_device);
6520 pipe.AddShader(&vs);
6521 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006522 pipe.AddColorAttachment();
6523 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006524
6525 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006526
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006528 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6529 // of PSO
6530 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6531 // cmd_pipeline.c
6532 // due to the fact that cmd_alloc_dset_data() has not been called in
6533 // cmd_bind_graphics_pipeline()
6534 // TODO : Want to cause various binding incompatibility issues here to test
6535 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006536 // First cause various verify_layout_compatibility() fails
6537 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006538 // verify_set_layout_compatibility fail cases:
6539 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6541 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6542 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006543 m_errorMonitor->VerifyFound();
6544
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006545 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6547 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6548 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006549 m_errorMonitor->VerifyFound();
6550
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006551 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006552 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6553 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6555 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6556 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006557 m_errorMonitor->VerifyFound();
6558
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006559 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6560 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6562 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6563 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006564 m_errorMonitor->VerifyFound();
6565
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006566 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6567 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6569 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6570 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6571 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006572 m_errorMonitor->VerifyFound();
6573
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006574 // Cause INFO messages due to disturbing previously bound Sets
6575 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006576 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6577 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006578 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6580 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6581 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006582 m_errorMonitor->VerifyFound();
6583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006584 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6585 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006586 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6588 "any subsequent sets were disturbed ");
6589 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6590 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006591 m_errorMonitor->VerifyFound();
6592
Tobin Ehlis10fad692016-07-07 12:00:36 -06006593 // Now that we're done actively using the pipelineLayout that gfx pipeline
6594 // was created with, we should be able to delete it. Do that now to verify
6595 // that validation obeys pipelineLayout lifetime
6596 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6597
Tobin Ehlis88452832015-12-03 09:40:56 -07006598 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006599 // 1. Error due to not binding required set (we actually use same code as
6600 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006601 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6602 &descriptorSet[0], 0, NULL);
6603 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6604 &descriptorSet[1], 0, NULL);
6605 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 -07006606 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006607 m_errorMonitor->VerifyFound();
6608
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006609 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006610 // 2. Error due to bound set not being compatible with PSO's
6611 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006612 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6613 &descriptorSet[0], 0, NULL);
6614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006615 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006616 m_errorMonitor->VerifyFound();
6617
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006618 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006619 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006620 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6621 }
6622 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006623 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006624 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006626 vkFreeMemory(m_device->device(), imageMem, NULL);
6627 vkDestroyImage(m_device->device(), image, NULL);
6628 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006629}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006630
Karl Schultz6addd812016-02-02 17:17:23 -07006631TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006632
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6634 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006635
6636 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006637 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006638 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006639 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006640
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006641 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006642}
6643
Karl Schultz6addd812016-02-02 17:17:23 -07006644TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6645 VkResult err;
6646 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006647
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006649
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006650 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006651
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006652 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006653 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006654 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006655 cmd.commandPool = m_commandPool;
6656 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006657 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006658
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006659 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006660 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006661
6662 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006663 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006664 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006665 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006666 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006667 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 -07006668 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006669
6670 // The error should be caught by validation of the BeginCommandBuffer call
6671 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6672
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006673 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006674 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006675}
6676
Karl Schultz6addd812016-02-02 17:17:23 -07006677TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006678 // Cause error due to Begin while recording CB
6679 // Then cause 2 errors for attempting to reset CB w/o having
6680 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6681 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006683
6684 ASSERT_NO_FATAL_FAILURE(InitState());
6685
6686 // Calls AllocateCommandBuffers
6687 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6688
Karl Schultz6addd812016-02-02 17:17:23 -07006689 // Force the failure by setting the Renderpass and Framebuffer fields with
6690 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006691 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006692 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006693 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6694 cmd_buf_info.pNext = NULL;
6695 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006696 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006697
6698 // Begin CB to transition to recording state
6699 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6700 // Can't re-begin. This should trigger error
6701 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006702 m_errorMonitor->VerifyFound();
6703
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006705 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6706 // Reset attempt will trigger error due to incorrect CommandPool state
6707 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006708 m_errorMonitor->VerifyFound();
6709
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006711 // Transition CB to RECORDED state
6712 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6713 // Now attempting to Begin will implicitly reset, which triggers error
6714 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006715 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006716}
6717
Karl Schultz6addd812016-02-02 17:17:23 -07006718TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006719 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006720 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006721
Mike Weiblencce7ec72016-10-17 19:33:05 -06006722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006723
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006724 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006726
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006727 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006728 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6729 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006730
6731 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006732 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6733 ds_pool_ci.pNext = NULL;
6734 ds_pool_ci.maxSets = 1;
6735 ds_pool_ci.poolSizeCount = 1;
6736 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006737
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006738 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006739 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006740 ASSERT_VK_SUCCESS(err);
6741
Tony Barboureb254902015-07-15 12:50:33 -06006742 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006743 dsl_binding.binding = 0;
6744 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6745 dsl_binding.descriptorCount = 1;
6746 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6747 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006748
Tony Barboureb254902015-07-15 12:50:33 -06006749 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006750 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6751 ds_layout_ci.pNext = NULL;
6752 ds_layout_ci.bindingCount = 1;
6753 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006754
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006755 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006756 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006757 ASSERT_VK_SUCCESS(err);
6758
6759 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006760 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006761 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006762 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006763 alloc_info.descriptorPool = ds_pool;
6764 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006765 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006766 ASSERT_VK_SUCCESS(err);
6767
Tony Barboureb254902015-07-15 12:50:33 -06006768 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006769 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6770 pipeline_layout_ci.setLayoutCount = 1;
6771 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006772
6773 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006774 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006775 ASSERT_VK_SUCCESS(err);
6776
Tobin Ehlise68360f2015-10-01 11:15:13 -06006777 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006778 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006779
6780 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006781 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6782 vp_state_ci.scissorCount = 1;
6783 vp_state_ci.pScissors = &sc;
6784 vp_state_ci.viewportCount = 1;
6785 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006786
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006787 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6788 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6789 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6790 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6791 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6792 rs_state_ci.depthClampEnable = VK_FALSE;
6793 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6794 rs_state_ci.depthBiasEnable = VK_FALSE;
6795
Tony Barboureb254902015-07-15 12:50:33 -06006796 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006797 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6798 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006799 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006800 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6801 gp_ci.layout = pipeline_layout;
6802 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006803
6804 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006805 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6806 pc_ci.initialDataSize = 0;
6807 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006808
6809 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006810 VkPipelineCache pipelineCache;
6811
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006812 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006813 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006814 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006815
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006816 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006817
Chia-I Wuf7458c52015-10-26 21:10:41 +08006818 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6819 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6820 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6821 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006822}
Tobin Ehlis912df022015-09-17 08:46:18 -06006823/*// TODO : This test should be good, but needs Tess support in compiler to run
6824TEST_F(VkLayerTest, InvalidPatchControlPoints)
6825{
6826 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006827 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006828
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006830 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6831primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006832
Tobin Ehlis912df022015-09-17 08:46:18 -06006833 ASSERT_NO_FATAL_FAILURE(InitState());
6834 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006835
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006836 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006837 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006838 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006839
6840 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6841 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6842 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006843 ds_pool_ci.poolSizeCount = 1;
6844 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006845
6846 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006847 err = vkCreateDescriptorPool(m_device->device(),
6848VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006849 ASSERT_VK_SUCCESS(err);
6850
6851 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006852 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006853 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006854 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006855 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6856 dsl_binding.pImmutableSamplers = NULL;
6857
6858 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006859 ds_layout_ci.sType =
6860VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006861 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006862 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006863 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006864
6865 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6867&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006868 ASSERT_VK_SUCCESS(err);
6869
6870 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006871 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6872VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006873 ASSERT_VK_SUCCESS(err);
6874
6875 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006876 pipeline_layout_ci.sType =
6877VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006878 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006879 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006880 pipeline_layout_ci.pSetLayouts = &ds_layout;
6881
6882 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006883 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6884&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006885 ASSERT_VK_SUCCESS(err);
6886
6887 VkPipelineShaderStageCreateInfo shaderStages[3];
6888 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6889
Karl Schultz6addd812016-02-02 17:17:23 -07006890 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6891this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006892 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006893 VkShaderObj
6894tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6895this);
6896 VkShaderObj
6897te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6898this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006899
Karl Schultz6addd812016-02-02 17:17:23 -07006900 shaderStages[0].sType =
6901VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006902 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006903 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006904 shaderStages[1].sType =
6905VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006906 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006907 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006908 shaderStages[2].sType =
6909VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006910 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006911 shaderStages[2].shader = te.handle();
6912
6913 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006914 iaCI.sType =
6915VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006916 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006917
6918 VkPipelineTessellationStateCreateInfo tsCI = {};
6919 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6920 tsCI.patchControlPoints = 0; // This will cause an error
6921
6922 VkGraphicsPipelineCreateInfo gp_ci = {};
6923 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6924 gp_ci.pNext = NULL;
6925 gp_ci.stageCount = 3;
6926 gp_ci.pStages = shaderStages;
6927 gp_ci.pVertexInputState = NULL;
6928 gp_ci.pInputAssemblyState = &iaCI;
6929 gp_ci.pTessellationState = &tsCI;
6930 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006931 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006932 gp_ci.pMultisampleState = NULL;
6933 gp_ci.pDepthStencilState = NULL;
6934 gp_ci.pColorBlendState = NULL;
6935 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6936 gp_ci.layout = pipeline_layout;
6937 gp_ci.renderPass = renderPass();
6938
6939 VkPipelineCacheCreateInfo pc_ci = {};
6940 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6941 pc_ci.pNext = NULL;
6942 pc_ci.initialSize = 0;
6943 pc_ci.initialData = 0;
6944 pc_ci.maxSize = 0;
6945
6946 VkPipeline pipeline;
6947 VkPipelineCache pipelineCache;
6948
Karl Schultz6addd812016-02-02 17:17:23 -07006949 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6950&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006951 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006952 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6953&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006954
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006955 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006956
Chia-I Wuf7458c52015-10-26 21:10:41 +08006957 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6958 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6959 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6960 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006961}
6962*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006963// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006964TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006965 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006966
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6968 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006969
Tobin Ehlise68360f2015-10-01 11:15:13 -06006970 ASSERT_NO_FATAL_FAILURE(InitState());
6971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006972
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006973 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006974 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6975 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006976
6977 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006978 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6979 ds_pool_ci.maxSets = 1;
6980 ds_pool_ci.poolSizeCount = 1;
6981 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006982
6983 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006984 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006985 ASSERT_VK_SUCCESS(err);
6986
6987 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006988 dsl_binding.binding = 0;
6989 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6990 dsl_binding.descriptorCount = 1;
6991 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006992
6993 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006994 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6995 ds_layout_ci.bindingCount = 1;
6996 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006997
6998 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006999 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007000 ASSERT_VK_SUCCESS(err);
7001
7002 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007003 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007004 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007005 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007006 alloc_info.descriptorPool = ds_pool;
7007 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007008 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007009 ASSERT_VK_SUCCESS(err);
7010
7011 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007012 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7013 pipeline_layout_ci.setLayoutCount = 1;
7014 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007015
7016 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007017 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007018 ASSERT_VK_SUCCESS(err);
7019
7020 VkViewport vp = {}; // Just need dummy vp to point to
7021
7022 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007023 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7024 vp_state_ci.scissorCount = 0;
7025 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7026 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007027
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007028 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7029 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7030 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7031 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7032 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7033 rs_state_ci.depthClampEnable = VK_FALSE;
7034 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7035 rs_state_ci.depthBiasEnable = VK_FALSE;
7036
Cody Northropeb3a6c12015-10-05 14:44:45 -06007037 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007038 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007040 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7041 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7042 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007043 shaderStages[0] = vs.GetStageCreateInfo();
7044 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007045
7046 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007047 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7048 gp_ci.stageCount = 2;
7049 gp_ci.pStages = shaderStages;
7050 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007051 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007052 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7053 gp_ci.layout = pipeline_layout;
7054 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007055
7056 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007057 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007058
7059 VkPipeline pipeline;
7060 VkPipelineCache pipelineCache;
7061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007062 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007063 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007064 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007065
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007066 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007067
Chia-I Wuf7458c52015-10-26 21:10:41 +08007068 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7069 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7070 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7071 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007072}
Karl Schultz6addd812016-02-02 17:17:23 -07007073// Don't set viewport state in PSO. This is an error b/c we always need this
7074// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007075// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007076TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007077 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007078 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007081
Tobin Ehlise68360f2015-10-01 11:15:13 -06007082 ASSERT_NO_FATAL_FAILURE(InitState());
7083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007084
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007085 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007086 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7087 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007088
7089 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007090 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7091 ds_pool_ci.maxSets = 1;
7092 ds_pool_ci.poolSizeCount = 1;
7093 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007094
7095 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007096 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007097 ASSERT_VK_SUCCESS(err);
7098
7099 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007100 dsl_binding.binding = 0;
7101 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7102 dsl_binding.descriptorCount = 1;
7103 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007104
7105 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007106 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7107 ds_layout_ci.bindingCount = 1;
7108 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007109
7110 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007111 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112 ASSERT_VK_SUCCESS(err);
7113
7114 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007115 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007116 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007117 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007118 alloc_info.descriptorPool = ds_pool;
7119 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007120 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007121 ASSERT_VK_SUCCESS(err);
7122
7123 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007124 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7125 pipeline_layout_ci.setLayoutCount = 1;
7126 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007127
7128 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007129 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130 ASSERT_VK_SUCCESS(err);
7131
7132 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7133 // Set scissor as dynamic to avoid second error
7134 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007135 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7136 dyn_state_ci.dynamicStateCount = 1;
7137 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007138
Cody Northropeb3a6c12015-10-05 14:44:45 -06007139 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007140 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007142 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7143 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7144 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007145 shaderStages[0] = vs.GetStageCreateInfo();
7146 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007147
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007148 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7149 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7150 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7151 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7152 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7153 rs_state_ci.depthClampEnable = VK_FALSE;
7154 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7155 rs_state_ci.depthBiasEnable = VK_FALSE;
7156
Tobin Ehlise68360f2015-10-01 11:15:13 -06007157 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007158 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7159 gp_ci.stageCount = 2;
7160 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007161 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007162 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7163 // should cause validation error
7164 gp_ci.pDynamicState = &dyn_state_ci;
7165 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7166 gp_ci.layout = pipeline_layout;
7167 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007168
7169 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007170 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171
7172 VkPipeline pipeline;
7173 VkPipelineCache pipelineCache;
7174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007177 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007179 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007180
Chia-I Wuf7458c52015-10-26 21:10:41 +08007181 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7182 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7183 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7184 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007185}
7186// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007187// Then run second test where dynamic scissor count doesn't match PSO scissor
7188// count
7189TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7190 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007191
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7193 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007194
Tobin Ehlise68360f2015-10-01 11:15:13 -06007195 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007196
7197 if (!m_device->phy().features().multiViewport) {
7198 printf("Device does not support multiple viewports/scissors; skipped.\n");
7199 return;
7200 }
7201
Tobin Ehlise68360f2015-10-01 11:15:13 -06007202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007203
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007204 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007205 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7206 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007207
7208 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007209 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7210 ds_pool_ci.maxSets = 1;
7211 ds_pool_ci.poolSizeCount = 1;
7212 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007213
7214 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007215 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007216 ASSERT_VK_SUCCESS(err);
7217
7218 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007219 dsl_binding.binding = 0;
7220 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7221 dsl_binding.descriptorCount = 1;
7222 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007223
7224 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007225 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7226 ds_layout_ci.bindingCount = 1;
7227 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007228
7229 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007230 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007231 ASSERT_VK_SUCCESS(err);
7232
7233 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007234 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007235 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007236 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007237 alloc_info.descriptorPool = ds_pool;
7238 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007239 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007240 ASSERT_VK_SUCCESS(err);
7241
7242 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007243 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7244 pipeline_layout_ci.setLayoutCount = 1;
7245 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007246
7247 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007249 ASSERT_VK_SUCCESS(err);
7250
7251 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007252 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7253 vp_state_ci.viewportCount = 1;
7254 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7255 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007256 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007257
7258 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7259 // Set scissor as dynamic to avoid that error
7260 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007261 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7262 dyn_state_ci.dynamicStateCount = 1;
7263 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007264
Cody Northropeb3a6c12015-10-05 14:44:45 -06007265 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007266 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007267
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007268 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7269 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7270 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007271 shaderStages[0] = vs.GetStageCreateInfo();
7272 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007273
Cody Northropf6622dc2015-10-06 10:33:21 -06007274 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7275 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7276 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007277 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007278 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007279 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007280 vi_ci.pVertexAttributeDescriptions = nullptr;
7281
7282 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7283 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7284 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7285
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007286 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007287 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007288 rs_ci.pNext = nullptr;
7289
Mark Youngc89c6312016-03-31 16:03:20 -06007290 VkPipelineColorBlendAttachmentState att = {};
7291 att.blendEnable = VK_FALSE;
7292 att.colorWriteMask = 0xf;
7293
Cody Northropf6622dc2015-10-06 10:33:21 -06007294 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7295 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7296 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007297 cb_ci.attachmentCount = 1;
7298 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007299
Tobin Ehlise68360f2015-10-01 11:15:13 -06007300 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007301 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7302 gp_ci.stageCount = 2;
7303 gp_ci.pStages = shaderStages;
7304 gp_ci.pVertexInputState = &vi_ci;
7305 gp_ci.pInputAssemblyState = &ia_ci;
7306 gp_ci.pViewportState = &vp_state_ci;
7307 gp_ci.pRasterizationState = &rs_ci;
7308 gp_ci.pColorBlendState = &cb_ci;
7309 gp_ci.pDynamicState = &dyn_state_ci;
7310 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7311 gp_ci.layout = pipeline_layout;
7312 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007313
7314 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007315 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007316
7317 VkPipeline pipeline;
7318 VkPipelineCache pipelineCache;
7319
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007320 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007321 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007322 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007323
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007324 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007325
Tobin Ehlisd332f282015-10-02 11:00:56 -06007326 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007327 // First need to successfully create the PSO from above by setting
7328 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007329 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 -07007330
7331 VkViewport vp = {}; // Just need dummy vp to point to
7332 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007333 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007334 ASSERT_VK_SUCCESS(err);
7335 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007336 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007337 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007338 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007339 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007340 Draw(1, 0, 0, 0);
7341
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007342 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007343
7344 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7345 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7346 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7347 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007348 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007349}
7350// Create PSO w/o non-zero scissorCount but no scissor data
7351// Then run second test where dynamic viewportCount doesn't match PSO
7352// viewportCount
7353TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7354 VkResult err;
7355
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007356 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 -07007357
7358 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007359
7360 if (!m_device->phy().features().multiViewport) {
7361 printf("Device does not support multiple viewports/scissors; skipped.\n");
7362 return;
7363 }
7364
Karl Schultz6addd812016-02-02 17:17:23 -07007365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7366
7367 VkDescriptorPoolSize ds_type_count = {};
7368 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7369 ds_type_count.descriptorCount = 1;
7370
7371 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7372 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7373 ds_pool_ci.maxSets = 1;
7374 ds_pool_ci.poolSizeCount = 1;
7375 ds_pool_ci.pPoolSizes = &ds_type_count;
7376
7377 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007378 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007379 ASSERT_VK_SUCCESS(err);
7380
7381 VkDescriptorSetLayoutBinding dsl_binding = {};
7382 dsl_binding.binding = 0;
7383 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7384 dsl_binding.descriptorCount = 1;
7385 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7386
7387 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7388 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7389 ds_layout_ci.bindingCount = 1;
7390 ds_layout_ci.pBindings = &dsl_binding;
7391
7392 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007393 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007394 ASSERT_VK_SUCCESS(err);
7395
7396 VkDescriptorSet descriptorSet;
7397 VkDescriptorSetAllocateInfo alloc_info = {};
7398 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7399 alloc_info.descriptorSetCount = 1;
7400 alloc_info.descriptorPool = ds_pool;
7401 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007402 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007403 ASSERT_VK_SUCCESS(err);
7404
7405 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7406 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7407 pipeline_layout_ci.setLayoutCount = 1;
7408 pipeline_layout_ci.pSetLayouts = &ds_layout;
7409
7410 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007411 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007412 ASSERT_VK_SUCCESS(err);
7413
7414 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7415 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7416 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007417 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007418 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007419 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007420
7421 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7422 // Set scissor as dynamic to avoid that error
7423 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7424 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7425 dyn_state_ci.dynamicStateCount = 1;
7426 dyn_state_ci.pDynamicStates = &vp_state;
7427
7428 VkPipelineShaderStageCreateInfo shaderStages[2];
7429 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7430
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007431 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7432 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7433 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007434 shaderStages[0] = vs.GetStageCreateInfo();
7435 shaderStages[1] = fs.GetStageCreateInfo();
7436
7437 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7438 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7439 vi_ci.pNext = nullptr;
7440 vi_ci.vertexBindingDescriptionCount = 0;
7441 vi_ci.pVertexBindingDescriptions = nullptr;
7442 vi_ci.vertexAttributeDescriptionCount = 0;
7443 vi_ci.pVertexAttributeDescriptions = nullptr;
7444
7445 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7446 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7447 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7448
7449 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7450 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7451 rs_ci.pNext = nullptr;
7452
Mark Youngc89c6312016-03-31 16:03:20 -06007453 VkPipelineColorBlendAttachmentState att = {};
7454 att.blendEnable = VK_FALSE;
7455 att.colorWriteMask = 0xf;
7456
Karl Schultz6addd812016-02-02 17:17:23 -07007457 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7458 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7459 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007460 cb_ci.attachmentCount = 1;
7461 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007462
7463 VkGraphicsPipelineCreateInfo gp_ci = {};
7464 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7465 gp_ci.stageCount = 2;
7466 gp_ci.pStages = shaderStages;
7467 gp_ci.pVertexInputState = &vi_ci;
7468 gp_ci.pInputAssemblyState = &ia_ci;
7469 gp_ci.pViewportState = &vp_state_ci;
7470 gp_ci.pRasterizationState = &rs_ci;
7471 gp_ci.pColorBlendState = &cb_ci;
7472 gp_ci.pDynamicState = &dyn_state_ci;
7473 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7474 gp_ci.layout = pipeline_layout;
7475 gp_ci.renderPass = renderPass();
7476
7477 VkPipelineCacheCreateInfo pc_ci = {};
7478 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7479
7480 VkPipeline pipeline;
7481 VkPipelineCache pipelineCache;
7482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007483 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007484 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007485 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007486
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007487 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007488
7489 // Now hit second fail case where we set scissor w/ different count than PSO
7490 // First need to successfully create the PSO from above by setting
7491 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007492 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 -06007493
Tobin Ehlisd332f282015-10-02 11:00:56 -06007494 VkRect2D sc = {}; // Just need dummy vp to point to
7495 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007496 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007497 ASSERT_VK_SUCCESS(err);
7498 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007499 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007500 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007501 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007502 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007503 Draw(1, 0, 0, 0);
7504
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007505 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007506
Chia-I Wuf7458c52015-10-26 21:10:41 +08007507 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7508 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7509 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7510 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007511 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007512}
7513
Mark Young7394fdd2016-03-31 14:56:43 -06007514TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7515 VkResult err;
7516
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007518
7519 ASSERT_NO_FATAL_FAILURE(InitState());
7520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7521
7522 VkDescriptorPoolSize ds_type_count = {};
7523 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7524 ds_type_count.descriptorCount = 1;
7525
7526 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7527 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7528 ds_pool_ci.maxSets = 1;
7529 ds_pool_ci.poolSizeCount = 1;
7530 ds_pool_ci.pPoolSizes = &ds_type_count;
7531
7532 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007533 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007534 ASSERT_VK_SUCCESS(err);
7535
7536 VkDescriptorSetLayoutBinding dsl_binding = {};
7537 dsl_binding.binding = 0;
7538 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7539 dsl_binding.descriptorCount = 1;
7540 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7541
7542 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7543 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7544 ds_layout_ci.bindingCount = 1;
7545 ds_layout_ci.pBindings = &dsl_binding;
7546
7547 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007548 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007549 ASSERT_VK_SUCCESS(err);
7550
7551 VkDescriptorSet descriptorSet;
7552 VkDescriptorSetAllocateInfo alloc_info = {};
7553 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7554 alloc_info.descriptorSetCount = 1;
7555 alloc_info.descriptorPool = ds_pool;
7556 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007557 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007558 ASSERT_VK_SUCCESS(err);
7559
7560 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7561 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7562 pipeline_layout_ci.setLayoutCount = 1;
7563 pipeline_layout_ci.pSetLayouts = &ds_layout;
7564
7565 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007566 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007567 ASSERT_VK_SUCCESS(err);
7568
7569 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7570 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7571 vp_state_ci.scissorCount = 1;
7572 vp_state_ci.pScissors = NULL;
7573 vp_state_ci.viewportCount = 1;
7574 vp_state_ci.pViewports = NULL;
7575
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007576 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007577 // Set scissor as dynamic to avoid that error
7578 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7579 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7580 dyn_state_ci.dynamicStateCount = 2;
7581 dyn_state_ci.pDynamicStates = dynamic_states;
7582
7583 VkPipelineShaderStageCreateInfo shaderStages[2];
7584 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007586 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7587 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007588 this); // TODO - We shouldn't need a fragment shader
7589 // but add it to be able to run on more devices
7590 shaderStages[0] = vs.GetStageCreateInfo();
7591 shaderStages[1] = fs.GetStageCreateInfo();
7592
7593 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7594 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7595 vi_ci.pNext = nullptr;
7596 vi_ci.vertexBindingDescriptionCount = 0;
7597 vi_ci.pVertexBindingDescriptions = nullptr;
7598 vi_ci.vertexAttributeDescriptionCount = 0;
7599 vi_ci.pVertexAttributeDescriptions = nullptr;
7600
7601 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7602 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7603 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7604
7605 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7606 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7607 rs_ci.pNext = nullptr;
7608
Mark Young47107952016-05-02 15:59:55 -06007609 // Check too low (line width of -1.0f).
7610 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007611
7612 VkPipelineColorBlendAttachmentState att = {};
7613 att.blendEnable = VK_FALSE;
7614 att.colorWriteMask = 0xf;
7615
7616 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7617 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7618 cb_ci.pNext = nullptr;
7619 cb_ci.attachmentCount = 1;
7620 cb_ci.pAttachments = &att;
7621
7622 VkGraphicsPipelineCreateInfo gp_ci = {};
7623 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7624 gp_ci.stageCount = 2;
7625 gp_ci.pStages = shaderStages;
7626 gp_ci.pVertexInputState = &vi_ci;
7627 gp_ci.pInputAssemblyState = &ia_ci;
7628 gp_ci.pViewportState = &vp_state_ci;
7629 gp_ci.pRasterizationState = &rs_ci;
7630 gp_ci.pColorBlendState = &cb_ci;
7631 gp_ci.pDynamicState = &dyn_state_ci;
7632 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7633 gp_ci.layout = pipeline_layout;
7634 gp_ci.renderPass = renderPass();
7635
7636 VkPipelineCacheCreateInfo pc_ci = {};
7637 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7638
7639 VkPipeline pipeline;
7640 VkPipelineCache pipelineCache;
7641
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007642 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007643 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007644 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007645
7646 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007647 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007648
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007650
7651 // Check too high (line width of 65536.0f).
7652 rs_ci.lineWidth = 65536.0f;
7653
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007654 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007655 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007656 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007657
7658 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007659 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007660
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007662
7663 dyn_state_ci.dynamicStateCount = 3;
7664
7665 rs_ci.lineWidth = 1.0f;
7666
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007667 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007668 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007669 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007670 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007671 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007672
7673 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007674 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007675 m_errorMonitor->VerifyFound();
7676
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007678
7679 // Check too high with dynamic setting.
7680 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7681 m_errorMonitor->VerifyFound();
7682 EndCommandBuffer();
7683
7684 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7685 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7686 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7687 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007688 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007689}
7690
Karl Schultz6addd812016-02-02 17:17:23 -07007691TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007692 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7694 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007695
7696 ASSERT_NO_FATAL_FAILURE(InitState());
7697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007698
Tony Barbourfe3351b2015-07-28 10:17:20 -06007699 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007700 // Don't care about RenderPass handle b/c error should be flagged before
7701 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007702 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007703
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007704 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007705}
7706
Karl Schultz6addd812016-02-02 17:17:23 -07007707TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007708 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7710 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007711
7712 ASSERT_NO_FATAL_FAILURE(InitState());
7713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007714
Tony Barbourfe3351b2015-07-28 10:17:20 -06007715 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007716 // Just create a dummy Renderpass that's non-NULL so we can get to the
7717 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007718 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007719
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007720 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007721}
7722
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007723TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7724 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7725 "the number of renderPass attachments that use loadOp"
7726 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7727
7728 ASSERT_NO_FATAL_FAILURE(InitState());
7729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7730
7731 // Create a renderPass with a single attachment that uses loadOp CLEAR
7732 VkAttachmentReference attach = {};
7733 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7734 VkSubpassDescription subpass = {};
7735 subpass.inputAttachmentCount = 1;
7736 subpass.pInputAttachments = &attach;
7737 VkRenderPassCreateInfo rpci = {};
7738 rpci.subpassCount = 1;
7739 rpci.pSubpasses = &subpass;
7740 rpci.attachmentCount = 1;
7741 VkAttachmentDescription attach_desc = {};
7742 attach_desc.format = VK_FORMAT_UNDEFINED;
7743 // Set loadOp to CLEAR
7744 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7745 rpci.pAttachments = &attach_desc;
7746 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7747 VkRenderPass rp;
7748 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7749
7750 VkCommandBufferInheritanceInfo hinfo = {};
7751 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7752 hinfo.renderPass = VK_NULL_HANDLE;
7753 hinfo.subpass = 0;
7754 hinfo.framebuffer = VK_NULL_HANDLE;
7755 hinfo.occlusionQueryEnable = VK_FALSE;
7756 hinfo.queryFlags = 0;
7757 hinfo.pipelineStatistics = 0;
7758 VkCommandBufferBeginInfo info = {};
7759 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7760 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7761 info.pInheritanceInfo = &hinfo;
7762
7763 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7764 VkRenderPassBeginInfo rp_begin = {};
7765 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7766 rp_begin.pNext = NULL;
7767 rp_begin.renderPass = renderPass();
7768 rp_begin.framebuffer = framebuffer();
7769 rp_begin.clearValueCount = 0; // Should be 1
7770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7772 "there must be at least 1 entries in "
7773 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007774
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007775 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007776
7777 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007778
7779 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007780}
7781
Cody Northrop3bb4d962016-05-09 16:15:57 -06007782TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7783
7784 TEST_DESCRIPTION("End a command buffer with an active render pass");
7785
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7787 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007788
7789 ASSERT_NO_FATAL_FAILURE(InitState());
7790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7791
7792 // The framework's BeginCommandBuffer calls CreateRenderPass
7793 BeginCommandBuffer();
7794
7795 // Call directly into vkEndCommandBuffer instead of the
7796 // the framework's EndCommandBuffer, which inserts a
7797 // vkEndRenderPass
7798 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7799
7800 m_errorMonitor->VerifyFound();
7801
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007802 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7803 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007804}
7805
Karl Schultz6addd812016-02-02 17:17:23 -07007806TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007807 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7809 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007810
7811 ASSERT_NO_FATAL_FAILURE(InitState());
7812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007813
7814 // Renderpass is started here
7815 BeginCommandBuffer();
7816
7817 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007818 vk_testing::Buffer dstBuffer;
7819 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007820
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007821 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
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, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007827 // Call CmdUpdateBuffer 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 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007838 vk_testing::Buffer dstBuffer;
7839 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007840
Karl Schultz6addd812016-02-02 17:17:23 -07007841 VkDeviceSize dstOffset = 0;
7842 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007843 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007844
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007845 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007846
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007847 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007848}
7849
Karl Schultz6addd812016-02-02 17:17:23 -07007850TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007851 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7853 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007854
7855 ASSERT_NO_FATAL_FAILURE(InitState());
7856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007857
7858 // Renderpass is started here
7859 BeginCommandBuffer();
7860
Michael Lentine0a369f62016-02-03 16:51:46 -06007861 VkClearColorValue clear_color;
7862 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007863 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7864 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7865 const int32_t tex_width = 32;
7866 const int32_t tex_height = 32;
7867 VkImageCreateInfo image_create_info = {};
7868 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7869 image_create_info.pNext = NULL;
7870 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7871 image_create_info.format = tex_format;
7872 image_create_info.extent.width = tex_width;
7873 image_create_info.extent.height = tex_height;
7874 image_create_info.extent.depth = 1;
7875 image_create_info.mipLevels = 1;
7876 image_create_info.arrayLayers = 1;
7877 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7878 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7879 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007880
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007881 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007882 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007883
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007884 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007885
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007886 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007887
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007888 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007889}
7890
Karl Schultz6addd812016-02-02 17:17:23 -07007891TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007892 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7894 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007895
7896 ASSERT_NO_FATAL_FAILURE(InitState());
7897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007898
7899 // Renderpass is started here
7900 BeginCommandBuffer();
7901
7902 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007903 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007904 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7905 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7906 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7907 image_create_info.extent.width = 64;
7908 image_create_info.extent.height = 64;
7909 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7910 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007911
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007912 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007913 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007915 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007916
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007917 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7918 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007919
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007920 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007921}
7922
Karl Schultz6addd812016-02-02 17:17:23 -07007923TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007924 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007925 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7928 "must be issued inside an active "
7929 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007930
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007931 ASSERT_NO_FATAL_FAILURE(InitState());
7932 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007933
7934 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007935 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007936 ASSERT_VK_SUCCESS(err);
7937
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007938 VkClearAttachment color_attachment;
7939 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7940 color_attachment.clearValue.color.float32[0] = 0;
7941 color_attachment.clearValue.color.float32[1] = 0;
7942 color_attachment.clearValue.color.float32[2] = 0;
7943 color_attachment.clearValue.color.float32[3] = 0;
7944 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007945 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007946 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007947
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007948 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007949}
7950
Chris Forbes3b97e932016-09-07 11:29:24 +12007951TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
7952 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
7953 "called too many times in a renderpass instance");
7954
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
7956 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12007957
7958 ASSERT_NO_FATAL_FAILURE(InitState());
7959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7960
7961 BeginCommandBuffer();
7962
7963 // error here.
7964 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
7965 m_errorMonitor->VerifyFound();
7966
7967 EndCommandBuffer();
7968}
7969
Chris Forbes6d624702016-09-07 13:57:05 +12007970TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
7971 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
7972 "called before the final subpass has been reached");
7973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
7975 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12007976
7977 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007978 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
7979 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12007980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007981 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12007982
7983 VkRenderPass rp;
7984 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
7985 ASSERT_VK_SUCCESS(err);
7986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007987 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12007988
7989 VkFramebuffer fb;
7990 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
7991 ASSERT_VK_SUCCESS(err);
7992
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007993 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12007994
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007995 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 +12007996
7997 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
7998
7999 // Error here.
8000 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8001 m_errorMonitor->VerifyFound();
8002
8003 // Clean up.
8004 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8005 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8006}
8007
Karl Schultz9e66a292016-04-21 15:57:51 -06008008TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8009 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8011 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008012
8013 ASSERT_NO_FATAL_FAILURE(InitState());
8014 BeginCommandBuffer();
8015
8016 VkBufferMemoryBarrier buf_barrier = {};
8017 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8018 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8019 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8020 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8021 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8022 buf_barrier.buffer = VK_NULL_HANDLE;
8023 buf_barrier.offset = 0;
8024 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008025 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8026 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008027
8028 m_errorMonitor->VerifyFound();
8029}
8030
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008031TEST_F(VkLayerTest, InvalidBarriers) {
8032 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008035
8036 ASSERT_NO_FATAL_FAILURE(InitState());
8037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8038
8039 VkMemoryBarrier mem_barrier = {};
8040 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8041 mem_barrier.pNext = NULL;
8042 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8043 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8044 BeginCommandBuffer();
8045 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008046 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008047 &mem_barrier, 0, nullptr, 0, nullptr);
8048 m_errorMonitor->VerifyFound();
8049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008051 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008052 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 -06008053 ASSERT_TRUE(image.initialized());
8054 VkImageMemoryBarrier img_barrier = {};
8055 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8056 img_barrier.pNext = NULL;
8057 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8058 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8059 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8060 // New layout can't be UNDEFINED
8061 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8062 img_barrier.image = image.handle();
8063 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8064 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8065 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8066 img_barrier.subresourceRange.baseArrayLayer = 0;
8067 img_barrier.subresourceRange.baseMipLevel = 0;
8068 img_barrier.subresourceRange.layerCount = 1;
8069 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008070 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8071 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008072 m_errorMonitor->VerifyFound();
8073 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8074
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8076 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008077 // baseArrayLayer + layerCount must be <= image's arrayLayers
8078 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008079 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8080 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008081 m_errorMonitor->VerifyFound();
8082 img_barrier.subresourceRange.baseArrayLayer = 0;
8083
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008085 // baseMipLevel + levelCount must be <= image's mipLevels
8086 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008087 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8088 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008089 m_errorMonitor->VerifyFound();
8090 img_barrier.subresourceRange.baseMipLevel = 0;
8091
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008092 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 -06008093 vk_testing::Buffer buffer;
8094 buffer.init(*m_device, 256);
8095 VkBufferMemoryBarrier buf_barrier = {};
8096 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8097 buf_barrier.pNext = NULL;
8098 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8099 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8100 buf_barrier.buffer = buffer.handle();
8101 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8102 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8103 buf_barrier.offset = 0;
8104 buf_barrier.size = VK_WHOLE_SIZE;
8105 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008106 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8107 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008108 m_errorMonitor->VerifyFound();
8109 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008112 buf_barrier.offset = 257;
8113 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008114 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8115 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008116 m_errorMonitor->VerifyFound();
8117 buf_barrier.offset = 0;
8118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008120 buf_barrier.size = 257;
8121 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008122 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8123 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008124 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008125
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008126 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008127 m_errorMonitor->SetDesiredFailureMsg(
8128 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8129 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8130 m_errorMonitor->SetDesiredFailureMsg(
8131 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8132 "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 -06008133 VkDepthStencilObj ds_image(m_device);
8134 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8135 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008136 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8137 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008138 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008139 // Use of COLOR aspect on DS image is error
8140 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8142 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008143 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008144 // Now test depth-only
8145 VkFormatProperties format_props;
8146
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008147 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8148 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8150 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8152 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008153 VkDepthStencilObj d_image(m_device);
8154 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8155 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008156 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008157 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008158 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008159 // Use of COLOR aspect on depth image is error
8160 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008161 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8162 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008163 m_errorMonitor->VerifyFound();
8164 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008165 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8166 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008167 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8169 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008170 VkDepthStencilObj s_image(m_device);
8171 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8172 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008174 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008175 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008176 // Use of COLOR aspect on depth image is error
8177 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8179 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008180 m_errorMonitor->VerifyFound();
8181 }
8182 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8184 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8186 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008187 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008188 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 -06008189 ASSERT_TRUE(c_image.initialized());
8190 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8191 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8192 img_barrier.image = c_image.handle();
8193 // Set aspect to depth (non-color)
8194 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008195 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8196 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008197 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008198}
8199
Tony Barbour18ba25c2016-09-29 13:42:40 -06008200TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8201 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8202
8203 m_errorMonitor->SetDesiredFailureMsg(
8204 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8205 "must have required access bit");
8206 ASSERT_NO_FATAL_FAILURE(InitState());
8207 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008208 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 -06008209 ASSERT_TRUE(image.initialized());
8210
8211 VkImageMemoryBarrier barrier = {};
8212 VkImageSubresourceRange range;
8213 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8214 barrier.srcAccessMask = 0;
8215 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8216 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8217 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8218 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8219 barrier.image = image.handle();
8220 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8221 range.baseMipLevel = 0;
8222 range.levelCount = 1;
8223 range.baseArrayLayer = 0;
8224 range.layerCount = 1;
8225 barrier.subresourceRange = range;
8226 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8227 cmdbuf.BeginCommandBuffer();
8228 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8229 &barrier);
8230 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8231 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8232 barrier.srcAccessMask = 0;
8233 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8234 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8235 &barrier);
8236
8237 m_errorMonitor->VerifyFound();
8238}
8239
Karl Schultz6addd812016-02-02 17:17:23 -07008240TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008241 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008242 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008243
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008245
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008246 ASSERT_NO_FATAL_FAILURE(InitState());
8247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008248 uint32_t qfi = 0;
8249 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008250 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8251 buffCI.size = 1024;
8252 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8253 buffCI.queueFamilyIndexCount = 1;
8254 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008255
8256 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008257 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008258 ASSERT_VK_SUCCESS(err);
8259
8260 BeginCommandBuffer();
8261 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008262 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8263 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008264 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008265 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008266
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008267 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008268
Chia-I Wuf7458c52015-10-26 21:10:41 +08008269 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008270}
8271
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008272TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8273 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8275 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8276 "of the indices specified when the device was created, via the "
8277 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008278
8279 ASSERT_NO_FATAL_FAILURE(InitState());
8280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8281 VkBufferCreateInfo buffCI = {};
8282 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8283 buffCI.size = 1024;
8284 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8285 buffCI.queueFamilyIndexCount = 1;
8286 // Introduce failure by specifying invalid queue_family_index
8287 uint32_t qfi = 777;
8288 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008289 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008290
8291 VkBuffer ib;
8292 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8293
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008294 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008295 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008296}
8297
Karl Schultz6addd812016-02-02 17:17:23 -07008298TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008299TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008300 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008301
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008302 ASSERT_NO_FATAL_FAILURE(InitState());
8303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008304
Chris Forbesf29a84f2016-10-06 18:39:28 +13008305 // An empty primary command buffer
8306 VkCommandBufferObj cb(m_device, m_commandPool);
8307 cb.BeginCommandBuffer();
8308 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008309
Chris Forbesf29a84f2016-10-06 18:39:28 +13008310 m_commandBuffer->BeginCommandBuffer();
8311 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8312 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008313
Chris Forbesf29a84f2016-10-06 18:39:28 +13008314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8315 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008316 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008317}
8318
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008319TEST_F(VkLayerTest, DSUsageBitsErrors) {
8320 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8321 "that do not have correct usage bits sets.");
8322 VkResult err;
8323
8324 ASSERT_NO_FATAL_FAILURE(InitState());
8325 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8326 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8327 ds_type_count[i].type = VkDescriptorType(i);
8328 ds_type_count[i].descriptorCount = 1;
8329 }
8330 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8331 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8332 ds_pool_ci.pNext = NULL;
8333 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8334 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8335 ds_pool_ci.pPoolSizes = ds_type_count;
8336
8337 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008338 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008339 ASSERT_VK_SUCCESS(err);
8340
8341 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008342 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008343 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8344 dsl_binding[i].binding = 0;
8345 dsl_binding[i].descriptorType = VkDescriptorType(i);
8346 dsl_binding[i].descriptorCount = 1;
8347 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8348 dsl_binding[i].pImmutableSamplers = NULL;
8349 }
8350
8351 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8352 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8353 ds_layout_ci.pNext = NULL;
8354 ds_layout_ci.bindingCount = 1;
8355 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8356 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8357 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008358 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008359 ASSERT_VK_SUCCESS(err);
8360 }
8361 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8362 VkDescriptorSetAllocateInfo alloc_info = {};
8363 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8364 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8365 alloc_info.descriptorPool = ds_pool;
8366 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008368 ASSERT_VK_SUCCESS(err);
8369
8370 // Create a buffer & bufferView to be used for invalid updates
8371 VkBufferCreateInfo buff_ci = {};
8372 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8373 // This usage is not valid for any descriptor type
8374 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8375 buff_ci.size = 256;
8376 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8377 VkBuffer buffer;
8378 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8379 ASSERT_VK_SUCCESS(err);
8380
8381 VkBufferViewCreateInfo buff_view_ci = {};
8382 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8383 buff_view_ci.buffer = buffer;
8384 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8385 buff_view_ci.range = VK_WHOLE_SIZE;
8386 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008387 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008388 ASSERT_VK_SUCCESS(err);
8389
8390 // Create an image to be used for invalid updates
8391 VkImageCreateInfo image_ci = {};
8392 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8393 image_ci.imageType = VK_IMAGE_TYPE_2D;
8394 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8395 image_ci.extent.width = 64;
8396 image_ci.extent.height = 64;
8397 image_ci.extent.depth = 1;
8398 image_ci.mipLevels = 1;
8399 image_ci.arrayLayers = 1;
8400 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8401 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8402 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8403 // This usage is not valid for any descriptor type
8404 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8405 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8406 VkImage image;
8407 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8408 ASSERT_VK_SUCCESS(err);
8409 // Bind memory to image
8410 VkMemoryRequirements mem_reqs;
8411 VkDeviceMemory image_mem;
8412 bool pass;
8413 VkMemoryAllocateInfo mem_alloc = {};
8414 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8415 mem_alloc.pNext = NULL;
8416 mem_alloc.allocationSize = 0;
8417 mem_alloc.memoryTypeIndex = 0;
8418 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8419 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008420 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008421 ASSERT_TRUE(pass);
8422 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8423 ASSERT_VK_SUCCESS(err);
8424 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8425 ASSERT_VK_SUCCESS(err);
8426 // Now create view for image
8427 VkImageViewCreateInfo image_view_ci = {};
8428 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8429 image_view_ci.image = image;
8430 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8431 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8432 image_view_ci.subresourceRange.layerCount = 1;
8433 image_view_ci.subresourceRange.baseArrayLayer = 0;
8434 image_view_ci.subresourceRange.levelCount = 1;
8435 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8436 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008437 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008438 ASSERT_VK_SUCCESS(err);
8439
8440 VkDescriptorBufferInfo buff_info = {};
8441 buff_info.buffer = buffer;
8442 VkDescriptorImageInfo img_info = {};
8443 img_info.imageView = image_view;
8444 VkWriteDescriptorSet descriptor_write = {};
8445 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8446 descriptor_write.dstBinding = 0;
8447 descriptor_write.descriptorCount = 1;
8448 descriptor_write.pTexelBufferView = &buff_view;
8449 descriptor_write.pBufferInfo = &buff_info;
8450 descriptor_write.pImageInfo = &img_info;
8451
8452 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008453 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8454 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8455 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8456 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8457 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8458 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8459 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8460 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8461 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8462 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8463 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008464 // Start loop at 1 as SAMPLER desc type has no usage bit error
8465 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8466 descriptor_write.descriptorType = VkDescriptorType(i);
8467 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008469
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008470 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008471
8472 m_errorMonitor->VerifyFound();
8473 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8474 }
8475 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8476 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008477 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008478 vkDestroyImageView(m_device->device(), image_view, NULL);
8479 vkDestroyBuffer(m_device->device(), buffer, NULL);
8480 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008482 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8483}
8484
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008485TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008486 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8487 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8488 "1. offset value greater than buffer size\n"
8489 "2. range value of 0\n"
8490 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008491 VkResult err;
8492
8493 ASSERT_NO_FATAL_FAILURE(InitState());
8494 VkDescriptorPoolSize ds_type_count = {};
8495 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8496 ds_type_count.descriptorCount = 1;
8497
8498 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8499 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8500 ds_pool_ci.pNext = NULL;
8501 ds_pool_ci.maxSets = 1;
8502 ds_pool_ci.poolSizeCount = 1;
8503 ds_pool_ci.pPoolSizes = &ds_type_count;
8504
8505 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008506 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008507 ASSERT_VK_SUCCESS(err);
8508
8509 // Create layout with single uniform buffer descriptor
8510 VkDescriptorSetLayoutBinding dsl_binding = {};
8511 dsl_binding.binding = 0;
8512 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8513 dsl_binding.descriptorCount = 1;
8514 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8515 dsl_binding.pImmutableSamplers = NULL;
8516
8517 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8518 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8519 ds_layout_ci.pNext = NULL;
8520 ds_layout_ci.bindingCount = 1;
8521 ds_layout_ci.pBindings = &dsl_binding;
8522 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008523 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008524 ASSERT_VK_SUCCESS(err);
8525
8526 VkDescriptorSet descriptor_set = {};
8527 VkDescriptorSetAllocateInfo alloc_info = {};
8528 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8529 alloc_info.descriptorSetCount = 1;
8530 alloc_info.descriptorPool = ds_pool;
8531 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008532 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008533 ASSERT_VK_SUCCESS(err);
8534
8535 // Create a buffer to be used for invalid updates
8536 VkBufferCreateInfo buff_ci = {};
8537 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8538 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8539 buff_ci.size = 256;
8540 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8541 VkBuffer buffer;
8542 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8543 ASSERT_VK_SUCCESS(err);
8544 // Have to bind memory to buffer before descriptor update
8545 VkMemoryAllocateInfo mem_alloc = {};
8546 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8547 mem_alloc.pNext = NULL;
8548 mem_alloc.allocationSize = 256;
8549 mem_alloc.memoryTypeIndex = 0;
8550
8551 VkMemoryRequirements mem_reqs;
8552 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008553 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008554 if (!pass) {
8555 vkDestroyBuffer(m_device->device(), buffer, NULL);
8556 return;
8557 }
8558
8559 VkDeviceMemory mem;
8560 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8561 ASSERT_VK_SUCCESS(err);
8562 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8563 ASSERT_VK_SUCCESS(err);
8564
8565 VkDescriptorBufferInfo buff_info = {};
8566 buff_info.buffer = buffer;
8567 // First make offset 1 larger than buffer size
8568 buff_info.offset = 257;
8569 buff_info.range = VK_WHOLE_SIZE;
8570 VkWriteDescriptorSet descriptor_write = {};
8571 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8572 descriptor_write.dstBinding = 0;
8573 descriptor_write.descriptorCount = 1;
8574 descriptor_write.pTexelBufferView = nullptr;
8575 descriptor_write.pBufferInfo = &buff_info;
8576 descriptor_write.pImageInfo = nullptr;
8577
8578 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8579 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008581
8582 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8583
8584 m_errorMonitor->VerifyFound();
8585 // Now cause error due to range of 0
8586 buff_info.offset = 0;
8587 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8589 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008590
8591 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8592
8593 m_errorMonitor->VerifyFound();
8594 // Now cause error due to range exceeding buffer size - offset
8595 buff_info.offset = 128;
8596 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008597 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 -06008598
8599 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8600
8601 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008602 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008603 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8604 vkDestroyBuffer(m_device->device(), buffer, NULL);
8605 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8606 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8607}
8608
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008609TEST_F(VkLayerTest, DSAspectBitsErrors) {
8610 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8611 // are set, but could expand this test to hit more cases.
8612 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8613 "that do not have correct aspect bits sets.");
8614 VkResult err;
8615
8616 ASSERT_NO_FATAL_FAILURE(InitState());
8617 VkDescriptorPoolSize ds_type_count = {};
8618 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8619 ds_type_count.descriptorCount = 1;
8620
8621 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8622 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8623 ds_pool_ci.pNext = NULL;
8624 ds_pool_ci.maxSets = 5;
8625 ds_pool_ci.poolSizeCount = 1;
8626 ds_pool_ci.pPoolSizes = &ds_type_count;
8627
8628 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008629 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008630 ASSERT_VK_SUCCESS(err);
8631
8632 VkDescriptorSetLayoutBinding dsl_binding = {};
8633 dsl_binding.binding = 0;
8634 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8635 dsl_binding.descriptorCount = 1;
8636 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8637 dsl_binding.pImmutableSamplers = NULL;
8638
8639 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8640 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8641 ds_layout_ci.pNext = NULL;
8642 ds_layout_ci.bindingCount = 1;
8643 ds_layout_ci.pBindings = &dsl_binding;
8644 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008646 ASSERT_VK_SUCCESS(err);
8647
8648 VkDescriptorSet descriptor_set = {};
8649 VkDescriptorSetAllocateInfo alloc_info = {};
8650 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8651 alloc_info.descriptorSetCount = 1;
8652 alloc_info.descriptorPool = ds_pool;
8653 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008654 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008655 ASSERT_VK_SUCCESS(err);
8656
8657 // Create an image to be used for invalid updates
8658 VkImageCreateInfo image_ci = {};
8659 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8660 image_ci.imageType = VK_IMAGE_TYPE_2D;
8661 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8662 image_ci.extent.width = 64;
8663 image_ci.extent.height = 64;
8664 image_ci.extent.depth = 1;
8665 image_ci.mipLevels = 1;
8666 image_ci.arrayLayers = 1;
8667 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8668 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8669 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8670 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8671 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8672 VkImage image;
8673 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8674 ASSERT_VK_SUCCESS(err);
8675 // Bind memory to image
8676 VkMemoryRequirements mem_reqs;
8677 VkDeviceMemory image_mem;
8678 bool pass;
8679 VkMemoryAllocateInfo mem_alloc = {};
8680 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8681 mem_alloc.pNext = NULL;
8682 mem_alloc.allocationSize = 0;
8683 mem_alloc.memoryTypeIndex = 0;
8684 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8685 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008686 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008687 ASSERT_TRUE(pass);
8688 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8689 ASSERT_VK_SUCCESS(err);
8690 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8691 ASSERT_VK_SUCCESS(err);
8692 // Now create view for image
8693 VkImageViewCreateInfo image_view_ci = {};
8694 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8695 image_view_ci.image = image;
8696 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8697 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8698 image_view_ci.subresourceRange.layerCount = 1;
8699 image_view_ci.subresourceRange.baseArrayLayer = 0;
8700 image_view_ci.subresourceRange.levelCount = 1;
8701 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008702 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008703
8704 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008705 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008706 ASSERT_VK_SUCCESS(err);
8707
8708 VkDescriptorImageInfo img_info = {};
8709 img_info.imageView = image_view;
8710 VkWriteDescriptorSet descriptor_write = {};
8711 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8712 descriptor_write.dstBinding = 0;
8713 descriptor_write.descriptorCount = 1;
8714 descriptor_write.pTexelBufferView = NULL;
8715 descriptor_write.pBufferInfo = NULL;
8716 descriptor_write.pImageInfo = &img_info;
8717 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8718 descriptor_write.dstSet = descriptor_set;
8719 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8720 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008722
8723 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8724
8725 m_errorMonitor->VerifyFound();
8726 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8727 vkDestroyImage(m_device->device(), image, NULL);
8728 vkFreeMemory(m_device->device(), image_mem, NULL);
8729 vkDestroyImageView(m_device->device(), image_view, NULL);
8730 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8731 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8732}
8733
Karl Schultz6addd812016-02-02 17:17:23 -07008734TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008735 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008736 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008737
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8739 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8740 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008741
Tobin Ehlis3b780662015-05-28 12:11:26 -06008742 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008743 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008744 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008745 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8746 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008747
8748 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008749 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8750 ds_pool_ci.pNext = NULL;
8751 ds_pool_ci.maxSets = 1;
8752 ds_pool_ci.poolSizeCount = 1;
8753 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008754
Tobin Ehlis3b780662015-05-28 12:11:26 -06008755 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008756 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008757 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008758 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008759 dsl_binding.binding = 0;
8760 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8761 dsl_binding.descriptorCount = 1;
8762 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8763 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008764
Tony Barboureb254902015-07-15 12:50:33 -06008765 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008766 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8767 ds_layout_ci.pNext = NULL;
8768 ds_layout_ci.bindingCount = 1;
8769 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008770
Tobin Ehlis3b780662015-05-28 12:11:26 -06008771 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008772 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008773 ASSERT_VK_SUCCESS(err);
8774
8775 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008776 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008777 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008778 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008779 alloc_info.descriptorPool = ds_pool;
8780 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008781 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008782 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008783
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008784 VkSamplerCreateInfo sampler_ci = {};
8785 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8786 sampler_ci.pNext = NULL;
8787 sampler_ci.magFilter = VK_FILTER_NEAREST;
8788 sampler_ci.minFilter = VK_FILTER_NEAREST;
8789 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8790 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8791 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8792 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8793 sampler_ci.mipLodBias = 1.0;
8794 sampler_ci.anisotropyEnable = VK_FALSE;
8795 sampler_ci.maxAnisotropy = 1;
8796 sampler_ci.compareEnable = VK_FALSE;
8797 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8798 sampler_ci.minLod = 1.0;
8799 sampler_ci.maxLod = 1.0;
8800 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8801 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8802 VkSampler sampler;
8803 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8804 ASSERT_VK_SUCCESS(err);
8805
8806 VkDescriptorImageInfo info = {};
8807 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008808
8809 VkWriteDescriptorSet descriptor_write;
8810 memset(&descriptor_write, 0, sizeof(descriptor_write));
8811 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008812 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008813 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008814 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008815 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008816 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008817
8818 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008820 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008821
Chia-I Wuf7458c52015-10-26 21:10:41 +08008822 vkDestroySampler(m_device->device(), sampler, NULL);
8823 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8824 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008825}
8826
Karl Schultz6addd812016-02-02 17:17:23 -07008827TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008828 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008829 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008830
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8832 " binding #0 with 1 total descriptors but update of 1 descriptors "
8833 "starting at binding offset of 0 combined with update array element "
8834 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008835
Tobin Ehlis3b780662015-05-28 12:11:26 -06008836 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008837 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008838 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008839 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8840 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008841
8842 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008843 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8844 ds_pool_ci.pNext = NULL;
8845 ds_pool_ci.maxSets = 1;
8846 ds_pool_ci.poolSizeCount = 1;
8847 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008848
Tobin Ehlis3b780662015-05-28 12:11:26 -06008849 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008850 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008851 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008852
Tony Barboureb254902015-07-15 12:50:33 -06008853 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008854 dsl_binding.binding = 0;
8855 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8856 dsl_binding.descriptorCount = 1;
8857 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8858 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008859
8860 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008861 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8862 ds_layout_ci.pNext = NULL;
8863 ds_layout_ci.bindingCount = 1;
8864 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008865
Tobin Ehlis3b780662015-05-28 12:11:26 -06008866 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008867 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008868 ASSERT_VK_SUCCESS(err);
8869
8870 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008871 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008872 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008873 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008874 alloc_info.descriptorPool = ds_pool;
8875 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008876 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008877 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008878
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008879 // Correctly update descriptor to avoid "NOT_UPDATED" error
8880 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008881 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008882 buff_info.offset = 0;
8883 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008884
8885 VkWriteDescriptorSet descriptor_write;
8886 memset(&descriptor_write, 0, sizeof(descriptor_write));
8887 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008888 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008889 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008890 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008891 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8892 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008893
8894 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8895
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008896 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008897
Chia-I Wuf7458c52015-10-26 21:10:41 +08008898 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8899 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008900}
8901
Karl Schultz6addd812016-02-02 17:17:23 -07008902TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8903 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8904 // index 2
8905 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008908
Tobin Ehlis3b780662015-05-28 12:11:26 -06008909 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008910 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008911 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008912 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8913 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008914
8915 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008916 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8917 ds_pool_ci.pNext = NULL;
8918 ds_pool_ci.maxSets = 1;
8919 ds_pool_ci.poolSizeCount = 1;
8920 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008921
Tobin Ehlis3b780662015-05-28 12:11:26 -06008922 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008923 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008924 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008925
Tony Barboureb254902015-07-15 12:50:33 -06008926 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008927 dsl_binding.binding = 0;
8928 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8929 dsl_binding.descriptorCount = 1;
8930 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8931 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008932
8933 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008934 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8935 ds_layout_ci.pNext = NULL;
8936 ds_layout_ci.bindingCount = 1;
8937 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008938 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008939 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008940 ASSERT_VK_SUCCESS(err);
8941
8942 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008943 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008944 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008945 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008946 alloc_info.descriptorPool = ds_pool;
8947 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008948 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008949 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008950
Tony Barboureb254902015-07-15 12:50:33 -06008951 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008952 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8953 sampler_ci.pNext = NULL;
8954 sampler_ci.magFilter = VK_FILTER_NEAREST;
8955 sampler_ci.minFilter = VK_FILTER_NEAREST;
8956 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8957 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8958 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8959 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8960 sampler_ci.mipLodBias = 1.0;
8961 sampler_ci.anisotropyEnable = VK_FALSE;
8962 sampler_ci.maxAnisotropy = 1;
8963 sampler_ci.compareEnable = VK_FALSE;
8964 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8965 sampler_ci.minLod = 1.0;
8966 sampler_ci.maxLod = 1.0;
8967 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8968 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008969
Tobin Ehlis3b780662015-05-28 12:11:26 -06008970 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008971 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008972 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008973
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008974 VkDescriptorImageInfo info = {};
8975 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008976
8977 VkWriteDescriptorSet descriptor_write;
8978 memset(&descriptor_write, 0, sizeof(descriptor_write));
8979 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008980 descriptor_write.dstSet = descriptorSet;
8981 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008982 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008983 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008985 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008986
8987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8988
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008989 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008990
Chia-I Wuf7458c52015-10-26 21:10:41 +08008991 vkDestroySampler(m_device->device(), sampler, NULL);
8992 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8993 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008994}
8995
Karl Schultz6addd812016-02-02 17:17:23 -07008996TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8997 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8998 // types
8999 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009000
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009001 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 -06009002
Tobin Ehlis3b780662015-05-28 12:11:26 -06009003 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009004
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009005 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009006 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9007 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009008
9009 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009010 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9011 ds_pool_ci.pNext = NULL;
9012 ds_pool_ci.maxSets = 1;
9013 ds_pool_ci.poolSizeCount = 1;
9014 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009015
Tobin Ehlis3b780662015-05-28 12:11:26 -06009016 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009017 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009018 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009019 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009020 dsl_binding.binding = 0;
9021 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9022 dsl_binding.descriptorCount = 1;
9023 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9024 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009025
Tony Barboureb254902015-07-15 12:50:33 -06009026 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009027 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9028 ds_layout_ci.pNext = NULL;
9029 ds_layout_ci.bindingCount = 1;
9030 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009031
Tobin Ehlis3b780662015-05-28 12:11:26 -06009032 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009033 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009034 ASSERT_VK_SUCCESS(err);
9035
9036 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009037 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009038 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009039 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009040 alloc_info.descriptorPool = ds_pool;
9041 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009042 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009043 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009044
Tony Barboureb254902015-07-15 12:50:33 -06009045 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009046 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9047 sampler_ci.pNext = NULL;
9048 sampler_ci.magFilter = VK_FILTER_NEAREST;
9049 sampler_ci.minFilter = VK_FILTER_NEAREST;
9050 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9051 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9052 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9053 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9054 sampler_ci.mipLodBias = 1.0;
9055 sampler_ci.anisotropyEnable = VK_FALSE;
9056 sampler_ci.maxAnisotropy = 1;
9057 sampler_ci.compareEnable = VK_FALSE;
9058 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9059 sampler_ci.minLod = 1.0;
9060 sampler_ci.maxLod = 1.0;
9061 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9062 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009063 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009064 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009065 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009066
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009067 VkDescriptorImageInfo info = {};
9068 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009069
9070 VkWriteDescriptorSet descriptor_write;
9071 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009072 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009073 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009074 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009075 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009076 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009077 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009078
9079 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9080
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009081 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009082
Chia-I Wuf7458c52015-10-26 21:10:41 +08009083 vkDestroySampler(m_device->device(), sampler, NULL);
9084 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9085 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009086}
9087
Karl Schultz6addd812016-02-02 17:17:23 -07009088TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009089 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009090 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009091
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9093 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009094
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009095 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009096 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9097 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009098 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009099 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9100 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009101
9102 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009103 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9104 ds_pool_ci.pNext = NULL;
9105 ds_pool_ci.maxSets = 1;
9106 ds_pool_ci.poolSizeCount = 1;
9107 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009108
9109 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009110 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009111 ASSERT_VK_SUCCESS(err);
9112
9113 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009114 dsl_binding.binding = 0;
9115 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9116 dsl_binding.descriptorCount = 1;
9117 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9118 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009119
9120 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009121 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9122 ds_layout_ci.pNext = NULL;
9123 ds_layout_ci.bindingCount = 1;
9124 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009125 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009127 ASSERT_VK_SUCCESS(err);
9128
9129 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009130 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009131 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009132 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009133 alloc_info.descriptorPool = ds_pool;
9134 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009135 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009136 ASSERT_VK_SUCCESS(err);
9137
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009138 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009139
9140 VkDescriptorImageInfo descriptor_info;
9141 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9142 descriptor_info.sampler = sampler;
9143
9144 VkWriteDescriptorSet descriptor_write;
9145 memset(&descriptor_write, 0, sizeof(descriptor_write));
9146 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009147 descriptor_write.dstSet = descriptorSet;
9148 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009149 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009150 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9151 descriptor_write.pImageInfo = &descriptor_info;
9152
9153 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9154
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009155 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009156
Chia-I Wuf7458c52015-10-26 21:10:41 +08009157 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9158 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009159}
9160
Karl Schultz6addd812016-02-02 17:17:23 -07009161TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9162 // Create a single combined Image/Sampler descriptor and send it an invalid
9163 // imageView
9164 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9167 "image sampler descriptor failed due "
9168 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009169
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009170 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009171 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009172 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9173 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009174
9175 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009176 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9177 ds_pool_ci.pNext = NULL;
9178 ds_pool_ci.maxSets = 1;
9179 ds_pool_ci.poolSizeCount = 1;
9180 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009181
9182 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009183 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009184 ASSERT_VK_SUCCESS(err);
9185
9186 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009187 dsl_binding.binding = 0;
9188 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9189 dsl_binding.descriptorCount = 1;
9190 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9191 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009192
9193 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009194 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9195 ds_layout_ci.pNext = NULL;
9196 ds_layout_ci.bindingCount = 1;
9197 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009198 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009199 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009200 ASSERT_VK_SUCCESS(err);
9201
9202 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009203 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009204 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009205 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009206 alloc_info.descriptorPool = ds_pool;
9207 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009208 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009209 ASSERT_VK_SUCCESS(err);
9210
9211 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009212 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9213 sampler_ci.pNext = NULL;
9214 sampler_ci.magFilter = VK_FILTER_NEAREST;
9215 sampler_ci.minFilter = VK_FILTER_NEAREST;
9216 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9217 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9218 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9219 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9220 sampler_ci.mipLodBias = 1.0;
9221 sampler_ci.anisotropyEnable = VK_FALSE;
9222 sampler_ci.maxAnisotropy = 1;
9223 sampler_ci.compareEnable = VK_FALSE;
9224 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9225 sampler_ci.minLod = 1.0;
9226 sampler_ci.maxLod = 1.0;
9227 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9228 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009229
9230 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009231 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009232 ASSERT_VK_SUCCESS(err);
9233
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009234 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009235
9236 VkDescriptorImageInfo descriptor_info;
9237 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9238 descriptor_info.sampler = sampler;
9239 descriptor_info.imageView = view;
9240
9241 VkWriteDescriptorSet descriptor_write;
9242 memset(&descriptor_write, 0, sizeof(descriptor_write));
9243 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009244 descriptor_write.dstSet = descriptorSet;
9245 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009246 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009247 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9248 descriptor_write.pImageInfo = &descriptor_info;
9249
9250 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9251
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009252 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009253
Chia-I Wuf7458c52015-10-26 21:10:41 +08009254 vkDestroySampler(m_device->device(), sampler, NULL);
9255 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9256 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009257}
9258
Karl Schultz6addd812016-02-02 17:17:23 -07009259TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9260 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9261 // into the other
9262 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009263
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9265 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9266 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009267
Tobin Ehlis04356f92015-10-27 16:35:27 -06009268 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009269 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009270 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009271 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9272 ds_type_count[0].descriptorCount = 1;
9273 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9274 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009275
9276 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009277 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9278 ds_pool_ci.pNext = NULL;
9279 ds_pool_ci.maxSets = 1;
9280 ds_pool_ci.poolSizeCount = 2;
9281 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009282
9283 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009284 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009285 ASSERT_VK_SUCCESS(err);
9286 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009287 dsl_binding[0].binding = 0;
9288 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9289 dsl_binding[0].descriptorCount = 1;
9290 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9291 dsl_binding[0].pImmutableSamplers = NULL;
9292 dsl_binding[1].binding = 1;
9293 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9294 dsl_binding[1].descriptorCount = 1;
9295 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9296 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009297
9298 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009299 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9300 ds_layout_ci.pNext = NULL;
9301 ds_layout_ci.bindingCount = 2;
9302 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009303
9304 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009305 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009306 ASSERT_VK_SUCCESS(err);
9307
9308 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009309 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009310 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009311 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009312 alloc_info.descriptorPool = ds_pool;
9313 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009314 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009315 ASSERT_VK_SUCCESS(err);
9316
9317 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009318 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9319 sampler_ci.pNext = NULL;
9320 sampler_ci.magFilter = VK_FILTER_NEAREST;
9321 sampler_ci.minFilter = VK_FILTER_NEAREST;
9322 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9323 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9324 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9325 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9326 sampler_ci.mipLodBias = 1.0;
9327 sampler_ci.anisotropyEnable = VK_FALSE;
9328 sampler_ci.maxAnisotropy = 1;
9329 sampler_ci.compareEnable = VK_FALSE;
9330 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9331 sampler_ci.minLod = 1.0;
9332 sampler_ci.maxLod = 1.0;
9333 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9334 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009335
9336 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009337 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009338 ASSERT_VK_SUCCESS(err);
9339
9340 VkDescriptorImageInfo info = {};
9341 info.sampler = sampler;
9342
9343 VkWriteDescriptorSet descriptor_write;
9344 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9345 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009346 descriptor_write.dstSet = descriptorSet;
9347 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009348 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009349 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9350 descriptor_write.pImageInfo = &info;
9351 // This write update should succeed
9352 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9353 // Now perform a copy update that fails due to type mismatch
9354 VkCopyDescriptorSet copy_ds_update;
9355 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9356 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9357 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009358 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009359 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009360 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009361 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009362 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9363
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009364 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009365 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009366 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 -06009367 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9368 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9369 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009370 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009371 copy_ds_update.dstSet = descriptorSet;
9372 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009373 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009374 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9375
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009376 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009377
Tobin Ehlis04356f92015-10-27 16:35:27 -06009378 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9380 "update array offset of 0 and update of "
9381 "5 descriptors oversteps total number "
9382 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009383
Tobin Ehlis04356f92015-10-27 16:35:27 -06009384 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9385 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9386 copy_ds_update.srcSet = descriptorSet;
9387 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009388 copy_ds_update.dstSet = descriptorSet;
9389 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009390 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009391 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9392
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009393 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009394
Chia-I Wuf7458c52015-10-26 21:10:41 +08009395 vkDestroySampler(m_device->device(), sampler, NULL);
9396 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9397 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009398}
9399
Karl Schultz6addd812016-02-02 17:17:23 -07009400TEST_F(VkLayerTest, NumSamplesMismatch) {
9401 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9402 // sampleCount
9403 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009406
Tobin Ehlis3b780662015-05-28 12:11:26 -06009407 ASSERT_NO_FATAL_FAILURE(InitState());
9408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009409 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009410 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009411 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009412
9413 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009414 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9415 ds_pool_ci.pNext = NULL;
9416 ds_pool_ci.maxSets = 1;
9417 ds_pool_ci.poolSizeCount = 1;
9418 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009419
Tobin Ehlis3b780662015-05-28 12:11:26 -06009420 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009421 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009422 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009423
Tony Barboureb254902015-07-15 12:50:33 -06009424 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009425 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009426 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009427 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009428 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9429 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009430
Tony Barboureb254902015-07-15 12:50:33 -06009431 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9432 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9433 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009434 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009435 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009436
Tobin Ehlis3b780662015-05-28 12:11:26 -06009437 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009438 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009439 ASSERT_VK_SUCCESS(err);
9440
9441 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009442 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009443 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009444 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009445 alloc_info.descriptorPool = ds_pool;
9446 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009447 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009448 ASSERT_VK_SUCCESS(err);
9449
Tony Barboureb254902015-07-15 12:50:33 -06009450 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009451 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009452 pipe_ms_state_ci.pNext = NULL;
9453 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9454 pipe_ms_state_ci.sampleShadingEnable = 0;
9455 pipe_ms_state_ci.minSampleShading = 1.0;
9456 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009457
Tony Barboureb254902015-07-15 12:50:33 -06009458 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009459 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9460 pipeline_layout_ci.pNext = NULL;
9461 pipeline_layout_ci.setLayoutCount = 1;
9462 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009463
9464 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009465 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009466 ASSERT_VK_SUCCESS(err);
9467
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009468 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9469 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9470 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009471 VkPipelineObj pipe(m_device);
9472 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009473 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009474 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009475 pipe.SetMSAA(&pipe_ms_state_ci);
9476 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009477
Tony Barbourfe3351b2015-07-28 10:17:20 -06009478 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009479 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009480
Mark Young29927482016-05-04 14:38:51 -06009481 // Render triangle (the error should trigger on the attempt to draw).
9482 Draw(3, 1, 0, 0);
9483
9484 // Finalize recording of the command buffer
9485 EndCommandBuffer();
9486
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009487 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009488
Chia-I Wuf7458c52015-10-26 21:10:41 +08009489 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9490 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9491 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009492}
Mark Young29927482016-05-04 14:38:51 -06009493
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009494TEST_F(VkLayerTest, RenderPassIncompatible) {
9495 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9496 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009497 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009498 VkResult err;
9499
9500 ASSERT_NO_FATAL_FAILURE(InitState());
9501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9502
9503 VkDescriptorSetLayoutBinding dsl_binding = {};
9504 dsl_binding.binding = 0;
9505 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9506 dsl_binding.descriptorCount = 1;
9507 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9508 dsl_binding.pImmutableSamplers = NULL;
9509
9510 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9511 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9512 ds_layout_ci.pNext = NULL;
9513 ds_layout_ci.bindingCount = 1;
9514 ds_layout_ci.pBindings = &dsl_binding;
9515
9516 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009517 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009518 ASSERT_VK_SUCCESS(err);
9519
9520 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9521 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9522 pipeline_layout_ci.pNext = NULL;
9523 pipeline_layout_ci.setLayoutCount = 1;
9524 pipeline_layout_ci.pSetLayouts = &ds_layout;
9525
9526 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009527 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009528 ASSERT_VK_SUCCESS(err);
9529
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009530 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9531 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9532 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009533 // Create a renderpass that will be incompatible with default renderpass
9534 VkAttachmentReference attach = {};
9535 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9536 VkAttachmentReference color_att = {};
9537 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9538 VkSubpassDescription subpass = {};
9539 subpass.inputAttachmentCount = 1;
9540 subpass.pInputAttachments = &attach;
9541 subpass.colorAttachmentCount = 1;
9542 subpass.pColorAttachments = &color_att;
9543 VkRenderPassCreateInfo rpci = {};
9544 rpci.subpassCount = 1;
9545 rpci.pSubpasses = &subpass;
9546 rpci.attachmentCount = 1;
9547 VkAttachmentDescription attach_desc = {};
9548 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009549 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9550 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009551 rpci.pAttachments = &attach_desc;
9552 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9553 VkRenderPass rp;
9554 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9555 VkPipelineObj pipe(m_device);
9556 pipe.AddShader(&vs);
9557 pipe.AddShader(&fs);
9558 pipe.AddColorAttachment();
9559 VkViewport view_port = {};
9560 m_viewports.push_back(view_port);
9561 pipe.SetViewport(m_viewports);
9562 VkRect2D rect = {};
9563 m_scissors.push_back(rect);
9564 pipe.SetScissor(m_scissors);
9565 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9566
9567 VkCommandBufferInheritanceInfo cbii = {};
9568 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9569 cbii.renderPass = rp;
9570 cbii.subpass = 0;
9571 VkCommandBufferBeginInfo cbbi = {};
9572 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9573 cbbi.pInheritanceInfo = &cbii;
9574 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9575 VkRenderPassBeginInfo rpbi = {};
9576 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9577 rpbi.framebuffer = m_framebuffer;
9578 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009579 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9580 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009581
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009583 // Render triangle (the error should trigger on the attempt to draw).
9584 Draw(3, 1, 0, 0);
9585
9586 // Finalize recording of the command buffer
9587 EndCommandBuffer();
9588
9589 m_errorMonitor->VerifyFound();
9590
9591 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9592 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9593 vkDestroyRenderPass(m_device->device(), rp, NULL);
9594}
9595
Mark Youngc89c6312016-03-31 16:03:20 -06009596TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9597 // Create Pipeline where the number of blend attachments doesn't match the
9598 // number of color attachments. In this case, we don't add any color
9599 // blend attachments even though we have a color attachment.
9600 VkResult err;
9601
9602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009603 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009604
9605 ASSERT_NO_FATAL_FAILURE(InitState());
9606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9607 VkDescriptorPoolSize ds_type_count = {};
9608 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9609 ds_type_count.descriptorCount = 1;
9610
9611 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9612 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9613 ds_pool_ci.pNext = NULL;
9614 ds_pool_ci.maxSets = 1;
9615 ds_pool_ci.poolSizeCount = 1;
9616 ds_pool_ci.pPoolSizes = &ds_type_count;
9617
9618 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009619 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009620 ASSERT_VK_SUCCESS(err);
9621
9622 VkDescriptorSetLayoutBinding dsl_binding = {};
9623 dsl_binding.binding = 0;
9624 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9625 dsl_binding.descriptorCount = 1;
9626 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9627 dsl_binding.pImmutableSamplers = NULL;
9628
9629 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9630 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9631 ds_layout_ci.pNext = NULL;
9632 ds_layout_ci.bindingCount = 1;
9633 ds_layout_ci.pBindings = &dsl_binding;
9634
9635 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009636 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009637 ASSERT_VK_SUCCESS(err);
9638
9639 VkDescriptorSet descriptorSet;
9640 VkDescriptorSetAllocateInfo alloc_info = {};
9641 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9642 alloc_info.descriptorSetCount = 1;
9643 alloc_info.descriptorPool = ds_pool;
9644 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009645 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009646 ASSERT_VK_SUCCESS(err);
9647
9648 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009649 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009650 pipe_ms_state_ci.pNext = NULL;
9651 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9652 pipe_ms_state_ci.sampleShadingEnable = 0;
9653 pipe_ms_state_ci.minSampleShading = 1.0;
9654 pipe_ms_state_ci.pSampleMask = NULL;
9655
9656 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9657 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9658 pipeline_layout_ci.pNext = NULL;
9659 pipeline_layout_ci.setLayoutCount = 1;
9660 pipeline_layout_ci.pSetLayouts = &ds_layout;
9661
9662 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009663 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009664 ASSERT_VK_SUCCESS(err);
9665
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009666 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9667 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9668 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009669 VkPipelineObj pipe(m_device);
9670 pipe.AddShader(&vs);
9671 pipe.AddShader(&fs);
9672 pipe.SetMSAA(&pipe_ms_state_ci);
9673 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9674
9675 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009676 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009677
Mark Young29927482016-05-04 14:38:51 -06009678 // Render triangle (the error should trigger on the attempt to draw).
9679 Draw(3, 1, 0, 0);
9680
9681 // Finalize recording of the command buffer
9682 EndCommandBuffer();
9683
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009684 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009685
9686 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9687 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9688 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9689}
Mark Young29927482016-05-04 14:38:51 -06009690
Mark Muellerd4914412016-06-13 17:52:06 -06009691TEST_F(VkLayerTest, MissingClearAttachment) {
9692 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9693 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009694 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009696 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009697
9698 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9699 m_errorMonitor->VerifyFound();
9700}
9701
Karl Schultz6addd812016-02-02 17:17:23 -07009702TEST_F(VkLayerTest, ClearCmdNoDraw) {
9703 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9704 // to issuing a Draw
9705 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009708 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009709
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009710 ASSERT_NO_FATAL_FAILURE(InitState());
9711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009712
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009713 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009714 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9715 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009716
9717 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009718 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9719 ds_pool_ci.pNext = NULL;
9720 ds_pool_ci.maxSets = 1;
9721 ds_pool_ci.poolSizeCount = 1;
9722 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009723
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009724 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009725 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009726 ASSERT_VK_SUCCESS(err);
9727
Tony Barboureb254902015-07-15 12:50:33 -06009728 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009729 dsl_binding.binding = 0;
9730 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9731 dsl_binding.descriptorCount = 1;
9732 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9733 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009734
Tony Barboureb254902015-07-15 12:50:33 -06009735 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009736 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9737 ds_layout_ci.pNext = NULL;
9738 ds_layout_ci.bindingCount = 1;
9739 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009740
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009741 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009743 ASSERT_VK_SUCCESS(err);
9744
9745 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009746 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009747 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009748 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009749 alloc_info.descriptorPool = ds_pool;
9750 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009751 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009752 ASSERT_VK_SUCCESS(err);
9753
Tony Barboureb254902015-07-15 12:50:33 -06009754 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009755 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009756 pipe_ms_state_ci.pNext = NULL;
9757 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9758 pipe_ms_state_ci.sampleShadingEnable = 0;
9759 pipe_ms_state_ci.minSampleShading = 1.0;
9760 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009761
Tony Barboureb254902015-07-15 12:50:33 -06009762 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009763 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9764 pipeline_layout_ci.pNext = NULL;
9765 pipeline_layout_ci.setLayoutCount = 1;
9766 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009767
9768 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009769 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009770 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009771
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009772 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009773 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009774 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009775 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009776
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009777 VkPipelineObj pipe(m_device);
9778 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009779 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009780 pipe.SetMSAA(&pipe_ms_state_ci);
9781 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009782
9783 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009784
Karl Schultz6addd812016-02-02 17:17:23 -07009785 // Main thing we care about for this test is that the VkImage obj we're
9786 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009787 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009788 VkClearAttachment color_attachment;
9789 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9790 color_attachment.clearValue.color.float32[0] = 1.0;
9791 color_attachment.clearValue.color.float32[1] = 1.0;
9792 color_attachment.clearValue.color.float32[2] = 1.0;
9793 color_attachment.clearValue.color.float32[3] = 1.0;
9794 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009795 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009796
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009797 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009798
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009799 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009800
Chia-I Wuf7458c52015-10-26 21:10:41 +08009801 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9802 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9803 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009804}
9805
Karl Schultz6addd812016-02-02 17:17:23 -07009806TEST_F(VkLayerTest, VtxBufferBadIndex) {
9807 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009808
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9810 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009811
Tobin Ehlis502480b2015-06-24 15:53:07 -06009812 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009813 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009815
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009816 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009817 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9818 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009819
9820 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009821 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9822 ds_pool_ci.pNext = NULL;
9823 ds_pool_ci.maxSets = 1;
9824 ds_pool_ci.poolSizeCount = 1;
9825 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009826
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009827 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009828 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009829 ASSERT_VK_SUCCESS(err);
9830
Tony Barboureb254902015-07-15 12:50:33 -06009831 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009832 dsl_binding.binding = 0;
9833 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9834 dsl_binding.descriptorCount = 1;
9835 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9836 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009837
Tony Barboureb254902015-07-15 12:50:33 -06009838 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009839 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9840 ds_layout_ci.pNext = NULL;
9841 ds_layout_ci.bindingCount = 1;
9842 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009843
Tobin Ehlis502480b2015-06-24 15:53:07 -06009844 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009845 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009846 ASSERT_VK_SUCCESS(err);
9847
9848 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009849 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009850 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009851 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009852 alloc_info.descriptorPool = ds_pool;
9853 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009854 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009855 ASSERT_VK_SUCCESS(err);
9856
Tony Barboureb254902015-07-15 12:50:33 -06009857 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009858 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009859 pipe_ms_state_ci.pNext = NULL;
9860 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9861 pipe_ms_state_ci.sampleShadingEnable = 0;
9862 pipe_ms_state_ci.minSampleShading = 1.0;
9863 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009864
Tony Barboureb254902015-07-15 12:50:33 -06009865 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009866 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9867 pipeline_layout_ci.pNext = NULL;
9868 pipeline_layout_ci.setLayoutCount = 1;
9869 pipeline_layout_ci.pSetLayouts = &ds_layout;
9870 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009871
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009872 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009873 ASSERT_VK_SUCCESS(err);
9874
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009875 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9876 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9877 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009878 VkPipelineObj pipe(m_device);
9879 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009880 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009881 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009882 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009883 pipe.SetViewport(m_viewports);
9884 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009885 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009886
9887 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009888 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009889 // Don't care about actual data, just need to get to draw to flag error
9890 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009891 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009892 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009893 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009894
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009895 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009896
Chia-I Wuf7458c52015-10-26 21:10:41 +08009897 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9898 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9899 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009900}
Mark Muellerdfe37552016-07-07 14:47:42 -06009901
Mark Mueller2ee294f2016-08-04 12:59:48 -06009902TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9903 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9904 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009905 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009907 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9908 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009909
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009910 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9911 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009912
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009913 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009916 // The following test fails with recent NVidia drivers.
9917 // By the time core_validation is reached, the NVidia
9918 // driver has sanitized the invalid condition and core_validation
9919 // is not introduced to the failure condition. This is not the case
9920 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009921 // uint32_t count = static_cast<uint32_t>(~0);
9922 // VkPhysicalDevice physical_device;
9923 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9924 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009925
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009927 float queue_priority = 0.0;
9928
9929 VkDeviceQueueCreateInfo queue_create_info = {};
9930 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9931 queue_create_info.queueCount = 1;
9932 queue_create_info.pQueuePriorities = &queue_priority;
9933 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9934
9935 VkPhysicalDeviceFeatures features = m_device->phy().features();
9936 VkDevice testDevice;
9937 VkDeviceCreateInfo device_create_info = {};
9938 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9939 device_create_info.queueCreateInfoCount = 1;
9940 device_create_info.pQueueCreateInfos = &queue_create_info;
9941 device_create_info.pEnabledFeatures = &features;
9942 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9943 m_errorMonitor->VerifyFound();
9944
9945 queue_create_info.queueFamilyIndex = 1;
9946
9947 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
9948 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
9949 for (unsigned i = 0; i < feature_count; i++) {
9950 if (VK_FALSE == feature_array[i]) {
9951 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009953 device_create_info.pEnabledFeatures = &features;
9954 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9955 m_errorMonitor->VerifyFound();
9956 break;
9957 }
9958 }
9959}
9960
9961TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
9962 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
9963 "End a command buffer with a query still in progress.");
9964
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009965 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
9966 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
9967 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009969 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009970
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009972
9973 ASSERT_NO_FATAL_FAILURE(InitState());
9974
9975 VkEvent event;
9976 VkEventCreateInfo event_create_info{};
9977 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9978 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9979
Mark Mueller2ee294f2016-08-04 12:59:48 -06009980 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009981 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009982
9983 BeginCommandBuffer();
9984
9985 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009986 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 -06009987 ASSERT_TRUE(image.initialized());
9988 VkImageMemoryBarrier img_barrier = {};
9989 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9990 img_barrier.pNext = NULL;
9991 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9992 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9993 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9994 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9995 img_barrier.image = image.handle();
9996 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -06009997
9998 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
9999 // that layer validation catches the case when it is not.
10000 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010001 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10002 img_barrier.subresourceRange.baseArrayLayer = 0;
10003 img_barrier.subresourceRange.baseMipLevel = 0;
10004 img_barrier.subresourceRange.layerCount = 1;
10005 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010006 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10007 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010008 m_errorMonitor->VerifyFound();
10009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010011
10012 VkQueryPool query_pool;
10013 VkQueryPoolCreateInfo query_pool_create_info = {};
10014 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10015 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10016 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010017 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010019 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010020 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10021
10022 vkEndCommandBuffer(m_commandBuffer->handle());
10023 m_errorMonitor->VerifyFound();
10024
10025 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10026 vkDestroyEvent(m_device->device(), event, nullptr);
10027}
10028
Mark Muellerdfe37552016-07-07 14:47:42 -060010029TEST_F(VkLayerTest, VertexBufferInvalid) {
10030 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10031 "delete a buffer twice, use an invalid offset for each "
10032 "buffer type, and attempt to bind a null buffer");
10033
10034 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10035 "using deleted buffer ";
10036 const char *double_destroy_message = "Cannot free buffer 0x";
10037 const char *invalid_offset_message = "vkBindBufferMemory(): "
10038 "memoryOffset is 0x";
10039 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10040 "storage memoryOffset "
10041 "is 0x";
10042 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10043 "texel memoryOffset "
10044 "is 0x";
10045 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10046 "uniform memoryOffset "
10047 "is 0x";
10048 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10049 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010050 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010051
10052 ASSERT_NO_FATAL_FAILURE(InitState());
10053 ASSERT_NO_FATAL_FAILURE(InitViewport());
10054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10055
10056 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010057 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010058 pipe_ms_state_ci.pNext = NULL;
10059 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10060 pipe_ms_state_ci.sampleShadingEnable = 0;
10061 pipe_ms_state_ci.minSampleShading = 1.0;
10062 pipe_ms_state_ci.pSampleMask = nullptr;
10063
10064 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10065 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10066 VkPipelineLayout pipeline_layout;
10067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010068 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010069 ASSERT_VK_SUCCESS(err);
10070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010071 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10072 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010073 VkPipelineObj pipe(m_device);
10074 pipe.AddShader(&vs);
10075 pipe.AddShader(&fs);
10076 pipe.AddColorAttachment();
10077 pipe.SetMSAA(&pipe_ms_state_ci);
10078 pipe.SetViewport(m_viewports);
10079 pipe.SetScissor(m_scissors);
10080 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10081
10082 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010083 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010084
10085 {
10086 // Create and bind a vertex buffer in a reduced scope, which will cause
10087 // it to be deleted upon leaving this scope
10088 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010089 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010090 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10091 draw_verticies.AddVertexInputToPipe(pipe);
10092 }
10093
10094 Draw(1, 0, 0, 0);
10095
10096 EndCommandBuffer();
10097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010099 QueueCommandBuffer(false);
10100 m_errorMonitor->VerifyFound();
10101
10102 {
10103 // Create and bind a vertex buffer in a reduced scope, and delete it
10104 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010107 buffer_test.TestDoubleDestroy();
10108 }
10109 m_errorMonitor->VerifyFound();
10110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010111 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010112 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10114 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10115 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010116 m_errorMonitor->VerifyFound();
10117 }
10118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010119 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10120 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010121 // Create and bind a memory buffer with an invalid offset again,
10122 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10124 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10125 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010126 m_errorMonitor->VerifyFound();
10127 }
10128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010129 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010130 // Create and bind a memory buffer with an invalid offset again, but
10131 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10133 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10134 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010135 m_errorMonitor->VerifyFound();
10136 }
10137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010138 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010139 // Create and bind a memory buffer with an invalid offset again, but
10140 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10142 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10143 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010144 m_errorMonitor->VerifyFound();
10145 }
10146
10147 {
10148 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10150 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10151 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010152 m_errorMonitor->VerifyFound();
10153 }
10154
10155 {
10156 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10158 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10159 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010160 }
10161 m_errorMonitor->VerifyFound();
10162
10163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10164}
10165
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010166// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10167TEST_F(VkLayerTest, InvalidImageLayout) {
10168 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010169 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10170 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010171 // 3 in ValidateCmdBufImageLayouts
10172 // * -1 Attempt to submit cmd buf w/ deleted image
10173 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10174 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10176 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010177
10178 ASSERT_NO_FATAL_FAILURE(InitState());
10179 // Create src & dst images to use for copy operations
10180 VkImage src_image;
10181 VkImage dst_image;
10182
10183 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10184 const int32_t tex_width = 32;
10185 const int32_t tex_height = 32;
10186
10187 VkImageCreateInfo image_create_info = {};
10188 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10189 image_create_info.pNext = NULL;
10190 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10191 image_create_info.format = tex_format;
10192 image_create_info.extent.width = tex_width;
10193 image_create_info.extent.height = tex_height;
10194 image_create_info.extent.depth = 1;
10195 image_create_info.mipLevels = 1;
10196 image_create_info.arrayLayers = 4;
10197 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10198 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10199 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10200 image_create_info.flags = 0;
10201
10202 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10203 ASSERT_VK_SUCCESS(err);
10204 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10205 ASSERT_VK_SUCCESS(err);
10206
10207 BeginCommandBuffer();
10208 VkImageCopy copyRegion;
10209 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10210 copyRegion.srcSubresource.mipLevel = 0;
10211 copyRegion.srcSubresource.baseArrayLayer = 0;
10212 copyRegion.srcSubresource.layerCount = 1;
10213 copyRegion.srcOffset.x = 0;
10214 copyRegion.srcOffset.y = 0;
10215 copyRegion.srcOffset.z = 0;
10216 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10217 copyRegion.dstSubresource.mipLevel = 0;
10218 copyRegion.dstSubresource.baseArrayLayer = 0;
10219 copyRegion.dstSubresource.layerCount = 1;
10220 copyRegion.dstOffset.x = 0;
10221 copyRegion.dstOffset.y = 0;
10222 copyRegion.dstOffset.z = 0;
10223 copyRegion.extent.width = 1;
10224 copyRegion.extent.height = 1;
10225 copyRegion.extent.depth = 1;
10226 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10227 m_errorMonitor->VerifyFound();
10228 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10230 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10231 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010232 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10233 m_errorMonitor->VerifyFound();
10234 // Final src error is due to bad layout type
10235 m_errorMonitor->SetDesiredFailureMsg(
10236 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10237 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10238 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10239 m_errorMonitor->VerifyFound();
10240 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10242 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010243 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10244 m_errorMonitor->VerifyFound();
10245 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10247 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10248 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010249 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10250 m_errorMonitor->VerifyFound();
10251 m_errorMonitor->SetDesiredFailureMsg(
10252 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10253 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10254 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10255 m_errorMonitor->VerifyFound();
10256 // Now cause error due to bad image layout transition in PipelineBarrier
10257 VkImageMemoryBarrier image_barrier[1] = {};
10258 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10259 image_barrier[0].image = src_image;
10260 image_barrier[0].subresourceRange.layerCount = 2;
10261 image_barrier[0].subresourceRange.levelCount = 2;
10262 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10264 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10265 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10266 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10267 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010268 m_errorMonitor->VerifyFound();
10269
10270 // Finally some layout errors at RenderPass create time
10271 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10272 VkAttachmentReference attach = {};
10273 // perf warning for GENERAL layout w/ non-DS input attachment
10274 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10275 VkSubpassDescription subpass = {};
10276 subpass.inputAttachmentCount = 1;
10277 subpass.pInputAttachments = &attach;
10278 VkRenderPassCreateInfo rpci = {};
10279 rpci.subpassCount = 1;
10280 rpci.pSubpasses = &subpass;
10281 rpci.attachmentCount = 1;
10282 VkAttachmentDescription attach_desc = {};
10283 attach_desc.format = VK_FORMAT_UNDEFINED;
10284 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010285 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010286 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10288 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010289 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10290 m_errorMonitor->VerifyFound();
10291 // error w/ non-general layout
10292 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10293
10294 m_errorMonitor->SetDesiredFailureMsg(
10295 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10296 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10297 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10298 m_errorMonitor->VerifyFound();
10299 subpass.inputAttachmentCount = 0;
10300 subpass.colorAttachmentCount = 1;
10301 subpass.pColorAttachments = &attach;
10302 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10303 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10305 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010306 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10307 m_errorMonitor->VerifyFound();
10308 // error w/ non-color opt or GENERAL layout for color attachment
10309 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10310 m_errorMonitor->SetDesiredFailureMsg(
10311 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10312 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10313 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10314 m_errorMonitor->VerifyFound();
10315 subpass.colorAttachmentCount = 0;
10316 subpass.pDepthStencilAttachment = &attach;
10317 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10318 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10320 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010321 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10322 m_errorMonitor->VerifyFound();
10323 // error w/ non-ds opt or GENERAL layout for color attachment
10324 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10326 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10327 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010328 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10329 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010330 // For this error we need a valid renderpass so create default one
10331 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10332 attach.attachment = 0;
10333 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10334 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10335 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10336 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10337 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10338 // Can't do a CLEAR load on READ_ONLY initialLayout
10339 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10340 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10341 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10343 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10344 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010345 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10346 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010347
10348 vkDestroyImage(m_device->device(), src_image, NULL);
10349 vkDestroyImage(m_device->device(), dst_image, NULL);
10350}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010351
Tobin Ehlise0936662016-10-11 08:10:51 -060010352TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10353 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10354 VkResult err;
10355
10356 ASSERT_NO_FATAL_FAILURE(InitState());
10357
10358 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10359 VkImageTiling tiling;
10360 VkFormatProperties format_properties;
10361 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10362 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10363 tiling = VK_IMAGE_TILING_LINEAR;
10364 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10365 tiling = VK_IMAGE_TILING_OPTIMAL;
10366 } else {
10367 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10368 "skipped.\n");
10369 return;
10370 }
10371
10372 VkDescriptorPoolSize ds_type = {};
10373 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10374 ds_type.descriptorCount = 1;
10375
10376 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10377 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10378 ds_pool_ci.maxSets = 1;
10379 ds_pool_ci.poolSizeCount = 1;
10380 ds_pool_ci.pPoolSizes = &ds_type;
10381 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10382
10383 VkDescriptorPool ds_pool;
10384 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10385 ASSERT_VK_SUCCESS(err);
10386
10387 VkDescriptorSetLayoutBinding dsl_binding = {};
10388 dsl_binding.binding = 0;
10389 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10390 dsl_binding.descriptorCount = 1;
10391 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10392 dsl_binding.pImmutableSamplers = NULL;
10393
10394 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10395 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10396 ds_layout_ci.pNext = NULL;
10397 ds_layout_ci.bindingCount = 1;
10398 ds_layout_ci.pBindings = &dsl_binding;
10399
10400 VkDescriptorSetLayout ds_layout;
10401 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10402 ASSERT_VK_SUCCESS(err);
10403
10404 VkDescriptorSetAllocateInfo alloc_info = {};
10405 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10406 alloc_info.descriptorSetCount = 1;
10407 alloc_info.descriptorPool = ds_pool;
10408 alloc_info.pSetLayouts = &ds_layout;
10409 VkDescriptorSet descriptor_set;
10410 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10411 ASSERT_VK_SUCCESS(err);
10412
10413 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10414 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10415 pipeline_layout_ci.pNext = NULL;
10416 pipeline_layout_ci.setLayoutCount = 1;
10417 pipeline_layout_ci.pSetLayouts = &ds_layout;
10418 VkPipelineLayout pipeline_layout;
10419 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10420 ASSERT_VK_SUCCESS(err);
10421
10422 VkImageObj image(m_device);
10423 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10424 ASSERT_TRUE(image.initialized());
10425 VkImageView view = image.targetView(tex_format);
10426
10427 VkDescriptorImageInfo image_info = {};
10428 image_info.imageView = view;
10429 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10430
10431 VkWriteDescriptorSet descriptor_write = {};
10432 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10433 descriptor_write.dstSet = descriptor_set;
10434 descriptor_write.dstBinding = 0;
10435 descriptor_write.descriptorCount = 1;
10436 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10437 descriptor_write.pImageInfo = &image_info;
10438
10439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10440 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10441 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10442 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10443 m_errorMonitor->VerifyFound();
10444
10445 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10446 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10447 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10448 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10449}
10450
Mark Mueller93b938f2016-08-18 10:27:40 -060010451TEST_F(VkLayerTest, SimultaneousUse) {
10452 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10453 "in primary and secondary command buffers.");
10454
10455 ASSERT_NO_FATAL_FAILURE(InitState());
10456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10457
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010458 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010459 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10460 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010461
10462 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010463 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010464 command_buffer_allocate_info.commandPool = m_commandPool;
10465 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10466 command_buffer_allocate_info.commandBufferCount = 1;
10467
10468 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010469 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010470 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10471 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010472 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010473 command_buffer_inheritance_info.renderPass = m_renderPass;
10474 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10475 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010476 command_buffer_begin_info.flags =
10477 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010478 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10479
10480 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010481 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10482 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010483 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010484 vkEndCommandBuffer(secondary_command_buffer);
10485
Mark Mueller93b938f2016-08-18 10:27:40 -060010486 VkSubmitInfo submit_info = {};
10487 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10488 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010490 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010491
Mark Mueller4042b652016-09-05 22:52:21 -060010492 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010493 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10495 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010496 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010497 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10498 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010499
10500 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010501 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10502
Mark Mueller4042b652016-09-05 22:52:21 -060010503 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010504 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010505 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10508 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010509 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010510 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10511 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010512}
10513
Mark Mueller917f6bc2016-08-30 10:57:19 -060010514TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10515 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10516 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010517 "Delete objects that are inuse. Call VkQueueSubmit "
10518 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010519
10520 ASSERT_NO_FATAL_FAILURE(InitState());
10521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10522
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010523 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10524 const char *cannot_delete_event_message = "Cannot delete event 0x";
10525 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10526 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010527
10528 BeginCommandBuffer();
10529
10530 VkEvent event;
10531 VkEventCreateInfo event_create_info = {};
10532 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10533 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010535
Mark Muellerc8d441e2016-08-23 17:36:00 -060010536 EndCommandBuffer();
10537 vkDestroyEvent(m_device->device(), event, nullptr);
10538
10539 VkSubmitInfo submit_info = {};
10540 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10541 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010542 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010544 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10545 m_errorMonitor->VerifyFound();
10546
10547 m_errorMonitor->SetDesiredFailureMsg(0, "");
10548 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10549
10550 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10551
Mark Mueller917f6bc2016-08-30 10:57:19 -060010552 VkSemaphoreCreateInfo semaphore_create_info = {};
10553 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10554 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010555 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010556 VkFenceCreateInfo fence_create_info = {};
10557 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10558 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010559 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010560
10561 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010562 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010563 descriptor_pool_type_count.descriptorCount = 1;
10564
10565 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10566 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10567 descriptor_pool_create_info.maxSets = 1;
10568 descriptor_pool_create_info.poolSizeCount = 1;
10569 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010570 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010571
10572 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010573 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010574
10575 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010576 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010577 descriptorset_layout_binding.descriptorCount = 1;
10578 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10579
10580 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010581 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010582 descriptorset_layout_create_info.bindingCount = 1;
10583 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10584
10585 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010586 ASSERT_VK_SUCCESS(
10587 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010588
10589 VkDescriptorSet descriptorset;
10590 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010591 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010592 descriptorset_allocate_info.descriptorSetCount = 1;
10593 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10594 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010595 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010596
Mark Mueller4042b652016-09-05 22:52:21 -060010597 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10598
10599 VkDescriptorBufferInfo buffer_info = {};
10600 buffer_info.buffer = buffer_test.GetBuffer();
10601 buffer_info.offset = 0;
10602 buffer_info.range = 1024;
10603
10604 VkWriteDescriptorSet write_descriptor_set = {};
10605 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10606 write_descriptor_set.dstSet = descriptorset;
10607 write_descriptor_set.descriptorCount = 1;
10608 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10609 write_descriptor_set.pBufferInfo = &buffer_info;
10610
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010611 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010613 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10614 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010615
10616 VkPipelineObj pipe(m_device);
10617 pipe.AddColorAttachment();
10618 pipe.AddShader(&vs);
10619 pipe.AddShader(&fs);
10620
10621 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010622 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010623 pipeline_layout_create_info.setLayoutCount = 1;
10624 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10625
10626 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010627 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010628
10629 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10630
Mark Muellerc8d441e2016-08-23 17:36:00 -060010631 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010632 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010634 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10635 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10636 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010637
Mark Muellerc8d441e2016-08-23 17:36:00 -060010638 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010639
Mark Mueller917f6bc2016-08-30 10:57:19 -060010640 submit_info.signalSemaphoreCount = 1;
10641 submit_info.pSignalSemaphores = &semaphore;
10642 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010645 vkDestroyEvent(m_device->device(), event, nullptr);
10646 m_errorMonitor->VerifyFound();
10647
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010649 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10650 m_errorMonitor->VerifyFound();
10651
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010653 vkDestroyFence(m_device->device(), fence, nullptr);
10654 m_errorMonitor->VerifyFound();
10655
Tobin Ehlis122207b2016-09-01 08:50:06 -070010656 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010657 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10658 vkDestroyFence(m_device->device(), fence, nullptr);
10659 vkDestroyEvent(m_device->device(), event, nullptr);
10660 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010661 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010662 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10663}
10664
Tobin Ehlis2adda372016-09-01 08:51:06 -070010665TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10666 TEST_DESCRIPTION("Delete in-use query pool.");
10667
10668 ASSERT_NO_FATAL_FAILURE(InitState());
10669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10670
10671 VkQueryPool query_pool;
10672 VkQueryPoolCreateInfo query_pool_ci{};
10673 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10674 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10675 query_pool_ci.queryCount = 1;
10676 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10677 BeginCommandBuffer();
10678 // Reset query pool to create binding with cmd buffer
10679 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10680
10681 EndCommandBuffer();
10682
10683 VkSubmitInfo submit_info = {};
10684 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10685 submit_info.commandBufferCount = 1;
10686 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10687 // Submit cmd buffer and then destroy query pool while in-flight
10688 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10689
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010691 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10692 m_errorMonitor->VerifyFound();
10693
10694 vkQueueWaitIdle(m_device->m_queue);
10695 // Now that cmd buffer done we can safely destroy query_pool
10696 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10697}
10698
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010699TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10700 TEST_DESCRIPTION("Delete in-use pipeline.");
10701
10702 ASSERT_NO_FATAL_FAILURE(InitState());
10703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10704
10705 // Empty pipeline layout used for binding PSO
10706 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10707 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10708 pipeline_layout_ci.setLayoutCount = 0;
10709 pipeline_layout_ci.pSetLayouts = NULL;
10710
10711 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010712 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010713 ASSERT_VK_SUCCESS(err);
10714
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010716 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010717 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10718 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010719 // Store pipeline handle so we can actually delete it before test finishes
10720 VkPipeline delete_this_pipeline;
10721 { // Scope pipeline so it will be auto-deleted
10722 VkPipelineObj pipe(m_device);
10723 pipe.AddShader(&vs);
10724 pipe.AddShader(&fs);
10725 pipe.AddColorAttachment();
10726 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10727 delete_this_pipeline = pipe.handle();
10728
10729 BeginCommandBuffer();
10730 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010731 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010732
10733 EndCommandBuffer();
10734
10735 VkSubmitInfo submit_info = {};
10736 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10737 submit_info.commandBufferCount = 1;
10738 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10739 // Submit cmd buffer and then pipeline destroyed while in-flight
10740 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10741 } // Pipeline deletion triggered here
10742 m_errorMonitor->VerifyFound();
10743 // Make sure queue finished and then actually delete pipeline
10744 vkQueueWaitIdle(m_device->m_queue);
10745 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10746 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10747}
10748
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010749TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10750 TEST_DESCRIPTION("Delete in-use imageView.");
10751
10752 ASSERT_NO_FATAL_FAILURE(InitState());
10753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10754
10755 VkDescriptorPoolSize ds_type_count;
10756 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10757 ds_type_count.descriptorCount = 1;
10758
10759 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10760 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10761 ds_pool_ci.maxSets = 1;
10762 ds_pool_ci.poolSizeCount = 1;
10763 ds_pool_ci.pPoolSizes = &ds_type_count;
10764
10765 VkDescriptorPool ds_pool;
10766 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10767 ASSERT_VK_SUCCESS(err);
10768
10769 VkSamplerCreateInfo sampler_ci = {};
10770 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10771 sampler_ci.pNext = NULL;
10772 sampler_ci.magFilter = VK_FILTER_NEAREST;
10773 sampler_ci.minFilter = VK_FILTER_NEAREST;
10774 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10775 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10776 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10777 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10778 sampler_ci.mipLodBias = 1.0;
10779 sampler_ci.anisotropyEnable = VK_FALSE;
10780 sampler_ci.maxAnisotropy = 1;
10781 sampler_ci.compareEnable = VK_FALSE;
10782 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10783 sampler_ci.minLod = 1.0;
10784 sampler_ci.maxLod = 1.0;
10785 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10786 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10787 VkSampler sampler;
10788
10789 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10790 ASSERT_VK_SUCCESS(err);
10791
10792 VkDescriptorSetLayoutBinding layout_binding;
10793 layout_binding.binding = 0;
10794 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10795 layout_binding.descriptorCount = 1;
10796 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10797 layout_binding.pImmutableSamplers = NULL;
10798
10799 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10800 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10801 ds_layout_ci.bindingCount = 1;
10802 ds_layout_ci.pBindings = &layout_binding;
10803 VkDescriptorSetLayout ds_layout;
10804 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10805 ASSERT_VK_SUCCESS(err);
10806
10807 VkDescriptorSetAllocateInfo alloc_info = {};
10808 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10809 alloc_info.descriptorSetCount = 1;
10810 alloc_info.descriptorPool = ds_pool;
10811 alloc_info.pSetLayouts = &ds_layout;
10812 VkDescriptorSet descriptor_set;
10813 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10814 ASSERT_VK_SUCCESS(err);
10815
10816 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10817 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10818 pipeline_layout_ci.pNext = NULL;
10819 pipeline_layout_ci.setLayoutCount = 1;
10820 pipeline_layout_ci.pSetLayouts = &ds_layout;
10821
10822 VkPipelineLayout pipeline_layout;
10823 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10824 ASSERT_VK_SUCCESS(err);
10825
10826 VkImageObj image(m_device);
10827 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10828 ASSERT_TRUE(image.initialized());
10829
10830 VkImageView view;
10831 VkImageViewCreateInfo ivci = {};
10832 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10833 ivci.image = image.handle();
10834 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10835 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10836 ivci.subresourceRange.layerCount = 1;
10837 ivci.subresourceRange.baseMipLevel = 0;
10838 ivci.subresourceRange.levelCount = 1;
10839 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10840
10841 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10842 ASSERT_VK_SUCCESS(err);
10843
10844 VkDescriptorImageInfo image_info{};
10845 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10846 image_info.imageView = view;
10847 image_info.sampler = sampler;
10848
10849 VkWriteDescriptorSet descriptor_write = {};
10850 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10851 descriptor_write.dstSet = descriptor_set;
10852 descriptor_write.dstBinding = 0;
10853 descriptor_write.descriptorCount = 1;
10854 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10855 descriptor_write.pImageInfo = &image_info;
10856
10857 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10858
10859 // Create PSO to use the sampler
10860 char const *vsSource = "#version 450\n"
10861 "\n"
10862 "out gl_PerVertex { \n"
10863 " vec4 gl_Position;\n"
10864 "};\n"
10865 "void main(){\n"
10866 " gl_Position = vec4(1);\n"
10867 "}\n";
10868 char const *fsSource = "#version 450\n"
10869 "\n"
10870 "layout(set=0, binding=0) uniform sampler2D s;\n"
10871 "layout(location=0) out vec4 x;\n"
10872 "void main(){\n"
10873 " x = texture(s, vec2(1));\n"
10874 "}\n";
10875 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10876 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10877 VkPipelineObj pipe(m_device);
10878 pipe.AddShader(&vs);
10879 pipe.AddShader(&fs);
10880 pipe.AddColorAttachment();
10881 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10882
10883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10884
10885 BeginCommandBuffer();
10886 // Bind pipeline to cmd buffer
10887 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10888 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10889 &descriptor_set, 0, nullptr);
10890 Draw(1, 0, 0, 0);
10891 EndCommandBuffer();
10892 // Submit cmd buffer then destroy sampler
10893 VkSubmitInfo submit_info = {};
10894 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10895 submit_info.commandBufferCount = 1;
10896 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10897 // Submit cmd buffer and then destroy imageView while in-flight
10898 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10899
10900 vkDestroyImageView(m_device->device(), view, nullptr);
10901 m_errorMonitor->VerifyFound();
10902 vkQueueWaitIdle(m_device->m_queue);
10903 // Now we can actually destroy imageView
10904 vkDestroyImageView(m_device->device(), view, NULL);
10905 vkDestroySampler(m_device->device(), sampler, nullptr);
10906 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10907 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10908 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10909}
10910
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010911TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10912 TEST_DESCRIPTION("Delete in-use bufferView.");
10913
10914 ASSERT_NO_FATAL_FAILURE(InitState());
10915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10916
10917 VkDescriptorPoolSize ds_type_count;
10918 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10919 ds_type_count.descriptorCount = 1;
10920
10921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10923 ds_pool_ci.maxSets = 1;
10924 ds_pool_ci.poolSizeCount = 1;
10925 ds_pool_ci.pPoolSizes = &ds_type_count;
10926
10927 VkDescriptorPool ds_pool;
10928 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10929 ASSERT_VK_SUCCESS(err);
10930
10931 VkDescriptorSetLayoutBinding layout_binding;
10932 layout_binding.binding = 0;
10933 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10934 layout_binding.descriptorCount = 1;
10935 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10936 layout_binding.pImmutableSamplers = NULL;
10937
10938 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10939 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10940 ds_layout_ci.bindingCount = 1;
10941 ds_layout_ci.pBindings = &layout_binding;
10942 VkDescriptorSetLayout ds_layout;
10943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10944 ASSERT_VK_SUCCESS(err);
10945
10946 VkDescriptorSetAllocateInfo alloc_info = {};
10947 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10948 alloc_info.descriptorSetCount = 1;
10949 alloc_info.descriptorPool = ds_pool;
10950 alloc_info.pSetLayouts = &ds_layout;
10951 VkDescriptorSet descriptor_set;
10952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10953 ASSERT_VK_SUCCESS(err);
10954
10955 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10956 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10957 pipeline_layout_ci.pNext = NULL;
10958 pipeline_layout_ci.setLayoutCount = 1;
10959 pipeline_layout_ci.pSetLayouts = &ds_layout;
10960
10961 VkPipelineLayout pipeline_layout;
10962 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10963 ASSERT_VK_SUCCESS(err);
10964
10965 VkBuffer buffer;
10966 uint32_t queue_family_index = 0;
10967 VkBufferCreateInfo buffer_create_info = {};
10968 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10969 buffer_create_info.size = 1024;
10970 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10971 buffer_create_info.queueFamilyIndexCount = 1;
10972 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
10973
10974 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
10975 ASSERT_VK_SUCCESS(err);
10976
10977 VkMemoryRequirements memory_reqs;
10978 VkDeviceMemory buffer_memory;
10979
10980 VkMemoryAllocateInfo memory_info = {};
10981 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10982 memory_info.allocationSize = 0;
10983 memory_info.memoryTypeIndex = 0;
10984
10985 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
10986 memory_info.allocationSize = memory_reqs.size;
10987 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
10988 ASSERT_TRUE(pass);
10989
10990 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
10991 ASSERT_VK_SUCCESS(err);
10992 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
10993 ASSERT_VK_SUCCESS(err);
10994
10995 VkBufferView view;
10996 VkBufferViewCreateInfo bvci = {};
10997 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10998 bvci.buffer = buffer;
10999 bvci.format = VK_FORMAT_R8_UNORM;
11000 bvci.range = VK_WHOLE_SIZE;
11001
11002 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11003 ASSERT_VK_SUCCESS(err);
11004
11005 VkWriteDescriptorSet descriptor_write = {};
11006 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11007 descriptor_write.dstSet = descriptor_set;
11008 descriptor_write.dstBinding = 0;
11009 descriptor_write.descriptorCount = 1;
11010 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11011 descriptor_write.pTexelBufferView = &view;
11012
11013 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11014
11015 char const *vsSource = "#version 450\n"
11016 "\n"
11017 "out gl_PerVertex { \n"
11018 " vec4 gl_Position;\n"
11019 "};\n"
11020 "void main(){\n"
11021 " gl_Position = vec4(1);\n"
11022 "}\n";
11023 char const *fsSource = "#version 450\n"
11024 "\n"
11025 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11026 "layout(location=0) out vec4 x;\n"
11027 "void main(){\n"
11028 " x = imageLoad(s, 0);\n"
11029 "}\n";
11030 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11031 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11032 VkPipelineObj pipe(m_device);
11033 pipe.AddShader(&vs);
11034 pipe.AddShader(&fs);
11035 pipe.AddColorAttachment();
11036 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11037
11038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11039
11040 BeginCommandBuffer();
11041 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11042 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11043 VkRect2D scissor = {{0, 0}, {16, 16}};
11044 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11045 // Bind pipeline to cmd buffer
11046 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11047 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11048 &descriptor_set, 0, nullptr);
11049 Draw(1, 0, 0, 0);
11050 EndCommandBuffer();
11051
11052 VkSubmitInfo submit_info = {};
11053 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11054 submit_info.commandBufferCount = 1;
11055 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11056 // Submit cmd buffer and then destroy bufferView while in-flight
11057 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11058
11059 vkDestroyBufferView(m_device->device(), view, nullptr);
11060 m_errorMonitor->VerifyFound();
11061 vkQueueWaitIdle(m_device->m_queue);
11062 // Now we can actually destroy bufferView
11063 vkDestroyBufferView(m_device->device(), view, NULL);
11064 vkDestroyBuffer(m_device->device(), buffer, NULL);
11065 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11066 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11067 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11068 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11069}
11070
Tobin Ehlis209532e2016-09-07 13:52:18 -060011071TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11072 TEST_DESCRIPTION("Delete in-use sampler.");
11073
11074 ASSERT_NO_FATAL_FAILURE(InitState());
11075 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11076
11077 VkDescriptorPoolSize ds_type_count;
11078 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11079 ds_type_count.descriptorCount = 1;
11080
11081 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11082 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11083 ds_pool_ci.maxSets = 1;
11084 ds_pool_ci.poolSizeCount = 1;
11085 ds_pool_ci.pPoolSizes = &ds_type_count;
11086
11087 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011088 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011089 ASSERT_VK_SUCCESS(err);
11090
11091 VkSamplerCreateInfo sampler_ci = {};
11092 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11093 sampler_ci.pNext = NULL;
11094 sampler_ci.magFilter = VK_FILTER_NEAREST;
11095 sampler_ci.minFilter = VK_FILTER_NEAREST;
11096 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11097 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11098 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11099 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11100 sampler_ci.mipLodBias = 1.0;
11101 sampler_ci.anisotropyEnable = VK_FALSE;
11102 sampler_ci.maxAnisotropy = 1;
11103 sampler_ci.compareEnable = VK_FALSE;
11104 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11105 sampler_ci.minLod = 1.0;
11106 sampler_ci.maxLod = 1.0;
11107 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11108 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11109 VkSampler sampler;
11110
11111 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11112 ASSERT_VK_SUCCESS(err);
11113
11114 VkDescriptorSetLayoutBinding layout_binding;
11115 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011116 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011117 layout_binding.descriptorCount = 1;
11118 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11119 layout_binding.pImmutableSamplers = NULL;
11120
11121 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11122 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11123 ds_layout_ci.bindingCount = 1;
11124 ds_layout_ci.pBindings = &layout_binding;
11125 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011127 ASSERT_VK_SUCCESS(err);
11128
11129 VkDescriptorSetAllocateInfo alloc_info = {};
11130 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11131 alloc_info.descriptorSetCount = 1;
11132 alloc_info.descriptorPool = ds_pool;
11133 alloc_info.pSetLayouts = &ds_layout;
11134 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011135 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011136 ASSERT_VK_SUCCESS(err);
11137
11138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11140 pipeline_layout_ci.pNext = NULL;
11141 pipeline_layout_ci.setLayoutCount = 1;
11142 pipeline_layout_ci.pSetLayouts = &ds_layout;
11143
11144 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011145 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011146 ASSERT_VK_SUCCESS(err);
11147
11148 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011149 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 -060011150 ASSERT_TRUE(image.initialized());
11151
11152 VkImageView view;
11153 VkImageViewCreateInfo ivci = {};
11154 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11155 ivci.image = image.handle();
11156 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11157 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11158 ivci.subresourceRange.layerCount = 1;
11159 ivci.subresourceRange.baseMipLevel = 0;
11160 ivci.subresourceRange.levelCount = 1;
11161 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11162
11163 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11164 ASSERT_VK_SUCCESS(err);
11165
11166 VkDescriptorImageInfo image_info{};
11167 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11168 image_info.imageView = view;
11169 image_info.sampler = sampler;
11170
11171 VkWriteDescriptorSet descriptor_write = {};
11172 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11173 descriptor_write.dstSet = descriptor_set;
11174 descriptor_write.dstBinding = 0;
11175 descriptor_write.descriptorCount = 1;
11176 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11177 descriptor_write.pImageInfo = &image_info;
11178
11179 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11180
11181 // Create PSO to use the sampler
11182 char const *vsSource = "#version 450\n"
11183 "\n"
11184 "out gl_PerVertex { \n"
11185 " vec4 gl_Position;\n"
11186 "};\n"
11187 "void main(){\n"
11188 " gl_Position = vec4(1);\n"
11189 "}\n";
11190 char const *fsSource = "#version 450\n"
11191 "\n"
11192 "layout(set=0, binding=0) uniform sampler2D s;\n"
11193 "layout(location=0) out vec4 x;\n"
11194 "void main(){\n"
11195 " x = texture(s, vec2(1));\n"
11196 "}\n";
11197 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11198 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11199 VkPipelineObj pipe(m_device);
11200 pipe.AddShader(&vs);
11201 pipe.AddShader(&fs);
11202 pipe.AddColorAttachment();
11203 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011206
11207 BeginCommandBuffer();
11208 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011209 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11210 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11211 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011212 Draw(1, 0, 0, 0);
11213 EndCommandBuffer();
11214 // Submit cmd buffer then destroy sampler
11215 VkSubmitInfo submit_info = {};
11216 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11217 submit_info.commandBufferCount = 1;
11218 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11219 // Submit cmd buffer and then destroy sampler while in-flight
11220 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11221
11222 vkDestroySampler(m_device->device(), sampler, nullptr);
11223 m_errorMonitor->VerifyFound();
11224 vkQueueWaitIdle(m_device->m_queue);
11225 // Now we can actually destroy sampler
11226 vkDestroySampler(m_device->device(), sampler, nullptr);
11227 vkDestroyImageView(m_device->device(), view, NULL);
11228 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11229 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11230 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11231}
11232
Mark Mueller1cd9f412016-08-25 13:23:52 -060011233TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011234 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011235 "signaled but not waited on by the queue. Wait on a "
11236 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011237
11238 ASSERT_NO_FATAL_FAILURE(InitState());
11239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011241 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11242 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11243 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011244
11245 BeginCommandBuffer();
11246 EndCommandBuffer();
11247
11248 VkSemaphoreCreateInfo semaphore_create_info = {};
11249 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11250 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011251 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011252 VkSubmitInfo submit_info = {};
11253 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11254 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011255 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011256 submit_info.signalSemaphoreCount = 1;
11257 submit_info.pSignalSemaphores = &semaphore;
11258 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11259 m_errorMonitor->SetDesiredFailureMsg(0, "");
11260 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11261 BeginCommandBuffer();
11262 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011264 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11265 m_errorMonitor->VerifyFound();
11266
Mark Mueller1cd9f412016-08-25 13:23:52 -060011267 VkFenceCreateInfo fence_create_info = {};
11268 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11269 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011270 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011273 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11274 m_errorMonitor->VerifyFound();
11275
Mark Mueller4042b652016-09-05 22:52:21 -060011276 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011277 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011278 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11279}
11280
Tobin Ehlis4af23302016-07-19 10:50:30 -060011281TEST_F(VkLayerTest, FramebufferIncompatible) {
11282 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11283 "that does not match the framebuffer for the active "
11284 "renderpass.");
11285 ASSERT_NO_FATAL_FAILURE(InitState());
11286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11287
11288 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011289 VkAttachmentDescription attachment = {0,
11290 VK_FORMAT_B8G8R8A8_UNORM,
11291 VK_SAMPLE_COUNT_1_BIT,
11292 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11293 VK_ATTACHMENT_STORE_OP_STORE,
11294 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11295 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11296 VK_IMAGE_LAYOUT_UNDEFINED,
11297 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011299 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011301 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011303 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011304
11305 VkRenderPass rp;
11306 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11307 ASSERT_VK_SUCCESS(err);
11308
11309 // A compatible framebuffer.
11310 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011311 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 -060011312 ASSERT_TRUE(image.initialized());
11313
11314 VkImageViewCreateInfo ivci = {
11315 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11316 nullptr,
11317 0,
11318 image.handle(),
11319 VK_IMAGE_VIEW_TYPE_2D,
11320 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011321 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11322 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011323 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11324 };
11325 VkImageView view;
11326 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11327 ASSERT_VK_SUCCESS(err);
11328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011329 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011330 VkFramebuffer fb;
11331 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11332 ASSERT_VK_SUCCESS(err);
11333
11334 VkCommandBufferAllocateInfo cbai = {};
11335 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11336 cbai.commandPool = m_commandPool;
11337 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11338 cbai.commandBufferCount = 1;
11339
11340 VkCommandBuffer sec_cb;
11341 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11342 ASSERT_VK_SUCCESS(err);
11343 VkCommandBufferBeginInfo cbbi = {};
11344 VkCommandBufferInheritanceInfo cbii = {};
11345 cbii.renderPass = renderPass();
11346 cbii.framebuffer = fb;
11347 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11348 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011349 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 -060011350 cbbi.pInheritanceInfo = &cbii;
11351 vkBeginCommandBuffer(sec_cb, &cbbi);
11352 vkEndCommandBuffer(sec_cb);
11353
Chris Forbes3400bc52016-09-13 18:10:34 +120011354 VkCommandBufferBeginInfo cbbi2 = {
11355 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11356 0, nullptr
11357 };
11358 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11359 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011360
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011362 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011363 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11364 m_errorMonitor->VerifyFound();
11365 // Cleanup
11366 vkDestroyImageView(m_device->device(), view, NULL);
11367 vkDestroyRenderPass(m_device->device(), rp, NULL);
11368 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11369}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011370
11371TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11372 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11373 "invalid value. If logicOp is not available, attempt to "
11374 "use it and verify that we see the correct error.");
11375 ASSERT_NO_FATAL_FAILURE(InitState());
11376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11377
11378 auto features = m_device->phy().features();
11379 // Set the expected error depending on whether or not logicOp available
11380 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11382 "enabled, logicOpEnable must be "
11383 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011384 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011386 }
11387 // Create a pipeline using logicOp
11388 VkResult err;
11389
11390 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11391 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11392
11393 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011394 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011395 ASSERT_VK_SUCCESS(err);
11396
11397 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11398 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11399 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011400 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011401 vp_state_ci.pViewports = &vp;
11402 vp_state_ci.scissorCount = 1;
11403 VkRect2D scissors = {}; // Dummy scissors to point to
11404 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011405
11406 VkPipelineShaderStageCreateInfo shaderStages[2];
11407 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011409 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11410 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011411 shaderStages[0] = vs.GetStageCreateInfo();
11412 shaderStages[1] = fs.GetStageCreateInfo();
11413
11414 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11415 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11416
11417 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11418 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11419 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11420
11421 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11422 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011423 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011424
11425 VkPipelineColorBlendAttachmentState att = {};
11426 att.blendEnable = VK_FALSE;
11427 att.colorWriteMask = 0xf;
11428
11429 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11430 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11431 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11432 cb_ci.logicOpEnable = VK_TRUE;
11433 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11434 cb_ci.attachmentCount = 1;
11435 cb_ci.pAttachments = &att;
11436
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011437 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11438 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11439 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11440
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011441 VkGraphicsPipelineCreateInfo gp_ci = {};
11442 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11443 gp_ci.stageCount = 2;
11444 gp_ci.pStages = shaderStages;
11445 gp_ci.pVertexInputState = &vi_ci;
11446 gp_ci.pInputAssemblyState = &ia_ci;
11447 gp_ci.pViewportState = &vp_state_ci;
11448 gp_ci.pRasterizationState = &rs_ci;
11449 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011450 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011451 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11452 gp_ci.layout = pipeline_layout;
11453 gp_ci.renderPass = renderPass();
11454
11455 VkPipelineCacheCreateInfo pc_ci = {};
11456 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11457
11458 VkPipeline pipeline;
11459 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011460 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011461 ASSERT_VK_SUCCESS(err);
11462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011463 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011464 m_errorMonitor->VerifyFound();
11465 if (VK_SUCCESS == err) {
11466 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11467 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011468 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11469 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11470}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011471#endif // DRAW_STATE_TESTS
11472
Tobin Ehlis0788f522015-05-26 16:11:58 -060011473#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011474#if GTEST_IS_THREADSAFE
11475struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011476 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011477 VkEvent event;
11478 bool bailout;
11479};
11480
Karl Schultz6addd812016-02-02 17:17:23 -070011481extern "C" void *AddToCommandBuffer(void *arg) {
11482 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011483
Mike Stroyana6d14942016-07-13 15:10:05 -060011484 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011485 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011486 if (data->bailout) {
11487 break;
11488 }
11489 }
11490 return NULL;
11491}
11492
Karl Schultz6addd812016-02-02 17:17:23 -070011493TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011494 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011497
Mike Stroyanaccf7692015-05-12 16:00:45 -060011498 ASSERT_NO_FATAL_FAILURE(InitState());
11499 ASSERT_NO_FATAL_FAILURE(InitViewport());
11500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11501
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011502 // Calls AllocateCommandBuffers
11503 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011504
11505 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011506 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011507
11508 VkEventCreateInfo event_info;
11509 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011510 VkResult err;
11511
11512 memset(&event_info, 0, sizeof(event_info));
11513 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11514
Chia-I Wuf7458c52015-10-26 21:10:41 +080011515 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011516 ASSERT_VK_SUCCESS(err);
11517
Mike Stroyanaccf7692015-05-12 16:00:45 -060011518 err = vkResetEvent(device(), event);
11519 ASSERT_VK_SUCCESS(err);
11520
11521 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011522 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011523 data.event = event;
11524 data.bailout = false;
11525 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011526
11527 // First do some correct operations using multiple threads.
11528 // Add many entries to command buffer from another thread.
11529 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11530 // Make non-conflicting calls from this thread at the same time.
11531 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011532 uint32_t count;
11533 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011534 }
11535 test_platform_thread_join(thread, NULL);
11536
11537 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011538 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011539 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011540 // Add many entries to command buffer from this thread at the same time.
11541 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011542
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011543 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011544 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011545
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011546 m_errorMonitor->SetBailout(NULL);
11547
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011548 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011549
Chia-I Wuf7458c52015-10-26 21:10:41 +080011550 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011551}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011552#endif // GTEST_IS_THREADSAFE
11553#endif // THREADING_TESTS
11554
Chris Forbes9f7ff632015-05-25 11:13:08 +120011555#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011556TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011557 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11558 "with an impossible code size");
11559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011561
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011562 ASSERT_NO_FATAL_FAILURE(InitState());
11563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11564
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011565 VkShaderModule module;
11566 VkShaderModuleCreateInfo moduleCreateInfo;
11567 struct icd_spv_header spv;
11568
11569 spv.magic = ICD_SPV_MAGIC;
11570 spv.version = ICD_SPV_VERSION;
11571 spv.gen_magic = 0;
11572
11573 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11574 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011575 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011576 moduleCreateInfo.codeSize = 4;
11577 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011578 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011579
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011580 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011581}
11582
Karl Schultz6addd812016-02-02 17:17:23 -070011583TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011584 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11585 "with a bad magic number");
11586
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011588
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011589 ASSERT_NO_FATAL_FAILURE(InitState());
11590 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11591
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011592 VkShaderModule module;
11593 VkShaderModuleCreateInfo moduleCreateInfo;
11594 struct icd_spv_header spv;
11595
11596 spv.magic = ~ICD_SPV_MAGIC;
11597 spv.version = ICD_SPV_VERSION;
11598 spv.gen_magic = 0;
11599
11600 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11601 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011602 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011603 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11604 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011605 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011606
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011607 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011608}
11609
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011610#if 0
11611// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011612TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011614 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011615
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011616 ASSERT_NO_FATAL_FAILURE(InitState());
11617 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11618
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011619 VkShaderModule module;
11620 VkShaderModuleCreateInfo moduleCreateInfo;
11621 struct icd_spv_header spv;
11622
11623 spv.magic = ICD_SPV_MAGIC;
11624 spv.version = ~ICD_SPV_VERSION;
11625 spv.gen_magic = 0;
11626
11627 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11628 moduleCreateInfo.pNext = NULL;
11629
Karl Schultz6addd812016-02-02 17:17:23 -070011630 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011631 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11632 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011633 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011634
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011635 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011636}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011637#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011638
Karl Schultz6addd812016-02-02 17:17:23 -070011639TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011640 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11641 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011643
Chris Forbes9f7ff632015-05-25 11:13:08 +120011644 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011647 char const *vsSource = "#version 450\n"
11648 "\n"
11649 "layout(location=0) out float x;\n"
11650 "out gl_PerVertex {\n"
11651 " vec4 gl_Position;\n"
11652 "};\n"
11653 "void main(){\n"
11654 " gl_Position = vec4(1);\n"
11655 " x = 0;\n"
11656 "}\n";
11657 char const *fsSource = "#version 450\n"
11658 "\n"
11659 "layout(location=0) out vec4 color;\n"
11660 "void main(){\n"
11661 " color = vec4(1);\n"
11662 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011663
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011664 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11665 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011666
11667 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011668 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011669 pipe.AddShader(&vs);
11670 pipe.AddShader(&fs);
11671
Chris Forbes9f7ff632015-05-25 11:13:08 +120011672 VkDescriptorSetObj descriptorSet(m_device);
11673 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011674 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011675
Tony Barbour5781e8f2015-08-04 16:23:11 -060011676 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011677
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011678 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011679}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011680
Mark Mueller098c9cb2016-09-08 09:01:57 -060011681TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11682 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11683
11684 ASSERT_NO_FATAL_FAILURE(InitState());
11685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11686
11687 const char *bad_specialization_message =
11688 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11689
11690 char const *vsSource =
11691 "#version 450\n"
11692 "\n"
11693 "out gl_PerVertex {\n"
11694 " vec4 gl_Position;\n"
11695 "};\n"
11696 "void main(){\n"
11697 " gl_Position = vec4(1);\n"
11698 "}\n";
11699
11700 char const *fsSource =
11701 "#version 450\n"
11702 "\n"
11703 "layout (constant_id = 0) const float r = 0.0f;\n"
11704 "layout(location = 0) out vec4 uFragColor;\n"
11705 "void main(){\n"
11706 " uFragColor = vec4(r,1,0,1);\n"
11707 "}\n";
11708
11709 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11710 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11711
11712 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11713 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11714
11715 VkPipelineLayout pipeline_layout;
11716 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11717
11718 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11719 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11720 vp_state_create_info.viewportCount = 1;
11721 VkViewport viewport = {};
11722 vp_state_create_info.pViewports = &viewport;
11723 vp_state_create_info.scissorCount = 1;
11724 VkRect2D scissors = {};
11725 vp_state_create_info.pScissors = &scissors;
11726
11727 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11728
11729 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11730 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11731 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11732 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11733
11734 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11735 vs.GetStageCreateInfo(),
11736 fs.GetStageCreateInfo()
11737 };
11738
11739 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11740 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11741
11742 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11743 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11744 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11745
11746 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11747 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11748 rasterization_state_create_info.pNext = nullptr;
11749 rasterization_state_create_info.lineWidth = 1.0f;
11750 rasterization_state_create_info.rasterizerDiscardEnable = true;
11751
11752 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11753 color_blend_attachment_state.blendEnable = VK_FALSE;
11754 color_blend_attachment_state.colorWriteMask = 0xf;
11755
11756 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11757 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11758 color_blend_state_create_info.attachmentCount = 1;
11759 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11760
11761 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11762 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11763 graphicspipe_create_info.stageCount = 2;
11764 graphicspipe_create_info.pStages = shader_stage_create_info;
11765 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11766 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11767 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11768 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11769 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11770 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11771 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11772 graphicspipe_create_info.layout = pipeline_layout;
11773 graphicspipe_create_info.renderPass = renderPass();
11774
11775 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11776 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11777
11778 VkPipelineCache pipelineCache;
11779 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11780
11781 // This structure maps constant ids to data locations.
11782 const VkSpecializationMapEntry entry =
11783 // id, offset, size
11784 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11785
11786 uint32_t data = 1;
11787
11788 // Set up the info describing spec map and data
11789 const VkSpecializationInfo specialization_info = {
11790 1,
11791 &entry,
11792 1 * sizeof(float),
11793 &data,
11794 };
11795 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11796
11797 VkPipeline pipeline;
11798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11799 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11800 m_errorMonitor->VerifyFound();
11801
11802 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11803 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11804}
11805
11806TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11807 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11808
11809 ASSERT_NO_FATAL_FAILURE(InitState());
11810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11811
11812 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11813
11814 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11815 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11816 descriptor_pool_type_count[0].descriptorCount = 1;
11817 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11818 descriptor_pool_type_count[1].descriptorCount = 1;
11819
11820 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11821 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11822 descriptor_pool_create_info.maxSets = 1;
11823 descriptor_pool_create_info.poolSizeCount = 2;
11824 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11825 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11826
11827 VkDescriptorPool descriptorset_pool;
11828 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11829
11830 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11831 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11832 descriptorset_layout_binding.descriptorCount = 1;
11833 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11834
11835 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11836 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11837 descriptorset_layout_create_info.bindingCount = 1;
11838 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11839
11840 VkDescriptorSetLayout descriptorset_layout;
11841 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11842
11843 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11844 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11845 descriptorset_allocate_info.descriptorSetCount = 1;
11846 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11847 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11848 VkDescriptorSet descriptorset;
11849 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11850
11851 // Challenge core_validation with a non uniform buffer type.
11852 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11853
Mark Mueller098c9cb2016-09-08 09:01:57 -060011854 char const *vsSource =
11855 "#version 450\n"
11856 "\n"
11857 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11858 " mat4 mvp;\n"
11859 "} ubuf;\n"
11860 "out gl_PerVertex {\n"
11861 " vec4 gl_Position;\n"
11862 "};\n"
11863 "void main(){\n"
11864 " gl_Position = ubuf.mvp * vec4(1);\n"
11865 "}\n";
11866
11867 char const *fsSource =
11868 "#version 450\n"
11869 "\n"
11870 "layout(location = 0) out vec4 uFragColor;\n"
11871 "void main(){\n"
11872 " uFragColor = vec4(0,1,0,1);\n"
11873 "}\n";
11874
11875 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11876 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11877
11878 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11879 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11880 pipeline_layout_create_info.setLayoutCount = 1;
11881 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11882
11883 VkPipelineLayout pipeline_layout;
11884 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11885
11886 VkPipelineObj pipe(m_device);
11887 pipe.AddColorAttachment();
11888 pipe.AddShader(&vs);
11889 pipe.AddShader(&fs);
11890
11891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11892 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11893 m_errorMonitor->VerifyFound();
11894
11895 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11896 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11897 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11898}
11899
11900TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11901 TEST_DESCRIPTION(
11902 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11903
11904 ASSERT_NO_FATAL_FAILURE(InitState());
11905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11906
11907 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11908
11909 VkDescriptorPoolSize descriptor_pool_type_count = {};
11910 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11911 descriptor_pool_type_count.descriptorCount = 1;
11912
11913 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11914 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11915 descriptor_pool_create_info.maxSets = 1;
11916 descriptor_pool_create_info.poolSizeCount = 1;
11917 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11918 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11919
11920 VkDescriptorPool descriptorset_pool;
11921 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11922
11923 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11924 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11925 descriptorset_layout_binding.descriptorCount = 1;
11926 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11927 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11928
11929 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11930 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11931 descriptorset_layout_create_info.bindingCount = 1;
11932 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11933
11934 VkDescriptorSetLayout descriptorset_layout;
11935 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11936 nullptr, &descriptorset_layout));
11937
11938 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11939 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11940 descriptorset_allocate_info.descriptorSetCount = 1;
11941 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11942 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11943 VkDescriptorSet descriptorset;
11944 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11945
11946 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11947
Mark Mueller098c9cb2016-09-08 09:01:57 -060011948 char const *vsSource =
11949 "#version 450\n"
11950 "\n"
11951 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11952 " mat4 mvp;\n"
11953 "} ubuf;\n"
11954 "out gl_PerVertex {\n"
11955 " vec4 gl_Position;\n"
11956 "};\n"
11957 "void main(){\n"
11958 " gl_Position = ubuf.mvp * vec4(1);\n"
11959 "}\n";
11960
11961 char const *fsSource =
11962 "#version 450\n"
11963 "\n"
11964 "layout(location = 0) out vec4 uFragColor;\n"
11965 "void main(){\n"
11966 " uFragColor = vec4(0,1,0,1);\n"
11967 "}\n";
11968
11969 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11970 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11971
11972 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11973 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11974 pipeline_layout_create_info.setLayoutCount = 1;
11975 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11976
11977 VkPipelineLayout pipeline_layout;
11978 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11979
11980 VkPipelineObj pipe(m_device);
11981 pipe.AddColorAttachment();
11982 pipe.AddShader(&vs);
11983 pipe.AddShader(&fs);
11984
11985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
11986 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11987 m_errorMonitor->VerifyFound();
11988
11989 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11990 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11991 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11992}
11993
11994TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
11995 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
11996 "accessible from the current shader stage.");
11997
11998 ASSERT_NO_FATAL_FAILURE(InitState());
11999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12000
12001 const char *push_constant_not_accessible_message =
12002 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12003
12004 char const *vsSource =
12005 "#version 450\n"
12006 "\n"
12007 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12008 "out gl_PerVertex {\n"
12009 " vec4 gl_Position;\n"
12010 "};\n"
12011 "void main(){\n"
12012 " gl_Position = vec4(consts.x);\n"
12013 "}\n";
12014
12015 char const *fsSource =
12016 "#version 450\n"
12017 "\n"
12018 "layout(location = 0) out vec4 uFragColor;\n"
12019 "void main(){\n"
12020 " uFragColor = vec4(0,1,0,1);\n"
12021 "}\n";
12022
12023 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12024 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12025
12026 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12027 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12028
12029 // Set up a push constant range
12030 VkPushConstantRange push_constant_ranges = {};
12031 // Set to the wrong stage to challenge core_validation
12032 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12033 push_constant_ranges.size = 4;
12034
12035 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12036 pipeline_layout_create_info.pushConstantRangeCount = 1;
12037
12038 VkPipelineLayout pipeline_layout;
12039 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12040
12041 VkPipelineObj pipe(m_device);
12042 pipe.AddColorAttachment();
12043 pipe.AddShader(&vs);
12044 pipe.AddShader(&fs);
12045
12046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12047 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12048 m_errorMonitor->VerifyFound();
12049
12050 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12051}
12052
12053TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12054 TEST_DESCRIPTION(
12055 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12056
12057 ASSERT_NO_FATAL_FAILURE(InitState());
12058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12059
12060 const char *feature_not_enabled_message =
12061 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12062
12063 // Some awkward steps are required to test with custom device features.
12064 std::vector<const char *> device_extension_names;
12065 auto features = m_device->phy().features();
12066 // Disable support for 64 bit floats
12067 features.shaderFloat64 = false;
12068 // The sacrificial device object
12069 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12070
12071 char const *vsSource = "#version 450\n"
12072 "\n"
12073 "out gl_PerVertex {\n"
12074 " vec4 gl_Position;\n"
12075 "};\n"
12076 "void main(){\n"
12077 " gl_Position = vec4(1);\n"
12078 "}\n";
12079 char const *fsSource = "#version 450\n"
12080 "\n"
12081 "layout(location=0) out vec4 color;\n"
12082 "void main(){\n"
12083 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12084 " color = vec4(green);\n"
12085 "}\n";
12086
12087 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12088 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12089
12090 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012091
12092 VkPipelineObj pipe(&test_device);
12093 pipe.AddColorAttachment();
12094 pipe.AddShader(&vs);
12095 pipe.AddShader(&fs);
12096
12097 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12098 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12099 VkPipelineLayout pipeline_layout;
12100 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12101
12102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12103 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12104 m_errorMonitor->VerifyFound();
12105
12106 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12107}
12108
12109TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12110 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12111
12112 ASSERT_NO_FATAL_FAILURE(InitState());
12113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12114
12115 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12116
12117 char const *vsSource = "#version 450\n"
12118 "\n"
12119 "out gl_PerVertex {\n"
12120 " vec4 gl_Position;\n"
12121 "};\n"
12122 "layout(xfb_buffer = 1) out;"
12123 "void main(){\n"
12124 " gl_Position = vec4(1);\n"
12125 "}\n";
12126 char const *fsSource = "#version 450\n"
12127 "\n"
12128 "layout(location=0) out vec4 color;\n"
12129 "void main(){\n"
12130 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12131 " color = vec4(green);\n"
12132 "}\n";
12133
12134 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12135 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12136
12137 VkPipelineObj pipe(m_device);
12138 pipe.AddColorAttachment();
12139 pipe.AddShader(&vs);
12140 pipe.AddShader(&fs);
12141
12142 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12143 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12144 VkPipelineLayout pipeline_layout;
12145 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12146
12147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12148 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12149 m_errorMonitor->VerifyFound();
12150
12151 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12152}
12153
Karl Schultz6addd812016-02-02 17:17:23 -070012154TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012155 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12156 "which is not present in the outputs of the previous stage");
12157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012159
Chris Forbes59cb88d2015-05-25 11:13:13 +120012160 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012162
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012163 char const *vsSource = "#version 450\n"
12164 "\n"
12165 "out gl_PerVertex {\n"
12166 " vec4 gl_Position;\n"
12167 "};\n"
12168 "void main(){\n"
12169 " gl_Position = vec4(1);\n"
12170 "}\n";
12171 char const *fsSource = "#version 450\n"
12172 "\n"
12173 "layout(location=0) in float x;\n"
12174 "layout(location=0) out vec4 color;\n"
12175 "void main(){\n"
12176 " color = vec4(x);\n"
12177 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012178
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012179 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12180 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012181
12182 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012183 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012184 pipe.AddShader(&vs);
12185 pipe.AddShader(&fs);
12186
Chris Forbes59cb88d2015-05-25 11:13:13 +120012187 VkDescriptorSetObj descriptorSet(m_device);
12188 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012189 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012190
Tony Barbour5781e8f2015-08-04 16:23:11 -060012191 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012192
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012193 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012194}
12195
Karl Schultz6addd812016-02-02 17:17:23 -070012196TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012197 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12198 "within an interace block, which is not present in the outputs "
12199 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012201
12202 ASSERT_NO_FATAL_FAILURE(InitState());
12203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012205 char const *vsSource = "#version 450\n"
12206 "\n"
12207 "out gl_PerVertex {\n"
12208 " vec4 gl_Position;\n"
12209 "};\n"
12210 "void main(){\n"
12211 " gl_Position = vec4(1);\n"
12212 "}\n";
12213 char const *fsSource = "#version 450\n"
12214 "\n"
12215 "in block { layout(location=0) float x; } ins;\n"
12216 "layout(location=0) out vec4 color;\n"
12217 "void main(){\n"
12218 " color = vec4(ins.x);\n"
12219 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012220
12221 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12222 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12223
12224 VkPipelineObj pipe(m_device);
12225 pipe.AddColorAttachment();
12226 pipe.AddShader(&vs);
12227 pipe.AddShader(&fs);
12228
12229 VkDescriptorSetObj descriptorSet(m_device);
12230 descriptorSet.AppendDummy();
12231 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12232
12233 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012235 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012236}
12237
Karl Schultz6addd812016-02-02 17:17:23 -070012238TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012239 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012240 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12242 "output arr[2] of float32' vs 'ptr to "
12243 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012244
12245 ASSERT_NO_FATAL_FAILURE(InitState());
12246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12247
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012248 char const *vsSource = "#version 450\n"
12249 "\n"
12250 "layout(location=0) out float x[2];\n"
12251 "out gl_PerVertex {\n"
12252 " vec4 gl_Position;\n"
12253 "};\n"
12254 "void main(){\n"
12255 " x[0] = 0; x[1] = 0;\n"
12256 " gl_Position = vec4(1);\n"
12257 "}\n";
12258 char const *fsSource = "#version 450\n"
12259 "\n"
12260 "layout(location=0) in float x[3];\n"
12261 "layout(location=0) out vec4 color;\n"
12262 "void main(){\n"
12263 " color = vec4(x[0] + x[1] + x[2]);\n"
12264 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012265
12266 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12267 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12268
12269 VkPipelineObj pipe(m_device);
12270 pipe.AddColorAttachment();
12271 pipe.AddShader(&vs);
12272 pipe.AddShader(&fs);
12273
12274 VkDescriptorSetObj descriptorSet(m_device);
12275 descriptorSet.AppendDummy();
12276 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12277
12278 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12279
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012280 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012281}
12282
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012283
Karl Schultz6addd812016-02-02 17:17:23 -070012284TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012285 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012286 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012288
Chris Forbesb56af562015-05-25 11:13:17 +120012289 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012291
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012292 char const *vsSource = "#version 450\n"
12293 "\n"
12294 "layout(location=0) out int x;\n"
12295 "out gl_PerVertex {\n"
12296 " vec4 gl_Position;\n"
12297 "};\n"
12298 "void main(){\n"
12299 " x = 0;\n"
12300 " gl_Position = vec4(1);\n"
12301 "}\n";
12302 char const *fsSource = "#version 450\n"
12303 "\n"
12304 "layout(location=0) in float x;\n" /* VS writes int */
12305 "layout(location=0) out vec4 color;\n"
12306 "void main(){\n"
12307 " color = vec4(x);\n"
12308 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012309
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012310 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12311 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012312
12313 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012314 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012315 pipe.AddShader(&vs);
12316 pipe.AddShader(&fs);
12317
Chris Forbesb56af562015-05-25 11:13:17 +120012318 VkDescriptorSetObj descriptorSet(m_device);
12319 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012320 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012321
Tony Barbour5781e8f2015-08-04 16:23:11 -060012322 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012323
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012324 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012325}
12326
Karl Schultz6addd812016-02-02 17:17:23 -070012327TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012328 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012329 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012330 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012332
12333 ASSERT_NO_FATAL_FAILURE(InitState());
12334 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012336 char const *vsSource = "#version 450\n"
12337 "\n"
12338 "out block { layout(location=0) int x; } outs;\n"
12339 "out gl_PerVertex {\n"
12340 " vec4 gl_Position;\n"
12341 "};\n"
12342 "void main(){\n"
12343 " outs.x = 0;\n"
12344 " gl_Position = vec4(1);\n"
12345 "}\n";
12346 char const *fsSource = "#version 450\n"
12347 "\n"
12348 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12349 "layout(location=0) out vec4 color;\n"
12350 "void main(){\n"
12351 " color = vec4(ins.x);\n"
12352 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012353
12354 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12355 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12356
12357 VkPipelineObj pipe(m_device);
12358 pipe.AddColorAttachment();
12359 pipe.AddShader(&vs);
12360 pipe.AddShader(&fs);
12361
12362 VkDescriptorSetObj descriptorSet(m_device);
12363 descriptorSet.AppendDummy();
12364 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12365
12366 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12367
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012368 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012369}
12370
12371TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012372 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012373 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012374 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012375 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 +130012376
12377 ASSERT_NO_FATAL_FAILURE(InitState());
12378 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012380 char const *vsSource = "#version 450\n"
12381 "\n"
12382 "out block { layout(location=1) float x; } outs;\n"
12383 "out gl_PerVertex {\n"
12384 " vec4 gl_Position;\n"
12385 "};\n"
12386 "void main(){\n"
12387 " outs.x = 0;\n"
12388 " gl_Position = vec4(1);\n"
12389 "}\n";
12390 char const *fsSource = "#version 450\n"
12391 "\n"
12392 "in block { layout(location=0) float x; } ins;\n"
12393 "layout(location=0) out vec4 color;\n"
12394 "void main(){\n"
12395 " color = vec4(ins.x);\n"
12396 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012397
12398 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12399 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12400
12401 VkPipelineObj pipe(m_device);
12402 pipe.AddColorAttachment();
12403 pipe.AddShader(&vs);
12404 pipe.AddShader(&fs);
12405
12406 VkDescriptorSetObj descriptorSet(m_device);
12407 descriptorSet.AppendDummy();
12408 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12409
12410 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12411
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012412 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012413}
12414
12415TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012416 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012417 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012418 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012419 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 +130012420
12421 ASSERT_NO_FATAL_FAILURE(InitState());
12422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12423
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012424 char const *vsSource = "#version 450\n"
12425 "\n"
12426 "out block { layout(location=0, component=0) float x; } outs;\n"
12427 "out gl_PerVertex {\n"
12428 " vec4 gl_Position;\n"
12429 "};\n"
12430 "void main(){\n"
12431 " outs.x = 0;\n"
12432 " gl_Position = vec4(1);\n"
12433 "}\n";
12434 char const *fsSource = "#version 450\n"
12435 "\n"
12436 "in block { layout(location=0, component=1) float x; } ins;\n"
12437 "layout(location=0) out vec4 color;\n"
12438 "void main(){\n"
12439 " color = vec4(ins.x);\n"
12440 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012441
12442 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12443 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12444
12445 VkPipelineObj pipe(m_device);
12446 pipe.AddColorAttachment();
12447 pipe.AddShader(&vs);
12448 pipe.AddShader(&fs);
12449
12450 VkDescriptorSetObj descriptorSet(m_device);
12451 descriptorSet.AppendDummy();
12452 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12453
12454 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12455
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012456 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012457}
12458
Karl Schultz6addd812016-02-02 17:17:23 -070012459TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012460 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12461 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012463
Chris Forbesde136e02015-05-25 11:13:28 +120012464 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012466
12467 VkVertexInputBindingDescription input_binding;
12468 memset(&input_binding, 0, sizeof(input_binding));
12469
12470 VkVertexInputAttributeDescription input_attrib;
12471 memset(&input_attrib, 0, sizeof(input_attrib));
12472 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012474 char const *vsSource = "#version 450\n"
12475 "\n"
12476 "out gl_PerVertex {\n"
12477 " vec4 gl_Position;\n"
12478 "};\n"
12479 "void main(){\n"
12480 " gl_Position = vec4(1);\n"
12481 "}\n";
12482 char const *fsSource = "#version 450\n"
12483 "\n"
12484 "layout(location=0) out vec4 color;\n"
12485 "void main(){\n"
12486 " color = vec4(1);\n"
12487 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012488
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012489 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12490 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012491
12492 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012493 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012494 pipe.AddShader(&vs);
12495 pipe.AddShader(&fs);
12496
12497 pipe.AddVertexInputBindings(&input_binding, 1);
12498 pipe.AddVertexInputAttribs(&input_attrib, 1);
12499
Chris Forbesde136e02015-05-25 11:13:28 +120012500 VkDescriptorSetObj descriptorSet(m_device);
12501 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012502 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012503
Tony Barbour5781e8f2015-08-04 16:23:11 -060012504 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012505
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012506 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012507}
12508
Karl Schultz6addd812016-02-02 17:17:23 -070012509TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012510 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12511 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012513
12514 ASSERT_NO_FATAL_FAILURE(InitState());
12515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12516
12517 VkVertexInputBindingDescription input_binding;
12518 memset(&input_binding, 0, sizeof(input_binding));
12519
12520 VkVertexInputAttributeDescription input_attrib;
12521 memset(&input_attrib, 0, sizeof(input_attrib));
12522 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012524 char const *vsSource = "#version 450\n"
12525 "\n"
12526 "layout(location=1) in float x;\n"
12527 "out gl_PerVertex {\n"
12528 " vec4 gl_Position;\n"
12529 "};\n"
12530 "void main(){\n"
12531 " gl_Position = vec4(x);\n"
12532 "}\n";
12533 char const *fsSource = "#version 450\n"
12534 "\n"
12535 "layout(location=0) out vec4 color;\n"
12536 "void main(){\n"
12537 " color = vec4(1);\n"
12538 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012539
12540 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12541 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12542
12543 VkPipelineObj pipe(m_device);
12544 pipe.AddColorAttachment();
12545 pipe.AddShader(&vs);
12546 pipe.AddShader(&fs);
12547
12548 pipe.AddVertexInputBindings(&input_binding, 1);
12549 pipe.AddVertexInputAttribs(&input_attrib, 1);
12550
12551 VkDescriptorSetObj descriptorSet(m_device);
12552 descriptorSet.AppendDummy();
12553 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12554
12555 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12556
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012557 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012558}
12559
Karl Schultz6addd812016-02-02 17:17:23 -070012560TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012561 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012562 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012563 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 -060012564
Chris Forbes62e8e502015-05-25 11:13:29 +120012565 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012568 char const *vsSource = "#version 450\n"
12569 "\n"
12570 "layout(location=0) in vec4 x;\n" /* not provided */
12571 "out gl_PerVertex {\n"
12572 " vec4 gl_Position;\n"
12573 "};\n"
12574 "void main(){\n"
12575 " gl_Position = x;\n"
12576 "}\n";
12577 char const *fsSource = "#version 450\n"
12578 "\n"
12579 "layout(location=0) out vec4 color;\n"
12580 "void main(){\n"
12581 " color = vec4(1);\n"
12582 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012583
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012584 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12585 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012586
12587 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012588 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012589 pipe.AddShader(&vs);
12590 pipe.AddShader(&fs);
12591
Chris Forbes62e8e502015-05-25 11:13:29 +120012592 VkDescriptorSetObj descriptorSet(m_device);
12593 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012594 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012595
Tony Barbour5781e8f2015-08-04 16:23:11 -060012596 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012597
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012598 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012599}
12600
Karl Schultz6addd812016-02-02 17:17:23 -070012601TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012602 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12603 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012604 "vertex shader input that consumes it");
12605 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 -060012606
Chris Forbesc97d98e2015-05-25 11:13:31 +120012607 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012608 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012609
12610 VkVertexInputBindingDescription input_binding;
12611 memset(&input_binding, 0, sizeof(input_binding));
12612
12613 VkVertexInputAttributeDescription input_attrib;
12614 memset(&input_attrib, 0, sizeof(input_attrib));
12615 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012617 char const *vsSource = "#version 450\n"
12618 "\n"
12619 "layout(location=0) in int x;\n" /* attrib provided float */
12620 "out gl_PerVertex {\n"
12621 " vec4 gl_Position;\n"
12622 "};\n"
12623 "void main(){\n"
12624 " gl_Position = vec4(x);\n"
12625 "}\n";
12626 char const *fsSource = "#version 450\n"
12627 "\n"
12628 "layout(location=0) out vec4 color;\n"
12629 "void main(){\n"
12630 " color = vec4(1);\n"
12631 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012632
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012633 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12634 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012635
12636 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012637 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012638 pipe.AddShader(&vs);
12639 pipe.AddShader(&fs);
12640
12641 pipe.AddVertexInputBindings(&input_binding, 1);
12642 pipe.AddVertexInputAttribs(&input_attrib, 1);
12643
Chris Forbesc97d98e2015-05-25 11:13:31 +120012644 VkDescriptorSetObj descriptorSet(m_device);
12645 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012646 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012647
Tony Barbour5781e8f2015-08-04 16:23:11 -060012648 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012649
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012650 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012651}
12652
Chris Forbesc68b43c2016-04-06 11:18:47 +120012653TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012654 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12655 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12657 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012658
12659 ASSERT_NO_FATAL_FAILURE(InitState());
12660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012662 char const *vsSource = "#version 450\n"
12663 "\n"
12664 "out gl_PerVertex {\n"
12665 " vec4 gl_Position;\n"
12666 "};\n"
12667 "void main(){\n"
12668 " gl_Position = vec4(1);\n"
12669 "}\n";
12670 char const *fsSource = "#version 450\n"
12671 "\n"
12672 "layout(location=0) out vec4 color;\n"
12673 "void main(){\n"
12674 " color = vec4(1);\n"
12675 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012676
12677 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12678 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12679
12680 VkPipelineObj pipe(m_device);
12681 pipe.AddColorAttachment();
12682 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012683 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012684 pipe.AddShader(&fs);
12685
12686 VkDescriptorSetObj descriptorSet(m_device);
12687 descriptorSet.AppendDummy();
12688 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12689
12690 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12691
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012692 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012693}
12694
Chris Forbes82ff92a2016-09-09 10:50:24 +120012695TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12697 "No entrypoint found named `foo`");
12698
12699 ASSERT_NO_FATAL_FAILURE(InitState());
12700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12701
12702 char const *vsSource = "#version 450\n"
12703 "out gl_PerVertex {\n"
12704 " vec4 gl_Position;\n"
12705 "};\n"
12706 "void main(){\n"
12707 " gl_Position = vec4(0);\n"
12708 "}\n";
12709 char const *fsSource = "#version 450\n"
12710 "\n"
12711 "layout(location=0) out vec4 color;\n"
12712 "void main(){\n"
12713 " color = vec4(1);\n"
12714 "}\n";
12715
12716 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12717 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12718
12719 VkPipelineObj pipe(m_device);
12720 pipe.AddColorAttachment();
12721 pipe.AddShader(&vs);
12722 pipe.AddShader(&fs);
12723
12724 VkDescriptorSetObj descriptorSet(m_device);
12725 descriptorSet.AppendDummy();
12726 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12727
12728 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12729
12730 m_errorMonitor->VerifyFound();
12731}
12732
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012733TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12734 m_errorMonitor->SetDesiredFailureMsg(
12735 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12736 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12737 "uses a depth/stencil attachment");
12738
12739 ASSERT_NO_FATAL_FAILURE(InitState());
12740 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12741
12742 char const *vsSource = "#version 450\n"
12743 "void main(){ gl_Position = vec4(0); }\n";
12744 char const *fsSource = "#version 450\n"
12745 "\n"
12746 "layout(location=0) out vec4 color;\n"
12747 "void main(){\n"
12748 " color = vec4(1);\n"
12749 "}\n";
12750
12751 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12752 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12753
12754 VkPipelineObj pipe(m_device);
12755 pipe.AddColorAttachment();
12756 pipe.AddShader(&vs);
12757 pipe.AddShader(&fs);
12758
12759 VkDescriptorSetObj descriptorSet(m_device);
12760 descriptorSet.AppendDummy();
12761 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12762
12763 VkAttachmentDescription attachments[] = {
12764 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12765 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12766 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12767 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12768 },
12769 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12770 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12771 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12772 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12773 },
12774 };
12775 VkAttachmentReference refs[] = {
12776 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12777 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12778 };
12779 VkSubpassDescription subpass = {
12780 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12781 1, &refs[0], nullptr, &refs[1],
12782 0, nullptr
12783 };
12784 VkRenderPassCreateInfo rpci = {
12785 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12786 0, 2, attachments, 1, &subpass, 0, nullptr
12787 };
12788 VkRenderPass rp;
12789 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12790 ASSERT_VK_SUCCESS(err);
12791
12792 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12793
12794 m_errorMonitor->VerifyFound();
12795
12796 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12797}
12798
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012799TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012800 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12801 "the TCS without the patch decoration, but consumed in the TES "
12802 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12804 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012805
12806 ASSERT_NO_FATAL_FAILURE(InitState());
12807 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12808
Chris Forbesc1e852d2016-04-04 19:26:42 +120012809 if (!m_device->phy().features().tessellationShader) {
12810 printf("Device does not support tessellation shaders; skipped.\n");
12811 return;
12812 }
12813
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012814 char const *vsSource = "#version 450\n"
12815 "void main(){}\n";
12816 char const *tcsSource = "#version 450\n"
12817 "layout(location=0) out int x[];\n"
12818 "layout(vertices=3) out;\n"
12819 "void main(){\n"
12820 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12821 " gl_TessLevelInner[0] = 1;\n"
12822 " x[gl_InvocationID] = gl_InvocationID;\n"
12823 "}\n";
12824 char const *tesSource = "#version 450\n"
12825 "layout(triangles, equal_spacing, cw) in;\n"
12826 "layout(location=0) patch in int x;\n"
12827 "out gl_PerVertex { vec4 gl_Position; };\n"
12828 "void main(){\n"
12829 " gl_Position.xyz = gl_TessCoord;\n"
12830 " gl_Position.w = x;\n"
12831 "}\n";
12832 char const *fsSource = "#version 450\n"
12833 "layout(location=0) out vec4 color;\n"
12834 "void main(){\n"
12835 " color = vec4(1);\n"
12836 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012837
12838 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12839 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12840 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12841 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12842
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012843 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12844 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012846 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012847
12848 VkPipelineObj pipe(m_device);
12849 pipe.SetInputAssembly(&iasci);
12850 pipe.SetTessellation(&tsci);
12851 pipe.AddColorAttachment();
12852 pipe.AddShader(&vs);
12853 pipe.AddShader(&tcs);
12854 pipe.AddShader(&tes);
12855 pipe.AddShader(&fs);
12856
12857 VkDescriptorSetObj descriptorSet(m_device);
12858 descriptorSet.AppendDummy();
12859 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12860
12861 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12862
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012863 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012864}
12865
Karl Schultz6addd812016-02-02 17:17:23 -070012866TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012867 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12868 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12870 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012871
Chris Forbes280ba2c2015-06-12 11:16:41 +120012872 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012873 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012874
12875 /* Two binding descriptions for binding 0 */
12876 VkVertexInputBindingDescription input_bindings[2];
12877 memset(input_bindings, 0, sizeof(input_bindings));
12878
12879 VkVertexInputAttributeDescription input_attrib;
12880 memset(&input_attrib, 0, sizeof(input_attrib));
12881 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012883 char const *vsSource = "#version 450\n"
12884 "\n"
12885 "layout(location=0) in float x;\n" /* attrib provided float */
12886 "out gl_PerVertex {\n"
12887 " vec4 gl_Position;\n"
12888 "};\n"
12889 "void main(){\n"
12890 " gl_Position = vec4(x);\n"
12891 "}\n";
12892 char const *fsSource = "#version 450\n"
12893 "\n"
12894 "layout(location=0) out vec4 color;\n"
12895 "void main(){\n"
12896 " color = vec4(1);\n"
12897 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012898
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012899 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12900 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012901
12902 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012903 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012904 pipe.AddShader(&vs);
12905 pipe.AddShader(&fs);
12906
12907 pipe.AddVertexInputBindings(input_bindings, 2);
12908 pipe.AddVertexInputAttribs(&input_attrib, 1);
12909
Chris Forbes280ba2c2015-06-12 11:16:41 +120012910 VkDescriptorSetObj descriptorSet(m_device);
12911 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012912 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012913
Tony Barbour5781e8f2015-08-04 16:23:11 -060012914 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012915
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012916 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012917}
Chris Forbes8f68b562015-05-25 11:13:32 +120012918
Karl Schultz6addd812016-02-02 17:17:23 -070012919TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012920 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012921 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012923
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012924 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012925
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012926 char const *vsSource = "#version 450\n"
12927 "\n"
12928 "out gl_PerVertex {\n"
12929 " vec4 gl_Position;\n"
12930 "};\n"
12931 "void main(){\n"
12932 " gl_Position = vec4(1);\n"
12933 "}\n";
12934 char const *fsSource = "#version 450\n"
12935 "\n"
12936 "void main(){\n"
12937 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012938
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012939 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12940 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012941
12942 VkPipelineObj pipe(m_device);
12943 pipe.AddShader(&vs);
12944 pipe.AddShader(&fs);
12945
Chia-I Wu08accc62015-07-07 11:50:03 +080012946 /* set up CB 0, not written */
12947 pipe.AddColorAttachment();
12948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012949
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012950 VkDescriptorSetObj descriptorSet(m_device);
12951 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012952 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012953
Tony Barbour5781e8f2015-08-04 16:23:11 -060012954 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012955
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012956 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012957}
12958
Karl Schultz6addd812016-02-02 17:17:23 -070012959TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012960 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120012961 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012963 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012964
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012965 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012967 char const *vsSource = "#version 450\n"
12968 "\n"
12969 "out gl_PerVertex {\n"
12970 " vec4 gl_Position;\n"
12971 "};\n"
12972 "void main(){\n"
12973 " gl_Position = vec4(1);\n"
12974 "}\n";
12975 char const *fsSource = "#version 450\n"
12976 "\n"
12977 "layout(location=0) out vec4 x;\n"
12978 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
12979 "void main(){\n"
12980 " x = vec4(1);\n"
12981 " y = vec4(1);\n"
12982 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012983
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012984 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12985 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012986
12987 VkPipelineObj pipe(m_device);
12988 pipe.AddShader(&vs);
12989 pipe.AddShader(&fs);
12990
Chia-I Wu08accc62015-07-07 11:50:03 +080012991 /* set up CB 0, not written */
12992 pipe.AddColorAttachment();
12993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012994 /* FS writes CB 1, but we don't configure it */
12995
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012996 VkDescriptorSetObj descriptorSet(m_device);
12997 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012998 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012999
Tony Barbour5781e8f2015-08-04 16:23:11 -060013000 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013001
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013002 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013003}
13004
Karl Schultz6addd812016-02-02 17:17:23 -070013005TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013006 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013007 "type of an fragment shader output variable, and the format of the corresponding attachment");
13008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013009
Chris Forbesa36d69e2015-05-25 11:13:44 +120013010 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013012 char const *vsSource = "#version 450\n"
13013 "\n"
13014 "out gl_PerVertex {\n"
13015 " vec4 gl_Position;\n"
13016 "};\n"
13017 "void main(){\n"
13018 " gl_Position = vec4(1);\n"
13019 "}\n";
13020 char const *fsSource = "#version 450\n"
13021 "\n"
13022 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13023 "void main(){\n"
13024 " x = ivec4(1);\n"
13025 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013026
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013027 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13028 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013029
13030 VkPipelineObj pipe(m_device);
13031 pipe.AddShader(&vs);
13032 pipe.AddShader(&fs);
13033
Chia-I Wu08accc62015-07-07 11:50:03 +080013034 /* set up CB 0; type is UNORM by default */
13035 pipe.AddColorAttachment();
13036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013037
Chris Forbesa36d69e2015-05-25 11:13:44 +120013038 VkDescriptorSetObj descriptorSet(m_device);
13039 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013040 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013041
Tony Barbour5781e8f2015-08-04 16:23:11 -060013042 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013043
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013044 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013045}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013046
Karl Schultz6addd812016-02-02 17:17:23 -070013047TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013048 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13049 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013051
Chris Forbes556c76c2015-08-14 12:04:59 +120013052 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013054 char const *vsSource = "#version 450\n"
13055 "\n"
13056 "out gl_PerVertex {\n"
13057 " vec4 gl_Position;\n"
13058 "};\n"
13059 "void main(){\n"
13060 " gl_Position = vec4(1);\n"
13061 "}\n";
13062 char const *fsSource = "#version 450\n"
13063 "\n"
13064 "layout(location=0) out vec4 x;\n"
13065 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13066 "void main(){\n"
13067 " x = vec4(bar.y);\n"
13068 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013069
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013070 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13071 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013072
Chris Forbes556c76c2015-08-14 12:04:59 +120013073 VkPipelineObj pipe(m_device);
13074 pipe.AddShader(&vs);
13075 pipe.AddShader(&fs);
13076
13077 /* set up CB 0; type is UNORM by default */
13078 pipe.AddColorAttachment();
13079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13080
13081 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013082 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013083
13084 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13085
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013086 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013087}
13088
Chris Forbes5c59e902016-02-26 16:56:09 +130013089TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013090 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13091 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013093
13094 ASSERT_NO_FATAL_FAILURE(InitState());
13095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013096 char const *vsSource = "#version 450\n"
13097 "\n"
13098 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13099 "out gl_PerVertex {\n"
13100 " vec4 gl_Position;\n"
13101 "};\n"
13102 "void main(){\n"
13103 " gl_Position = vec4(consts.x);\n"
13104 "}\n";
13105 char const *fsSource = "#version 450\n"
13106 "\n"
13107 "layout(location=0) out vec4 x;\n"
13108 "void main(){\n"
13109 " x = vec4(1);\n"
13110 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013111
13112 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13113 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13114
13115 VkPipelineObj pipe(m_device);
13116 pipe.AddShader(&vs);
13117 pipe.AddShader(&fs);
13118
13119 /* set up CB 0; type is UNORM by default */
13120 pipe.AddColorAttachment();
13121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13122
13123 VkDescriptorSetObj descriptorSet(m_device);
13124 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13125
13126 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13127
13128 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013129 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013130}
13131
Chris Forbes3fb17902016-08-22 14:57:55 +120013132TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13133 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13134 "which is not included in the subpass description");
13135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13136 "consumes input attachment index 0 but not provided in subpass");
13137
13138 ASSERT_NO_FATAL_FAILURE(InitState());
13139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013140 char const *vsSource = "#version 450\n"
13141 "\n"
13142 "out gl_PerVertex {\n"
13143 " vec4 gl_Position;\n"
13144 "};\n"
13145 "void main(){\n"
13146 " gl_Position = vec4(1);\n"
13147 "}\n";
13148 char const *fsSource = "#version 450\n"
13149 "\n"
13150 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13151 "layout(location=0) out vec4 color;\n"
13152 "void main() {\n"
13153 " color = subpassLoad(x);\n"
13154 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013155
13156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13158
13159 VkPipelineObj pipe(m_device);
13160 pipe.AddShader(&vs);
13161 pipe.AddShader(&fs);
13162 pipe.AddColorAttachment();
13163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013165 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13166 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013167 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013168 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013169 ASSERT_VK_SUCCESS(err);
13170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013171 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013172 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013173 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013174 ASSERT_VK_SUCCESS(err);
13175
13176 // error here.
13177 pipe.CreateVKPipeline(pl, renderPass());
13178
13179 m_errorMonitor->VerifyFound();
13180
13181 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13182 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13183}
13184
Chris Forbes5a9a0472016-08-22 16:02:09 +120013185TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13186 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13187 "with a format having a different fundamental type");
13188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13189 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13190
13191 ASSERT_NO_FATAL_FAILURE(InitState());
13192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013193 char const *vsSource = "#version 450\n"
13194 "\n"
13195 "out gl_PerVertex {\n"
13196 " vec4 gl_Position;\n"
13197 "};\n"
13198 "void main(){\n"
13199 " gl_Position = vec4(1);\n"
13200 "}\n";
13201 char const *fsSource = "#version 450\n"
13202 "\n"
13203 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13204 "layout(location=0) out vec4 color;\n"
13205 "void main() {\n"
13206 " color = subpassLoad(x);\n"
13207 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013208
13209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13210 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13211
13212 VkPipelineObj pipe(m_device);
13213 pipe.AddShader(&vs);
13214 pipe.AddShader(&fs);
13215 pipe.AddColorAttachment();
13216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013218 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13219 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013220 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013221 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013222 ASSERT_VK_SUCCESS(err);
13223
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013224 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013225 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013226 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013227 ASSERT_VK_SUCCESS(err);
13228
13229 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013230 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13231 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13232 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13233 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13234 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 +120013235 };
13236 VkAttachmentReference color = {
13237 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13238 };
13239 VkAttachmentReference input = {
13240 1, VK_IMAGE_LAYOUT_GENERAL,
13241 };
13242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013243 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013245 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013246 VkRenderPass rp;
13247 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13248 ASSERT_VK_SUCCESS(err);
13249
13250 // error here.
13251 pipe.CreateVKPipeline(pl, rp);
13252
13253 m_errorMonitor->VerifyFound();
13254
13255 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13256 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13257 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13258}
13259
Chris Forbes541f7b02016-08-22 15:30:27 +120013260TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13261 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13262 "which is not included in the subpass description -- array case");
13263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13264 "consumes input attachment index 1 but not provided in subpass");
13265
13266 ASSERT_NO_FATAL_FAILURE(InitState());
13267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013268 char const *vsSource = "#version 450\n"
13269 "\n"
13270 "out gl_PerVertex {\n"
13271 " vec4 gl_Position;\n"
13272 "};\n"
13273 "void main(){\n"
13274 " gl_Position = vec4(1);\n"
13275 "}\n";
13276 char const *fsSource = "#version 450\n"
13277 "\n"
13278 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13279 "layout(location=0) out vec4 color;\n"
13280 "void main() {\n"
13281 " color = subpassLoad(xs[1]);\n"
13282 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013283
13284 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13285 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13286
13287 VkPipelineObj pipe(m_device);
13288 pipe.AddShader(&vs);
13289 pipe.AddShader(&fs);
13290 pipe.AddColorAttachment();
13291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013293 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13294 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013295 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013296 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013297 ASSERT_VK_SUCCESS(err);
13298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013299 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013300 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013301 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013302 ASSERT_VK_SUCCESS(err);
13303
13304 // error here.
13305 pipe.CreateVKPipeline(pl, renderPass());
13306
13307 m_errorMonitor->VerifyFound();
13308
13309 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13310 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13311}
13312
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013313TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013314 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13315 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013317
13318 ASSERT_NO_FATAL_FAILURE(InitState());
13319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013320 char const *csSource = "#version 450\n"
13321 "\n"
13322 "layout(local_size_x=1) in;\n"
13323 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13324 "void main(){\n"
13325 " x = vec4(1);\n"
13326 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013327
13328 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13329
13330 VkDescriptorSetObj descriptorSet(m_device);
13331 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13332
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013333 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13334 nullptr,
13335 0,
13336 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13337 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13338 descriptorSet.GetPipelineLayout(),
13339 VK_NULL_HANDLE,
13340 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013341
13342 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013343 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013344
13345 m_errorMonitor->VerifyFound();
13346
13347 if (err == VK_SUCCESS) {
13348 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13349 }
13350}
13351
Chris Forbes22a9b092016-07-19 14:34:05 +120013352TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013353 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13354 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13356 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013357
13358 ASSERT_NO_FATAL_FAILURE(InitState());
13359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013360 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13361 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013362 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013363 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013364 ASSERT_VK_SUCCESS(err);
13365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013366 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013367 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013368 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013369 ASSERT_VK_SUCCESS(err);
13370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013371 char const *csSource = "#version 450\n"
13372 "\n"
13373 "layout(local_size_x=1) in;\n"
13374 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13375 "void main() {\n"
13376 " x.x = 1.0f;\n"
13377 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013378 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013380 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13381 nullptr,
13382 0,
13383 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13384 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13385 pl,
13386 VK_NULL_HANDLE,
13387 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013388
13389 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013390 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013391
13392 m_errorMonitor->VerifyFound();
13393
13394 if (err == VK_SUCCESS) {
13395 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13396 }
13397
13398 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13399 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13400}
13401
Chris Forbes50020592016-07-27 13:52:41 +120013402TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13403 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13404 "does not match the dimensionality declared in the shader");
13405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013406 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 +120013407
13408 ASSERT_NO_FATAL_FAILURE(InitState());
13409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13410
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013411 char const *vsSource = "#version 450\n"
13412 "\n"
13413 "out gl_PerVertex { vec4 gl_Position; };\n"
13414 "void main() { gl_Position = vec4(0); }\n";
13415 char const *fsSource = "#version 450\n"
13416 "\n"
13417 "layout(set=0, binding=0) uniform sampler3D s;\n"
13418 "layout(location=0) out vec4 color;\n"
13419 "void main() {\n"
13420 " color = texture(s, vec3(0));\n"
13421 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013422 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13423 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13424
13425 VkPipelineObj pipe(m_device);
13426 pipe.AddShader(&vs);
13427 pipe.AddShader(&fs);
13428 pipe.AddColorAttachment();
13429
13430 VkTextureObj texture(m_device, nullptr);
13431 VkSamplerObj sampler(m_device);
13432
13433 VkDescriptorSetObj descriptorSet(m_device);
13434 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13435 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13436
13437 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13438 ASSERT_VK_SUCCESS(err);
13439
13440 BeginCommandBuffer();
13441
13442 m_commandBuffer->BindPipeline(pipe);
13443 m_commandBuffer->BindDescriptorSet(descriptorSet);
13444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013445 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013446 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013447 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013448 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13449
13450 // error produced here.
13451 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13452
13453 m_errorMonitor->VerifyFound();
13454
13455 EndCommandBuffer();
13456}
13457
Chris Forbes5533bfc2016-07-27 14:12:34 +120013458TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13459 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13460 "are consumed via singlesample images types in the shader, or vice versa.");
13461
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013463
13464 ASSERT_NO_FATAL_FAILURE(InitState());
13465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13466
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013467 char const *vsSource = "#version 450\n"
13468 "\n"
13469 "out gl_PerVertex { vec4 gl_Position; };\n"
13470 "void main() { gl_Position = vec4(0); }\n";
13471 char const *fsSource = "#version 450\n"
13472 "\n"
13473 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13474 "layout(location=0) out vec4 color;\n"
13475 "void main() {\n"
13476 " color = texelFetch(s, ivec2(0), 0);\n"
13477 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013478 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13479 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13480
13481 VkPipelineObj pipe(m_device);
13482 pipe.AddShader(&vs);
13483 pipe.AddShader(&fs);
13484 pipe.AddColorAttachment();
13485
13486 VkTextureObj texture(m_device, nullptr);
13487 VkSamplerObj sampler(m_device);
13488
13489 VkDescriptorSetObj descriptorSet(m_device);
13490 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13491 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13492
13493 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13494 ASSERT_VK_SUCCESS(err);
13495
13496 BeginCommandBuffer();
13497
13498 m_commandBuffer->BindPipeline(pipe);
13499 m_commandBuffer->BindDescriptorSet(descriptorSet);
13500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013501 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013502 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013503 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013504 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13505
13506 // error produced here.
13507 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13508
13509 m_errorMonitor->VerifyFound();
13510
13511 EndCommandBuffer();
13512}
13513
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013514#endif // SHADER_CHECKER_TESTS
13515
13516#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013517TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013519
13520 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013521
13522 // Create an image
13523 VkImage image;
13524
Karl Schultz6addd812016-02-02 17:17:23 -070013525 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13526 const int32_t tex_width = 32;
13527 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013528
13529 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013530 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13531 image_create_info.pNext = NULL;
13532 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13533 image_create_info.format = tex_format;
13534 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013535 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013536 image_create_info.extent.depth = 1;
13537 image_create_info.mipLevels = 1;
13538 image_create_info.arrayLayers = 1;
13539 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13540 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13541 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13542 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013543
13544 // Introduce error by sending down a bogus width extent
13545 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013546 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013547
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013548 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013549}
13550
Mark Youngc48c4c12016-04-11 14:26:49 -060013551TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13553 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013554
13555 ASSERT_NO_FATAL_FAILURE(InitState());
13556
13557 // Create an image
13558 VkImage image;
13559
13560 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13561 const int32_t tex_width = 32;
13562 const int32_t tex_height = 32;
13563
13564 VkImageCreateInfo image_create_info = {};
13565 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13566 image_create_info.pNext = NULL;
13567 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13568 image_create_info.format = tex_format;
13569 image_create_info.extent.width = tex_width;
13570 image_create_info.extent.height = tex_height;
13571 image_create_info.extent.depth = 1;
13572 image_create_info.mipLevels = 1;
13573 image_create_info.arrayLayers = 1;
13574 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13575 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13576 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13577 image_create_info.flags = 0;
13578
13579 // Introduce error by sending down a bogus width extent
13580 image_create_info.extent.width = 0;
13581 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13582
13583 m_errorMonitor->VerifyFound();
13584}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013585#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013586
Tobin Ehliscde08892015-09-22 10:11:37 -060013587#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013588
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013589TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13590 TEST_DESCRIPTION("Create a render pass with an attachment description "
13591 "format set to VK_FORMAT_UNDEFINED");
13592
13593 ASSERT_NO_FATAL_FAILURE(InitState());
13594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013597
13598 VkAttachmentReference color_attach = {};
13599 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13600 color_attach.attachment = 0;
13601 VkSubpassDescription subpass = {};
13602 subpass.colorAttachmentCount = 1;
13603 subpass.pColorAttachments = &color_attach;
13604
13605 VkRenderPassCreateInfo rpci = {};
13606 rpci.subpassCount = 1;
13607 rpci.pSubpasses = &subpass;
13608 rpci.attachmentCount = 1;
13609 VkAttachmentDescription attach_desc = {};
13610 attach_desc.format = VK_FORMAT_UNDEFINED;
13611 rpci.pAttachments = &attach_desc;
13612 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13613 VkRenderPass rp;
13614 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13615
13616 m_errorMonitor->VerifyFound();
13617
13618 if (result == VK_SUCCESS) {
13619 vkDestroyRenderPass(m_device->device(), rp, NULL);
13620 }
13621}
13622
Karl Schultz6addd812016-02-02 17:17:23 -070013623TEST_F(VkLayerTest, InvalidImageView) {
13624 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013627
Tobin Ehliscde08892015-09-22 10:11:37 -060013628 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013629
Mike Stroyana3082432015-09-25 13:39:21 -060013630 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013631 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013632
Karl Schultz6addd812016-02-02 17:17:23 -070013633 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13634 const int32_t tex_width = 32;
13635 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013636
13637 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013638 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13639 image_create_info.pNext = NULL;
13640 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13641 image_create_info.format = tex_format;
13642 image_create_info.extent.width = tex_width;
13643 image_create_info.extent.height = tex_height;
13644 image_create_info.extent.depth = 1;
13645 image_create_info.mipLevels = 1;
13646 image_create_info.arrayLayers = 1;
13647 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13648 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13649 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13650 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013651
Chia-I Wuf7458c52015-10-26 21:10:41 +080013652 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013653 ASSERT_VK_SUCCESS(err);
13654
13655 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013656 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13657 image_view_create_info.image = image;
13658 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13659 image_view_create_info.format = tex_format;
13660 image_view_create_info.subresourceRange.layerCount = 1;
13661 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13662 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013663 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013664
13665 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013666 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013667
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013668 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013669 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013670}
Mike Stroyana3082432015-09-25 13:39:21 -060013671
Mark Youngd339ba32016-05-30 13:28:35 -060013672TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13673 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013675 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013676
13677 ASSERT_NO_FATAL_FAILURE(InitState());
13678
13679 // Create an image and try to create a view with no memory backing the image
13680 VkImage image;
13681
13682 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13683 const int32_t tex_width = 32;
13684 const int32_t tex_height = 32;
13685
13686 VkImageCreateInfo image_create_info = {};
13687 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13688 image_create_info.pNext = NULL;
13689 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13690 image_create_info.format = tex_format;
13691 image_create_info.extent.width = tex_width;
13692 image_create_info.extent.height = tex_height;
13693 image_create_info.extent.depth = 1;
13694 image_create_info.mipLevels = 1;
13695 image_create_info.arrayLayers = 1;
13696 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13697 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13698 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13699 image_create_info.flags = 0;
13700
13701 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13702 ASSERT_VK_SUCCESS(err);
13703
13704 VkImageViewCreateInfo image_view_create_info = {};
13705 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13706 image_view_create_info.image = image;
13707 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13708 image_view_create_info.format = tex_format;
13709 image_view_create_info.subresourceRange.layerCount = 1;
13710 image_view_create_info.subresourceRange.baseMipLevel = 0;
13711 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013712 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013713
13714 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013715 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013716
13717 m_errorMonitor->VerifyFound();
13718 vkDestroyImage(m_device->device(), image, NULL);
13719 // If last error is success, it still created the view, so delete it.
13720 if (err == VK_SUCCESS) {
13721 vkDestroyImageView(m_device->device(), view, NULL);
13722 }
Mark Youngd339ba32016-05-30 13:28:35 -060013723}
13724
Karl Schultz6addd812016-02-02 17:17:23 -070013725TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013726 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013728 "formats must have ONLY the "
13729 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13731 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013732
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013733 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013734
Karl Schultz6addd812016-02-02 17:17:23 -070013735 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013736 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013737 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013738 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013739
13740 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013741 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013742 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013743 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13744 image_view_create_info.format = tex_format;
13745 image_view_create_info.subresourceRange.baseMipLevel = 0;
13746 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013747 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013748 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013749 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013750
13751 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013752 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013753
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013754 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013755}
13756
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013757TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013758 VkResult err;
13759 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013760
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13762 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013763
Mike Stroyana3082432015-09-25 13:39:21 -060013764 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013765
13766 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013767 VkImage srcImage;
13768 VkImage dstImage;
13769 VkDeviceMemory srcMem;
13770 VkDeviceMemory destMem;
13771 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013772
13773 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013774 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13775 image_create_info.pNext = NULL;
13776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13777 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13778 image_create_info.extent.width = 32;
13779 image_create_info.extent.height = 32;
13780 image_create_info.extent.depth = 1;
13781 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013782 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013783 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13784 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13785 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13786 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013788 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013789 ASSERT_VK_SUCCESS(err);
13790
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013791 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013792 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013793 ASSERT_VK_SUCCESS(err);
13794
13795 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013796 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013797 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13798 memAlloc.pNext = NULL;
13799 memAlloc.allocationSize = 0;
13800 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013801
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013802 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013803 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013804 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013805 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013806 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013807 ASSERT_VK_SUCCESS(err);
13808
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013809 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013810 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013811 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013812 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013813 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013814 ASSERT_VK_SUCCESS(err);
13815
13816 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13817 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013818 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013819 ASSERT_VK_SUCCESS(err);
13820
13821 BeginCommandBuffer();
13822 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013823 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013824 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013825 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013826 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013827 copyRegion.srcOffset.x = 0;
13828 copyRegion.srcOffset.y = 0;
13829 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013830 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013831 copyRegion.dstSubresource.mipLevel = 0;
13832 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013833 // Introduce failure by forcing the dst layerCount to differ from src
13834 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013835 copyRegion.dstOffset.x = 0;
13836 copyRegion.dstOffset.y = 0;
13837 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013838 copyRegion.extent.width = 1;
13839 copyRegion.extent.height = 1;
13840 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013841 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013842 EndCommandBuffer();
13843
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013844 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013845
Chia-I Wuf7458c52015-10-26 21:10:41 +080013846 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013847 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013848 vkFreeMemory(m_device->device(), srcMem, NULL);
13849 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013850}
13851
Tony Barbourd6673642016-05-05 14:46:39 -060013852TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13853
13854 TEST_DESCRIPTION("Creating images with unsuported formats ");
13855
13856 ASSERT_NO_FATAL_FAILURE(InitState());
13857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13858 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013859 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 -060013860 VK_IMAGE_TILING_OPTIMAL, 0);
13861 ASSERT_TRUE(image.initialized());
13862
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013863 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13864 VkImageCreateInfo image_create_info;
13865 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13866 image_create_info.pNext = NULL;
13867 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13868 image_create_info.format = VK_FORMAT_UNDEFINED;
13869 image_create_info.extent.width = 32;
13870 image_create_info.extent.height = 32;
13871 image_create_info.extent.depth = 1;
13872 image_create_info.mipLevels = 1;
13873 image_create_info.arrayLayers = 1;
13874 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13875 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13876 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13877 image_create_info.flags = 0;
13878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13880 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013881
13882 VkImage localImage;
13883 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13884 m_errorMonitor->VerifyFound();
13885
Tony Barbourd6673642016-05-05 14:46:39 -060013886 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013887 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013888 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13889 VkFormat format = static_cast<VkFormat>(f);
13890 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013891 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013892 unsupported = format;
13893 break;
13894 }
13895 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013896
Tony Barbourd6673642016-05-05 14:46:39 -060013897 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013898 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013900
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013901 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013902 m_errorMonitor->VerifyFound();
13903 }
13904}
13905
13906TEST_F(VkLayerTest, ImageLayerViewTests) {
13907 VkResult ret;
13908 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13909
13910 ASSERT_NO_FATAL_FAILURE(InitState());
13911
13912 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013913 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 -060013914 VK_IMAGE_TILING_OPTIMAL, 0);
13915 ASSERT_TRUE(image.initialized());
13916
13917 VkImageView imgView;
13918 VkImageViewCreateInfo imgViewInfo = {};
13919 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13920 imgViewInfo.image = image.handle();
13921 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13922 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13923 imgViewInfo.subresourceRange.layerCount = 1;
13924 imgViewInfo.subresourceRange.baseMipLevel = 0;
13925 imgViewInfo.subresourceRange.levelCount = 1;
13926 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13927
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013929 // View can't have baseMipLevel >= image's mipLevels - Expect
13930 // VIEW_CREATE_ERROR
13931 imgViewInfo.subresourceRange.baseMipLevel = 1;
13932 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13933 m_errorMonitor->VerifyFound();
13934 imgViewInfo.subresourceRange.baseMipLevel = 0;
13935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013937 // View can't have baseArrayLayer >= image's arraySize - Expect
13938 // VIEW_CREATE_ERROR
13939 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13940 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13941 m_errorMonitor->VerifyFound();
13942 imgViewInfo.subresourceRange.baseArrayLayer = 0;
13943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13945 "pCreateInfo->subresourceRange."
13946 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013947 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
13948 imgViewInfo.subresourceRange.levelCount = 0;
13949 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13950 m_errorMonitor->VerifyFound();
13951 imgViewInfo.subresourceRange.levelCount = 1;
13952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13954 "pCreateInfo->subresourceRange."
13955 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013956 m_errorMonitor->SetDesiredFailureMsg(
13957 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13958 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060013959 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
13960 imgViewInfo.subresourceRange.layerCount = 0;
13961 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13962 m_errorMonitor->VerifyFound();
13963 imgViewInfo.subresourceRange.layerCount = 1;
13964
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13967 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13968 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013969 // Can't use depth format for view into color image - Expect INVALID_FORMAT
13970 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
13971 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13972 m_errorMonitor->VerifyFound();
13973 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13976 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13977 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013978 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
13979 // VIEW_CREATE_ERROR
13980 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
13981 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13982 m_errorMonitor->VerifyFound();
13983 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
13986 "differing formats but they must be "
13987 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013988 // TODO: Update framework to easily passing mutable flag into ImageObj init
13989 // For now just allowing image for this one test to not have memory bound
13990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13991 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060013992 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
13993 // VIEW_CREATE_ERROR
13994 VkImageCreateInfo mutImgInfo = image.create_info();
13995 VkImage mutImage;
13996 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013997 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060013998 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
13999 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14000 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14001 ASSERT_VK_SUCCESS(ret);
14002 imgViewInfo.image = mutImage;
14003 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14004 m_errorMonitor->VerifyFound();
14005 imgViewInfo.image = image.handle();
14006 vkDestroyImage(m_device->handle(), mutImage, NULL);
14007}
14008
14009TEST_F(VkLayerTest, MiscImageLayerTests) {
14010
14011 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14012
14013 ASSERT_NO_FATAL_FAILURE(InitState());
14014
14015 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014016 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 -060014017 VK_IMAGE_TILING_OPTIMAL, 0);
14018 ASSERT_TRUE(image.initialized());
14019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060014021 vk_testing::Buffer buffer;
14022 VkMemoryPropertyFlags reqs = 0;
14023 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14024 VkBufferImageCopy region = {};
14025 region.bufferRowLength = 128;
14026 region.bufferImageHeight = 128;
14027 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14028 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14029 region.imageSubresource.layerCount = 0;
14030 region.imageExtent.height = 4;
14031 region.imageExtent.width = 4;
14032 region.imageExtent.depth = 1;
14033 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014034 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14035 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014036 m_errorMonitor->VerifyFound();
14037 region.imageSubresource.layerCount = 1;
14038
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014039 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14040 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14041 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
14043 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14044 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014045 m_errorMonitor->VerifyFound();
14046
14047 // BufferOffset must be a multiple of 4
14048 // Introduce failure by setting bufferOffset to a value not divisible by 4
14049 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
14051 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14052 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014053 m_errorMonitor->VerifyFound();
14054
14055 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14056 region.bufferOffset = 0;
14057 region.imageExtent.height = 128;
14058 region.imageExtent.width = 128;
14059 // Introduce failure by setting bufferRowLength > 0 but less than width
14060 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14062 "must be zero or greater-than-or-equal-to imageExtent.width");
14063 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14064 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014065 m_errorMonitor->VerifyFound();
14066
14067 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14068 region.bufferRowLength = 128;
14069 // Introduce failure by setting bufferRowHeight > 0 but less than height
14070 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14072 "must be zero or greater-than-or-equal-to imageExtent.height");
14073 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14074 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014075 m_errorMonitor->VerifyFound();
14076
14077 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14079 "specify only COLOR or DEPTH or "
14080 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014081 // Expect MISMATCHED_IMAGE_ASPECT
14082 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014083 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14084 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014085 m_errorMonitor->VerifyFound();
14086 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14089 "If the format of srcImage is a depth, stencil, depth stencil or "
14090 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014091 // Expect INVALID_FILTER
14092 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014093 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 -060014094 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014095 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 -060014096 VkImageBlit blitRegion = {};
14097 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14098 blitRegion.srcSubresource.baseArrayLayer = 0;
14099 blitRegion.srcSubresource.layerCount = 1;
14100 blitRegion.srcSubresource.mipLevel = 0;
14101 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14102 blitRegion.dstSubresource.baseArrayLayer = 0;
14103 blitRegion.dstSubresource.layerCount = 1;
14104 blitRegion.dstSubresource.mipLevel = 0;
14105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014106 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14107 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014108 m_errorMonitor->VerifyFound();
14109
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014110 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14112 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14113 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014114 m_errorMonitor->VerifyFound();
14115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014117 VkImageMemoryBarrier img_barrier;
14118 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14119 img_barrier.pNext = NULL;
14120 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14121 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14122 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14123 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14124 img_barrier.image = image.handle();
14125 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14126 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14127 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14128 img_barrier.subresourceRange.baseArrayLayer = 0;
14129 img_barrier.subresourceRange.baseMipLevel = 0;
14130 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14131 img_barrier.subresourceRange.layerCount = 0;
14132 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014133 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14134 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014135 m_errorMonitor->VerifyFound();
14136 img_barrier.subresourceRange.layerCount = 1;
14137}
14138
14139TEST_F(VkLayerTest, ImageFormatLimits) {
14140
14141 TEST_DESCRIPTION("Exceed the limits of image format ");
14142
Cody Northropc31a84f2016-08-22 10:41:47 -060014143 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014145 VkImageCreateInfo image_create_info = {};
14146 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14147 image_create_info.pNext = NULL;
14148 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14149 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14150 image_create_info.extent.width = 32;
14151 image_create_info.extent.height = 32;
14152 image_create_info.extent.depth = 1;
14153 image_create_info.mipLevels = 1;
14154 image_create_info.arrayLayers = 1;
14155 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14156 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14157 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14158 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14159 image_create_info.flags = 0;
14160
14161 VkImage nullImg;
14162 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014163 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14164 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014165 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14166 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14167 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14168 m_errorMonitor->VerifyFound();
14169 image_create_info.extent.depth = 1;
14170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014172 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14173 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14174 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14175 m_errorMonitor->VerifyFound();
14176 image_create_info.mipLevels = 1;
14177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014179 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14180 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14181 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14182 m_errorMonitor->VerifyFound();
14183 image_create_info.arrayLayers = 1;
14184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014186 int samples = imgFmtProps.sampleCounts >> 1;
14187 image_create_info.samples = (VkSampleCountFlagBits)samples;
14188 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14189 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14190 m_errorMonitor->VerifyFound();
14191 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14194 "VK_IMAGE_LAYOUT_UNDEFINED or "
14195 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014196 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14197 // Expect INVALID_LAYOUT
14198 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14199 m_errorMonitor->VerifyFound();
14200 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14201}
14202
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014203TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14204
14205 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014207
14208 ASSERT_NO_FATAL_FAILURE(InitState());
14209
14210 VkImageObj src_image(m_device);
14211 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14212 VkImageObj dst_image(m_device);
14213 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14214
14215 BeginCommandBuffer();
14216 VkImageCopy copy_region;
14217 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14218 copy_region.srcSubresource.mipLevel = 0;
14219 copy_region.srcSubresource.baseArrayLayer = 0;
14220 copy_region.srcSubresource.layerCount = 0;
14221 copy_region.srcOffset.x = 0;
14222 copy_region.srcOffset.y = 0;
14223 copy_region.srcOffset.z = 0;
14224 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14225 copy_region.dstSubresource.mipLevel = 0;
14226 copy_region.dstSubresource.baseArrayLayer = 0;
14227 copy_region.dstSubresource.layerCount = 0;
14228 copy_region.dstOffset.x = 0;
14229 copy_region.dstOffset.y = 0;
14230 copy_region.dstOffset.z = 0;
14231 copy_region.extent.width = 64;
14232 copy_region.extent.height = 64;
14233 copy_region.extent.depth = 1;
14234 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14235 &copy_region);
14236 EndCommandBuffer();
14237
14238 m_errorMonitor->VerifyFound();
14239}
14240
14241TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14242
14243 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014245
14246 ASSERT_NO_FATAL_FAILURE(InitState());
14247
14248 VkImageObj src_image(m_device);
14249 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14250 VkImageObj dst_image(m_device);
14251 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14252
14253 BeginCommandBuffer();
14254 VkImageCopy copy_region;
14255 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14256 copy_region.srcSubresource.mipLevel = 0;
14257 copy_region.srcSubresource.baseArrayLayer = 0;
14258 copy_region.srcSubresource.layerCount = 0;
14259 copy_region.srcOffset.x = 0;
14260 copy_region.srcOffset.y = 0;
14261 copy_region.srcOffset.z = 0;
14262 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14263 copy_region.dstSubresource.mipLevel = 0;
14264 copy_region.dstSubresource.baseArrayLayer = 0;
14265 copy_region.dstSubresource.layerCount = 0;
14266 copy_region.dstOffset.x = 0;
14267 copy_region.dstOffset.y = 0;
14268 copy_region.dstOffset.z = 0;
14269 copy_region.extent.width = 64;
14270 copy_region.extent.height = 64;
14271 copy_region.extent.depth = 1;
14272 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14273 &copy_region);
14274 EndCommandBuffer();
14275
14276 m_errorMonitor->VerifyFound();
14277}
14278
Karl Schultz6addd812016-02-02 17:17:23 -070014279TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014280 VkResult err;
14281 bool pass;
14282
14283 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14285 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014286
14287 ASSERT_NO_FATAL_FAILURE(InitState());
14288
14289 // Create two images of different types and try to copy between them
14290 VkImage srcImage;
14291 VkImage dstImage;
14292 VkDeviceMemory srcMem;
14293 VkDeviceMemory destMem;
14294 VkMemoryRequirements memReqs;
14295
14296 VkImageCreateInfo image_create_info = {};
14297 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14298 image_create_info.pNext = NULL;
14299 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14300 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14301 image_create_info.extent.width = 32;
14302 image_create_info.extent.height = 32;
14303 image_create_info.extent.depth = 1;
14304 image_create_info.mipLevels = 1;
14305 image_create_info.arrayLayers = 1;
14306 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14307 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14308 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14309 image_create_info.flags = 0;
14310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014311 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014312 ASSERT_VK_SUCCESS(err);
14313
14314 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14315 // Introduce failure by creating second image with a different-sized format.
14316 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14317
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014318 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014319 ASSERT_VK_SUCCESS(err);
14320
14321 // Allocate memory
14322 VkMemoryAllocateInfo memAlloc = {};
14323 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14324 memAlloc.pNext = NULL;
14325 memAlloc.allocationSize = 0;
14326 memAlloc.memoryTypeIndex = 0;
14327
14328 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14329 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014330 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014331 ASSERT_TRUE(pass);
14332 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14333 ASSERT_VK_SUCCESS(err);
14334
14335 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14336 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014337 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014338 ASSERT_TRUE(pass);
14339 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14340 ASSERT_VK_SUCCESS(err);
14341
14342 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14343 ASSERT_VK_SUCCESS(err);
14344 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14345 ASSERT_VK_SUCCESS(err);
14346
14347 BeginCommandBuffer();
14348 VkImageCopy copyRegion;
14349 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14350 copyRegion.srcSubresource.mipLevel = 0;
14351 copyRegion.srcSubresource.baseArrayLayer = 0;
14352 copyRegion.srcSubresource.layerCount = 0;
14353 copyRegion.srcOffset.x = 0;
14354 copyRegion.srcOffset.y = 0;
14355 copyRegion.srcOffset.z = 0;
14356 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14357 copyRegion.dstSubresource.mipLevel = 0;
14358 copyRegion.dstSubresource.baseArrayLayer = 0;
14359 copyRegion.dstSubresource.layerCount = 0;
14360 copyRegion.dstOffset.x = 0;
14361 copyRegion.dstOffset.y = 0;
14362 copyRegion.dstOffset.z = 0;
14363 copyRegion.extent.width = 1;
14364 copyRegion.extent.height = 1;
14365 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014366 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014367 EndCommandBuffer();
14368
14369 m_errorMonitor->VerifyFound();
14370
14371 vkDestroyImage(m_device->device(), srcImage, NULL);
14372 vkDestroyImage(m_device->device(), dstImage, NULL);
14373 vkFreeMemory(m_device->device(), srcMem, NULL);
14374 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014375}
14376
Karl Schultz6addd812016-02-02 17:17:23 -070014377TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14378 VkResult err;
14379 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014380
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014381 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14383 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014384
Mike Stroyana3082432015-09-25 13:39:21 -060014385 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014386
14387 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014388 VkImage srcImage;
14389 VkImage dstImage;
14390 VkDeviceMemory srcMem;
14391 VkDeviceMemory destMem;
14392 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014393
14394 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014395 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14396 image_create_info.pNext = NULL;
14397 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14398 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14399 image_create_info.extent.width = 32;
14400 image_create_info.extent.height = 32;
14401 image_create_info.extent.depth = 1;
14402 image_create_info.mipLevels = 1;
14403 image_create_info.arrayLayers = 1;
14404 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14405 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14406 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14407 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014409 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014410 ASSERT_VK_SUCCESS(err);
14411
Karl Schultzbdb75952016-04-19 11:36:49 -060014412 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14413
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014414 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014415 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014416 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014417 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014419 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014420 ASSERT_VK_SUCCESS(err);
14421
14422 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014423 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014424 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14425 memAlloc.pNext = NULL;
14426 memAlloc.allocationSize = 0;
14427 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014428
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014429 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014430 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014431 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014432 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014433 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014434 ASSERT_VK_SUCCESS(err);
14435
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014436 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014437 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014438 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014439 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014440 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014441 ASSERT_VK_SUCCESS(err);
14442
14443 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14444 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014445 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014446 ASSERT_VK_SUCCESS(err);
14447
14448 BeginCommandBuffer();
14449 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014450 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014451 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014452 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014453 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014454 copyRegion.srcOffset.x = 0;
14455 copyRegion.srcOffset.y = 0;
14456 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014457 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014458 copyRegion.dstSubresource.mipLevel = 0;
14459 copyRegion.dstSubresource.baseArrayLayer = 0;
14460 copyRegion.dstSubresource.layerCount = 0;
14461 copyRegion.dstOffset.x = 0;
14462 copyRegion.dstOffset.y = 0;
14463 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014464 copyRegion.extent.width = 1;
14465 copyRegion.extent.height = 1;
14466 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014467 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014468 EndCommandBuffer();
14469
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014470 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014471
Chia-I Wuf7458c52015-10-26 21:10:41 +080014472 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014473 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014474 vkFreeMemory(m_device->device(), srcMem, NULL);
14475 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014476}
14477
Karl Schultz6addd812016-02-02 17:17:23 -070014478TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14479 VkResult err;
14480 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014481
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14483 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014484
Mike Stroyana3082432015-09-25 13:39:21 -060014485 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014486
14487 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014488 VkImage srcImage;
14489 VkImage dstImage;
14490 VkDeviceMemory srcMem;
14491 VkDeviceMemory destMem;
14492 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014493
14494 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014495 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14496 image_create_info.pNext = NULL;
14497 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14498 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14499 image_create_info.extent.width = 32;
14500 image_create_info.extent.height = 1;
14501 image_create_info.extent.depth = 1;
14502 image_create_info.mipLevels = 1;
14503 image_create_info.arrayLayers = 1;
14504 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14505 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14506 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14507 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014509 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014510 ASSERT_VK_SUCCESS(err);
14511
Karl Schultz6addd812016-02-02 17:17:23 -070014512 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014514 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014515 ASSERT_VK_SUCCESS(err);
14516
14517 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014518 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014519 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14520 memAlloc.pNext = NULL;
14521 memAlloc.allocationSize = 0;
14522 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014523
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014524 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014525 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014526 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014527 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014528 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014529 ASSERT_VK_SUCCESS(err);
14530
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014531 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014532 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014533 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014534 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014535 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014536 ASSERT_VK_SUCCESS(err);
14537
14538 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14539 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014540 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014541 ASSERT_VK_SUCCESS(err);
14542
14543 BeginCommandBuffer();
14544 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014545 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14546 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014547 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014548 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014549 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014550 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014551 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014552 resolveRegion.srcOffset.x = 0;
14553 resolveRegion.srcOffset.y = 0;
14554 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014555 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014556 resolveRegion.dstSubresource.mipLevel = 0;
14557 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014558 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014559 resolveRegion.dstOffset.x = 0;
14560 resolveRegion.dstOffset.y = 0;
14561 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014562 resolveRegion.extent.width = 1;
14563 resolveRegion.extent.height = 1;
14564 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014565 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014566 EndCommandBuffer();
14567
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014568 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014569
Chia-I Wuf7458c52015-10-26 21:10:41 +080014570 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014571 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014572 vkFreeMemory(m_device->device(), srcMem, NULL);
14573 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014574}
14575
Karl Schultz6addd812016-02-02 17:17:23 -070014576TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14577 VkResult err;
14578 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014579
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14581 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014582
Mike Stroyana3082432015-09-25 13:39:21 -060014583 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014584
Chris Forbesa7530692016-05-08 12:35:39 +120014585 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014586 VkImage srcImage;
14587 VkImage dstImage;
14588 VkDeviceMemory srcMem;
14589 VkDeviceMemory destMem;
14590 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014591
14592 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014593 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14594 image_create_info.pNext = NULL;
14595 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14596 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14597 image_create_info.extent.width = 32;
14598 image_create_info.extent.height = 1;
14599 image_create_info.extent.depth = 1;
14600 image_create_info.mipLevels = 1;
14601 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014602 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014603 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14604 // Note: Some implementations expect color attachment usage for any
14605 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014606 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014607 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014609 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014610 ASSERT_VK_SUCCESS(err);
14611
Karl Schultz6addd812016-02-02 17:17:23 -070014612 // Note: Some implementations expect color attachment usage for any
14613 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014614 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014615
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014616 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014617 ASSERT_VK_SUCCESS(err);
14618
14619 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014620 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014621 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14622 memAlloc.pNext = NULL;
14623 memAlloc.allocationSize = 0;
14624 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014625
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014626 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014627 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014628 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014629 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014630 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014631 ASSERT_VK_SUCCESS(err);
14632
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014633 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014634 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014635 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014636 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014637 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014638 ASSERT_VK_SUCCESS(err);
14639
14640 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14641 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014642 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014643 ASSERT_VK_SUCCESS(err);
14644
14645 BeginCommandBuffer();
14646 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014647 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14648 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014649 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014650 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014651 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014652 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014653 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014654 resolveRegion.srcOffset.x = 0;
14655 resolveRegion.srcOffset.y = 0;
14656 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014657 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014658 resolveRegion.dstSubresource.mipLevel = 0;
14659 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014660 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014661 resolveRegion.dstOffset.x = 0;
14662 resolveRegion.dstOffset.y = 0;
14663 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014664 resolveRegion.extent.width = 1;
14665 resolveRegion.extent.height = 1;
14666 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014667 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014668 EndCommandBuffer();
14669
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014670 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014671
Chia-I Wuf7458c52015-10-26 21:10:41 +080014672 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014673 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014674 vkFreeMemory(m_device->device(), srcMem, NULL);
14675 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014676}
14677
Karl Schultz6addd812016-02-02 17:17:23 -070014678TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14679 VkResult err;
14680 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014681
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14683 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014684
Mike Stroyana3082432015-09-25 13:39:21 -060014685 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014686
14687 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014688 VkImage srcImage;
14689 VkImage dstImage;
14690 VkDeviceMemory srcMem;
14691 VkDeviceMemory destMem;
14692 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014693
14694 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014695 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14696 image_create_info.pNext = NULL;
14697 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14698 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14699 image_create_info.extent.width = 32;
14700 image_create_info.extent.height = 1;
14701 image_create_info.extent.depth = 1;
14702 image_create_info.mipLevels = 1;
14703 image_create_info.arrayLayers = 1;
14704 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14705 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14706 // Note: Some implementations expect color attachment usage for any
14707 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014708 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014709 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014711 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014712 ASSERT_VK_SUCCESS(err);
14713
Karl Schultz6addd812016-02-02 17:17:23 -070014714 // Set format to something other than source image
14715 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14716 // Note: Some implementations expect color attachment usage for any
14717 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014718 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014719 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014722 ASSERT_VK_SUCCESS(err);
14723
14724 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014725 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014726 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14727 memAlloc.pNext = NULL;
14728 memAlloc.allocationSize = 0;
14729 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014730
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014731 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014732 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014733 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014734 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014735 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014736 ASSERT_VK_SUCCESS(err);
14737
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014738 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014739 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014740 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014741 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014742 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014743 ASSERT_VK_SUCCESS(err);
14744
14745 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14746 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014747 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014748 ASSERT_VK_SUCCESS(err);
14749
14750 BeginCommandBuffer();
14751 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014752 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14753 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014754 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014755 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014756 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014757 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014758 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014759 resolveRegion.srcOffset.x = 0;
14760 resolveRegion.srcOffset.y = 0;
14761 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014762 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014763 resolveRegion.dstSubresource.mipLevel = 0;
14764 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014765 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014766 resolveRegion.dstOffset.x = 0;
14767 resolveRegion.dstOffset.y = 0;
14768 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014769 resolveRegion.extent.width = 1;
14770 resolveRegion.extent.height = 1;
14771 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014772 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014773 EndCommandBuffer();
14774
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014775 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014776
Chia-I Wuf7458c52015-10-26 21:10:41 +080014777 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014778 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014779 vkFreeMemory(m_device->device(), srcMem, NULL);
14780 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014781}
14782
Karl Schultz6addd812016-02-02 17:17:23 -070014783TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14784 VkResult err;
14785 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14788 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014789
Mike Stroyana3082432015-09-25 13:39:21 -060014790 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014791
14792 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014793 VkImage srcImage;
14794 VkImage dstImage;
14795 VkDeviceMemory srcMem;
14796 VkDeviceMemory destMem;
14797 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014798
14799 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014800 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14801 image_create_info.pNext = NULL;
14802 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14803 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14804 image_create_info.extent.width = 32;
14805 image_create_info.extent.height = 1;
14806 image_create_info.extent.depth = 1;
14807 image_create_info.mipLevels = 1;
14808 image_create_info.arrayLayers = 1;
14809 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14810 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14811 // Note: Some implementations expect color attachment usage for any
14812 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014813 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014814 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014815
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014816 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014817 ASSERT_VK_SUCCESS(err);
14818
Karl Schultz6addd812016-02-02 17:17:23 -070014819 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14820 // Note: Some implementations expect color attachment usage for any
14821 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014822 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014823 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014825 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014826 ASSERT_VK_SUCCESS(err);
14827
14828 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014829 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014830 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14831 memAlloc.pNext = NULL;
14832 memAlloc.allocationSize = 0;
14833 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014834
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014835 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014836 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014837 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014838 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014839 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014840 ASSERT_VK_SUCCESS(err);
14841
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014842 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014843 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014844 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014845 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014846 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014847 ASSERT_VK_SUCCESS(err);
14848
14849 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14850 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014851 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014852 ASSERT_VK_SUCCESS(err);
14853
14854 BeginCommandBuffer();
14855 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014856 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14857 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014858 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014859 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014860 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014861 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014862 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014863 resolveRegion.srcOffset.x = 0;
14864 resolveRegion.srcOffset.y = 0;
14865 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014866 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014867 resolveRegion.dstSubresource.mipLevel = 0;
14868 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014869 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014870 resolveRegion.dstOffset.x = 0;
14871 resolveRegion.dstOffset.y = 0;
14872 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014873 resolveRegion.extent.width = 1;
14874 resolveRegion.extent.height = 1;
14875 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014876 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014877 EndCommandBuffer();
14878
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014879 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014880
Chia-I Wuf7458c52015-10-26 21:10:41 +080014881 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014882 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014883 vkFreeMemory(m_device->device(), srcMem, NULL);
14884 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014885}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014886
Karl Schultz6addd812016-02-02 17:17:23 -070014887TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014888 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014889 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14890 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014891 // The image format check comes 2nd in validation so we trigger it first,
14892 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014893 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014894
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14896 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014897
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014898 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014899
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014900 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014901 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14902 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014903
14904 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014905 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14906 ds_pool_ci.pNext = NULL;
14907 ds_pool_ci.maxSets = 1;
14908 ds_pool_ci.poolSizeCount = 1;
14909 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014910
14911 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014912 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014913 ASSERT_VK_SUCCESS(err);
14914
14915 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014916 dsl_binding.binding = 0;
14917 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14918 dsl_binding.descriptorCount = 1;
14919 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14920 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014921
14922 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014923 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14924 ds_layout_ci.pNext = NULL;
14925 ds_layout_ci.bindingCount = 1;
14926 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014927 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014928 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014929 ASSERT_VK_SUCCESS(err);
14930
14931 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014932 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014933 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014934 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014935 alloc_info.descriptorPool = ds_pool;
14936 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014937 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014938 ASSERT_VK_SUCCESS(err);
14939
Karl Schultz6addd812016-02-02 17:17:23 -070014940 VkImage image_bad;
14941 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014942 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060014943 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014944 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070014945 const int32_t tex_width = 32;
14946 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014947
14948 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014949 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14950 image_create_info.pNext = NULL;
14951 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14952 image_create_info.format = tex_format_bad;
14953 image_create_info.extent.width = tex_width;
14954 image_create_info.extent.height = tex_height;
14955 image_create_info.extent.depth = 1;
14956 image_create_info.mipLevels = 1;
14957 image_create_info.arrayLayers = 1;
14958 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14959 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014960 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014961 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014963 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014964 ASSERT_VK_SUCCESS(err);
14965 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014966 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14967 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014968 ASSERT_VK_SUCCESS(err);
14969
14970 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014971 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14972 image_view_create_info.image = image_bad;
14973 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14974 image_view_create_info.format = tex_format_bad;
14975 image_view_create_info.subresourceRange.baseArrayLayer = 0;
14976 image_view_create_info.subresourceRange.baseMipLevel = 0;
14977 image_view_create_info.subresourceRange.layerCount = 1;
14978 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014979 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014980
14981 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014982 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014983
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014984 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014985
Chia-I Wuf7458c52015-10-26 21:10:41 +080014986 vkDestroyImage(m_device->device(), image_bad, NULL);
14987 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014988 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
14989 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014990}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014991
14992TEST_F(VkLayerTest, ClearImageErrors) {
14993 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
14994 "ClearDepthStencilImage with a color image.");
14995
14996 ASSERT_NO_FATAL_FAILURE(InitState());
14997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14998
14999 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15000 BeginCommandBuffer();
15001 m_commandBuffer->EndRenderPass();
15002
15003 // Color image
15004 VkClearColorValue clear_color;
15005 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15006 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15007 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15008 const int32_t img_width = 32;
15009 const int32_t img_height = 32;
15010 VkImageCreateInfo image_create_info = {};
15011 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15012 image_create_info.pNext = NULL;
15013 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15014 image_create_info.format = color_format;
15015 image_create_info.extent.width = img_width;
15016 image_create_info.extent.height = img_height;
15017 image_create_info.extent.depth = 1;
15018 image_create_info.mipLevels = 1;
15019 image_create_info.arrayLayers = 1;
15020 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15021 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15022 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15023
15024 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015025 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015027 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015028
15029 // Depth/Stencil image
15030 VkClearDepthStencilValue clear_value = {0};
15031 reqs = 0; // don't need HOST_VISIBLE DS image
15032 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15033 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15034 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15035 ds_image_create_info.extent.width = 64;
15036 ds_image_create_info.extent.height = 64;
15037 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15038 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15039
15040 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015041 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015043 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 -060015044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015048 &color_range);
15049
15050 m_errorMonitor->VerifyFound();
15051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15053 "image created without "
15054 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015055
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015056 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015057 &color_range);
15058
15059 m_errorMonitor->VerifyFound();
15060
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015061 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15063 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015064
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015065 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15066 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015067
15068 m_errorMonitor->VerifyFound();
15069}
Tobin Ehliscde08892015-09-22 10:11:37 -060015070#endif // IMAGE_TESTS
15071
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015072
15073// WSI Enabled Tests
15074//
15075TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15076
15077#if defined(VK_USE_PLATFORM_XCB_KHR)
15078 VkSurfaceKHR surface = VK_NULL_HANDLE;
15079
15080 VkResult err;
15081 bool pass;
15082 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15083 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15084 // uint32_t swapchain_image_count = 0;
15085 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15086 // uint32_t image_index = 0;
15087 // VkPresentInfoKHR present_info = {};
15088
15089 ASSERT_NO_FATAL_FAILURE(InitState());
15090
15091 // Use the create function from one of the VK_KHR_*_surface extension in
15092 // order to create a surface, testing all known errors in the process,
15093 // before successfully creating a surface:
15094 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15096 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15097 pass = (err != VK_SUCCESS);
15098 ASSERT_TRUE(pass);
15099 m_errorMonitor->VerifyFound();
15100
15101 // Next, try to create a surface with the wrong
15102 // VkXcbSurfaceCreateInfoKHR::sType:
15103 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15104 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15106 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15107 pass = (err != VK_SUCCESS);
15108 ASSERT_TRUE(pass);
15109 m_errorMonitor->VerifyFound();
15110
15111 // Create a native window, and then correctly create a surface:
15112 xcb_connection_t *connection;
15113 xcb_screen_t *screen;
15114 xcb_window_t xcb_window;
15115 xcb_intern_atom_reply_t *atom_wm_delete_window;
15116
15117 const xcb_setup_t *setup;
15118 xcb_screen_iterator_t iter;
15119 int scr;
15120 uint32_t value_mask, value_list[32];
15121 int width = 1;
15122 int height = 1;
15123
15124 connection = xcb_connect(NULL, &scr);
15125 ASSERT_TRUE(connection != NULL);
15126 setup = xcb_get_setup(connection);
15127 iter = xcb_setup_roots_iterator(setup);
15128 while (scr-- > 0)
15129 xcb_screen_next(&iter);
15130 screen = iter.data;
15131
15132 xcb_window = xcb_generate_id(connection);
15133
15134 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15135 value_list[0] = screen->black_pixel;
15136 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15137
15138 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15139 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15140
15141 /* Magic code that will send notification when window is destroyed */
15142 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15143 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15144
15145 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15146 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15147 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15148 free(reply);
15149
15150 xcb_map_window(connection, xcb_window);
15151
15152 // Force the x/y coordinates to 100,100 results are identical in consecutive
15153 // runs
15154 const uint32_t coords[] = { 100, 100 };
15155 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15156
15157 // Finally, try to correctly create a surface:
15158 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15159 xcb_create_info.pNext = NULL;
15160 xcb_create_info.flags = 0;
15161 xcb_create_info.connection = connection;
15162 xcb_create_info.window = xcb_window;
15163 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15164 pass = (err == VK_SUCCESS);
15165 ASSERT_TRUE(pass);
15166
15167 // Check if surface supports presentation:
15168
15169 // 1st, do so without having queried the queue families:
15170 VkBool32 supported = false;
15171 // TODO: Get the following error to come out:
15172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15173 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15174 "function");
15175 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15176 pass = (err != VK_SUCCESS);
15177 // ASSERT_TRUE(pass);
15178 // m_errorMonitor->VerifyFound();
15179
15180 // Next, query a queue family index that's too large:
15181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15182 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15183 pass = (err != VK_SUCCESS);
15184 ASSERT_TRUE(pass);
15185 m_errorMonitor->VerifyFound();
15186
15187 // Finally, do so correctly:
15188 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15189 // SUPPORTED
15190 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15191 pass = (err == VK_SUCCESS);
15192 ASSERT_TRUE(pass);
15193
15194 // Before proceeding, try to create a swapchain without having called
15195 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15196 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15197 swapchain_create_info.pNext = NULL;
15198 swapchain_create_info.flags = 0;
15199 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15200 swapchain_create_info.surface = surface;
15201 swapchain_create_info.imageArrayLayers = 1;
15202 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15203 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15205 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15206 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15207 pass = (err != VK_SUCCESS);
15208 ASSERT_TRUE(pass);
15209 m_errorMonitor->VerifyFound();
15210
15211 // Get the surface capabilities:
15212 VkSurfaceCapabilitiesKHR surface_capabilities;
15213
15214 // Do so correctly (only error logged by this entrypoint is if the
15215 // extension isn't enabled):
15216 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15217 pass = (err == VK_SUCCESS);
15218 ASSERT_TRUE(pass);
15219
15220 // Get the surface formats:
15221 uint32_t surface_format_count;
15222
15223 // First, try without a pointer to surface_format_count:
15224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15225 "specified as NULL");
15226 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15227 pass = (err == VK_SUCCESS);
15228 ASSERT_TRUE(pass);
15229 m_errorMonitor->VerifyFound();
15230
15231 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15232 // correctly done a 1st try (to get the count):
15233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15234 surface_format_count = 0;
15235 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15236 pass = (err == VK_SUCCESS);
15237 ASSERT_TRUE(pass);
15238 m_errorMonitor->VerifyFound();
15239
15240 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15241 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15242 pass = (err == VK_SUCCESS);
15243 ASSERT_TRUE(pass);
15244
15245 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15246 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15247
15248 // Next, do a 2nd try with surface_format_count being set too high:
15249 surface_format_count += 5;
15250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15251 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15252 pass = (err == VK_SUCCESS);
15253 ASSERT_TRUE(pass);
15254 m_errorMonitor->VerifyFound();
15255
15256 // Finally, do a correct 1st and 2nd try:
15257 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15258 pass = (err == VK_SUCCESS);
15259 ASSERT_TRUE(pass);
15260 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15261 pass = (err == VK_SUCCESS);
15262 ASSERT_TRUE(pass);
15263
15264 // Get the surface present modes:
15265 uint32_t surface_present_mode_count;
15266
15267 // First, try without a pointer to surface_format_count:
15268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15269 "specified as NULL");
15270
15271 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15272 pass = (err == VK_SUCCESS);
15273 ASSERT_TRUE(pass);
15274 m_errorMonitor->VerifyFound();
15275
15276 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15277 // correctly done a 1st try (to get the count):
15278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15279 surface_present_mode_count = 0;
15280 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15281 (VkPresentModeKHR *)&surface_present_mode_count);
15282 pass = (err == VK_SUCCESS);
15283 ASSERT_TRUE(pass);
15284 m_errorMonitor->VerifyFound();
15285
15286 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15287 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15288 pass = (err == VK_SUCCESS);
15289 ASSERT_TRUE(pass);
15290
15291 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15292 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15293
15294 // Next, do a 2nd try with surface_format_count being set too high:
15295 surface_present_mode_count += 5;
15296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15297 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15298 pass = (err == VK_SUCCESS);
15299 ASSERT_TRUE(pass);
15300 m_errorMonitor->VerifyFound();
15301
15302 // Finally, do a correct 1st and 2nd try:
15303 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15304 pass = (err == VK_SUCCESS);
15305 ASSERT_TRUE(pass);
15306 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15307 pass = (err == VK_SUCCESS);
15308 ASSERT_TRUE(pass);
15309
15310 // Create a swapchain:
15311
15312 // First, try without a pointer to swapchain_create_info:
15313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15314 "specified as NULL");
15315
15316 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15317 pass = (err != VK_SUCCESS);
15318 ASSERT_TRUE(pass);
15319 m_errorMonitor->VerifyFound();
15320
15321 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15322 // sType:
15323 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15325
15326 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15327 pass = (err != VK_SUCCESS);
15328 ASSERT_TRUE(pass);
15329 m_errorMonitor->VerifyFound();
15330
15331 // Next, call with a NULL swapchain pointer:
15332 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15333 swapchain_create_info.pNext = NULL;
15334 swapchain_create_info.flags = 0;
15335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15336 "specified as NULL");
15337
15338 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15339 pass = (err != VK_SUCCESS);
15340 ASSERT_TRUE(pass);
15341 m_errorMonitor->VerifyFound();
15342
15343 // TODO: Enhance swapchain layer so that
15344 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15345
15346 // Next, call with a queue family index that's too large:
15347 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15348 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15349 swapchain_create_info.queueFamilyIndexCount = 2;
15350 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15352 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15353 pass = (err != VK_SUCCESS);
15354 ASSERT_TRUE(pass);
15355 m_errorMonitor->VerifyFound();
15356
15357 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15358 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15359 swapchain_create_info.queueFamilyIndexCount = 1;
15360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15361 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15362 "pCreateInfo->pQueueFamilyIndices).");
15363 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15364 pass = (err != VK_SUCCESS);
15365 ASSERT_TRUE(pass);
15366 m_errorMonitor->VerifyFound();
15367
15368 // Next, call with an invalid imageSharingMode:
15369 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15370 swapchain_create_info.queueFamilyIndexCount = 1;
15371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15372 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15373 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15374 pass = (err != VK_SUCCESS);
15375 ASSERT_TRUE(pass);
15376 m_errorMonitor->VerifyFound();
15377 // Fix for the future:
15378 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15379 // SUPPORTED
15380 swapchain_create_info.queueFamilyIndexCount = 0;
15381 queueFamilyIndex[0] = 0;
15382 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15383
15384 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15385 // Get the images from a swapchain:
15386 // Acquire an image from a swapchain:
15387 // Present an image to a swapchain:
15388 // Destroy the swapchain:
15389
15390 // TODOs:
15391 //
15392 // - Try destroying the device without first destroying the swapchain
15393 //
15394 // - Try destroying the device without first destroying the surface
15395 //
15396 // - Try destroying the surface without first destroying the swapchain
15397
15398 // Destroy the surface:
15399 vkDestroySurfaceKHR(instance(), surface, NULL);
15400
15401 // Tear down the window:
15402 xcb_destroy_window(connection, xcb_window);
15403 xcb_disconnect(connection);
15404
15405#else // VK_USE_PLATFORM_XCB_KHR
15406 return;
15407#endif // VK_USE_PLATFORM_XCB_KHR
15408}
15409
15410//
15411// POSITIVE VALIDATION TESTS
15412//
15413// These tests do not expect to encounter ANY validation errors pass only if this is true
15414
Tobin Ehlise0006882016-11-03 10:14:28 -060015415TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15416 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15417 "by a transition in the primary.");
15418 VkResult err;
15419 m_errorMonitor->ExpectSuccess();
15420 ASSERT_NO_FATAL_FAILURE(InitState());
15421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15422 // Allocate a secondary and primary cmd buffer
15423 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15424 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15425 command_buffer_allocate_info.commandPool = m_commandPool;
15426 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15427 command_buffer_allocate_info.commandBufferCount = 1;
15428
15429 VkCommandBuffer secondary_command_buffer;
15430 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15431 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15432 VkCommandBuffer primary_command_buffer;
15433 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15434 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15435 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15436 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15437 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15438 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15439 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15440
15441 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15442 ASSERT_VK_SUCCESS(err);
15443 VkImageObj image(m_device);
15444 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15445 ASSERT_TRUE(image.initialized());
15446 VkImageMemoryBarrier img_barrier = {};
15447 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15448 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15449 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15450 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15451 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15452 img_barrier.image = image.handle();
15453 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15454 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15455 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15456 img_barrier.subresourceRange.baseArrayLayer = 0;
15457 img_barrier.subresourceRange.baseMipLevel = 0;
15458 img_barrier.subresourceRange.layerCount = 1;
15459 img_barrier.subresourceRange.levelCount = 1;
15460 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15461 0, nullptr, 1, &img_barrier);
15462 err = vkEndCommandBuffer(secondary_command_buffer);
15463 ASSERT_VK_SUCCESS(err);
15464
15465 // Now update primary cmd buffer to execute secondary and transitions image
15466 command_buffer_begin_info.pInheritanceInfo = nullptr;
15467 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15468 ASSERT_VK_SUCCESS(err);
15469 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15470 VkImageMemoryBarrier img_barrier2 = {};
15471 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15472 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15473 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15474 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15475 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15476 img_barrier2.image = image.handle();
15477 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15478 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15479 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15480 img_barrier2.subresourceRange.baseArrayLayer = 0;
15481 img_barrier2.subresourceRange.baseMipLevel = 0;
15482 img_barrier2.subresourceRange.layerCount = 1;
15483 img_barrier2.subresourceRange.levelCount = 1;
15484 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15485 nullptr, 1, &img_barrier2);
15486 err = vkEndCommandBuffer(primary_command_buffer);
15487 ASSERT_VK_SUCCESS(err);
15488 VkSubmitInfo submit_info = {};
15489 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15490 submit_info.commandBufferCount = 1;
15491 submit_info.pCommandBuffers = &primary_command_buffer;
15492 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15493 ASSERT_VK_SUCCESS(err);
15494 m_errorMonitor->VerifyNotFound();
15495 err = vkDeviceWaitIdle(m_device->device());
15496 ASSERT_VK_SUCCESS(err);
15497 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15498 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15499}
15500
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015501// This is a positive test. No failures are expected.
15502TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15503 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15504 "is ignoring VkWriteDescriptorSet members that are not "
15505 "related to the descriptor type specified by "
15506 "VkWriteDescriptorSet::descriptorType. Correct "
15507 "validation behavior will result in the test running to "
15508 "completion without validation errors.");
15509
15510 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15511
15512 ASSERT_NO_FATAL_FAILURE(InitState());
15513
15514 // Image Case
15515 {
15516 m_errorMonitor->ExpectSuccess();
15517
15518 VkImage image;
15519 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15520 const int32_t tex_width = 32;
15521 const int32_t tex_height = 32;
15522 VkImageCreateInfo image_create_info = {};
15523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15524 image_create_info.pNext = NULL;
15525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15526 image_create_info.format = tex_format;
15527 image_create_info.extent.width = tex_width;
15528 image_create_info.extent.height = tex_height;
15529 image_create_info.extent.depth = 1;
15530 image_create_info.mipLevels = 1;
15531 image_create_info.arrayLayers = 1;
15532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15533 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15535 image_create_info.flags = 0;
15536 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15537 ASSERT_VK_SUCCESS(err);
15538
15539 VkMemoryRequirements memory_reqs;
15540 VkDeviceMemory image_memory;
15541 bool pass;
15542 VkMemoryAllocateInfo memory_info = {};
15543 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15544 memory_info.pNext = NULL;
15545 memory_info.allocationSize = 0;
15546 memory_info.memoryTypeIndex = 0;
15547 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15548 memory_info.allocationSize = memory_reqs.size;
15549 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15550 ASSERT_TRUE(pass);
15551 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15552 ASSERT_VK_SUCCESS(err);
15553 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15554 ASSERT_VK_SUCCESS(err);
15555
15556 VkImageViewCreateInfo image_view_create_info = {};
15557 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15558 image_view_create_info.image = image;
15559 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15560 image_view_create_info.format = tex_format;
15561 image_view_create_info.subresourceRange.layerCount = 1;
15562 image_view_create_info.subresourceRange.baseMipLevel = 0;
15563 image_view_create_info.subresourceRange.levelCount = 1;
15564 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15565
15566 VkImageView view;
15567 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15568 ASSERT_VK_SUCCESS(err);
15569
15570 VkDescriptorPoolSize ds_type_count = {};
15571 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15572 ds_type_count.descriptorCount = 1;
15573
15574 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15575 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15576 ds_pool_ci.pNext = NULL;
15577 ds_pool_ci.maxSets = 1;
15578 ds_pool_ci.poolSizeCount = 1;
15579 ds_pool_ci.pPoolSizes = &ds_type_count;
15580
15581 VkDescriptorPool ds_pool;
15582 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15583 ASSERT_VK_SUCCESS(err);
15584
15585 VkDescriptorSetLayoutBinding dsl_binding = {};
15586 dsl_binding.binding = 0;
15587 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15588 dsl_binding.descriptorCount = 1;
15589 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15590 dsl_binding.pImmutableSamplers = NULL;
15591
15592 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15593 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15594 ds_layout_ci.pNext = NULL;
15595 ds_layout_ci.bindingCount = 1;
15596 ds_layout_ci.pBindings = &dsl_binding;
15597 VkDescriptorSetLayout ds_layout;
15598 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15599 ASSERT_VK_SUCCESS(err);
15600
15601 VkDescriptorSet descriptor_set;
15602 VkDescriptorSetAllocateInfo alloc_info = {};
15603 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15604 alloc_info.descriptorSetCount = 1;
15605 alloc_info.descriptorPool = ds_pool;
15606 alloc_info.pSetLayouts = &ds_layout;
15607 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15608 ASSERT_VK_SUCCESS(err);
15609
15610 VkDescriptorImageInfo image_info = {};
15611 image_info.imageView = view;
15612 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15613
15614 VkWriteDescriptorSet descriptor_write;
15615 memset(&descriptor_write, 0, sizeof(descriptor_write));
15616 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15617 descriptor_write.dstSet = descriptor_set;
15618 descriptor_write.dstBinding = 0;
15619 descriptor_write.descriptorCount = 1;
15620 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15621 descriptor_write.pImageInfo = &image_info;
15622
15623 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15624 // be
15625 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15626 // This will most likely produce a crash if the parameter_validation
15627 // layer
15628 // does not correctly ignore pBufferInfo.
15629 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15630 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15631
15632 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15633
15634 m_errorMonitor->VerifyNotFound();
15635
15636 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15637 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15638 vkDestroyImageView(m_device->device(), view, NULL);
15639 vkDestroyImage(m_device->device(), image, NULL);
15640 vkFreeMemory(m_device->device(), image_memory, NULL);
15641 }
15642
15643 // Buffer Case
15644 {
15645 m_errorMonitor->ExpectSuccess();
15646
15647 VkBuffer buffer;
15648 uint32_t queue_family_index = 0;
15649 VkBufferCreateInfo buffer_create_info = {};
15650 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15651 buffer_create_info.size = 1024;
15652 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15653 buffer_create_info.queueFamilyIndexCount = 1;
15654 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15655
15656 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15657 ASSERT_VK_SUCCESS(err);
15658
15659 VkMemoryRequirements memory_reqs;
15660 VkDeviceMemory buffer_memory;
15661 bool pass;
15662 VkMemoryAllocateInfo memory_info = {};
15663 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15664 memory_info.pNext = NULL;
15665 memory_info.allocationSize = 0;
15666 memory_info.memoryTypeIndex = 0;
15667
15668 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15669 memory_info.allocationSize = memory_reqs.size;
15670 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15671 ASSERT_TRUE(pass);
15672
15673 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15674 ASSERT_VK_SUCCESS(err);
15675 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15676 ASSERT_VK_SUCCESS(err);
15677
15678 VkDescriptorPoolSize ds_type_count = {};
15679 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15680 ds_type_count.descriptorCount = 1;
15681
15682 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15683 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15684 ds_pool_ci.pNext = NULL;
15685 ds_pool_ci.maxSets = 1;
15686 ds_pool_ci.poolSizeCount = 1;
15687 ds_pool_ci.pPoolSizes = &ds_type_count;
15688
15689 VkDescriptorPool ds_pool;
15690 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15691 ASSERT_VK_SUCCESS(err);
15692
15693 VkDescriptorSetLayoutBinding dsl_binding = {};
15694 dsl_binding.binding = 0;
15695 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15696 dsl_binding.descriptorCount = 1;
15697 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15698 dsl_binding.pImmutableSamplers = NULL;
15699
15700 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15701 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15702 ds_layout_ci.pNext = NULL;
15703 ds_layout_ci.bindingCount = 1;
15704 ds_layout_ci.pBindings = &dsl_binding;
15705 VkDescriptorSetLayout ds_layout;
15706 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15707 ASSERT_VK_SUCCESS(err);
15708
15709 VkDescriptorSet descriptor_set;
15710 VkDescriptorSetAllocateInfo alloc_info = {};
15711 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15712 alloc_info.descriptorSetCount = 1;
15713 alloc_info.descriptorPool = ds_pool;
15714 alloc_info.pSetLayouts = &ds_layout;
15715 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15716 ASSERT_VK_SUCCESS(err);
15717
15718 VkDescriptorBufferInfo buffer_info = {};
15719 buffer_info.buffer = buffer;
15720 buffer_info.offset = 0;
15721 buffer_info.range = 1024;
15722
15723 VkWriteDescriptorSet descriptor_write;
15724 memset(&descriptor_write, 0, sizeof(descriptor_write));
15725 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15726 descriptor_write.dstSet = descriptor_set;
15727 descriptor_write.dstBinding = 0;
15728 descriptor_write.descriptorCount = 1;
15729 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15730 descriptor_write.pBufferInfo = &buffer_info;
15731
15732 // Set pImageInfo and pTexelBufferView to invalid values, which should
15733 // be
15734 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15735 // This will most likely produce a crash if the parameter_validation
15736 // layer
15737 // does not correctly ignore pImageInfo.
15738 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15739 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15740
15741 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15742
15743 m_errorMonitor->VerifyNotFound();
15744
15745 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15746 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15747 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15748 vkDestroyBuffer(m_device->device(), buffer, NULL);
15749 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15750 }
15751
15752 // Texel Buffer Case
15753 {
15754 m_errorMonitor->ExpectSuccess();
15755
15756 VkBuffer buffer;
15757 uint32_t queue_family_index = 0;
15758 VkBufferCreateInfo buffer_create_info = {};
15759 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15760 buffer_create_info.size = 1024;
15761 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15762 buffer_create_info.queueFamilyIndexCount = 1;
15763 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15764
15765 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15766 ASSERT_VK_SUCCESS(err);
15767
15768 VkMemoryRequirements memory_reqs;
15769 VkDeviceMemory buffer_memory;
15770 bool pass;
15771 VkMemoryAllocateInfo memory_info = {};
15772 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15773 memory_info.pNext = NULL;
15774 memory_info.allocationSize = 0;
15775 memory_info.memoryTypeIndex = 0;
15776
15777 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15778 memory_info.allocationSize = memory_reqs.size;
15779 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15780 ASSERT_TRUE(pass);
15781
15782 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15783 ASSERT_VK_SUCCESS(err);
15784 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15785 ASSERT_VK_SUCCESS(err);
15786
15787 VkBufferViewCreateInfo buff_view_ci = {};
15788 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15789 buff_view_ci.buffer = buffer;
15790 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15791 buff_view_ci.range = VK_WHOLE_SIZE;
15792 VkBufferView buffer_view;
15793 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15794
15795 VkDescriptorPoolSize ds_type_count = {};
15796 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15797 ds_type_count.descriptorCount = 1;
15798
15799 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15800 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15801 ds_pool_ci.pNext = NULL;
15802 ds_pool_ci.maxSets = 1;
15803 ds_pool_ci.poolSizeCount = 1;
15804 ds_pool_ci.pPoolSizes = &ds_type_count;
15805
15806 VkDescriptorPool ds_pool;
15807 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15808 ASSERT_VK_SUCCESS(err);
15809
15810 VkDescriptorSetLayoutBinding dsl_binding = {};
15811 dsl_binding.binding = 0;
15812 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15813 dsl_binding.descriptorCount = 1;
15814 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15815 dsl_binding.pImmutableSamplers = NULL;
15816
15817 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15818 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15819 ds_layout_ci.pNext = NULL;
15820 ds_layout_ci.bindingCount = 1;
15821 ds_layout_ci.pBindings = &dsl_binding;
15822 VkDescriptorSetLayout ds_layout;
15823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15824 ASSERT_VK_SUCCESS(err);
15825
15826 VkDescriptorSet descriptor_set;
15827 VkDescriptorSetAllocateInfo alloc_info = {};
15828 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15829 alloc_info.descriptorSetCount = 1;
15830 alloc_info.descriptorPool = ds_pool;
15831 alloc_info.pSetLayouts = &ds_layout;
15832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15833 ASSERT_VK_SUCCESS(err);
15834
15835 VkWriteDescriptorSet descriptor_write;
15836 memset(&descriptor_write, 0, sizeof(descriptor_write));
15837 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15838 descriptor_write.dstSet = descriptor_set;
15839 descriptor_write.dstBinding = 0;
15840 descriptor_write.descriptorCount = 1;
15841 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15842 descriptor_write.pTexelBufferView = &buffer_view;
15843
15844 // Set pImageInfo and pBufferInfo to invalid values, which should be
15845 // ignored for descriptorType ==
15846 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15847 // This will most likely produce a crash if the parameter_validation
15848 // layer
15849 // does not correctly ignore pImageInfo and pBufferInfo.
15850 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15851 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15852
15853 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15854
15855 m_errorMonitor->VerifyNotFound();
15856
15857 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15858 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15859 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15860 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15861 vkDestroyBuffer(m_device->device(), buffer, NULL);
15862 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15863 }
15864}
15865
Tobin Ehlisf7428442016-10-25 07:58:24 -060015866TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15867 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15868
15869 ASSERT_NO_FATAL_FAILURE(InitState());
15870 // Create layout where two binding #s are "1"
15871 static const uint32_t NUM_BINDINGS = 3;
15872 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15873 dsl_binding[0].binding = 1;
15874 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15875 dsl_binding[0].descriptorCount = 1;
15876 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15877 dsl_binding[0].pImmutableSamplers = NULL;
15878 dsl_binding[1].binding = 0;
15879 dsl_binding[1].descriptorCount = 1;
15880 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15881 dsl_binding[1].descriptorCount = 1;
15882 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15883 dsl_binding[1].pImmutableSamplers = NULL;
15884 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15885 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15886 dsl_binding[2].descriptorCount = 1;
15887 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15888 dsl_binding[2].pImmutableSamplers = NULL;
15889
15890 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15891 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15892 ds_layout_ci.pNext = NULL;
15893 ds_layout_ci.bindingCount = NUM_BINDINGS;
15894 ds_layout_ci.pBindings = dsl_binding;
15895 VkDescriptorSetLayout ds_layout;
15896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15897 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15898 m_errorMonitor->VerifyFound();
15899}
15900
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015901TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015902 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
15903
15904 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015905
15906 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015907
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015908 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
15909
15910 {
15911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
15912 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
15913 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15914 m_errorMonitor->VerifyFound();
15915 }
15916
15917 {
15918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
15919 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
15920 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15921 m_errorMonitor->VerifyFound();
15922 }
15923
15924 {
15925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15926 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
15927 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15928 m_errorMonitor->VerifyFound();
15929 }
15930
15931 {
15932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15933 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
15934 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15935 m_errorMonitor->VerifyFound();
15936 }
15937
15938 {
15939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
15940 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
15941 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15942 m_errorMonitor->VerifyFound();
15943 }
15944
15945 {
15946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
15947 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
15948 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15949 m_errorMonitor->VerifyFound();
15950 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015951
15952 {
15953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15954 VkRect2D scissor = {{-1, 0}, {16, 16}};
15955 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15956 m_errorMonitor->VerifyFound();
15957 }
15958
15959 {
15960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15961 VkRect2D scissor = {{0, -2}, {16, 16}};
15962 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15963 m_errorMonitor->VerifyFound();
15964 }
15965
15966 {
15967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
15968 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
15969 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15970 m_errorMonitor->VerifyFound();
15971 }
15972
15973 {
15974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
15975 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
15976 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15977 m_errorMonitor->VerifyFound();
15978 }
15979
15980 EndCommandBuffer();
15981}
15982
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015983// This is a positive test. No failures are expected.
15984TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
15985 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
15986 VkResult err;
15987
15988 ASSERT_NO_FATAL_FAILURE(InitState());
15989 m_errorMonitor->ExpectSuccess();
15990 VkDescriptorPoolSize ds_type_count = {};
15991 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15992 ds_type_count.descriptorCount = 2;
15993
15994 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15995 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15996 ds_pool_ci.pNext = NULL;
15997 ds_pool_ci.maxSets = 1;
15998 ds_pool_ci.poolSizeCount = 1;
15999 ds_pool_ci.pPoolSizes = &ds_type_count;
16000
16001 VkDescriptorPool ds_pool;
16002 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16003 ASSERT_VK_SUCCESS(err);
16004
16005 // Create layout with two uniform buffer descriptors w/ empty binding between them
16006 static const uint32_t NUM_BINDINGS = 3;
16007 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16008 dsl_binding[0].binding = 0;
16009 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16010 dsl_binding[0].descriptorCount = 1;
16011 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16012 dsl_binding[0].pImmutableSamplers = NULL;
16013 dsl_binding[1].binding = 1;
16014 dsl_binding[1].descriptorCount = 0; // empty binding
16015 dsl_binding[2].binding = 2;
16016 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16017 dsl_binding[2].descriptorCount = 1;
16018 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16019 dsl_binding[2].pImmutableSamplers = NULL;
16020
16021 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16022 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16023 ds_layout_ci.pNext = NULL;
16024 ds_layout_ci.bindingCount = NUM_BINDINGS;
16025 ds_layout_ci.pBindings = dsl_binding;
16026 VkDescriptorSetLayout ds_layout;
16027 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16028 ASSERT_VK_SUCCESS(err);
16029
16030 VkDescriptorSet descriptor_set = {};
16031 VkDescriptorSetAllocateInfo alloc_info = {};
16032 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16033 alloc_info.descriptorSetCount = 1;
16034 alloc_info.descriptorPool = ds_pool;
16035 alloc_info.pSetLayouts = &ds_layout;
16036 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16037 ASSERT_VK_SUCCESS(err);
16038
16039 // Create a buffer to be used for update
16040 VkBufferCreateInfo buff_ci = {};
16041 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16042 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16043 buff_ci.size = 256;
16044 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16045 VkBuffer buffer;
16046 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16047 ASSERT_VK_SUCCESS(err);
16048 // Have to bind memory to buffer before descriptor update
16049 VkMemoryAllocateInfo mem_alloc = {};
16050 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16051 mem_alloc.pNext = NULL;
16052 mem_alloc.allocationSize = 512; // one allocation for both buffers
16053 mem_alloc.memoryTypeIndex = 0;
16054
16055 VkMemoryRequirements mem_reqs;
16056 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16057 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16058 if (!pass) {
16059 vkDestroyBuffer(m_device->device(), buffer, NULL);
16060 return;
16061 }
16062
16063 VkDeviceMemory mem;
16064 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16065 ASSERT_VK_SUCCESS(err);
16066 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16067 ASSERT_VK_SUCCESS(err);
16068
16069 // Only update the descriptor at binding 2
16070 VkDescriptorBufferInfo buff_info = {};
16071 buff_info.buffer = buffer;
16072 buff_info.offset = 0;
16073 buff_info.range = VK_WHOLE_SIZE;
16074 VkWriteDescriptorSet descriptor_write = {};
16075 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16076 descriptor_write.dstBinding = 2;
16077 descriptor_write.descriptorCount = 1;
16078 descriptor_write.pTexelBufferView = nullptr;
16079 descriptor_write.pBufferInfo = &buff_info;
16080 descriptor_write.pImageInfo = nullptr;
16081 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16082 descriptor_write.dstSet = descriptor_set;
16083
16084 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16085
16086 m_errorMonitor->VerifyNotFound();
16087 // Cleanup
16088 vkFreeMemory(m_device->device(), mem, NULL);
16089 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16090 vkDestroyBuffer(m_device->device(), buffer, NULL);
16091 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16092}
16093
16094// This is a positive test. No failures are expected.
16095TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16096 VkResult err;
16097 bool pass;
16098
16099 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16100 "the buffer, create an image, and bind the same memory to "
16101 "it");
16102
16103 m_errorMonitor->ExpectSuccess();
16104
16105 ASSERT_NO_FATAL_FAILURE(InitState());
16106
16107 VkBuffer buffer;
16108 VkImage image;
16109 VkDeviceMemory mem;
16110 VkMemoryRequirements mem_reqs;
16111
16112 VkBufferCreateInfo buf_info = {};
16113 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16114 buf_info.pNext = NULL;
16115 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16116 buf_info.size = 256;
16117 buf_info.queueFamilyIndexCount = 0;
16118 buf_info.pQueueFamilyIndices = NULL;
16119 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16120 buf_info.flags = 0;
16121 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16122 ASSERT_VK_SUCCESS(err);
16123
16124 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16125
16126 VkMemoryAllocateInfo alloc_info = {};
16127 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16128 alloc_info.pNext = NULL;
16129 alloc_info.memoryTypeIndex = 0;
16130
16131 // Ensure memory is big enough for both bindings
16132 alloc_info.allocationSize = 0x10000;
16133
16134 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16135 if (!pass) {
16136 vkDestroyBuffer(m_device->device(), buffer, NULL);
16137 return;
16138 }
16139
16140 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16141 ASSERT_VK_SUCCESS(err);
16142
16143 uint8_t *pData;
16144 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16145 ASSERT_VK_SUCCESS(err);
16146
16147 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16148
16149 vkUnmapMemory(m_device->device(), mem);
16150
16151 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16152 ASSERT_VK_SUCCESS(err);
16153
16154 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16155 // memory. In fact, it was never used by the GPU.
16156 // Just be be sure, wait for idle.
16157 vkDestroyBuffer(m_device->device(), buffer, NULL);
16158 vkDeviceWaitIdle(m_device->device());
16159
16160 VkImageCreateInfo image_create_info = {};
16161 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16162 image_create_info.pNext = NULL;
16163 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16164 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16165 image_create_info.extent.width = 64;
16166 image_create_info.extent.height = 64;
16167 image_create_info.extent.depth = 1;
16168 image_create_info.mipLevels = 1;
16169 image_create_info.arrayLayers = 1;
16170 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16171 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16172 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16173 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16174 image_create_info.queueFamilyIndexCount = 0;
16175 image_create_info.pQueueFamilyIndices = NULL;
16176 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16177 image_create_info.flags = 0;
16178
16179 VkMemoryAllocateInfo mem_alloc = {};
16180 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16181 mem_alloc.pNext = NULL;
16182 mem_alloc.allocationSize = 0;
16183 mem_alloc.memoryTypeIndex = 0;
16184
16185 /* Create a mappable image. It will be the texture if linear images are ok
16186 * to be textures or it will be the staging image if they are not.
16187 */
16188 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16189 ASSERT_VK_SUCCESS(err);
16190
16191 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16192
16193 mem_alloc.allocationSize = mem_reqs.size;
16194
16195 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16196 if (!pass) {
16197 vkDestroyImage(m_device->device(), image, NULL);
16198 return;
16199 }
16200
16201 // VALIDATION FAILURE:
16202 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16203 ASSERT_VK_SUCCESS(err);
16204
16205 m_errorMonitor->VerifyNotFound();
16206
16207 vkFreeMemory(m_device->device(), mem, NULL);
16208 vkDestroyBuffer(m_device->device(), buffer, NULL);
16209 vkDestroyImage(m_device->device(), image, NULL);
16210}
16211
16212TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16213
16214 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16215 "mapping while using VK_WHOLE_SIZE does not cause access "
16216 "violations");
16217 VkResult err;
16218 uint8_t *pData;
16219 ASSERT_NO_FATAL_FAILURE(InitState());
16220
16221 VkDeviceMemory mem;
16222 VkMemoryRequirements mem_reqs;
16223 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16224 VkMemoryAllocateInfo alloc_info = {};
16225 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16226 alloc_info.pNext = NULL;
16227 alloc_info.memoryTypeIndex = 0;
16228
16229 static const VkDeviceSize allocation_size = 0x1000;
16230 alloc_info.allocationSize = allocation_size;
16231
16232 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16233 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16234 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16235 if (!pass) {
16236 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16237 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16238 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16239 if (!pass) {
16240 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16241 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16242 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16243 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16244 if (!pass) {
16245 return;
16246 }
16247 }
16248 }
16249
16250 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16251 ASSERT_VK_SUCCESS(err);
16252
16253 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16254 // mapped range
16255 m_errorMonitor->ExpectSuccess();
16256 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16257 ASSERT_VK_SUCCESS(err);
16258 VkMappedMemoryRange mmr = {};
16259 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16260 mmr.memory = mem;
16261 mmr.offset = 0;
16262 mmr.size = VK_WHOLE_SIZE;
16263 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16264 ASSERT_VK_SUCCESS(err);
16265 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16266 ASSERT_VK_SUCCESS(err);
16267 m_errorMonitor->VerifyNotFound();
16268 vkUnmapMemory(m_device->device(), mem);
16269
16270 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16271 // mapped range
16272 m_errorMonitor->ExpectSuccess();
16273 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16274 ASSERT_VK_SUCCESS(err);
16275 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16276 mmr.memory = mem;
16277 mmr.offset = 13;
16278 mmr.size = VK_WHOLE_SIZE;
16279 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16280 ASSERT_VK_SUCCESS(err);
16281 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16282 ASSERT_VK_SUCCESS(err);
16283 m_errorMonitor->VerifyNotFound();
16284 vkUnmapMemory(m_device->device(), mem);
16285
16286 // Map with prime offset and size
16287 // Flush/Invalidate subrange of mapped area with prime offset and size
16288 m_errorMonitor->ExpectSuccess();
16289 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16290 ASSERT_VK_SUCCESS(err);
16291 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16292 mmr.memory = mem;
16293 mmr.offset = allocation_size - 107;
16294 mmr.size = 61;
16295 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16296 ASSERT_VK_SUCCESS(err);
16297 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16298 ASSERT_VK_SUCCESS(err);
16299 m_errorMonitor->VerifyNotFound();
16300 vkUnmapMemory(m_device->device(), mem);
16301
16302 // Map without offset and flush WHOLE_SIZE with two separate offsets
16303 m_errorMonitor->ExpectSuccess();
16304 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16305 ASSERT_VK_SUCCESS(err);
16306 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16307 mmr.memory = mem;
16308 mmr.offset = allocation_size - 100;
16309 mmr.size = VK_WHOLE_SIZE;
16310 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16311 ASSERT_VK_SUCCESS(err);
16312 mmr.offset = allocation_size - 200;
16313 mmr.size = VK_WHOLE_SIZE;
16314 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16315 ASSERT_VK_SUCCESS(err);
16316 m_errorMonitor->VerifyNotFound();
16317 vkUnmapMemory(m_device->device(), mem);
16318
16319 vkFreeMemory(m_device->device(), mem, NULL);
16320}
16321
16322// This is a positive test. We used to expect error in this case but spec now allows it
16323TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16324 m_errorMonitor->ExpectSuccess();
16325 vk_testing::Fence testFence;
16326 VkFenceCreateInfo fenceInfo = {};
16327 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16328 fenceInfo.pNext = NULL;
16329
16330 ASSERT_NO_FATAL_FAILURE(InitState());
16331 testFence.init(*m_device, fenceInfo);
16332 VkFence fences[1] = { testFence.handle() };
16333 VkResult result = vkResetFences(m_device->device(), 1, fences);
16334 ASSERT_VK_SUCCESS(result);
16335
16336 m_errorMonitor->VerifyNotFound();
16337}
16338
16339TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16340 m_errorMonitor->ExpectSuccess();
16341
16342 ASSERT_NO_FATAL_FAILURE(InitState());
16343 VkResult err;
16344
16345 // Record (empty!) command buffer that can be submitted multiple times
16346 // simultaneously.
16347 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16348 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16349 m_commandBuffer->BeginCommandBuffer(&cbbi);
16350 m_commandBuffer->EndCommandBuffer();
16351
16352 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16353 VkFence fence;
16354 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16355 ASSERT_VK_SUCCESS(err);
16356
16357 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16358 VkSemaphore s1, s2;
16359 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16360 ASSERT_VK_SUCCESS(err);
16361 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16362 ASSERT_VK_SUCCESS(err);
16363
16364 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16365 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16366 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16367 ASSERT_VK_SUCCESS(err);
16368
16369 // Submit CB again, signaling s2.
16370 si.pSignalSemaphores = &s2;
16371 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16372 ASSERT_VK_SUCCESS(err);
16373
16374 // Wait for fence.
16375 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16376 ASSERT_VK_SUCCESS(err);
16377
16378 // CB is still in flight from second submission, but semaphore s1 is no
16379 // longer in flight. delete it.
16380 vkDestroySemaphore(m_device->device(), s1, nullptr);
16381
16382 m_errorMonitor->VerifyNotFound();
16383
16384 // Force device idle and clean up remaining objects
16385 vkDeviceWaitIdle(m_device->device());
16386 vkDestroySemaphore(m_device->device(), s2, nullptr);
16387 vkDestroyFence(m_device->device(), fence, nullptr);
16388}
16389
16390TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16391 m_errorMonitor->ExpectSuccess();
16392
16393 ASSERT_NO_FATAL_FAILURE(InitState());
16394 VkResult err;
16395
16396 // A fence created signaled
16397 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16398 VkFence f1;
16399 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16400 ASSERT_VK_SUCCESS(err);
16401
16402 // A fence created not
16403 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16404 VkFence f2;
16405 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16406 ASSERT_VK_SUCCESS(err);
16407
16408 // Submit the unsignaled fence
16409 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16410 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16411
16412 // Wait on both fences, with signaled first.
16413 VkFence fences[] = { f1, f2 };
16414 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16415
16416 // Should have both retired!
16417 vkDestroyFence(m_device->device(), f1, nullptr);
16418 vkDestroyFence(m_device->device(), f2, nullptr);
16419
16420 m_errorMonitor->VerifyNotFound();
16421}
16422
16423TEST_F(VkPositiveLayerTest, ValidUsage) {
16424 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16425 "doesn't generate validation errors");
16426
16427 ASSERT_NO_FATAL_FAILURE(InitState());
16428
16429 m_errorMonitor->ExpectSuccess();
16430 // Verify that we can create a view with usage INPUT_ATTACHMENT
16431 VkImageObj image(m_device);
16432 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16433 ASSERT_TRUE(image.initialized());
16434 VkImageView imageView;
16435 VkImageViewCreateInfo ivci = {};
16436 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16437 ivci.image = image.handle();
16438 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16439 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16440 ivci.subresourceRange.layerCount = 1;
16441 ivci.subresourceRange.baseMipLevel = 0;
16442 ivci.subresourceRange.levelCount = 1;
16443 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16444
16445 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16446 m_errorMonitor->VerifyNotFound();
16447 vkDestroyImageView(m_device->device(), imageView, NULL);
16448}
16449
16450// This is a positive test. No failures are expected.
16451TEST_F(VkPositiveLayerTest, BindSparse) {
16452 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16453 "and then free the memory");
16454
16455 ASSERT_NO_FATAL_FAILURE(InitState());
16456
16457 auto index = m_device->graphics_queue_node_index_;
16458 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16459 return;
16460
16461 m_errorMonitor->ExpectSuccess();
16462
16463 VkImage image;
16464 VkImageCreateInfo image_create_info = {};
16465 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16466 image_create_info.pNext = NULL;
16467 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16468 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16469 image_create_info.extent.width = 64;
16470 image_create_info.extent.height = 64;
16471 image_create_info.extent.depth = 1;
16472 image_create_info.mipLevels = 1;
16473 image_create_info.arrayLayers = 1;
16474 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16475 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16476 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16477 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16478 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16479 ASSERT_VK_SUCCESS(err);
16480
16481 VkMemoryRequirements memory_reqs;
16482 VkDeviceMemory memory_one, memory_two;
16483 bool pass;
16484 VkMemoryAllocateInfo memory_info = {};
16485 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16486 memory_info.pNext = NULL;
16487 memory_info.allocationSize = 0;
16488 memory_info.memoryTypeIndex = 0;
16489 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16490 // Find an image big enough to allow sparse mapping of 2 memory regions
16491 // Increase the image size until it is at least twice the
16492 // size of the required alignment, to ensure we can bind both
16493 // allocated memory blocks to the image on aligned offsets.
16494 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16495 vkDestroyImage(m_device->device(), image, nullptr);
16496 image_create_info.extent.width *= 2;
16497 image_create_info.extent.height *= 2;
16498 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16499 ASSERT_VK_SUCCESS(err);
16500 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16501 }
16502 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16503 // at the end of the first
16504 memory_info.allocationSize = memory_reqs.alignment;
16505 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16506 ASSERT_TRUE(pass);
16507 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16508 ASSERT_VK_SUCCESS(err);
16509 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16510 ASSERT_VK_SUCCESS(err);
16511 VkSparseMemoryBind binds[2];
16512 binds[0].flags = 0;
16513 binds[0].memory = memory_one;
16514 binds[0].memoryOffset = 0;
16515 binds[0].resourceOffset = 0;
16516 binds[0].size = memory_info.allocationSize;
16517 binds[1].flags = 0;
16518 binds[1].memory = memory_two;
16519 binds[1].memoryOffset = 0;
16520 binds[1].resourceOffset = memory_info.allocationSize;
16521 binds[1].size = memory_info.allocationSize;
16522
16523 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16524 opaqueBindInfo.image = image;
16525 opaqueBindInfo.bindCount = 2;
16526 opaqueBindInfo.pBinds = binds;
16527
16528 VkFence fence = VK_NULL_HANDLE;
16529 VkBindSparseInfo bindSparseInfo = {};
16530 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16531 bindSparseInfo.imageOpaqueBindCount = 1;
16532 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16533
16534 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16535 vkQueueWaitIdle(m_device->m_queue);
16536 vkDestroyImage(m_device->device(), image, NULL);
16537 vkFreeMemory(m_device->device(), memory_one, NULL);
16538 vkFreeMemory(m_device->device(), memory_two, NULL);
16539 m_errorMonitor->VerifyNotFound();
16540}
16541
16542TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16543 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16544 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16545 "the command buffer has prior knowledge of that "
16546 "attachment's layout.");
16547
16548 m_errorMonitor->ExpectSuccess();
16549
16550 ASSERT_NO_FATAL_FAILURE(InitState());
16551
16552 // A renderpass with one color attachment.
16553 VkAttachmentDescription attachment = { 0,
16554 VK_FORMAT_R8G8B8A8_UNORM,
16555 VK_SAMPLE_COUNT_1_BIT,
16556 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16557 VK_ATTACHMENT_STORE_OP_STORE,
16558 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16559 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16560 VK_IMAGE_LAYOUT_UNDEFINED,
16561 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16562
16563 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16564
16565 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16566
16567 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16568
16569 VkRenderPass rp;
16570 VkResult 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 uses this renderpass twice. The
16599 // bug is triggered at the beginning of the second renderpass, when the
16600 // command buffer already has a layout recorded for the attachment.
16601 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16602 BeginCommandBuffer();
16603 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16604 vkCmdEndRenderPass(m_commandBuffer->handle());
16605 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16606
16607 m_errorMonitor->VerifyNotFound();
16608
16609 vkCmdEndRenderPass(m_commandBuffer->handle());
16610 EndCommandBuffer();
16611
16612 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16613 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16614 vkDestroyImageView(m_device->device(), view, nullptr);
16615}
16616
16617TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16618 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16619 "command buffer, bind them together, then destroy "
16620 "command pool and framebuffer and verify there are no "
16621 "errors.");
16622
16623 m_errorMonitor->ExpectSuccess();
16624
16625 ASSERT_NO_FATAL_FAILURE(InitState());
16626
16627 // A renderpass with one color attachment.
16628 VkAttachmentDescription attachment = { 0,
16629 VK_FORMAT_R8G8B8A8_UNORM,
16630 VK_SAMPLE_COUNT_1_BIT,
16631 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16632 VK_ATTACHMENT_STORE_OP_STORE,
16633 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16634 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16635 VK_IMAGE_LAYOUT_UNDEFINED,
16636 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16637
16638 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16639
16640 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16641
16642 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16643
16644 VkRenderPass rp;
16645 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16646 ASSERT_VK_SUCCESS(err);
16647
16648 // A compatible framebuffer.
16649 VkImageObj image(m_device);
16650 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16651 ASSERT_TRUE(image.initialized());
16652
16653 VkImageViewCreateInfo ivci = {
16654 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16655 nullptr,
16656 0,
16657 image.handle(),
16658 VK_IMAGE_VIEW_TYPE_2D,
16659 VK_FORMAT_R8G8B8A8_UNORM,
16660 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16661 VK_COMPONENT_SWIZZLE_IDENTITY },
16662 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16663 };
16664 VkImageView view;
16665 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16666 ASSERT_VK_SUCCESS(err);
16667
16668 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16669 VkFramebuffer fb;
16670 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16671 ASSERT_VK_SUCCESS(err);
16672
16673 // Explicitly create a command buffer to bind the FB to so that we can then
16674 // destroy the command pool in order to implicitly free command buffer
16675 VkCommandPool command_pool;
16676 VkCommandPoolCreateInfo pool_create_info{};
16677 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16678 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16679 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16680 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16681
16682 VkCommandBuffer command_buffer;
16683 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16684 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16685 command_buffer_allocate_info.commandPool = command_pool;
16686 command_buffer_allocate_info.commandBufferCount = 1;
16687 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16688 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16689
16690 // Begin our cmd buffer with renderpass using our framebuffer
16691 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16692 VkCommandBufferBeginInfo begin_info{};
16693 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16694 vkBeginCommandBuffer(command_buffer, &begin_info);
16695
16696 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16697 vkCmdEndRenderPass(command_buffer);
16698 vkEndCommandBuffer(command_buffer);
16699 vkDestroyImageView(m_device->device(), view, nullptr);
16700 // Destroy command pool to implicitly free command buffer
16701 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16702 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16703 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16704 m_errorMonitor->VerifyNotFound();
16705}
16706
16707TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16708 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16709 "transitions for the first subpass");
16710
16711 m_errorMonitor->ExpectSuccess();
16712
16713 ASSERT_NO_FATAL_FAILURE(InitState());
16714
16715 // A renderpass with one color attachment.
16716 VkAttachmentDescription attachment = { 0,
16717 VK_FORMAT_R8G8B8A8_UNORM,
16718 VK_SAMPLE_COUNT_1_BIT,
16719 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16720 VK_ATTACHMENT_STORE_OP_STORE,
16721 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16722 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16723 VK_IMAGE_LAYOUT_UNDEFINED,
16724 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16725
16726 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16727
16728 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16729
16730 VkSubpassDependency dep = { 0,
16731 0,
16732 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16733 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16734 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16735 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16736 VK_DEPENDENCY_BY_REGION_BIT };
16737
16738 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16739
16740 VkResult err;
16741 VkRenderPass rp;
16742 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16743 ASSERT_VK_SUCCESS(err);
16744
16745 // A compatible framebuffer.
16746 VkImageObj image(m_device);
16747 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16748 ASSERT_TRUE(image.initialized());
16749
16750 VkImageViewCreateInfo ivci = {
16751 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16752 nullptr,
16753 0,
16754 image.handle(),
16755 VK_IMAGE_VIEW_TYPE_2D,
16756 VK_FORMAT_R8G8B8A8_UNORM,
16757 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16758 VK_COMPONENT_SWIZZLE_IDENTITY },
16759 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16760 };
16761 VkImageView view;
16762 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16763 ASSERT_VK_SUCCESS(err);
16764
16765 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16766 VkFramebuffer fb;
16767 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16768 ASSERT_VK_SUCCESS(err);
16769
16770 // Record a single command buffer which issues a pipeline barrier w/
16771 // image memory barrier for the attachment. This detects the previously
16772 // missing tracking of the subpass layout by throwing a validation error
16773 // if it doesn't occur.
16774 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16775 BeginCommandBuffer();
16776 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16777
16778 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
16779 nullptr,
16780 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16781 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16782 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16783 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16784 VK_QUEUE_FAMILY_IGNORED,
16785 VK_QUEUE_FAMILY_IGNORED,
16786 image.handle(),
16787 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
16788 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16789 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16790 &imb);
16791
16792 vkCmdEndRenderPass(m_commandBuffer->handle());
16793 m_errorMonitor->VerifyNotFound();
16794 EndCommandBuffer();
16795
16796 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16797 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16798 vkDestroyImageView(m_device->device(), view, nullptr);
16799}
16800
16801TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
16802 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
16803 "is used as a depth/stencil framebuffer attachment, the "
16804 "aspectMask is ignored and both depth and stencil image "
16805 "subresources are used.");
16806
16807 VkFormatProperties format_properties;
16808 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
16809 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
16810 return;
16811 }
16812
16813 m_errorMonitor->ExpectSuccess();
16814
16815 ASSERT_NO_FATAL_FAILURE(InitState());
16816
16817 VkAttachmentDescription attachment = { 0,
16818 VK_FORMAT_D32_SFLOAT_S8_UINT,
16819 VK_SAMPLE_COUNT_1_BIT,
16820 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16821 VK_ATTACHMENT_STORE_OP_STORE,
16822 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16823 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16824 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
16825 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16826
16827 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16828
16829 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
16830
16831 VkSubpassDependency dep = { 0,
16832 0,
16833 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16834 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16835 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16836 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16837 VK_DEPENDENCY_BY_REGION_BIT};
16838
16839 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16840
16841 VkResult err;
16842 VkRenderPass rp;
16843 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16844 ASSERT_VK_SUCCESS(err);
16845
16846 VkImageObj image(m_device);
16847 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
16848 0x26, // usage
16849 VK_IMAGE_TILING_OPTIMAL, 0);
16850 ASSERT_TRUE(image.initialized());
16851 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
16852
16853 VkImageViewCreateInfo ivci = {
16854 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16855 nullptr,
16856 0,
16857 image.handle(),
16858 VK_IMAGE_VIEW_TYPE_2D,
16859 VK_FORMAT_D32_SFLOAT_S8_UINT,
16860 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
16861 { 0x2, 0, 1, 0, 1 },
16862 };
16863 VkImageView view;
16864 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16865 ASSERT_VK_SUCCESS(err);
16866
16867 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16868 VkFramebuffer fb;
16869 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16870 ASSERT_VK_SUCCESS(err);
16871
16872 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16873 BeginCommandBuffer();
16874 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16875
16876 VkImageMemoryBarrier imb = {};
16877 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16878 imb.pNext = nullptr;
16879 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16880 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16881 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16882 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16883 imb.srcQueueFamilyIndex = 0;
16884 imb.dstQueueFamilyIndex = 0;
16885 imb.image = image.handle();
16886 imb.subresourceRange.aspectMask = 0x6;
16887 imb.subresourceRange.baseMipLevel = 0;
16888 imb.subresourceRange.levelCount = 0x1;
16889 imb.subresourceRange.baseArrayLayer = 0;
16890 imb.subresourceRange.layerCount = 0x1;
16891
16892 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16893 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16894 &imb);
16895
16896 vkCmdEndRenderPass(m_commandBuffer->handle());
16897 EndCommandBuffer();
16898 QueueCommandBuffer(false);
16899 m_errorMonitor->VerifyNotFound();
16900
16901 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16902 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16903 vkDestroyImageView(m_device->device(), view, nullptr);
16904}
16905
16906TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
16907 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
16908 "errors, when an attachment reference is "
16909 "VK_ATTACHMENT_UNUSED");
16910
16911 m_errorMonitor->ExpectSuccess();
16912
16913 ASSERT_NO_FATAL_FAILURE(InitState());
16914
16915 // A renderpass with no attachments
16916 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16917
16918 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16919
16920 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
16921
16922 VkRenderPass rp;
16923 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16924 ASSERT_VK_SUCCESS(err);
16925
16926 // A compatible framebuffer.
16927 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
16928 VkFramebuffer fb;
16929 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16930 ASSERT_VK_SUCCESS(err);
16931
16932 // Record a command buffer which just begins and ends the renderpass. The
16933 // bug manifests in BeginRenderPass.
16934 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16935 BeginCommandBuffer();
16936 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16937 vkCmdEndRenderPass(m_commandBuffer->handle());
16938 m_errorMonitor->VerifyNotFound();
16939 EndCommandBuffer();
16940
16941 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16942 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16943}
16944
16945// This is a positive test. No errors are expected.
16946TEST_F(VkPositiveLayerTest, StencilLoadOp) {
16947 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
16948 "CLEAR. stencil[Load|Store]Op used to be ignored.");
16949 VkResult result = VK_SUCCESS;
16950 VkImageFormatProperties formatProps;
16951 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
16952 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
16953 &formatProps);
16954 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
16955 return;
16956 }
16957
16958 ASSERT_NO_FATAL_FAILURE(InitState());
16959 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
16960 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
16961 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
16962 VkAttachmentDescription att = {};
16963 VkAttachmentReference ref = {};
16964 att.format = depth_stencil_fmt;
16965 att.samples = VK_SAMPLE_COUNT_1_BIT;
16966 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
16967 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
16968 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
16969 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
16970 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16971 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16972
16973 VkClearValue clear;
16974 clear.depthStencil.depth = 1.0;
16975 clear.depthStencil.stencil = 0;
16976 ref.attachment = 0;
16977 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16978
16979 VkSubpassDescription subpass = {};
16980 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
16981 subpass.flags = 0;
16982 subpass.inputAttachmentCount = 0;
16983 subpass.pInputAttachments = NULL;
16984 subpass.colorAttachmentCount = 0;
16985 subpass.pColorAttachments = NULL;
16986 subpass.pResolveAttachments = NULL;
16987 subpass.pDepthStencilAttachment = &ref;
16988 subpass.preserveAttachmentCount = 0;
16989 subpass.pPreserveAttachments = NULL;
16990
16991 VkRenderPass rp;
16992 VkRenderPassCreateInfo rp_info = {};
16993 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16994 rp_info.attachmentCount = 1;
16995 rp_info.pAttachments = &att;
16996 rp_info.subpassCount = 1;
16997 rp_info.pSubpasses = &subpass;
16998 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
16999 ASSERT_VK_SUCCESS(result);
17000
17001 VkImageView *depthView = m_depthStencil->BindInfo();
17002 VkFramebufferCreateInfo fb_info = {};
17003 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17004 fb_info.pNext = NULL;
17005 fb_info.renderPass = rp;
17006 fb_info.attachmentCount = 1;
17007 fb_info.pAttachments = depthView;
17008 fb_info.width = 100;
17009 fb_info.height = 100;
17010 fb_info.layers = 1;
17011 VkFramebuffer fb;
17012 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17013 ASSERT_VK_SUCCESS(result);
17014
17015 VkRenderPassBeginInfo rpbinfo = {};
17016 rpbinfo.clearValueCount = 1;
17017 rpbinfo.pClearValues = &clear;
17018 rpbinfo.pNext = NULL;
17019 rpbinfo.renderPass = rp;
17020 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17021 rpbinfo.renderArea.extent.width = 100;
17022 rpbinfo.renderArea.extent.height = 100;
17023 rpbinfo.renderArea.offset.x = 0;
17024 rpbinfo.renderArea.offset.y = 0;
17025 rpbinfo.framebuffer = fb;
17026
17027 VkFence fence = {};
17028 VkFenceCreateInfo fence_ci = {};
17029 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17030 fence_ci.pNext = nullptr;
17031 fence_ci.flags = 0;
17032 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17033 ASSERT_VK_SUCCESS(result);
17034
17035 m_commandBuffer->BeginCommandBuffer();
17036 m_commandBuffer->BeginRenderPass(rpbinfo);
17037 m_commandBuffer->EndRenderPass();
17038 m_commandBuffer->EndCommandBuffer();
17039 m_commandBuffer->QueueCommandBuffer(fence);
17040
17041 VkImageObj destImage(m_device);
17042 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17043 VK_IMAGE_TILING_OPTIMAL, 0);
17044 VkImageMemoryBarrier barrier = {};
17045 VkImageSubresourceRange range;
17046 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17047 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17048 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17049 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17050 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17051 barrier.image = m_depthStencil->handle();
17052 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17053 range.baseMipLevel = 0;
17054 range.levelCount = 1;
17055 range.baseArrayLayer = 0;
17056 range.layerCount = 1;
17057 barrier.subresourceRange = range;
17058 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17059 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17060 cmdbuf.BeginCommandBuffer();
17061 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17062 &barrier);
17063 barrier.srcAccessMask = 0;
17064 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17065 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17066 barrier.image = destImage.handle();
17067 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17068 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17069 &barrier);
17070 VkImageCopy cregion;
17071 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17072 cregion.srcSubresource.mipLevel = 0;
17073 cregion.srcSubresource.baseArrayLayer = 0;
17074 cregion.srcSubresource.layerCount = 1;
17075 cregion.srcOffset.x = 0;
17076 cregion.srcOffset.y = 0;
17077 cregion.srcOffset.z = 0;
17078 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17079 cregion.dstSubresource.mipLevel = 0;
17080 cregion.dstSubresource.baseArrayLayer = 0;
17081 cregion.dstSubresource.layerCount = 1;
17082 cregion.dstOffset.x = 0;
17083 cregion.dstOffset.y = 0;
17084 cregion.dstOffset.z = 0;
17085 cregion.extent.width = 100;
17086 cregion.extent.height = 100;
17087 cregion.extent.depth = 1;
17088 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17089 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17090 cmdbuf.EndCommandBuffer();
17091
17092 VkSubmitInfo submit_info;
17093 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17094 submit_info.pNext = NULL;
17095 submit_info.waitSemaphoreCount = 0;
17096 submit_info.pWaitSemaphores = NULL;
17097 submit_info.pWaitDstStageMask = NULL;
17098 submit_info.commandBufferCount = 1;
17099 submit_info.pCommandBuffers = &cmdbuf.handle();
17100 submit_info.signalSemaphoreCount = 0;
17101 submit_info.pSignalSemaphores = NULL;
17102
17103 m_errorMonitor->ExpectSuccess();
17104 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17105 m_errorMonitor->VerifyNotFound();
17106
17107 vkQueueWaitIdle(m_device->m_queue);
17108 vkDestroyFence(m_device->device(), fence, nullptr);
17109 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17110 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17111}
17112
17113// This is a positive test. No errors should be generated.
17114TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17115 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17116
17117 m_errorMonitor->ExpectSuccess();
17118 ASSERT_NO_FATAL_FAILURE(InitState());
17119
17120 VkEvent event;
17121 VkEventCreateInfo event_create_info{};
17122 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17123 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17124
17125 VkCommandPool command_pool;
17126 VkCommandPoolCreateInfo pool_create_info{};
17127 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17128 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17129 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17130 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17131
17132 VkCommandBuffer command_buffer;
17133 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17134 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17135 command_buffer_allocate_info.commandPool = command_pool;
17136 command_buffer_allocate_info.commandBufferCount = 1;
17137 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17138 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17139
17140 VkQueue queue = VK_NULL_HANDLE;
17141 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17142
17143 {
17144 VkCommandBufferBeginInfo begin_info{};
17145 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17146 vkBeginCommandBuffer(command_buffer, &begin_info);
17147
17148 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17149 nullptr, 0, nullptr);
17150 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17151 vkEndCommandBuffer(command_buffer);
17152 }
17153 {
17154 VkSubmitInfo submit_info{};
17155 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17156 submit_info.commandBufferCount = 1;
17157 submit_info.pCommandBuffers = &command_buffer;
17158 submit_info.signalSemaphoreCount = 0;
17159 submit_info.pSignalSemaphores = nullptr;
17160 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17161 }
17162 { vkSetEvent(m_device->device(), event); }
17163
17164 vkQueueWaitIdle(queue);
17165
17166 vkDestroyEvent(m_device->device(), event, nullptr);
17167 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17168 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17169
17170 m_errorMonitor->VerifyNotFound();
17171}
17172// This is a positive test. No errors should be generated.
17173TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17174 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17175
17176 ASSERT_NO_FATAL_FAILURE(InitState());
17177 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17178 return;
17179
17180 m_errorMonitor->ExpectSuccess();
17181
17182 VkQueryPool query_pool;
17183 VkQueryPoolCreateInfo query_pool_create_info{};
17184 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17185 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17186 query_pool_create_info.queryCount = 1;
17187 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17188
17189 VkCommandPool command_pool;
17190 VkCommandPoolCreateInfo pool_create_info{};
17191 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17192 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17193 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17194 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17195
17196 VkCommandBuffer command_buffer;
17197 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17198 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17199 command_buffer_allocate_info.commandPool = command_pool;
17200 command_buffer_allocate_info.commandBufferCount = 1;
17201 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17202 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17203
17204 VkCommandBuffer secondary_command_buffer;
17205 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17206 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17207
17208 VkQueue queue = VK_NULL_HANDLE;
17209 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17210
17211 uint32_t qfi = 0;
17212 VkBufferCreateInfo buff_create_info = {};
17213 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17214 buff_create_info.size = 1024;
17215 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17216 buff_create_info.queueFamilyIndexCount = 1;
17217 buff_create_info.pQueueFamilyIndices = &qfi;
17218
17219 VkResult err;
17220 VkBuffer buffer;
17221 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17222 ASSERT_VK_SUCCESS(err);
17223 VkMemoryAllocateInfo mem_alloc = {};
17224 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17225 mem_alloc.pNext = NULL;
17226 mem_alloc.allocationSize = 1024;
17227 mem_alloc.memoryTypeIndex = 0;
17228
17229 VkMemoryRequirements memReqs;
17230 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17231 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17232 if (!pass) {
17233 vkDestroyBuffer(m_device->device(), buffer, NULL);
17234 return;
17235 }
17236
17237 VkDeviceMemory mem;
17238 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17239 ASSERT_VK_SUCCESS(err);
17240 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17241 ASSERT_VK_SUCCESS(err);
17242
17243 VkCommandBufferInheritanceInfo hinfo = {};
17244 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17245 hinfo.renderPass = VK_NULL_HANDLE;
17246 hinfo.subpass = 0;
17247 hinfo.framebuffer = VK_NULL_HANDLE;
17248 hinfo.occlusionQueryEnable = VK_FALSE;
17249 hinfo.queryFlags = 0;
17250 hinfo.pipelineStatistics = 0;
17251
17252 {
17253 VkCommandBufferBeginInfo begin_info{};
17254 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17255 begin_info.pInheritanceInfo = &hinfo;
17256 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17257
17258 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17259 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17260
17261 vkEndCommandBuffer(secondary_command_buffer);
17262
17263 begin_info.pInheritanceInfo = nullptr;
17264 vkBeginCommandBuffer(command_buffer, &begin_info);
17265
17266 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17267 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17268
17269 vkEndCommandBuffer(command_buffer);
17270 }
17271 {
17272 VkSubmitInfo submit_info{};
17273 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17274 submit_info.commandBufferCount = 1;
17275 submit_info.pCommandBuffers = &command_buffer;
17276 submit_info.signalSemaphoreCount = 0;
17277 submit_info.pSignalSemaphores = nullptr;
17278 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17279 }
17280
17281 vkQueueWaitIdle(queue);
17282
17283 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17284 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17285 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17286 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17287 vkDestroyBuffer(m_device->device(), buffer, NULL);
17288 vkFreeMemory(m_device->device(), mem, NULL);
17289
17290 m_errorMonitor->VerifyNotFound();
17291}
17292
17293// This is a positive test. No errors should be generated.
17294TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17295 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17296
17297 ASSERT_NO_FATAL_FAILURE(InitState());
17298 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17299 return;
17300
17301 m_errorMonitor->ExpectSuccess();
17302
17303 VkQueryPool query_pool;
17304 VkQueryPoolCreateInfo query_pool_create_info{};
17305 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17306 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17307 query_pool_create_info.queryCount = 1;
17308 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17309
17310 VkCommandPool command_pool;
17311 VkCommandPoolCreateInfo pool_create_info{};
17312 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17313 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17314 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17315 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17316
17317 VkCommandBuffer command_buffer[2];
17318 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17319 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17320 command_buffer_allocate_info.commandPool = command_pool;
17321 command_buffer_allocate_info.commandBufferCount = 2;
17322 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17323 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17324
17325 VkQueue queue = VK_NULL_HANDLE;
17326 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17327
17328 uint32_t qfi = 0;
17329 VkBufferCreateInfo buff_create_info = {};
17330 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17331 buff_create_info.size = 1024;
17332 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17333 buff_create_info.queueFamilyIndexCount = 1;
17334 buff_create_info.pQueueFamilyIndices = &qfi;
17335
17336 VkResult err;
17337 VkBuffer buffer;
17338 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17339 ASSERT_VK_SUCCESS(err);
17340 VkMemoryAllocateInfo mem_alloc = {};
17341 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17342 mem_alloc.pNext = NULL;
17343 mem_alloc.allocationSize = 1024;
17344 mem_alloc.memoryTypeIndex = 0;
17345
17346 VkMemoryRequirements memReqs;
17347 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17348 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17349 if (!pass) {
17350 vkDestroyBuffer(m_device->device(), buffer, NULL);
17351 return;
17352 }
17353
17354 VkDeviceMemory mem;
17355 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17356 ASSERT_VK_SUCCESS(err);
17357 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17358 ASSERT_VK_SUCCESS(err);
17359
17360 {
17361 VkCommandBufferBeginInfo begin_info{};
17362 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17363 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17364
17365 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17366 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17367
17368 vkEndCommandBuffer(command_buffer[0]);
17369
17370 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17371
17372 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17373
17374 vkEndCommandBuffer(command_buffer[1]);
17375 }
17376 {
17377 VkSubmitInfo submit_info{};
17378 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17379 submit_info.commandBufferCount = 2;
17380 submit_info.pCommandBuffers = command_buffer;
17381 submit_info.signalSemaphoreCount = 0;
17382 submit_info.pSignalSemaphores = nullptr;
17383 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17384 }
17385
17386 vkQueueWaitIdle(queue);
17387
17388 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17389 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17390 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17391 vkDestroyBuffer(m_device->device(), buffer, NULL);
17392 vkFreeMemory(m_device->device(), mem, NULL);
17393
17394 m_errorMonitor->VerifyNotFound();
17395}
17396
Tony Barbourc46924f2016-11-04 11:49:52 -060017397TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017398 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17399
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017400 ASSERT_NO_FATAL_FAILURE(InitState());
17401 VkEvent event;
17402 VkEventCreateInfo event_create_info{};
17403 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17404 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17405
17406 VkCommandPool command_pool;
17407 VkCommandPoolCreateInfo pool_create_info{};
17408 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17409 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17410 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17411 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17412
17413 VkCommandBuffer command_buffer;
17414 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17415 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17416 command_buffer_allocate_info.commandPool = command_pool;
17417 command_buffer_allocate_info.commandBufferCount = 1;
17418 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17419 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17420
17421 VkQueue queue = VK_NULL_HANDLE;
17422 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17423
17424 {
17425 VkCommandBufferBeginInfo begin_info{};
17426 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17427 vkBeginCommandBuffer(command_buffer, &begin_info);
17428
17429 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017430 vkEndCommandBuffer(command_buffer);
17431 }
17432 {
17433 VkSubmitInfo submit_info{};
17434 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17435 submit_info.commandBufferCount = 1;
17436 submit_info.pCommandBuffers = &command_buffer;
17437 submit_info.signalSemaphoreCount = 0;
17438 submit_info.pSignalSemaphores = nullptr;
17439 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17440 }
17441 {
17442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17443 "command buffer.");
17444 vkSetEvent(m_device->device(), event);
17445 m_errorMonitor->VerifyFound();
17446 }
17447
17448 vkQueueWaitIdle(queue);
17449
17450 vkDestroyEvent(m_device->device(), event, nullptr);
17451 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17452 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17453}
17454
17455// This is a positive test. No errors should be generated.
17456TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17457 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17458 "run through a Submit & WaitForFences cycle 3 times. This "
17459 "previously revealed a bug so running this positive test "
17460 "to prevent a regression.");
17461 m_errorMonitor->ExpectSuccess();
17462
17463 ASSERT_NO_FATAL_FAILURE(InitState());
17464 VkQueue queue = VK_NULL_HANDLE;
17465 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17466
17467 static const uint32_t NUM_OBJECTS = 2;
17468 static const uint32_t NUM_FRAMES = 3;
17469 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17470 VkFence fences[NUM_OBJECTS] = {};
17471
17472 VkCommandPool cmd_pool;
17473 VkCommandPoolCreateInfo cmd_pool_ci = {};
17474 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17475 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17476 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17477 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17478 ASSERT_VK_SUCCESS(err);
17479
17480 VkCommandBufferAllocateInfo cmd_buf_info = {};
17481 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17482 cmd_buf_info.commandPool = cmd_pool;
17483 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17484 cmd_buf_info.commandBufferCount = 1;
17485
17486 VkFenceCreateInfo fence_ci = {};
17487 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17488 fence_ci.pNext = nullptr;
17489 fence_ci.flags = 0;
17490
17491 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17492 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17493 ASSERT_VK_SUCCESS(err);
17494 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17495 ASSERT_VK_SUCCESS(err);
17496 }
17497
17498 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17499 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17500 // Create empty cmd buffer
17501 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17502 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17503
17504 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17505 ASSERT_VK_SUCCESS(err);
17506 err = vkEndCommandBuffer(cmd_buffers[obj]);
17507 ASSERT_VK_SUCCESS(err);
17508
17509 VkSubmitInfo submit_info = {};
17510 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17511 submit_info.commandBufferCount = 1;
17512 submit_info.pCommandBuffers = &cmd_buffers[obj];
17513 // Submit cmd buffer and wait for fence
17514 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17515 ASSERT_VK_SUCCESS(err);
17516 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17517 ASSERT_VK_SUCCESS(err);
17518 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17519 ASSERT_VK_SUCCESS(err);
17520 }
17521 }
17522 m_errorMonitor->VerifyNotFound();
17523 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17524 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17525 vkDestroyFence(m_device->device(), fences[i], nullptr);
17526 }
17527}
17528// This is a positive test. No errors should be generated.
17529TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17530
17531 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17532 "submitted on separate queues followed by a QueueWaitIdle.");
17533
17534 ASSERT_NO_FATAL_FAILURE(InitState());
17535 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17536 return;
17537
17538 m_errorMonitor->ExpectSuccess();
17539
17540 VkSemaphore semaphore;
17541 VkSemaphoreCreateInfo semaphore_create_info{};
17542 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17543 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17544
17545 VkCommandPool command_pool;
17546 VkCommandPoolCreateInfo pool_create_info{};
17547 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17548 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17549 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17550 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17551
17552 VkCommandBuffer command_buffer[2];
17553 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17554 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17555 command_buffer_allocate_info.commandPool = command_pool;
17556 command_buffer_allocate_info.commandBufferCount = 2;
17557 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17558 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17559
17560 VkQueue queue = VK_NULL_HANDLE;
17561 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17562
17563 {
17564 VkCommandBufferBeginInfo begin_info{};
17565 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17566 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17567
17568 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17569 nullptr, 0, nullptr, 0, nullptr);
17570
17571 VkViewport viewport{};
17572 viewport.maxDepth = 1.0f;
17573 viewport.minDepth = 0.0f;
17574 viewport.width = 512;
17575 viewport.height = 512;
17576 viewport.x = 0;
17577 viewport.y = 0;
17578 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17579 vkEndCommandBuffer(command_buffer[0]);
17580 }
17581 {
17582 VkCommandBufferBeginInfo begin_info{};
17583 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17584 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17585
17586 VkViewport viewport{};
17587 viewport.maxDepth = 1.0f;
17588 viewport.minDepth = 0.0f;
17589 viewport.width = 512;
17590 viewport.height = 512;
17591 viewport.x = 0;
17592 viewport.y = 0;
17593 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17594 vkEndCommandBuffer(command_buffer[1]);
17595 }
17596 {
17597 VkSubmitInfo submit_info{};
17598 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17599 submit_info.commandBufferCount = 1;
17600 submit_info.pCommandBuffers = &command_buffer[0];
17601 submit_info.signalSemaphoreCount = 1;
17602 submit_info.pSignalSemaphores = &semaphore;
17603 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17604 }
17605 {
17606 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17607 VkSubmitInfo submit_info{};
17608 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17609 submit_info.commandBufferCount = 1;
17610 submit_info.pCommandBuffers = &command_buffer[1];
17611 submit_info.waitSemaphoreCount = 1;
17612 submit_info.pWaitSemaphores = &semaphore;
17613 submit_info.pWaitDstStageMask = flags;
17614 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17615 }
17616
17617 vkQueueWaitIdle(m_device->m_queue);
17618
17619 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17620 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17621 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17622
17623 m_errorMonitor->VerifyNotFound();
17624}
17625
17626// This is a positive test. No errors should be generated.
17627TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17628
17629 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17630 "submitted on separate queues, the second having a fence"
17631 "followed by a QueueWaitIdle.");
17632
17633 ASSERT_NO_FATAL_FAILURE(InitState());
17634 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17635 return;
17636
17637 m_errorMonitor->ExpectSuccess();
17638
17639 VkFence fence;
17640 VkFenceCreateInfo fence_create_info{};
17641 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17642 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17643
17644 VkSemaphore semaphore;
17645 VkSemaphoreCreateInfo semaphore_create_info{};
17646 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17647 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17648
17649 VkCommandPool command_pool;
17650 VkCommandPoolCreateInfo pool_create_info{};
17651 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17652 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17653 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17654 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17655
17656 VkCommandBuffer command_buffer[2];
17657 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17658 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17659 command_buffer_allocate_info.commandPool = command_pool;
17660 command_buffer_allocate_info.commandBufferCount = 2;
17661 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17662 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17663
17664 VkQueue queue = VK_NULL_HANDLE;
17665 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17666
17667 {
17668 VkCommandBufferBeginInfo begin_info{};
17669 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17670 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17671
17672 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17673 nullptr, 0, nullptr, 0, nullptr);
17674
17675 VkViewport viewport{};
17676 viewport.maxDepth = 1.0f;
17677 viewport.minDepth = 0.0f;
17678 viewport.width = 512;
17679 viewport.height = 512;
17680 viewport.x = 0;
17681 viewport.y = 0;
17682 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17683 vkEndCommandBuffer(command_buffer[0]);
17684 }
17685 {
17686 VkCommandBufferBeginInfo begin_info{};
17687 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17688 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17689
17690 VkViewport viewport{};
17691 viewport.maxDepth = 1.0f;
17692 viewport.minDepth = 0.0f;
17693 viewport.width = 512;
17694 viewport.height = 512;
17695 viewport.x = 0;
17696 viewport.y = 0;
17697 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17698 vkEndCommandBuffer(command_buffer[1]);
17699 }
17700 {
17701 VkSubmitInfo submit_info{};
17702 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17703 submit_info.commandBufferCount = 1;
17704 submit_info.pCommandBuffers = &command_buffer[0];
17705 submit_info.signalSemaphoreCount = 1;
17706 submit_info.pSignalSemaphores = &semaphore;
17707 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17708 }
17709 {
17710 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17711 VkSubmitInfo submit_info{};
17712 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17713 submit_info.commandBufferCount = 1;
17714 submit_info.pCommandBuffers = &command_buffer[1];
17715 submit_info.waitSemaphoreCount = 1;
17716 submit_info.pWaitSemaphores = &semaphore;
17717 submit_info.pWaitDstStageMask = flags;
17718 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17719 }
17720
17721 vkQueueWaitIdle(m_device->m_queue);
17722
17723 vkDestroyFence(m_device->device(), fence, nullptr);
17724 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17725 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17726 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17727
17728 m_errorMonitor->VerifyNotFound();
17729}
17730
17731// This is a positive test. No errors should be generated.
17732TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17733
17734 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17735 "submitted on separate queues, the second having a fence"
17736 "followed by two consecutive WaitForFences calls on the same fence.");
17737
17738 ASSERT_NO_FATAL_FAILURE(InitState());
17739 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17740 return;
17741
17742 m_errorMonitor->ExpectSuccess();
17743
17744 VkFence fence;
17745 VkFenceCreateInfo fence_create_info{};
17746 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17747 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17748
17749 VkSemaphore semaphore;
17750 VkSemaphoreCreateInfo semaphore_create_info{};
17751 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17752 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17753
17754 VkCommandPool command_pool;
17755 VkCommandPoolCreateInfo pool_create_info{};
17756 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17757 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17758 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17759 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17760
17761 VkCommandBuffer command_buffer[2];
17762 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17763 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17764 command_buffer_allocate_info.commandPool = command_pool;
17765 command_buffer_allocate_info.commandBufferCount = 2;
17766 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17767 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17768
17769 VkQueue queue = VK_NULL_HANDLE;
17770 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17771
17772 {
17773 VkCommandBufferBeginInfo begin_info{};
17774 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17775 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17776
17777 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17778 nullptr, 0, nullptr, 0, nullptr);
17779
17780 VkViewport viewport{};
17781 viewport.maxDepth = 1.0f;
17782 viewport.minDepth = 0.0f;
17783 viewport.width = 512;
17784 viewport.height = 512;
17785 viewport.x = 0;
17786 viewport.y = 0;
17787 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17788 vkEndCommandBuffer(command_buffer[0]);
17789 }
17790 {
17791 VkCommandBufferBeginInfo begin_info{};
17792 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17793 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17794
17795 VkViewport viewport{};
17796 viewport.maxDepth = 1.0f;
17797 viewport.minDepth = 0.0f;
17798 viewport.width = 512;
17799 viewport.height = 512;
17800 viewport.x = 0;
17801 viewport.y = 0;
17802 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17803 vkEndCommandBuffer(command_buffer[1]);
17804 }
17805 {
17806 VkSubmitInfo submit_info{};
17807 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17808 submit_info.commandBufferCount = 1;
17809 submit_info.pCommandBuffers = &command_buffer[0];
17810 submit_info.signalSemaphoreCount = 1;
17811 submit_info.pSignalSemaphores = &semaphore;
17812 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17813 }
17814 {
17815 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17816 VkSubmitInfo submit_info{};
17817 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17818 submit_info.commandBufferCount = 1;
17819 submit_info.pCommandBuffers = &command_buffer[1];
17820 submit_info.waitSemaphoreCount = 1;
17821 submit_info.pWaitSemaphores = &semaphore;
17822 submit_info.pWaitDstStageMask = flags;
17823 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17824 }
17825
17826 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17827 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17828
17829 vkDestroyFence(m_device->device(), fence, nullptr);
17830 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17831 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17832 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17833
17834 m_errorMonitor->VerifyNotFound();
17835}
17836
17837TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
17838
17839 ASSERT_NO_FATAL_FAILURE(InitState());
17840 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
17841 printf("Test requires two queues, skipping\n");
17842 return;
17843 }
17844
17845 VkResult err;
17846
17847 m_errorMonitor->ExpectSuccess();
17848
17849 VkQueue q0 = m_device->m_queue;
17850 VkQueue q1 = nullptr;
17851 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
17852 ASSERT_NE(q1, nullptr);
17853
17854 // An (empty) command buffer. We must have work in the first submission --
17855 // the layer treats unfenced work differently from fenced work.
17856 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
17857 VkCommandPool pool;
17858 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
17859 ASSERT_VK_SUCCESS(err);
17860 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
17861 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
17862 VkCommandBuffer cb;
17863 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
17864 ASSERT_VK_SUCCESS(err);
17865 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
17866 err = vkBeginCommandBuffer(cb, &cbbi);
17867 ASSERT_VK_SUCCESS(err);
17868 err = vkEndCommandBuffer(cb);
17869 ASSERT_VK_SUCCESS(err);
17870
17871 // A semaphore
17872 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17873 VkSemaphore s;
17874 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
17875 ASSERT_VK_SUCCESS(err);
17876
17877 // First submission, to q0
17878 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
17879
17880 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
17881 ASSERT_VK_SUCCESS(err);
17882
17883 // Second submission, to q1, waiting on s
17884 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
17885 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
17886
17887 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
17888 ASSERT_VK_SUCCESS(err);
17889
17890 // Wait for q0 idle
17891 err = vkQueueWaitIdle(q0);
17892 ASSERT_VK_SUCCESS(err);
17893
17894 // Command buffer should have been completed (it was on q0); reset the pool.
17895 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
17896
17897 m_errorMonitor->VerifyNotFound();
17898
17899 // Force device completely idle and clean up resources
17900 vkDeviceWaitIdle(m_device->device());
17901 vkDestroyCommandPool(m_device->device(), pool, nullptr);
17902 vkDestroySemaphore(m_device->device(), s, nullptr);
17903}
17904
17905// This is a positive test. No errors should be generated.
17906TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
17907
17908 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17909 "submitted on separate queues, the second having a fence, "
17910 "followed by a WaitForFences call.");
17911
17912 ASSERT_NO_FATAL_FAILURE(InitState());
17913 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17914 return;
17915
17916 m_errorMonitor->ExpectSuccess();
17917
17918 ASSERT_NO_FATAL_FAILURE(InitState());
17919 VkFence fence;
17920 VkFenceCreateInfo fence_create_info{};
17921 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17922 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17923
17924 VkSemaphore semaphore;
17925 VkSemaphoreCreateInfo semaphore_create_info{};
17926 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17927 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17928
17929 VkCommandPool command_pool;
17930 VkCommandPoolCreateInfo pool_create_info{};
17931 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17932 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17933 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17934 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17935
17936 VkCommandBuffer command_buffer[2];
17937 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17938 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17939 command_buffer_allocate_info.commandPool = command_pool;
17940 command_buffer_allocate_info.commandBufferCount = 2;
17941 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17942 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17943
17944 VkQueue queue = VK_NULL_HANDLE;
17945 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17946
17947 {
17948 VkCommandBufferBeginInfo begin_info{};
17949 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17950 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17951
17952 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17953 nullptr, 0, nullptr, 0, nullptr);
17954
17955 VkViewport viewport{};
17956 viewport.maxDepth = 1.0f;
17957 viewport.minDepth = 0.0f;
17958 viewport.width = 512;
17959 viewport.height = 512;
17960 viewport.x = 0;
17961 viewport.y = 0;
17962 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17963 vkEndCommandBuffer(command_buffer[0]);
17964 }
17965 {
17966 VkCommandBufferBeginInfo begin_info{};
17967 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17968 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17969
17970 VkViewport viewport{};
17971 viewport.maxDepth = 1.0f;
17972 viewport.minDepth = 0.0f;
17973 viewport.width = 512;
17974 viewport.height = 512;
17975 viewport.x = 0;
17976 viewport.y = 0;
17977 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17978 vkEndCommandBuffer(command_buffer[1]);
17979 }
17980 {
17981 VkSubmitInfo submit_info{};
17982 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17983 submit_info.commandBufferCount = 1;
17984 submit_info.pCommandBuffers = &command_buffer[0];
17985 submit_info.signalSemaphoreCount = 1;
17986 submit_info.pSignalSemaphores = &semaphore;
17987 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17988 }
17989 {
17990 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17991 VkSubmitInfo submit_info{};
17992 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17993 submit_info.commandBufferCount = 1;
17994 submit_info.pCommandBuffers = &command_buffer[1];
17995 submit_info.waitSemaphoreCount = 1;
17996 submit_info.pWaitSemaphores = &semaphore;
17997 submit_info.pWaitDstStageMask = flags;
17998 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17999 }
18000
18001 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18002
18003 vkDestroyFence(m_device->device(), fence, nullptr);
18004 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18005 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18006 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18007
18008 m_errorMonitor->VerifyNotFound();
18009}
18010
18011// This is a positive test. No errors should be generated.
18012TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18013
18014 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18015 "on the same queue, sharing a signal/wait semaphore, the "
18016 "second having a fence, "
18017 "followed by a WaitForFences call.");
18018
18019 m_errorMonitor->ExpectSuccess();
18020
18021 ASSERT_NO_FATAL_FAILURE(InitState());
18022 VkFence fence;
18023 VkFenceCreateInfo fence_create_info{};
18024 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18025 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18026
18027 VkSemaphore semaphore;
18028 VkSemaphoreCreateInfo semaphore_create_info{};
18029 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18030 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18031
18032 VkCommandPool command_pool;
18033 VkCommandPoolCreateInfo pool_create_info{};
18034 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18035 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18036 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18037 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18038
18039 VkCommandBuffer command_buffer[2];
18040 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18041 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18042 command_buffer_allocate_info.commandPool = command_pool;
18043 command_buffer_allocate_info.commandBufferCount = 2;
18044 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18045 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18046
18047 {
18048 VkCommandBufferBeginInfo begin_info{};
18049 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18050 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18051
18052 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18053 nullptr, 0, nullptr, 0, nullptr);
18054
18055 VkViewport viewport{};
18056 viewport.maxDepth = 1.0f;
18057 viewport.minDepth = 0.0f;
18058 viewport.width = 512;
18059 viewport.height = 512;
18060 viewport.x = 0;
18061 viewport.y = 0;
18062 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18063 vkEndCommandBuffer(command_buffer[0]);
18064 }
18065 {
18066 VkCommandBufferBeginInfo begin_info{};
18067 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18068 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18069
18070 VkViewport viewport{};
18071 viewport.maxDepth = 1.0f;
18072 viewport.minDepth = 0.0f;
18073 viewport.width = 512;
18074 viewport.height = 512;
18075 viewport.x = 0;
18076 viewport.y = 0;
18077 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18078 vkEndCommandBuffer(command_buffer[1]);
18079 }
18080 {
18081 VkSubmitInfo submit_info{};
18082 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18083 submit_info.commandBufferCount = 1;
18084 submit_info.pCommandBuffers = &command_buffer[0];
18085 submit_info.signalSemaphoreCount = 1;
18086 submit_info.pSignalSemaphores = &semaphore;
18087 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18088 }
18089 {
18090 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18091 VkSubmitInfo submit_info{};
18092 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18093 submit_info.commandBufferCount = 1;
18094 submit_info.pCommandBuffers = &command_buffer[1];
18095 submit_info.waitSemaphoreCount = 1;
18096 submit_info.pWaitSemaphores = &semaphore;
18097 submit_info.pWaitDstStageMask = flags;
18098 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18099 }
18100
18101 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18102
18103 vkDestroyFence(m_device->device(), fence, nullptr);
18104 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18105 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18106 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18107
18108 m_errorMonitor->VerifyNotFound();
18109}
18110
18111// This is a positive test. No errors should be generated.
18112TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18113
18114 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18115 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18116 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18117
18118 m_errorMonitor->ExpectSuccess();
18119
18120 ASSERT_NO_FATAL_FAILURE(InitState());
18121 VkFence fence;
18122 VkFenceCreateInfo fence_create_info{};
18123 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18124 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18125
18126 VkCommandPool command_pool;
18127 VkCommandPoolCreateInfo pool_create_info{};
18128 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18129 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18130 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18131 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18132
18133 VkCommandBuffer command_buffer[2];
18134 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18135 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18136 command_buffer_allocate_info.commandPool = command_pool;
18137 command_buffer_allocate_info.commandBufferCount = 2;
18138 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18139 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18140
18141 {
18142 VkCommandBufferBeginInfo begin_info{};
18143 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18144 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18145
18146 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18147 nullptr, 0, nullptr, 0, nullptr);
18148
18149 VkViewport viewport{};
18150 viewport.maxDepth = 1.0f;
18151 viewport.minDepth = 0.0f;
18152 viewport.width = 512;
18153 viewport.height = 512;
18154 viewport.x = 0;
18155 viewport.y = 0;
18156 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18157 vkEndCommandBuffer(command_buffer[0]);
18158 }
18159 {
18160 VkCommandBufferBeginInfo begin_info{};
18161 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18162 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18163
18164 VkViewport viewport{};
18165 viewport.maxDepth = 1.0f;
18166 viewport.minDepth = 0.0f;
18167 viewport.width = 512;
18168 viewport.height = 512;
18169 viewport.x = 0;
18170 viewport.y = 0;
18171 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18172 vkEndCommandBuffer(command_buffer[1]);
18173 }
18174 {
18175 VkSubmitInfo submit_info{};
18176 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18177 submit_info.commandBufferCount = 1;
18178 submit_info.pCommandBuffers = &command_buffer[0];
18179 submit_info.signalSemaphoreCount = 0;
18180 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18181 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18182 }
18183 {
18184 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18185 VkSubmitInfo submit_info{};
18186 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18187 submit_info.commandBufferCount = 1;
18188 submit_info.pCommandBuffers = &command_buffer[1];
18189 submit_info.waitSemaphoreCount = 0;
18190 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18191 submit_info.pWaitDstStageMask = flags;
18192 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18193 }
18194
18195 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18196
18197 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18198 ASSERT_VK_SUCCESS(err);
18199
18200 vkDestroyFence(m_device->device(), fence, nullptr);
18201 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18202 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18203
18204 m_errorMonitor->VerifyNotFound();
18205}
18206
18207// This is a positive test. No errors should be generated.
18208TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18209
18210 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18211 "on the same queue, the second having a fence, followed "
18212 "by a WaitForFences call.");
18213
18214 m_errorMonitor->ExpectSuccess();
18215
18216 ASSERT_NO_FATAL_FAILURE(InitState());
18217 VkFence fence;
18218 VkFenceCreateInfo fence_create_info{};
18219 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18220 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18221
18222 VkCommandPool command_pool;
18223 VkCommandPoolCreateInfo pool_create_info{};
18224 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18225 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18226 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18227 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18228
18229 VkCommandBuffer command_buffer[2];
18230 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18231 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18232 command_buffer_allocate_info.commandPool = command_pool;
18233 command_buffer_allocate_info.commandBufferCount = 2;
18234 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18235 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18236
18237 {
18238 VkCommandBufferBeginInfo begin_info{};
18239 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18240 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18241
18242 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18243 nullptr, 0, nullptr, 0, nullptr);
18244
18245 VkViewport viewport{};
18246 viewport.maxDepth = 1.0f;
18247 viewport.minDepth = 0.0f;
18248 viewport.width = 512;
18249 viewport.height = 512;
18250 viewport.x = 0;
18251 viewport.y = 0;
18252 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18253 vkEndCommandBuffer(command_buffer[0]);
18254 }
18255 {
18256 VkCommandBufferBeginInfo begin_info{};
18257 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18258 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18259
18260 VkViewport viewport{};
18261 viewport.maxDepth = 1.0f;
18262 viewport.minDepth = 0.0f;
18263 viewport.width = 512;
18264 viewport.height = 512;
18265 viewport.x = 0;
18266 viewport.y = 0;
18267 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18268 vkEndCommandBuffer(command_buffer[1]);
18269 }
18270 {
18271 VkSubmitInfo submit_info{};
18272 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18273 submit_info.commandBufferCount = 1;
18274 submit_info.pCommandBuffers = &command_buffer[0];
18275 submit_info.signalSemaphoreCount = 0;
18276 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18277 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18278 }
18279 {
18280 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18281 VkSubmitInfo submit_info{};
18282 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18283 submit_info.commandBufferCount = 1;
18284 submit_info.pCommandBuffers = &command_buffer[1];
18285 submit_info.waitSemaphoreCount = 0;
18286 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18287 submit_info.pWaitDstStageMask = flags;
18288 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18289 }
18290
18291 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18292
18293 vkDestroyFence(m_device->device(), fence, nullptr);
18294 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18295 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18296
18297 m_errorMonitor->VerifyNotFound();
18298}
18299
18300// This is a positive test. No errors should be generated.
18301TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18302
18303 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18304 "QueueSubmit call followed by a WaitForFences call.");
18305 ASSERT_NO_FATAL_FAILURE(InitState());
18306
18307 m_errorMonitor->ExpectSuccess();
18308
18309 VkFence fence;
18310 VkFenceCreateInfo fence_create_info{};
18311 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18312 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18313
18314 VkSemaphore semaphore;
18315 VkSemaphoreCreateInfo semaphore_create_info{};
18316 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18317 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18318
18319 VkCommandPool command_pool;
18320 VkCommandPoolCreateInfo pool_create_info{};
18321 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18322 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18323 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18324 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18325
18326 VkCommandBuffer command_buffer[2];
18327 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18328 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18329 command_buffer_allocate_info.commandPool = command_pool;
18330 command_buffer_allocate_info.commandBufferCount = 2;
18331 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18332 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18333
18334 {
18335 VkCommandBufferBeginInfo begin_info{};
18336 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18337 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18338
18339 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18340 nullptr, 0, nullptr, 0, nullptr);
18341
18342 VkViewport viewport{};
18343 viewport.maxDepth = 1.0f;
18344 viewport.minDepth = 0.0f;
18345 viewport.width = 512;
18346 viewport.height = 512;
18347 viewport.x = 0;
18348 viewport.y = 0;
18349 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18350 vkEndCommandBuffer(command_buffer[0]);
18351 }
18352 {
18353 VkCommandBufferBeginInfo begin_info{};
18354 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18355 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18356
18357 VkViewport viewport{};
18358 viewport.maxDepth = 1.0f;
18359 viewport.minDepth = 0.0f;
18360 viewport.width = 512;
18361 viewport.height = 512;
18362 viewport.x = 0;
18363 viewport.y = 0;
18364 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18365 vkEndCommandBuffer(command_buffer[1]);
18366 }
18367 {
18368 VkSubmitInfo submit_info[2];
18369 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18370
18371 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18372 submit_info[0].pNext = NULL;
18373 submit_info[0].commandBufferCount = 1;
18374 submit_info[0].pCommandBuffers = &command_buffer[0];
18375 submit_info[0].signalSemaphoreCount = 1;
18376 submit_info[0].pSignalSemaphores = &semaphore;
18377 submit_info[0].waitSemaphoreCount = 0;
18378 submit_info[0].pWaitSemaphores = NULL;
18379 submit_info[0].pWaitDstStageMask = 0;
18380
18381 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18382 submit_info[1].pNext = NULL;
18383 submit_info[1].commandBufferCount = 1;
18384 submit_info[1].pCommandBuffers = &command_buffer[1];
18385 submit_info[1].waitSemaphoreCount = 1;
18386 submit_info[1].pWaitSemaphores = &semaphore;
18387 submit_info[1].pWaitDstStageMask = flags;
18388 submit_info[1].signalSemaphoreCount = 0;
18389 submit_info[1].pSignalSemaphores = NULL;
18390 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18391 }
18392
18393 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18394
18395 vkDestroyFence(m_device->device(), fence, nullptr);
18396 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18397 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18398 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18399
18400 m_errorMonitor->VerifyNotFound();
18401}
18402
18403TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18404 m_errorMonitor->ExpectSuccess();
18405
18406 ASSERT_NO_FATAL_FAILURE(InitState());
18407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18408
18409 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18410 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18411
18412 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18413 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18414 m_errorMonitor->VerifyNotFound();
18415 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18416 m_errorMonitor->VerifyNotFound();
18417 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18418 m_errorMonitor->VerifyNotFound();
18419
18420 m_commandBuffer->EndCommandBuffer();
18421 m_errorMonitor->VerifyNotFound();
18422}
18423
18424TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18425 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18426 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18427 "has a valid layout, and a second subpass then uses a "
18428 "valid *READ_ONLY* layout.");
18429 m_errorMonitor->ExpectSuccess();
18430 ASSERT_NO_FATAL_FAILURE(InitState());
18431
18432 VkAttachmentReference attach[2] = {};
18433 attach[0].attachment = 0;
18434 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18435 attach[1].attachment = 0;
18436 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18437 VkSubpassDescription subpasses[2] = {};
18438 // First subpass clears DS attach on load
18439 subpasses[0].pDepthStencilAttachment = &attach[0];
18440 // 2nd subpass reads in DS as input attachment
18441 subpasses[1].inputAttachmentCount = 1;
18442 subpasses[1].pInputAttachments = &attach[1];
18443 VkAttachmentDescription attach_desc = {};
18444 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18445 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18446 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18447 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18448 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18449 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18450 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18451 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18452 VkRenderPassCreateInfo rpci = {};
18453 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18454 rpci.attachmentCount = 1;
18455 rpci.pAttachments = &attach_desc;
18456 rpci.subpassCount = 2;
18457 rpci.pSubpasses = subpasses;
18458
18459 // Now create RenderPass and verify no errors
18460 VkRenderPass rp;
18461 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18462 m_errorMonitor->VerifyNotFound();
18463
18464 vkDestroyRenderPass(m_device->device(), rp, NULL);
18465}
18466
18467TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18468 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18469 "as vertex attributes");
18470 m_errorMonitor->ExpectSuccess();
18471
18472 ASSERT_NO_FATAL_FAILURE(InitState());
18473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18474
18475 VkVertexInputBindingDescription input_binding;
18476 memset(&input_binding, 0, sizeof(input_binding));
18477
18478 VkVertexInputAttributeDescription input_attribs[2];
18479 memset(input_attribs, 0, sizeof(input_attribs));
18480
18481 for (int i = 0; i < 2; i++) {
18482 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18483 input_attribs[i].location = i;
18484 }
18485
18486 char const *vsSource = "#version 450\n"
18487 "\n"
18488 "layout(location=0) in mat2x4 x;\n"
18489 "out gl_PerVertex {\n"
18490 " vec4 gl_Position;\n"
18491 "};\n"
18492 "void main(){\n"
18493 " gl_Position = x[0] + x[1];\n"
18494 "}\n";
18495 char const *fsSource = "#version 450\n"
18496 "\n"
18497 "layout(location=0) out vec4 color;\n"
18498 "void main(){\n"
18499 " color = vec4(1);\n"
18500 "}\n";
18501
18502 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18503 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18504
18505 VkPipelineObj pipe(m_device);
18506 pipe.AddColorAttachment();
18507 pipe.AddShader(&vs);
18508 pipe.AddShader(&fs);
18509
18510 pipe.AddVertexInputBindings(&input_binding, 1);
18511 pipe.AddVertexInputAttribs(input_attribs, 2);
18512
18513 VkDescriptorSetObj descriptorSet(m_device);
18514 descriptorSet.AppendDummy();
18515 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18516
18517 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18518
18519 /* expect success */
18520 m_errorMonitor->VerifyNotFound();
18521}
18522
18523TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18524 m_errorMonitor->ExpectSuccess();
18525
18526 ASSERT_NO_FATAL_FAILURE(InitState());
18527 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18528
18529 VkVertexInputBindingDescription input_binding;
18530 memset(&input_binding, 0, sizeof(input_binding));
18531
18532 VkVertexInputAttributeDescription input_attribs[2];
18533 memset(input_attribs, 0, sizeof(input_attribs));
18534
18535 for (int i = 0; i < 2; i++) {
18536 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18537 input_attribs[i].location = i;
18538 }
18539
18540 char const *vsSource = "#version 450\n"
18541 "\n"
18542 "layout(location=0) in vec4 x[2];\n"
18543 "out gl_PerVertex {\n"
18544 " vec4 gl_Position;\n"
18545 "};\n"
18546 "void main(){\n"
18547 " gl_Position = x[0] + x[1];\n"
18548 "}\n";
18549 char const *fsSource = "#version 450\n"
18550 "\n"
18551 "layout(location=0) out vec4 color;\n"
18552 "void main(){\n"
18553 " color = vec4(1);\n"
18554 "}\n";
18555
18556 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18557 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18558
18559 VkPipelineObj pipe(m_device);
18560 pipe.AddColorAttachment();
18561 pipe.AddShader(&vs);
18562 pipe.AddShader(&fs);
18563
18564 pipe.AddVertexInputBindings(&input_binding, 1);
18565 pipe.AddVertexInputAttribs(input_attribs, 2);
18566
18567 VkDescriptorSetObj descriptorSet(m_device);
18568 descriptorSet.AppendDummy();
18569 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18570
18571 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18572
18573 m_errorMonitor->VerifyNotFound();
18574}
18575
18576TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18577 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18578 "through multiple vertex shader inputs, each consuming a different "
18579 "subset of the components.");
18580 m_errorMonitor->ExpectSuccess();
18581
18582 ASSERT_NO_FATAL_FAILURE(InitState());
18583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18584
18585 VkVertexInputBindingDescription input_binding;
18586 memset(&input_binding, 0, sizeof(input_binding));
18587
18588 VkVertexInputAttributeDescription input_attribs[3];
18589 memset(input_attribs, 0, sizeof(input_attribs));
18590
18591 for (int i = 0; i < 3; i++) {
18592 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18593 input_attribs[i].location = i;
18594 }
18595
18596 char const *vsSource = "#version 450\n"
18597 "\n"
18598 "layout(location=0) in vec4 x;\n"
18599 "layout(location=1) in vec3 y1;\n"
18600 "layout(location=1, component=3) in float y2;\n"
18601 "layout(location=2) in vec4 z;\n"
18602 "out gl_PerVertex {\n"
18603 " vec4 gl_Position;\n"
18604 "};\n"
18605 "void main(){\n"
18606 " gl_Position = x + vec4(y1, y2) + z;\n"
18607 "}\n";
18608 char const *fsSource = "#version 450\n"
18609 "\n"
18610 "layout(location=0) out vec4 color;\n"
18611 "void main(){\n"
18612 " color = vec4(1);\n"
18613 "}\n";
18614
18615 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18616 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18617
18618 VkPipelineObj pipe(m_device);
18619 pipe.AddColorAttachment();
18620 pipe.AddShader(&vs);
18621 pipe.AddShader(&fs);
18622
18623 pipe.AddVertexInputBindings(&input_binding, 1);
18624 pipe.AddVertexInputAttribs(input_attribs, 3);
18625
18626 VkDescriptorSetObj descriptorSet(m_device);
18627 descriptorSet.AppendDummy();
18628 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18629
18630 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18631
18632 m_errorMonitor->VerifyNotFound();
18633}
18634
18635TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18636 m_errorMonitor->ExpectSuccess();
18637
18638 ASSERT_NO_FATAL_FAILURE(InitState());
18639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18640
18641 char const *vsSource = "#version 450\n"
18642 "out gl_PerVertex {\n"
18643 " vec4 gl_Position;\n"
18644 "};\n"
18645 "void main(){\n"
18646 " gl_Position = vec4(0);\n"
18647 "}\n";
18648 char const *fsSource = "#version 450\n"
18649 "\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 fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18657
18658 VkPipelineObj pipe(m_device);
18659 pipe.AddColorAttachment();
18660 pipe.AddShader(&vs);
18661 pipe.AddShader(&fs);
18662
18663 VkDescriptorSetObj descriptorSet(m_device);
18664 descriptorSet.AppendDummy();
18665 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18666
18667 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18668
18669 m_errorMonitor->VerifyNotFound();
18670}
18671
18672TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18673 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18674 "set out in 14.1.3: fundamental type must match, and producer side must "
18675 "have at least as many components");
18676 m_errorMonitor->ExpectSuccess();
18677
18678 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18679
18680 ASSERT_NO_FATAL_FAILURE(InitState());
18681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18682
18683 char const *vsSource = "#version 450\n"
18684 "out gl_PerVertex {\n"
18685 " vec4 gl_Position;\n"
18686 "};\n"
18687 "layout(location=0) out vec3 x;\n"
18688 "layout(location=1) out ivec3 y;\n"
18689 "layout(location=2) out vec3 z;\n"
18690 "void main(){\n"
18691 " gl_Position = vec4(0);\n"
18692 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18693 "}\n";
18694 char const *fsSource = "#version 450\n"
18695 "\n"
18696 "layout(location=0) out vec4 color;\n"
18697 "layout(location=0) in float x;\n"
18698 "layout(location=1) flat in int y;\n"
18699 "layout(location=2) in vec2 z;\n"
18700 "void main(){\n"
18701 " color = vec4(1 + x + y + z.x);\n"
18702 "}\n";
18703
18704 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18705 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18706
18707 VkPipelineObj pipe(m_device);
18708 pipe.AddColorAttachment();
18709 pipe.AddShader(&vs);
18710 pipe.AddShader(&fs);
18711
18712 VkDescriptorSetObj descriptorSet(m_device);
18713 descriptorSet.AppendDummy();
18714 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18715
18716 VkResult err = VK_SUCCESS;
18717 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18718 ASSERT_VK_SUCCESS(err);
18719
18720 m_errorMonitor->VerifyNotFound();
18721}
18722
18723TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18724 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18725 "passed between the TCS and TES stages");
18726 m_errorMonitor->ExpectSuccess();
18727
18728 ASSERT_NO_FATAL_FAILURE(InitState());
18729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18730
18731 if (!m_device->phy().features().tessellationShader) {
18732 printf("Device does not support tessellation shaders; skipped.\n");
18733 return;
18734 }
18735
18736 char const *vsSource = "#version 450\n"
18737 "void main(){}\n";
18738 char const *tcsSource = "#version 450\n"
18739 "layout(location=0) out int x[];\n"
18740 "layout(vertices=3) out;\n"
18741 "void main(){\n"
18742 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18743 " gl_TessLevelInner[0] = 1;\n"
18744 " x[gl_InvocationID] = gl_InvocationID;\n"
18745 "}\n";
18746 char const *tesSource = "#version 450\n"
18747 "layout(triangles, equal_spacing, cw) in;\n"
18748 "layout(location=0) in int x[];\n"
18749 "out gl_PerVertex { vec4 gl_Position; };\n"
18750 "void main(){\n"
18751 " gl_Position.xyz = gl_TessCoord;\n"
18752 " gl_Position.w = x[0] + x[1] + x[2];\n"
18753 "}\n";
18754 char const *fsSource = "#version 450\n"
18755 "layout(location=0) out vec4 color;\n"
18756 "void main(){\n"
18757 " color = vec4(1);\n"
18758 "}\n";
18759
18760 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18761 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
18762 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
18763 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18764
18765 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
18766 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
18767
18768 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
18769
18770 VkPipelineObj pipe(m_device);
18771 pipe.SetInputAssembly(&iasci);
18772 pipe.SetTessellation(&tsci);
18773 pipe.AddColorAttachment();
18774 pipe.AddShader(&vs);
18775 pipe.AddShader(&tcs);
18776 pipe.AddShader(&tes);
18777 pipe.AddShader(&fs);
18778
18779 VkDescriptorSetObj descriptorSet(m_device);
18780 descriptorSet.AppendDummy();
18781 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18782
18783 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18784
18785 m_errorMonitor->VerifyNotFound();
18786}
18787
18788TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
18789 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
18790 "interface block passed into the geometry shader. This "
18791 "is interesting because the 'extra' array level is not "
18792 "present on the member type, but on the block instance.");
18793 m_errorMonitor->ExpectSuccess();
18794
18795 ASSERT_NO_FATAL_FAILURE(InitState());
18796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18797
18798 if (!m_device->phy().features().geometryShader) {
18799 printf("Device does not support geometry shaders; skipped.\n");
18800 return;
18801 }
18802
18803 char const *vsSource = "#version 450\n"
18804 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
18805 "void main(){\n"
18806 " vs_out.x = vec4(1);\n"
18807 "}\n";
18808 char const *gsSource = "#version 450\n"
18809 "layout(triangles) in;\n"
18810 "layout(triangle_strip, max_vertices=3) out;\n"
18811 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
18812 "out gl_PerVertex { vec4 gl_Position; };\n"
18813 "void main() {\n"
18814 " gl_Position = gs_in[0].x;\n"
18815 " EmitVertex();\n"
18816 "}\n";
18817 char const *fsSource = "#version 450\n"
18818 "layout(location=0) out vec4 color;\n"
18819 "void main(){\n"
18820 " color = vec4(1);\n"
18821 "}\n";
18822
18823 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18824 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
18825 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18826
18827 VkPipelineObj pipe(m_device);
18828 pipe.AddColorAttachment();
18829 pipe.AddShader(&vs);
18830 pipe.AddShader(&gs);
18831 pipe.AddShader(&fs);
18832
18833 VkDescriptorSetObj descriptorSet(m_device);
18834 descriptorSet.AppendDummy();
18835 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18836
18837 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18838
18839 m_errorMonitor->VerifyNotFound();
18840}
18841
18842TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
18843 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
18844 "attributes. This is interesting because they consume multiple "
18845 "locations.");
18846 m_errorMonitor->ExpectSuccess();
18847
18848 ASSERT_NO_FATAL_FAILURE(InitState());
18849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18850
18851 if (!m_device->phy().features().shaderFloat64) {
18852 printf("Device does not support 64bit vertex attributes; skipped.\n");
18853 return;
18854 }
18855
18856 VkVertexInputBindingDescription input_bindings[1];
18857 memset(input_bindings, 0, sizeof(input_bindings));
18858
18859 VkVertexInputAttributeDescription input_attribs[4];
18860 memset(input_attribs, 0, sizeof(input_attribs));
18861 input_attribs[0].location = 0;
18862 input_attribs[0].offset = 0;
18863 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18864 input_attribs[1].location = 2;
18865 input_attribs[1].offset = 32;
18866 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18867 input_attribs[2].location = 4;
18868 input_attribs[2].offset = 64;
18869 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18870 input_attribs[3].location = 6;
18871 input_attribs[3].offset = 96;
18872 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18873
18874 char const *vsSource = "#version 450\n"
18875 "\n"
18876 "layout(location=0) in dmat4 x;\n"
18877 "out gl_PerVertex {\n"
18878 " vec4 gl_Position;\n"
18879 "};\n"
18880 "void main(){\n"
18881 " gl_Position = vec4(x[0][0]);\n"
18882 "}\n";
18883 char const *fsSource = "#version 450\n"
18884 "\n"
18885 "layout(location=0) out vec4 color;\n"
18886 "void main(){\n"
18887 " color = vec4(1);\n"
18888 "}\n";
18889
18890 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18891 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18892
18893 VkPipelineObj pipe(m_device);
18894 pipe.AddColorAttachment();
18895 pipe.AddShader(&vs);
18896 pipe.AddShader(&fs);
18897
18898 pipe.AddVertexInputBindings(input_bindings, 1);
18899 pipe.AddVertexInputAttribs(input_attribs, 4);
18900
18901 VkDescriptorSetObj descriptorSet(m_device);
18902 descriptorSet.AppendDummy();
18903 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18904
18905 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18906
18907 m_errorMonitor->VerifyNotFound();
18908}
18909
18910TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
18911 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
18912 m_errorMonitor->ExpectSuccess();
18913
18914 ASSERT_NO_FATAL_FAILURE(InitState());
18915
18916 char const *vsSource = "#version 450\n"
18917 "\n"
18918 "out gl_PerVertex {\n"
18919 " vec4 gl_Position;\n"
18920 "};\n"
18921 "void main(){\n"
18922 " gl_Position = vec4(1);\n"
18923 "}\n";
18924 char const *fsSource = "#version 450\n"
18925 "\n"
18926 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
18927 "layout(location=0) out vec4 color;\n"
18928 "void main() {\n"
18929 " color = subpassLoad(x);\n"
18930 "}\n";
18931
18932 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18933 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18934
18935 VkPipelineObj pipe(m_device);
18936 pipe.AddShader(&vs);
18937 pipe.AddShader(&fs);
18938 pipe.AddColorAttachment();
18939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18940
18941 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
18942 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
18943 VkDescriptorSetLayout dsl;
18944 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18945 ASSERT_VK_SUCCESS(err);
18946
18947 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18948 VkPipelineLayout pl;
18949 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18950 ASSERT_VK_SUCCESS(err);
18951
18952 VkAttachmentDescription descs[2] = {
18953 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18954 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18955 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
18956 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18957 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
18958 };
18959 VkAttachmentReference color = {
18960 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18961 };
18962 VkAttachmentReference input = {
18963 1, VK_IMAGE_LAYOUT_GENERAL,
18964 };
18965
18966 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
18967
18968 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
18969 VkRenderPass rp;
18970 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18971 ASSERT_VK_SUCCESS(err);
18972
18973 // should be OK. would go wrong here if it's going to...
18974 pipe.CreateVKPipeline(pl, rp);
18975
18976 m_errorMonitor->VerifyNotFound();
18977
18978 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18979 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18980 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18981}
18982
18983TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
18984 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
18985 "descriptor-backed resource which is not provided, but the shader does not "
18986 "statically use it. This is interesting because it requires compute pipelines "
18987 "to have a proper descriptor use walk, which they didn't for some time.");
18988 m_errorMonitor->ExpectSuccess();
18989
18990 ASSERT_NO_FATAL_FAILURE(InitState());
18991
18992 char const *csSource = "#version 450\n"
18993 "\n"
18994 "layout(local_size_x=1) in;\n"
18995 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
18996 "void main(){\n"
18997 " // x is not used.\n"
18998 "}\n";
18999
19000 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19001
19002 VkDescriptorSetObj descriptorSet(m_device);
19003 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19004
19005 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19006 nullptr,
19007 0,
19008 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19009 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19010 descriptorSet.GetPipelineLayout(),
19011 VK_NULL_HANDLE,
19012 -1 };
19013
19014 VkPipeline pipe;
19015 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19016
19017 m_errorMonitor->VerifyNotFound();
19018
19019 if (err == VK_SUCCESS) {
19020 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19021 }
19022}
19023
19024TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19025 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19026 "sampler portion of a combined image + sampler");
19027 m_errorMonitor->ExpectSuccess();
19028
19029 ASSERT_NO_FATAL_FAILURE(InitState());
19030
19031 VkDescriptorSetLayoutBinding bindings[] = {
19032 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19033 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19034 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19035 };
19036 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19037 VkDescriptorSetLayout dsl;
19038 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19039 ASSERT_VK_SUCCESS(err);
19040
19041 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19042 VkPipelineLayout pl;
19043 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19044 ASSERT_VK_SUCCESS(err);
19045
19046 char const *csSource = "#version 450\n"
19047 "\n"
19048 "layout(local_size_x=1) in;\n"
19049 "layout(set=0, binding=0) uniform sampler s;\n"
19050 "layout(set=0, binding=1) uniform texture2D t;\n"
19051 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19052 "void main() {\n"
19053 " x = texture(sampler2D(t, s), vec2(0));\n"
19054 "}\n";
19055 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19056
19057 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19058 nullptr,
19059 0,
19060 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19061 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19062 pl,
19063 VK_NULL_HANDLE,
19064 -1 };
19065
19066 VkPipeline pipe;
19067 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19068
19069 m_errorMonitor->VerifyNotFound();
19070
19071 if (err == VK_SUCCESS) {
19072 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19073 }
19074
19075 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19076 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19077}
19078
19079TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19080 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19081 "image portion of a combined image + sampler");
19082 m_errorMonitor->ExpectSuccess();
19083
19084 ASSERT_NO_FATAL_FAILURE(InitState());
19085
19086 VkDescriptorSetLayoutBinding bindings[] = {
19087 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19088 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19089 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19090 };
19091 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19092 VkDescriptorSetLayout dsl;
19093 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19094 ASSERT_VK_SUCCESS(err);
19095
19096 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19097 VkPipelineLayout pl;
19098 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19099 ASSERT_VK_SUCCESS(err);
19100
19101 char const *csSource = "#version 450\n"
19102 "\n"
19103 "layout(local_size_x=1) in;\n"
19104 "layout(set=0, binding=0) uniform texture2D t;\n"
19105 "layout(set=0, binding=1) uniform sampler s;\n"
19106 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19107 "void main() {\n"
19108 " x = texture(sampler2D(t, s), vec2(0));\n"
19109 "}\n";
19110 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19111
19112 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19113 nullptr,
19114 0,
19115 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19116 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19117 pl,
19118 VK_NULL_HANDLE,
19119 -1 };
19120
19121 VkPipeline pipe;
19122 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19123
19124 m_errorMonitor->VerifyNotFound();
19125
19126 if (err == VK_SUCCESS) {
19127 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19128 }
19129
19130 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19131 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19132}
19133
19134TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19135 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19136 "both the sampler and the image of a combined image+sampler "
19137 "but via separate variables");
19138 m_errorMonitor->ExpectSuccess();
19139
19140 ASSERT_NO_FATAL_FAILURE(InitState());
19141
19142 VkDescriptorSetLayoutBinding bindings[] = {
19143 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19144 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19145 };
19146 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19147 VkDescriptorSetLayout dsl;
19148 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19149 ASSERT_VK_SUCCESS(err);
19150
19151 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19152 VkPipelineLayout pl;
19153 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19154 ASSERT_VK_SUCCESS(err);
19155
19156 char const *csSource = "#version 450\n"
19157 "\n"
19158 "layout(local_size_x=1) in;\n"
19159 "layout(set=0, binding=0) uniform texture2D t;\n"
19160 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19161 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19162 "void main() {\n"
19163 " x = texture(sampler2D(t, s), vec2(0));\n"
19164 "}\n";
19165 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19166
19167 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19168 nullptr,
19169 0,
19170 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19171 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19172 pl,
19173 VK_NULL_HANDLE,
19174 -1 };
19175
19176 VkPipeline pipe;
19177 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19178
19179 m_errorMonitor->VerifyNotFound();
19180
19181 if (err == VK_SUCCESS) {
19182 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19183 }
19184
19185 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19186 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19187}
19188
19189TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19190 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19191
19192 ASSERT_NO_FATAL_FAILURE(InitState());
19193
19194 // Positive test to check parameter_validation and unique_objects support
19195 // for NV_dedicated_allocation
19196 uint32_t extension_count = 0;
19197 bool supports_nv_dedicated_allocation = false;
19198 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19199 ASSERT_VK_SUCCESS(err);
19200
19201 if (extension_count > 0) {
19202 std::vector<VkExtensionProperties> available_extensions(extension_count);
19203
19204 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19205 ASSERT_VK_SUCCESS(err);
19206
19207 for (const auto &extension_props : available_extensions) {
19208 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19209 supports_nv_dedicated_allocation = true;
19210 }
19211 }
19212 }
19213
19214 if (supports_nv_dedicated_allocation) {
19215 m_errorMonitor->ExpectSuccess();
19216
19217 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19218 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19219 dedicated_buffer_create_info.pNext = nullptr;
19220 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19221
19222 uint32_t queue_family_index = 0;
19223 VkBufferCreateInfo buffer_create_info = {};
19224 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19225 buffer_create_info.pNext = &dedicated_buffer_create_info;
19226 buffer_create_info.size = 1024;
19227 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19228 buffer_create_info.queueFamilyIndexCount = 1;
19229 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19230
19231 VkBuffer buffer;
19232 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19233 ASSERT_VK_SUCCESS(err);
19234
19235 VkMemoryRequirements memory_reqs;
19236 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19237
19238 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19239 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19240 dedicated_memory_info.pNext = nullptr;
19241 dedicated_memory_info.buffer = buffer;
19242 dedicated_memory_info.image = VK_NULL_HANDLE;
19243
19244 VkMemoryAllocateInfo memory_info = {};
19245 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19246 memory_info.pNext = &dedicated_memory_info;
19247 memory_info.allocationSize = memory_reqs.size;
19248
19249 bool pass;
19250 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19251 ASSERT_TRUE(pass);
19252
19253 VkDeviceMemory buffer_memory;
19254 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19255 ASSERT_VK_SUCCESS(err);
19256
19257 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19258 ASSERT_VK_SUCCESS(err);
19259
19260 vkDestroyBuffer(m_device->device(), buffer, NULL);
19261 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19262
19263 m_errorMonitor->VerifyNotFound();
19264 }
19265}
19266
19267TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19268 VkResult err;
19269
19270 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19271
19272 ASSERT_NO_FATAL_FAILURE(InitState());
19273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19274
19275 std::vector<const char *> device_extension_names;
19276 auto features = m_device->phy().features();
19277 // Artificially disable support for non-solid fill modes
19278 features.fillModeNonSolid = false;
19279 // The sacrificial device object
19280 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19281
19282 VkRenderpassObj render_pass(&test_device);
19283
19284 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19285 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19286 pipeline_layout_ci.setLayoutCount = 0;
19287 pipeline_layout_ci.pSetLayouts = NULL;
19288
19289 VkPipelineLayout pipeline_layout;
19290 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19291 ASSERT_VK_SUCCESS(err);
19292
19293 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19294 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19295 rs_ci.pNext = nullptr;
19296 rs_ci.lineWidth = 1.0f;
19297 rs_ci.rasterizerDiscardEnable = true;
19298
19299 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19300 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19301
19302 // Set polygonMode=FILL. No error is expected
19303 m_errorMonitor->ExpectSuccess();
19304 {
19305 VkPipelineObj pipe(&test_device);
19306 pipe.AddShader(&vs);
19307 pipe.AddShader(&fs);
19308 pipe.AddColorAttachment();
19309 // Set polygonMode to a good value
19310 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19311 pipe.SetRasterization(&rs_ci);
19312 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19313 }
19314 m_errorMonitor->VerifyNotFound();
19315
19316 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19317}
19318
19319TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19320 VkResult err;
19321 ASSERT_NO_FATAL_FAILURE(InitState());
19322 ASSERT_NO_FATAL_FAILURE(InitViewport());
19323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19324
19325 VkPipelineLayout pipeline_layout;
19326 VkPushConstantRange pc_range = {};
19327 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19328 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19329 pipeline_layout_ci.pushConstantRangeCount = 1;
19330 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19331
19332 //
19333 // Check for invalid push constant ranges in pipeline layouts.
19334 //
19335 struct PipelineLayoutTestCase {
19336 VkPushConstantRange const range;
19337 char const *msg;
19338 };
19339
19340 // Check for overlapping ranges
19341 const uint32_t ranges_per_test = 5;
19342 struct OverlappingRangeTestCase {
19343 VkPushConstantRange const ranges[ranges_per_test];
19344 char const *msg;
19345 };
19346
19347 // Run some positive tests to make sure overlap checking in the layer is OK
19348 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19349 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19350 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19351 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19352 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19353 "" },
19354 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19355 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19356 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19357 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19358 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19359 "" } } };
19360 for (const auto &iter : overlapping_range_tests_pos) {
19361 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19362 m_errorMonitor->ExpectSuccess();
19363 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19364 m_errorMonitor->VerifyNotFound();
19365 if (VK_SUCCESS == err) {
19366 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19367 }
19368 }
19369
19370 //
19371 // CmdPushConstants tests
19372 //
19373 const uint8_t dummy_values[100] = {};
19374
19375 BeginCommandBuffer();
19376
19377 // positive overlapping range tests with cmd
19378 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19379 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19380 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19381 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19382 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19383 } };
19384
19385 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19386 const VkPushConstantRange pc_range4[] = {
19387 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19388 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19389 };
19390
19391 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19392 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19393 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19394 ASSERT_VK_SUCCESS(err);
19395 for (const auto &iter : cmd_overlap_tests_pos) {
19396 m_errorMonitor->ExpectSuccess();
19397 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19398 iter.range.size, dummy_values);
19399 m_errorMonitor->VerifyNotFound();
19400 }
19401 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19402
19403 EndCommandBuffer();
19404}
19405
19406
19407
19408
19409
19410
19411
19412#if 0 // A few devices have issues with this test so disabling for now
19413TEST_F(VkPositiveLayerTest, LongFenceChain)
19414{
19415 m_errorMonitor->ExpectSuccess();
19416
19417 ASSERT_NO_FATAL_FAILURE(InitState());
19418 VkResult err;
19419
19420 std::vector<VkFence> fences;
19421
19422 const int chainLength = 32768;
19423
19424 for (int i = 0; i < chainLength; i++) {
19425 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19426 VkFence fence;
19427 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19428 ASSERT_VK_SUCCESS(err);
19429
19430 fences.push_back(fence);
19431
19432 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19433 0, nullptr, 0, nullptr };
19434 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19435 ASSERT_VK_SUCCESS(err);
19436
19437 }
19438
19439 // BOOM, stack overflow.
19440 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19441
19442 for (auto fence : fences)
19443 vkDestroyFence(m_device->device(), fence, nullptr);
19444
19445 m_errorMonitor->VerifyNotFound();
19446}
19447#endif
19448
19449
Cody Northrop1242dfd2016-07-13 17:24:59 -060019450#if defined(ANDROID) && defined(VALIDATION_APK)
19451static bool initialized = false;
19452static bool active = false;
19453
19454// Convert Intents to argv
19455// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019456std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019457 std::vector<std::string> args;
19458 JavaVM &vm = *app.activity->vm;
19459 JNIEnv *p_env;
19460 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19461 return args;
19462
19463 JNIEnv &env = *p_env;
19464 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019465 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019466 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019467 jmethodID get_string_extra_method =
19468 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019469 jvalue get_string_extra_args;
19470 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019471 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019472
19473 std::string args_str;
19474 if (extra_str) {
19475 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19476 args_str = extra_utf;
19477 env.ReleaseStringUTFChars(extra_str, extra_utf);
19478 env.DeleteLocalRef(extra_str);
19479 }
19480
19481 env.DeleteLocalRef(get_string_extra_args.l);
19482 env.DeleteLocalRef(intent);
19483 vm.DetachCurrentThread();
19484
19485 // split args_str
19486 std::stringstream ss(args_str);
19487 std::string arg;
19488 while (std::getline(ss, arg, ' ')) {
19489 if (!arg.empty())
19490 args.push_back(arg);
19491 }
19492
19493 return args;
19494}
19495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019496static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019498static void processCommand(struct android_app *app, int32_t cmd) {
19499 switch (cmd) {
19500 case APP_CMD_INIT_WINDOW: {
19501 if (app->window) {
19502 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019503 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019504 break;
19505 }
19506 case APP_CMD_GAINED_FOCUS: {
19507 active = true;
19508 break;
19509 }
19510 case APP_CMD_LOST_FOCUS: {
19511 active = false;
19512 break;
19513 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019514 }
19515}
19516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019517void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019518 app_dummy();
19519
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019520 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019521
19522 int vulkanSupport = InitVulkan();
19523 if (vulkanSupport == 0) {
19524 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19525 return;
19526 }
19527
19528 app->onAppCmd = processCommand;
19529 app->onInputEvent = processInput;
19530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019531 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019532 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019533 struct android_poll_source *source;
19534 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019535 if (source) {
19536 source->process(app, source);
19537 }
19538
19539 if (app->destroyRequested != 0) {
19540 VkTestFramework::Finish();
19541 return;
19542 }
19543 }
19544
19545 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019546 // Use the following key to send arguments to gtest, i.e.
19547 // --es args "--gtest_filter=-VkLayerTest.foo"
19548 const char key[] = "args";
19549 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019550
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019551 std::string filter = "";
19552 if (args.size() > 0) {
19553 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19554 filter += args[0];
19555 } else {
19556 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19557 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019559 int argc = 2;
19560 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19561 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019563 // Route output to files until we can override the gtest output
19564 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19565 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019566
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019567 ::testing::InitGoogleTest(&argc, argv);
19568 VkTestFramework::InitArgs(&argc, argv);
19569 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019570
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019571 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019573 if (result != 0) {
19574 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19575 } else {
19576 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19577 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019579 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019581 fclose(stdout);
19582 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019583
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019584 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019586 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019587 }
19588 }
19589}
19590#endif
19591
Tony Barbour300a6082015-04-07 13:44:53 -060019592int main(int argc, char **argv) {
19593 int result;
19594
Cody Northrop8e54a402016-03-08 22:25:52 -070019595#ifdef ANDROID
19596 int vulkanSupport = InitVulkan();
19597 if (vulkanSupport == 0)
19598 return 1;
19599#endif
19600
Tony Barbour300a6082015-04-07 13:44:53 -060019601 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019602 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019603
19604 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19605
19606 result = RUN_ALL_TESTS();
19607
Tony Barbour6918cd52015-04-09 12:58:51 -060019608 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019609 return result;
19610}