blob: 4af4517a5d11148cc5e42c4e410f378397941ebe [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
Ian Elliott3f06ce52016-04-29 14:46:21 -06001578
Ian Elliott1c32c772016-04-28 14:47:13 -06001579#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1581 // TO NON-LINUX PLATFORMS:
1582 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1584 // that extension:
1585
1586 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001587 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001589 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1590 pass = (err != VK_SUCCESS);
1591 ASSERT_TRUE(pass);
1592 m_errorMonitor->VerifyFound();
1593
1594 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001595 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001596 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1598 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001599 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001600// Set this (for now, until all platforms are supported and tested):
1601#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001602#endif // VK_USE_PLATFORM_XCB_KHR
1603
Ian Elliott12630812016-04-29 14:35:43 -06001604#if defined(VK_USE_PLATFORM_XLIB_KHR)
1605 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1606 // that extension:
1607
1608 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001609 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001611 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1612 pass = (err != VK_SUCCESS);
1613 ASSERT_TRUE(pass);
1614 m_errorMonitor->VerifyFound();
1615
1616 // Tell whether an Xlib VisualID supports presentation:
1617 Display *dpy = NULL;
1618 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001620 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1621 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001622// Set this (for now, until all platforms are supported and tested):
1623#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001624#endif // VK_USE_PLATFORM_XLIB_KHR
1625
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001626// Use the functions from the VK_KHR_surface extension without enabling
1627// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001628
Ian Elliott489eec02016-05-05 14:12:44 -06001629#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001630 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001632 vkDestroySurfaceKHR(instance(), surface, NULL);
1633 m_errorMonitor->VerifyFound();
1634
1635 // Check if surface supports presentation:
1636 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001638 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1639 pass = (err != VK_SUCCESS);
1640 ASSERT_TRUE(pass);
1641 m_errorMonitor->VerifyFound();
1642
1643 // Check surface capabilities:
1644 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1646 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001647 pass = (err != VK_SUCCESS);
1648 ASSERT_TRUE(pass);
1649 m_errorMonitor->VerifyFound();
1650
1651 // Check surface formats:
1652 uint32_t format_count = 0;
1653 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1655 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001656 pass = (err != VK_SUCCESS);
1657 ASSERT_TRUE(pass);
1658 m_errorMonitor->VerifyFound();
1659
1660 // Check surface present modes:
1661 uint32_t present_mode_count = 0;
1662 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1664 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001665 pass = (err != VK_SUCCESS);
1666 ASSERT_TRUE(pass);
1667 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001668#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001669
Ian Elliott1c32c772016-04-28 14:47:13 -06001670 // Use the functions from the VK_KHR_swapchain extension without enabling
1671 // that extension:
1672
1673 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001675 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1676 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001678 pass = (err != VK_SUCCESS);
1679 ASSERT_TRUE(pass);
1680 m_errorMonitor->VerifyFound();
1681
1682 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1684 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001685 pass = (err != VK_SUCCESS);
1686 ASSERT_TRUE(pass);
1687 m_errorMonitor->VerifyFound();
1688
Chris Forbeseb7d5502016-09-13 18:19:21 +12001689 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1690 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1691 VkFence fence;
1692 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1693
Ian Elliott1c32c772016-04-28 14:47:13 -06001694 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001696 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001697 pass = (err != VK_SUCCESS);
1698 ASSERT_TRUE(pass);
1699 m_errorMonitor->VerifyFound();
1700
Chris Forbeseb7d5502016-09-13 18:19:21 +12001701 vkDestroyFence(m_device->device(), fence, nullptr);
1702
Ian Elliott1c32c772016-04-28 14:47:13 -06001703 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001704 //
1705 // NOTE: Currently can't test this because a real swapchain is needed (as
1706 // opposed to the fake one we created) in order for the layer to lookup the
1707 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001708
1709 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001711 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1712 m_errorMonitor->VerifyFound();
1713}
1714
Karl Schultz6addd812016-02-02 17:17:23 -07001715TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1716 VkResult err;
1717 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1720 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001721
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001722 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001723
1724 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001725 VkImage image;
1726 VkDeviceMemory mem;
1727 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001728
Karl Schultz6addd812016-02-02 17:17:23 -07001729 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1730 const int32_t tex_width = 32;
1731 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001732
Tony Barboureb254902015-07-15 12:50:33 -06001733 VkImageCreateInfo image_create_info = {};
1734 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001735 image_create_info.pNext = NULL;
1736 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1737 image_create_info.format = tex_format;
1738 image_create_info.extent.width = tex_width;
1739 image_create_info.extent.height = tex_height;
1740 image_create_info.extent.depth = 1;
1741 image_create_info.mipLevels = 1;
1742 image_create_info.arrayLayers = 1;
1743 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1744 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1745 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1746 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001747 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001748
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001749 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001750 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001751 mem_alloc.pNext = NULL;
1752 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001753
Chia-I Wuf7458c52015-10-26 21:10:41 +08001754 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001755 ASSERT_VK_SUCCESS(err);
1756
Karl Schultz6addd812016-02-02 17:17:23 -07001757 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001758
Mark Lobodzinski23065352015-05-29 09:32:35 -05001759 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001761 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 -07001762 if (!pass) { // If we can't find any unmappable memory this test doesn't
1763 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001764 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001765 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001766 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001767
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001768 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001769 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001770 ASSERT_VK_SUCCESS(err);
1771
1772 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001773 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001774 ASSERT_VK_SUCCESS(err);
1775
1776 // Map memory as if to initialize the image
1777 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001778 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001779
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001780 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001781
Chia-I Wuf7458c52015-10-26 21:10:41 +08001782 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001783 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001784}
1785
Karl Schultz6addd812016-02-02 17:17:23 -07001786TEST_F(VkLayerTest, RebindMemory) {
1787 VkResult err;
1788 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001791
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001792 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001793
1794 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001795 VkImage image;
1796 VkDeviceMemory mem1;
1797 VkDeviceMemory mem2;
1798 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001799
Karl Schultz6addd812016-02-02 17:17:23 -07001800 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1801 const int32_t tex_width = 32;
1802 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001803
Tony Barboureb254902015-07-15 12:50:33 -06001804 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001805 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1806 image_create_info.pNext = NULL;
1807 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1808 image_create_info.format = tex_format;
1809 image_create_info.extent.width = tex_width;
1810 image_create_info.extent.height = tex_height;
1811 image_create_info.extent.depth = 1;
1812 image_create_info.mipLevels = 1;
1813 image_create_info.arrayLayers = 1;
1814 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1815 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1816 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1817 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001818
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001819 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001820 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1821 mem_alloc.pNext = NULL;
1822 mem_alloc.allocationSize = 0;
1823 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001824
Karl Schultz6addd812016-02-02 17:17:23 -07001825 // Introduce failure, do NOT set memProps to
1826 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001827 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001828 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001829 ASSERT_VK_SUCCESS(err);
1830
Karl Schultz6addd812016-02-02 17:17:23 -07001831 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001832
1833 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001834 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001835 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001836
1837 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001838 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001839 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001840 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001841 ASSERT_VK_SUCCESS(err);
1842
1843 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001844 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001845 ASSERT_VK_SUCCESS(err);
1846
Karl Schultz6addd812016-02-02 17:17:23 -07001847 // Introduce validation failure, try to bind a different memory object to
1848 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001849 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001850
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001851 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001852
Chia-I Wuf7458c52015-10-26 21:10:41 +08001853 vkDestroyImage(m_device->device(), image, NULL);
1854 vkFreeMemory(m_device->device(), mem1, NULL);
1855 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001856}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001857
Karl Schultz6addd812016-02-02 17:17:23 -07001858TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001859 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1862 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001863
1864 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001865 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1866 fenceInfo.pNext = NULL;
1867 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001868
Tony Barbour300a6082015-04-07 13:44:53 -06001869 ASSERT_NO_FATAL_FAILURE(InitState());
1870 ASSERT_NO_FATAL_FAILURE(InitViewport());
1871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1872
Tony Barbourfe3351b2015-07-28 10:17:20 -06001873 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001875 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001876
1877 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001878
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001879 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001880 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1881 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001882 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001883 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001884 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001885 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001886 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001887 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001888 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001889
1890 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001891 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001892
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001893 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001894}
Chris Forbes4e44c912016-06-16 10:20:00 +12001895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896TEST_F(VkLayerTest, InvalidUsageBits) {
1897 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1898 "Initialize buffer with wrong usage then perform copy expecting errors "
1899 "from both the image and the buffer (2 calls)");
1900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001901
1902 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001903 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001904 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001905 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 -06001906 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001907
Tony Barbourf92621a2016-05-02 14:28:12 -06001908 VkImageView dsv;
1909 VkImageViewCreateInfo dsvci = {};
1910 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1911 dsvci.image = image.handle();
1912 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1913 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1914 dsvci.subresourceRange.layerCount = 1;
1915 dsvci.subresourceRange.baseMipLevel = 0;
1916 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001917 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001918
Tony Barbourf92621a2016-05-02 14:28:12 -06001919 // Create a view with depth / stencil aspect for image with different usage
1920 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001921
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001922 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001923
1924 // Initialize buffer with TRANSFER_DST usage
1925 vk_testing::Buffer buffer;
1926 VkMemoryPropertyFlags reqs = 0;
1927 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1928 VkBufferImageCopy region = {};
1929 region.bufferRowLength = 128;
1930 region.bufferImageHeight = 128;
1931 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1932 region.imageSubresource.layerCount = 1;
1933 region.imageExtent.height = 16;
1934 region.imageExtent.width = 16;
1935 region.imageExtent.depth = 1;
1936
Tony Barbourf92621a2016-05-02 14:28:12 -06001937 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1938 // TRANSFER_DST
1939 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001940
Chris Forbesda581202016-10-06 18:25:26 +13001941 // two separate errors from this call:
1942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1944
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001945 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1946 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001947 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001948}
Tony Barbour75d79f02016-08-30 09:39:07 -06001949
Tony Barbour75d79f02016-08-30 09:39:07 -06001950
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001951#endif // MEM_TRACKER_TESTS
1952
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001953#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001954
1955TEST_F(VkLayerTest, LeakAnObject) {
1956 VkResult err;
1957
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001958 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001959
1960 // Note that we have to create a new device since destroying the
1961 // framework's device causes Teardown() to fail and just calling Teardown
1962 // will destroy the errorMonitor.
1963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001965
1966 ASSERT_NO_FATAL_FAILURE(InitState());
1967
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001968 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001969 std::vector<VkDeviceQueueCreateInfo> queue_info;
1970 queue_info.reserve(queue_props.size());
1971 std::vector<std::vector<float>> queue_priorities;
1972 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
1973 VkDeviceQueueCreateInfo qi = {};
1974 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
1975 qi.pNext = NULL;
1976 qi.queueFamilyIndex = i;
1977 qi.queueCount = queue_props[i].queueCount;
1978 queue_priorities.emplace_back(qi.queueCount, 0.0f);
1979 qi.pQueuePriorities = queue_priorities[i].data();
1980 queue_info.push_back(qi);
1981 }
1982
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001983 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001984
1985 // The sacrificial device object
1986 VkDevice testDevice;
1987 VkDeviceCreateInfo device_create_info = {};
1988 auto features = m_device->phy().features();
1989 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
1990 device_create_info.pNext = NULL;
1991 device_create_info.queueCreateInfoCount = queue_info.size();
1992 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06001993 device_create_info.enabledLayerCount = 0;
1994 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001995 device_create_info.pEnabledFeatures = &features;
1996 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
1997 ASSERT_VK_SUCCESS(err);
1998
1999 VkFence fence;
2000 VkFenceCreateInfo fence_create_info = {};
2001 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2002 fence_create_info.pNext = NULL;
2003 fence_create_info.flags = 0;
2004 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2005 ASSERT_VK_SUCCESS(err);
2006
2007 // Induce failure by not calling vkDestroyFence
2008 vkDestroyDevice(testDevice, NULL);
2009 m_errorMonitor->VerifyFound();
2010}
2011
2012TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2013
2014 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2015 "attempt to delete them from another.");
2016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002018
Cody Northropc31a84f2016-08-22 10:41:47 -06002019 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002020 VkCommandPool command_pool_one;
2021 VkCommandPool command_pool_two;
2022
2023 VkCommandPoolCreateInfo pool_create_info{};
2024 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2025 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2026 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002028 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002029
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002030 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002031
2032 VkCommandBuffer command_buffer[9];
2033 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002034 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002035 command_buffer_allocate_info.commandPool = command_pool_one;
2036 command_buffer_allocate_info.commandBufferCount = 9;
2037 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002040 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002041
2042 m_errorMonitor->VerifyFound();
2043
2044 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2045 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2046}
2047
2048TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2049 VkResult err;
2050
2051 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002052 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002055
2056 ASSERT_NO_FATAL_FAILURE(InitState());
2057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2058
2059 VkDescriptorPoolSize ds_type_count = {};
2060 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2061 ds_type_count.descriptorCount = 1;
2062
2063 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2064 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2065 ds_pool_ci.pNext = NULL;
2066 ds_pool_ci.flags = 0;
2067 ds_pool_ci.maxSets = 1;
2068 ds_pool_ci.poolSizeCount = 1;
2069 ds_pool_ci.pPoolSizes = &ds_type_count;
2070
2071 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002072 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002073 ASSERT_VK_SUCCESS(err);
2074
2075 // Create a second descriptor pool
2076 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002077 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002078 ASSERT_VK_SUCCESS(err);
2079
2080 VkDescriptorSetLayoutBinding dsl_binding = {};
2081 dsl_binding.binding = 0;
2082 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2083 dsl_binding.descriptorCount = 1;
2084 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2085 dsl_binding.pImmutableSamplers = NULL;
2086
2087 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2088 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2089 ds_layout_ci.pNext = NULL;
2090 ds_layout_ci.bindingCount = 1;
2091 ds_layout_ci.pBindings = &dsl_binding;
2092
2093 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002095 ASSERT_VK_SUCCESS(err);
2096
2097 VkDescriptorSet descriptorSet;
2098 VkDescriptorSetAllocateInfo alloc_info = {};
2099 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2100 alloc_info.descriptorSetCount = 1;
2101 alloc_info.descriptorPool = ds_pool_one;
2102 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002103 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002104 ASSERT_VK_SUCCESS(err);
2105
2106 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2107
2108 m_errorMonitor->VerifyFound();
2109
2110 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2111 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2112 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2113}
2114
2115TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002118 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002119
2120 ASSERT_NO_FATAL_FAILURE(InitState());
2121
2122 // Pass bogus handle into GetImageMemoryRequirements
2123 VkMemoryRequirements mem_reqs;
2124 uint64_t fakeImageHandle = 0xCADECADE;
2125 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2126
2127 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2128
2129 m_errorMonitor->VerifyFound();
2130}
2131
Karl Schultz6addd812016-02-02 17:17:23 -07002132TEST_F(VkLayerTest, PipelineNotBound) {
2133 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002134
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002135 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002138
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002139 ASSERT_NO_FATAL_FAILURE(InitState());
2140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002141
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002142 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002143 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2144 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002145
2146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2148 ds_pool_ci.pNext = NULL;
2149 ds_pool_ci.maxSets = 1;
2150 ds_pool_ci.poolSizeCount = 1;
2151 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002152
2153 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002154 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002155 ASSERT_VK_SUCCESS(err);
2156
2157 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002158 dsl_binding.binding = 0;
2159 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2160 dsl_binding.descriptorCount = 1;
2161 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2162 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002163
2164 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002165 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2166 ds_layout_ci.pNext = NULL;
2167 ds_layout_ci.bindingCount = 1;
2168 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002169
2170 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002171 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002172 ASSERT_VK_SUCCESS(err);
2173
2174 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002175 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002176 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002177 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002178 alloc_info.descriptorPool = ds_pool;
2179 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002180 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002181 ASSERT_VK_SUCCESS(err);
2182
2183 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002184 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2185 pipeline_layout_ci.pNext = NULL;
2186 pipeline_layout_ci.setLayoutCount = 1;
2187 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002188
2189 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002190 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002191 ASSERT_VK_SUCCESS(err);
2192
Mark Youngad779052016-01-06 14:26:04 -07002193 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002194
2195 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002196 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002197
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002198 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002199
Chia-I Wuf7458c52015-10-26 21:10:41 +08002200 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2201 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2202 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002203}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002204
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002205TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2206 VkResult err;
2207
2208 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2209 "during bind[Buffer|Image]Memory time");
2210
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002211 ASSERT_NO_FATAL_FAILURE(InitState());
2212
2213 // Create an image, allocate memory, set a bad typeIndex and then try to
2214 // bind it
2215 VkImage image;
2216 VkDeviceMemory mem;
2217 VkMemoryRequirements mem_reqs;
2218 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2219 const int32_t tex_width = 32;
2220 const int32_t tex_height = 32;
2221
2222 VkImageCreateInfo image_create_info = {};
2223 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2224 image_create_info.pNext = NULL;
2225 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2226 image_create_info.format = tex_format;
2227 image_create_info.extent.width = tex_width;
2228 image_create_info.extent.height = tex_height;
2229 image_create_info.extent.depth = 1;
2230 image_create_info.mipLevels = 1;
2231 image_create_info.arrayLayers = 1;
2232 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2233 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2234 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2235 image_create_info.flags = 0;
2236
2237 VkMemoryAllocateInfo mem_alloc = {};
2238 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2239 mem_alloc.pNext = NULL;
2240 mem_alloc.allocationSize = 0;
2241 mem_alloc.memoryTypeIndex = 0;
2242
2243 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2244 ASSERT_VK_SUCCESS(err);
2245
2246 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2247 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002248
2249 // Introduce Failure, select invalid TypeIndex
2250 VkPhysicalDeviceMemoryProperties memory_info;
2251
2252 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2253 unsigned int i;
2254 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2255 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2256 mem_alloc.memoryTypeIndex = i;
2257 break;
2258 }
2259 }
2260 if (i >= memory_info.memoryTypeCount) {
2261 printf("No invalid memory type index could be found; skipped.\n");
2262 vkDestroyImage(m_device->device(), image, NULL);
2263 return;
2264 }
2265
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002266 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 -06002267
2268 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2269 ASSERT_VK_SUCCESS(err);
2270
2271 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2272 (void)err;
2273
2274 m_errorMonitor->VerifyFound();
2275
2276 vkDestroyImage(m_device->device(), image, NULL);
2277 vkFreeMemory(m_device->device(), mem, NULL);
2278}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002279
Karl Schultz6addd812016-02-02 17:17:23 -07002280TEST_F(VkLayerTest, BindInvalidMemory) {
2281 VkResult err;
2282 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002283
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002285
Tobin Ehlisec598302015-09-15 15:02:17 -06002286 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002287
2288 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002289 VkImage image;
2290 VkDeviceMemory mem;
2291 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002292
Karl Schultz6addd812016-02-02 17:17:23 -07002293 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2294 const int32_t tex_width = 32;
2295 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002296
2297 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002298 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2299 image_create_info.pNext = NULL;
2300 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2301 image_create_info.format = tex_format;
2302 image_create_info.extent.width = tex_width;
2303 image_create_info.extent.height = tex_height;
2304 image_create_info.extent.depth = 1;
2305 image_create_info.mipLevels = 1;
2306 image_create_info.arrayLayers = 1;
2307 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2308 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2309 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2310 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002311
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002312 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002313 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2314 mem_alloc.pNext = NULL;
2315 mem_alloc.allocationSize = 0;
2316 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002317
Chia-I Wuf7458c52015-10-26 21:10:41 +08002318 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002319 ASSERT_VK_SUCCESS(err);
2320
Karl Schultz6addd812016-02-02 17:17:23 -07002321 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002322
2323 mem_alloc.allocationSize = mem_reqs.size;
2324
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002325 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002326 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002327
2328 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002329 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002330 ASSERT_VK_SUCCESS(err);
2331
2332 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002333 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002334
2335 // Try to bind free memory that has been freed
2336 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2337 // This may very well return an error.
2338 (void)err;
2339
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002340 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002341
Chia-I Wuf7458c52015-10-26 21:10:41 +08002342 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002343}
2344
Karl Schultz6addd812016-02-02 17:17:23 -07002345TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2346 VkResult err;
2347 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002348
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002350
Tobin Ehlisec598302015-09-15 15:02:17 -06002351 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002352
Karl Schultz6addd812016-02-02 17:17:23 -07002353 // Create an image object, allocate memory, destroy the object and then try
2354 // to bind it
2355 VkImage image;
2356 VkDeviceMemory mem;
2357 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002358
Karl Schultz6addd812016-02-02 17:17:23 -07002359 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2360 const int32_t tex_width = 32;
2361 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002362
2363 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2365 image_create_info.pNext = NULL;
2366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2367 image_create_info.format = tex_format;
2368 image_create_info.extent.width = tex_width;
2369 image_create_info.extent.height = tex_height;
2370 image_create_info.extent.depth = 1;
2371 image_create_info.mipLevels = 1;
2372 image_create_info.arrayLayers = 1;
2373 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2374 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2375 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2376 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002378 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002379 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2380 mem_alloc.pNext = NULL;
2381 mem_alloc.allocationSize = 0;
2382 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002383
Chia-I Wuf7458c52015-10-26 21:10:41 +08002384 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002385 ASSERT_VK_SUCCESS(err);
2386
Karl Schultz6addd812016-02-02 17:17:23 -07002387 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002388
2389 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002390 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002391 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002392
2393 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002394 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002395 ASSERT_VK_SUCCESS(err);
2396
2397 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002398 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002399 ASSERT_VK_SUCCESS(err);
2400
2401 // Now Try to bind memory to this destroyed object
2402 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2403 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002404 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002405
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002406 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002407
Chia-I Wuf7458c52015-10-26 21:10:41 +08002408 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002409}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002410
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002411#endif // OBJ_TRACKER_TESTS
2412
Tobin Ehlis0788f522015-05-26 16:11:58 -06002413#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002414
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002415TEST_F(VkLayerTest, ImageSampleCounts) {
2416
2417 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2418 "validation errors.");
2419 ASSERT_NO_FATAL_FAILURE(InitState());
2420
2421 VkMemoryPropertyFlags reqs = 0;
2422 VkImageCreateInfo image_create_info = {};
2423 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2424 image_create_info.pNext = NULL;
2425 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2426 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2427 image_create_info.extent.width = 256;
2428 image_create_info.extent.height = 256;
2429 image_create_info.extent.depth = 1;
2430 image_create_info.mipLevels = 1;
2431 image_create_info.arrayLayers = 1;
2432 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2433 image_create_info.flags = 0;
2434
2435 VkImageBlit blit_region = {};
2436 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2437 blit_region.srcSubresource.baseArrayLayer = 0;
2438 blit_region.srcSubresource.layerCount = 1;
2439 blit_region.srcSubresource.mipLevel = 0;
2440 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2441 blit_region.dstSubresource.baseArrayLayer = 0;
2442 blit_region.dstSubresource.layerCount = 1;
2443 blit_region.dstSubresource.mipLevel = 0;
2444
2445 // Create two images, the source with sampleCount = 2, and attempt to blit
2446 // between them
2447 {
2448 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002449 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002450 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002451 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002452 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002453 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002454 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002455 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002456 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2458 "of VK_SAMPLE_COUNT_2_BIT but "
2459 "must be VK_SAMPLE_COUNT_1_BIT");
2460 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2461 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002462 m_errorMonitor->VerifyFound();
2463 m_commandBuffer->EndCommandBuffer();
2464 }
2465
2466 // Create two images, the dest with sampleCount = 4, and attempt to blit
2467 // between them
2468 {
2469 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002471 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002472 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002473 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002474 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002475 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002476 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002477 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2479 "of VK_SAMPLE_COUNT_4_BIT but "
2480 "must be VK_SAMPLE_COUNT_1_BIT");
2481 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2482 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002483 m_errorMonitor->VerifyFound();
2484 m_commandBuffer->EndCommandBuffer();
2485 }
2486
2487 VkBufferImageCopy copy_region = {};
2488 copy_region.bufferRowLength = 128;
2489 copy_region.bufferImageHeight = 128;
2490 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2491 copy_region.imageSubresource.layerCount = 1;
2492 copy_region.imageExtent.height = 64;
2493 copy_region.imageExtent.width = 64;
2494 copy_region.imageExtent.depth = 1;
2495
2496 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2497 // buffer to image
2498 {
2499 vk_testing::Buffer src_buffer;
2500 VkMemoryPropertyFlags reqs = 0;
2501 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2502 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002504 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002505 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002506 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2508 "of VK_SAMPLE_COUNT_8_BIT but "
2509 "must be VK_SAMPLE_COUNT_1_BIT");
2510 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2511 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002512 m_errorMonitor->VerifyFound();
2513 m_commandBuffer->EndCommandBuffer();
2514 }
2515
2516 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2517 // image to buffer
2518 {
2519 vk_testing::Buffer dst_buffer;
2520 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2521 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002522 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002523 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002524 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002525 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2527 "of VK_SAMPLE_COUNT_2_BIT but "
2528 "must be VK_SAMPLE_COUNT_1_BIT");
2529 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002530 dst_buffer.handle(), 1, &copy_region);
2531 m_errorMonitor->VerifyFound();
2532 m_commandBuffer->EndCommandBuffer();
2533 }
2534}
2535
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002536TEST_F(VkLayerTest, BlitImageFormats) {
2537
2538 // Image blit with mismatched formats
2539 const char * expected_message =
2540 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2541 " the other one must also have signed/unsigned integer format";
2542
2543 ASSERT_NO_FATAL_FAILURE(InitState());
2544
2545 VkImageObj src_image(m_device);
2546 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2547 VkImageObj dst_image(m_device);
2548 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2549 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002550 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 -06002551
2552 VkImageBlit blitRegion = {};
2553 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2554 blitRegion.srcSubresource.baseArrayLayer = 0;
2555 blitRegion.srcSubresource.layerCount = 1;
2556 blitRegion.srcSubresource.mipLevel = 0;
2557 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2558 blitRegion.dstSubresource.baseArrayLayer = 0;
2559 blitRegion.dstSubresource.layerCount = 1;
2560 blitRegion.dstSubresource.mipLevel = 0;
2561
2562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2563
2564 // Unsigned int vs not an int
2565 BeginCommandBuffer();
2566 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2567 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2568
2569 m_errorMonitor->VerifyFound();
2570
2571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2572
2573 // Unsigned int vs signed int
2574 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2575 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2576
2577 m_errorMonitor->VerifyFound();
2578
2579 EndCommandBuffer();
2580}
2581
2582
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002583TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2584 VkResult err;
2585 bool pass;
2586
2587 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2588 ASSERT_NO_FATAL_FAILURE(InitState());
2589
2590 // If w/d/h granularity is 1, test is not meaningful
2591 // TODO: When virtual device limits are available, create a set of limits for this test that
2592 // will always have a granularity of > 1 for w, h, and d
2593 auto index = m_device->graphics_queue_node_index_;
2594 auto queue_family_properties = m_device->phy().queue_properties();
2595
2596 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2597 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2598 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2599 return;
2600 }
2601
2602 // Create two images of different types and try to copy between them
2603 VkImage srcImage;
2604 VkImage dstImage;
2605 VkDeviceMemory srcMem;
2606 VkDeviceMemory destMem;
2607 VkMemoryRequirements memReqs;
2608
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002609 VkImageCreateInfo image_create_info = {};
2610 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2611 image_create_info.pNext = NULL;
2612 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2613 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2614 image_create_info.extent.width = 32;
2615 image_create_info.extent.height = 32;
2616 image_create_info.extent.depth = 1;
2617 image_create_info.mipLevels = 1;
2618 image_create_info.arrayLayers = 4;
2619 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2620 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2621 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2622 image_create_info.flags = 0;
2623
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002624 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002625 ASSERT_VK_SUCCESS(err);
2626
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002627 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002628 ASSERT_VK_SUCCESS(err);
2629
2630 // Allocate memory
2631 VkMemoryAllocateInfo memAlloc = {};
2632 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2633 memAlloc.pNext = NULL;
2634 memAlloc.allocationSize = 0;
2635 memAlloc.memoryTypeIndex = 0;
2636
2637 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2638 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002639 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002640 ASSERT_TRUE(pass);
2641 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2642 ASSERT_VK_SUCCESS(err);
2643
2644 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2645 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002646 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002647 ASSERT_VK_SUCCESS(err);
2648 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2649 ASSERT_VK_SUCCESS(err);
2650
2651 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2652 ASSERT_VK_SUCCESS(err);
2653 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2654 ASSERT_VK_SUCCESS(err);
2655
2656 BeginCommandBuffer();
2657 VkImageCopy copyRegion;
2658 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2659 copyRegion.srcSubresource.mipLevel = 0;
2660 copyRegion.srcSubresource.baseArrayLayer = 0;
2661 copyRegion.srcSubresource.layerCount = 1;
2662 copyRegion.srcOffset.x = 0;
2663 copyRegion.srcOffset.y = 0;
2664 copyRegion.srcOffset.z = 0;
2665 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2666 copyRegion.dstSubresource.mipLevel = 0;
2667 copyRegion.dstSubresource.baseArrayLayer = 0;
2668 copyRegion.dstSubresource.layerCount = 1;
2669 copyRegion.dstOffset.x = 0;
2670 copyRegion.dstOffset.y = 0;
2671 copyRegion.dstOffset.z = 0;
2672 copyRegion.extent.width = 1;
2673 copyRegion.extent.height = 1;
2674 copyRegion.extent.depth = 1;
2675
2676 // Introduce failure by setting srcOffset to a bad granularity value
2677 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2679 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002680 m_errorMonitor->VerifyFound();
2681
2682 // Introduce failure by setting extent to a bad granularity value
2683 copyRegion.srcOffset.y = 0;
2684 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2686 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002687 m_errorMonitor->VerifyFound();
2688
2689 // Now do some buffer/image copies
2690 vk_testing::Buffer buffer;
2691 VkMemoryPropertyFlags reqs = 0;
2692 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2693 VkBufferImageCopy region = {};
2694 region.bufferOffset = 0;
2695 region.bufferRowLength = 3;
2696 region.bufferImageHeight = 128;
2697 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2698 region.imageSubresource.layerCount = 1;
2699 region.imageExtent.height = 16;
2700 region.imageExtent.width = 16;
2701 region.imageExtent.depth = 1;
2702 region.imageOffset.x = 0;
2703 region.imageOffset.y = 0;
2704 region.imageOffset.z = 0;
2705
2706 // Introduce failure by setting bufferRowLength to a bad granularity value
2707 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2709 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2710 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002711 m_errorMonitor->VerifyFound();
2712 region.bufferRowLength = 128;
2713
2714 // Introduce failure by setting bufferOffset to a bad granularity value
2715 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2717 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2718 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002719 m_errorMonitor->VerifyFound();
2720 region.bufferOffset = 0;
2721
2722 // Introduce failure by setting bufferImageHeight to a bad granularity value
2723 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2725 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2726 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002727 m_errorMonitor->VerifyFound();
2728 region.bufferImageHeight = 128;
2729
2730 // Introduce failure by setting imageExtent to a bad granularity value
2731 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2733 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2734 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002735 m_errorMonitor->VerifyFound();
2736 region.imageExtent.width = 16;
2737
2738 // Introduce failure by setting imageOffset to a bad granularity value
2739 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2741 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2742 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002743 m_errorMonitor->VerifyFound();
2744
2745 EndCommandBuffer();
2746
2747 vkDestroyImage(m_device->device(), srcImage, NULL);
2748 vkDestroyImage(m_device->device(), dstImage, NULL);
2749 vkFreeMemory(m_device->device(), srcMem, NULL);
2750 vkFreeMemory(m_device->device(), destMem, NULL);
2751}
2752
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002753TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002754 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2755 "attempt to submit them on a queue created in a different "
2756 "queue family.");
2757
Cody Northropc31a84f2016-08-22 10:41:47 -06002758 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002759 // This test is meaningless unless we have multiple queue families
2760 auto queue_family_properties = m_device->phy().queue_properties();
2761 if (queue_family_properties.size() < 2) {
2762 return;
2763 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002765 // Get safe index of another queue family
2766 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2767 ASSERT_NO_FATAL_FAILURE(InitState());
2768 // Create a second queue using a different queue family
2769 VkQueue other_queue;
2770 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2771
2772 // Record an empty cmd buffer
2773 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2774 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2775 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2776 vkEndCommandBuffer(m_commandBuffer->handle());
2777
2778 // And submit on the wrong queue
2779 VkSubmitInfo submit_info = {};
2780 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2781 submit_info.commandBufferCount = 1;
2782 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002783 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002784
2785 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002786}
2787
Chris Forbesa58c4522016-09-28 15:19:39 +13002788TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2789 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2790 ASSERT_NO_FATAL_FAILURE(InitState());
2791
2792 // A renderpass with two subpasses, both writing the same attachment.
2793 VkAttachmentDescription attach[] = {
2794 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2795 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2796 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2797 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2798 },
2799 };
2800 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2801 VkSubpassDescription subpasses[] = {
2802 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2803 1, &ref, nullptr, nullptr, 0, nullptr },
2804 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2805 1, &ref, nullptr, nullptr, 0, nullptr },
2806 };
2807 VkSubpassDependency dep = {
2808 0, 1,
2809 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2810 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2811 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2812 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2813 VK_DEPENDENCY_BY_REGION_BIT
2814 };
2815 VkRenderPassCreateInfo rpci = {
2816 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2817 0, 1, attach, 2, subpasses, 1, &dep
2818 };
2819 VkRenderPass rp;
2820 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2821 ASSERT_VK_SUCCESS(err);
2822
2823 VkImageObj image(m_device);
2824 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2825 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2826 VK_IMAGE_TILING_OPTIMAL, 0);
2827 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2828
2829 VkFramebufferCreateInfo fbci = {
2830 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2831 0, rp, 1, &imageView, 32, 32, 1
2832 };
2833 VkFramebuffer fb;
2834 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2835 ASSERT_VK_SUCCESS(err);
2836
2837 char const *vsSource =
2838 "#version 450\n"
2839 "void main() { gl_Position = vec4(1); }\n";
2840 char const *fsSource =
2841 "#version 450\n"
2842 "layout(location=0) out vec4 color;\n"
2843 "void main() { color = vec4(1); }\n";
2844
2845 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2846 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2847 VkPipelineObj pipe(m_device);
2848 pipe.AddColorAttachment();
2849 pipe.AddShader(&vs);
2850 pipe.AddShader(&fs);
2851 VkViewport view_port = {};
2852 m_viewports.push_back(view_port);
2853 pipe.SetViewport(m_viewports);
2854 VkRect2D rect = {};
2855 m_scissors.push_back(rect);
2856 pipe.SetScissor(m_scissors);
2857
2858 VkPipelineLayoutCreateInfo plci = {
2859 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2860 0, 0, nullptr, 0, nullptr
2861 };
2862 VkPipelineLayout pl;
2863 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2864 ASSERT_VK_SUCCESS(err);
2865 pipe.CreateVKPipeline(pl, rp);
2866
2867 BeginCommandBuffer();
2868
2869 VkRenderPassBeginInfo rpbi = {
2870 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2871 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2872 };
2873
2874 // subtest 1: bind in the wrong subpass
2875 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2876 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2878 "built for subpass 0 but used in subpass 1");
2879 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2880 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2881 m_errorMonitor->VerifyFound();
2882
2883 vkCmdEndRenderPass(m_commandBuffer->handle());
2884
2885 // subtest 2: bind in correct subpass, then transition to next subpass
2886 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2887 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2888 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2890 "built for subpass 0 but used in subpass 1");
2891 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2892 m_errorMonitor->VerifyFound();
2893
2894 vkCmdEndRenderPass(m_commandBuffer->handle());
2895
2896 EndCommandBuffer();
2897
2898 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
2899 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2900 vkDestroyRenderPass(m_device->device(), rp, nullptr);
2901}
2902
Tony Barbour4e919972016-08-09 13:27:40 -06002903TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
2904 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
2905 "with extent outside of framebuffer");
2906 ASSERT_NO_FATAL_FAILURE(InitState());
2907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
2910 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06002911
2912 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
2913 m_renderPassBeginInfo.renderArea.extent.width = 257;
2914 m_renderPassBeginInfo.renderArea.extent.height = 257;
2915 BeginCommandBuffer();
2916 m_errorMonitor->VerifyFound();
2917}
2918
2919TEST_F(VkLayerTest, DisabledIndependentBlend) {
2920 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
2921 "blend and then specifying different blend states for two "
2922 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06002923 VkPhysicalDeviceFeatures features = {};
2924 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06002925 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06002926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2928 "Invalid Pipeline CreateInfo: If independent blend feature not "
2929 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06002930
Cody Northropc31a84f2016-08-22 10:41:47 -06002931 VkDescriptorSetObj descriptorSet(m_device);
2932 descriptorSet.AppendDummy();
2933 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06002934
Cody Northropc31a84f2016-08-22 10:41:47 -06002935 VkPipelineObj pipeline(m_device);
2936 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002937 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06002938 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06002939
Cody Northropc31a84f2016-08-22 10:41:47 -06002940 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
2941 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2942 att_state1.blendEnable = VK_TRUE;
2943 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2944 att_state2.blendEnable = VK_FALSE;
2945 pipeline.AddColorAttachment(0, &att_state1);
2946 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002947 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06002948 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06002949}
2950
2951TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
2952 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
2953 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06002954 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06002955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2957 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06002958
2959 // Create a renderPass with a single color attachment
2960 VkAttachmentReference attach = {};
2961 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2962 VkSubpassDescription subpass = {};
2963 VkRenderPassCreateInfo rpci = {};
2964 rpci.subpassCount = 1;
2965 rpci.pSubpasses = &subpass;
2966 rpci.attachmentCount = 1;
2967 VkAttachmentDescription attach_desc = {};
2968 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
2969 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
2970 rpci.pAttachments = &attach_desc;
2971 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2972 VkRenderPass rp;
2973 subpass.pDepthStencilAttachment = &attach;
2974 subpass.pColorAttachments = NULL;
2975 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
2976 m_errorMonitor->VerifyFound();
2977}
2978
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002979TEST_F(VkLayerTest, UnusedPreserveAttachment) {
2980 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
2981 "attachment reference of VK_ATTACHMENT_UNUSED");
2982
2983 ASSERT_NO_FATAL_FAILURE(InitState());
2984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2985
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002987
2988 VkAttachmentReference color_attach = {};
2989 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
2990 color_attach.attachment = 0;
2991 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
2992 VkSubpassDescription subpass = {};
2993 subpass.colorAttachmentCount = 1;
2994 subpass.pColorAttachments = &color_attach;
2995 subpass.preserveAttachmentCount = 1;
2996 subpass.pPreserveAttachments = &preserve_attachment;
2997
2998 VkRenderPassCreateInfo rpci = {};
2999 rpci.subpassCount = 1;
3000 rpci.pSubpasses = &subpass;
3001 rpci.attachmentCount = 1;
3002 VkAttachmentDescription attach_desc = {};
3003 attach_desc.format = VK_FORMAT_UNDEFINED;
3004 rpci.pAttachments = &attach_desc;
3005 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3006 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003007 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003008
3009 m_errorMonitor->VerifyFound();
3010
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003011 if (result == VK_SUCCESS) {
3012 vkDestroyRenderPass(m_device->device(), rp, NULL);
3013 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003014}
3015
Chris Forbesc5389742016-06-29 11:49:23 +12003016TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003017 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3018 "when the source of a subpass multisample resolve "
3019 "does not have multiple samples.");
3020
Chris Forbesc5389742016-06-29 11:49:23 +12003021 ASSERT_NO_FATAL_FAILURE(InitState());
3022
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3024 "Subpass 0 requests multisample resolve from attachment 0 which has "
3025 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003026
3027 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003028 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3029 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3030 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3031 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3032 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3033 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003034 };
3035
3036 VkAttachmentReference color = {
3037 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3038 };
3039
3040 VkAttachmentReference resolve = {
3041 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3042 };
3043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003044 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003045
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003046 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003047
3048 VkRenderPass rp;
3049 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3050
3051 m_errorMonitor->VerifyFound();
3052
3053 if (err == VK_SUCCESS)
3054 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3055}
3056
3057TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003058 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3059 "when a subpass multisample resolve operation is "
3060 "requested, and the destination of that resolve has "
3061 "multiple samples.");
3062
Chris Forbesc5389742016-06-29 11:49:23 +12003063 ASSERT_NO_FATAL_FAILURE(InitState());
3064
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3066 "Subpass 0 requests multisample resolve into attachment 1, which "
3067 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003068
3069 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003070 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3071 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3072 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3073 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3074 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3075 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003076 };
3077
3078 VkAttachmentReference color = {
3079 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3080 };
3081
3082 VkAttachmentReference resolve = {
3083 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3084 };
3085
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003086 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003087
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003088 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003089
3090 VkRenderPass rp;
3091 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3092
3093 m_errorMonitor->VerifyFound();
3094
3095 if (err == VK_SUCCESS)
3096 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3097}
3098
Chris Forbes3f128ef2016-06-29 14:58:53 +12003099TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003100 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3101 "when the color and depth attachments used by a subpass "
3102 "have inconsistent sample counts");
3103
Chris Forbes3f128ef2016-06-29 14:58:53 +12003104 ASSERT_NO_FATAL_FAILURE(InitState());
3105
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003108
3109 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003110 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3111 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3112 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3113 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3114 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3115 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003116 };
3117
3118 VkAttachmentReference color[] = {
3119 {
3120 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3121 },
3122 {
3123 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3124 },
3125 };
3126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003127 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003129 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003130
3131 VkRenderPass rp;
3132 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3133
3134 m_errorMonitor->VerifyFound();
3135
3136 if (err == VK_SUCCESS)
3137 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3138}
3139
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003140TEST_F(VkLayerTest, FramebufferCreateErrors) {
3141 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003142 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003143 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003144 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3145 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3146 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3147 " 6. Framebuffer attachment where dimensions don't match\n"
3148 " 7. Framebuffer attachment w/o identity swizzle\n"
3149 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003150
3151 ASSERT_NO_FATAL_FAILURE(InitState());
3152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3153
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3155 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3156 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003157
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003158 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003159 VkAttachmentReference attach = {};
3160 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3161 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003162 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003163 VkRenderPassCreateInfo rpci = {};
3164 rpci.subpassCount = 1;
3165 rpci.pSubpasses = &subpass;
3166 rpci.attachmentCount = 1;
3167 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003168 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003169 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003170 rpci.pAttachments = &attach_desc;
3171 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3172 VkRenderPass rp;
3173 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3174 ASSERT_VK_SUCCESS(err);
3175
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003176 VkImageView ivs[2];
3177 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3178 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003179 VkFramebufferCreateInfo fb_info = {};
3180 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3181 fb_info.pNext = NULL;
3182 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003183 // Set mis-matching attachmentCount
3184 fb_info.attachmentCount = 2;
3185 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003186 fb_info.width = 100;
3187 fb_info.height = 100;
3188 fb_info.layers = 1;
3189
3190 VkFramebuffer fb;
3191 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3192
3193 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003194 if (err == VK_SUCCESS) {
3195 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3196 }
3197 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003198
3199 // Create a renderPass with a depth-stencil attachment created with
3200 // IMAGE_USAGE_COLOR_ATTACHMENT
3201 // Add our color attachment to pDepthStencilAttachment
3202 subpass.pDepthStencilAttachment = &attach;
3203 subpass.pColorAttachments = NULL;
3204 VkRenderPass rp_ds;
3205 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3206 ASSERT_VK_SUCCESS(err);
3207 // Set correct attachment count, but attachment has COLOR usage bit set
3208 fb_info.attachmentCount = 1;
3209 fb_info.renderPass = rp_ds;
3210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003212 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3213
3214 m_errorMonitor->VerifyFound();
3215 if (err == VK_SUCCESS) {
3216 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3217 }
3218 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003219
3220 // Create new renderpass with alternate attachment format from fb
3221 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3222 subpass.pDepthStencilAttachment = NULL;
3223 subpass.pColorAttachments = &attach;
3224 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3225 ASSERT_VK_SUCCESS(err);
3226
3227 // Cause error due to mis-matched formats between rp & fb
3228 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3229 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3231 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003232 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3233
3234 m_errorMonitor->VerifyFound();
3235 if (err == VK_SUCCESS) {
3236 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3237 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003238 vkDestroyRenderPass(m_device->device(), rp, NULL);
3239
3240 // Create new renderpass with alternate sample count from fb
3241 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3242 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3243 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3244 ASSERT_VK_SUCCESS(err);
3245
3246 // Cause error due to mis-matched sample count between rp & fb
3247 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3249 "that do not match the "
3250 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003251 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3252
3253 m_errorMonitor->VerifyFound();
3254 if (err == VK_SUCCESS) {
3255 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3256 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003257
3258 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003259
3260 // Create a custom imageView with non-1 mip levels
3261 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003262 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 -06003263 ASSERT_TRUE(image.initialized());
3264
3265 VkImageView view;
3266 VkImageViewCreateInfo ivci = {};
3267 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3268 ivci.image = image.handle();
3269 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3270 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3271 ivci.subresourceRange.layerCount = 1;
3272 ivci.subresourceRange.baseMipLevel = 0;
3273 // Set level count 2 (only 1 is allowed for FB attachment)
3274 ivci.subresourceRange.levelCount = 2;
3275 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3276 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3277 ASSERT_VK_SUCCESS(err);
3278 // Re-create renderpass to have matching sample count
3279 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3280 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3281 ASSERT_VK_SUCCESS(err);
3282
3283 fb_info.renderPass = rp;
3284 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003286 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3287
3288 m_errorMonitor->VerifyFound();
3289 if (err == VK_SUCCESS) {
3290 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3291 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003292 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003293 // Update view to original color buffer and grow FB dimensions too big
3294 fb_info.pAttachments = ivs;
3295 fb_info.height = 1024;
3296 fb_info.width = 1024;
3297 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3299 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003300 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3301
3302 m_errorMonitor->VerifyFound();
3303 if (err == VK_SUCCESS) {
3304 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3305 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003306 // Create view attachment with non-identity swizzle
3307 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3308 ivci.image = image.handle();
3309 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3310 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3311 ivci.subresourceRange.layerCount = 1;
3312 ivci.subresourceRange.baseMipLevel = 0;
3313 ivci.subresourceRange.levelCount = 1;
3314 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3315 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3316 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3317 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3318 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3319 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3320 ASSERT_VK_SUCCESS(err);
3321
3322 fb_info.pAttachments = &view;
3323 fb_info.height = 100;
3324 fb_info.width = 100;
3325 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3327 "framebuffer attachments must have "
3328 "been created with the identity "
3329 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003330 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3331
3332 m_errorMonitor->VerifyFound();
3333 if (err == VK_SUCCESS) {
3334 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3335 }
3336 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003337 // Request fb that exceeds max dimensions
3338 // reset attachment to color attachment
3339 fb_info.pAttachments = ivs;
3340 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3341 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3342 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3344 "dimensions exceed physical device "
3345 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003346 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3347
3348 m_errorMonitor->VerifyFound();
3349 if (err == VK_SUCCESS) {
3350 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3351 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003352
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003353 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003354}
3355
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003356TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003357 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3358 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003359
Cody Northropc31a84f2016-08-22 10:41:47 -06003360 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003361 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3363 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003364 m_errorMonitor->VerifyFound();
3365}
3366
3367TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003368 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3369 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003370
Cody Northropc31a84f2016-08-22 10:41:47 -06003371 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003372 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3374 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003375 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003376}
3377
3378TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003379 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3380 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003381
Cody Northropc31a84f2016-08-22 10:41:47 -06003382 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003383 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003384 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 -06003385 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003386 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003387}
3388
3389TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003390 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3391 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003392
Cody Northropc31a84f2016-08-22 10:41:47 -06003393 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003394 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003395 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 -06003396 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003397 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003398}
3399
Cortd713fe82016-07-27 09:51:27 -07003400TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003401 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3402 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003403
3404 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003405 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3407 "Dynamic blend constants state not set for this command buffer");
3408 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003409 m_errorMonitor->VerifyFound();
3410}
3411
3412TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3414 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003415
3416 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003417 if (!m_device->phy().features().depthBounds) {
3418 printf("Device does not support depthBounds test; skipped.\n");
3419 return;
3420 }
3421 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3423 "Dynamic depth bounds state not set for this command buffer");
3424 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003425 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003426}
3427
3428TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003429 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3430 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003431
3432 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003433 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3435 "Dynamic stencil read mask state not set for this command buffer");
3436 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003437 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003438}
3439
3440TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003441 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3442 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003443
3444 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003445 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3447 "Dynamic stencil write mask state not set for this command buffer");
3448 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003449 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003450}
3451
3452TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003453 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3454 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003455
3456 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003457 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3459 "Dynamic stencil reference state not set for this command buffer");
3460 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003461 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003462}
3463
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003464TEST_F(VkLayerTest, IndexBufferNotBound) {
3465 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003466
3467 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3469 "Index buffer object not bound to this command buffer when Indexed ");
3470 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003471 m_errorMonitor->VerifyFound();
3472}
3473
Karl Schultz6addd812016-02-02 17:17:23 -07003474TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3476 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3477 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003478
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003479 ASSERT_NO_FATAL_FAILURE(InitState());
3480 ASSERT_NO_FATAL_FAILURE(InitViewport());
3481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3482
Karl Schultz6addd812016-02-02 17:17:23 -07003483 // We luck out b/c by default the framework creates CB w/ the
3484 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003485 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003486 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003487 EndCommandBuffer();
3488
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003489 // Bypass framework since it does the waits automatically
3490 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003491 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003492 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3493 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003494 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003495 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003496 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003497 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003498 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003499 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003500 submit_info.pSignalSemaphores = NULL;
3501
Chris Forbes40028e22016-06-13 09:59:34 +12003502 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003503 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003504 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003505
Karl Schultz6addd812016-02-02 17:17:23 -07003506 // Cause validation error by re-submitting cmd buffer that should only be
3507 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003508 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003509 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003510
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003511 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003512}
3513
Karl Schultz6addd812016-02-02 17:17:23 -07003514TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003515 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003516 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003517
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3519 "type "
3520 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003521
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003522 ASSERT_NO_FATAL_FAILURE(InitState());
3523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003524
Karl Schultz6addd812016-02-02 17:17:23 -07003525 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3526 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003527 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003528 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3529 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003530
3531 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003532 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3533 ds_pool_ci.pNext = NULL;
3534 ds_pool_ci.flags = 0;
3535 ds_pool_ci.maxSets = 1;
3536 ds_pool_ci.poolSizeCount = 1;
3537 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003538
3539 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003540 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003541 ASSERT_VK_SUCCESS(err);
3542
3543 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003544 dsl_binding.binding = 0;
3545 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3546 dsl_binding.descriptorCount = 1;
3547 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3548 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003549
3550 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003551 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3552 ds_layout_ci.pNext = NULL;
3553 ds_layout_ci.bindingCount = 1;
3554 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003555
3556 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003557 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003558 ASSERT_VK_SUCCESS(err);
3559
3560 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003561 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003562 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003563 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003564 alloc_info.descriptorPool = ds_pool;
3565 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003568 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003569
Chia-I Wuf7458c52015-10-26 21:10:41 +08003570 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3571 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003572}
3573
Karl Schultz6addd812016-02-02 17:17:23 -07003574TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3575 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003576
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3578 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3579 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003580
Tobin Ehlise735c692015-10-08 13:13:50 -06003581 ASSERT_NO_FATAL_FAILURE(InitState());
3582 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003583
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003584 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003585 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3586 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003587
3588 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003589 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3590 ds_pool_ci.pNext = NULL;
3591 ds_pool_ci.maxSets = 1;
3592 ds_pool_ci.poolSizeCount = 1;
3593 ds_pool_ci.flags = 0;
3594 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3595 // app can only call vkResetDescriptorPool on this pool.;
3596 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003597
3598 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003599 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003600 ASSERT_VK_SUCCESS(err);
3601
3602 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003603 dsl_binding.binding = 0;
3604 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3605 dsl_binding.descriptorCount = 1;
3606 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3607 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003608
3609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3611 ds_layout_ci.pNext = NULL;
3612 ds_layout_ci.bindingCount = 1;
3613 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003614
3615 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003617 ASSERT_VK_SUCCESS(err);
3618
3619 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003620 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003621 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003622 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003623 alloc_info.descriptorPool = ds_pool;
3624 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003625 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003626 ASSERT_VK_SUCCESS(err);
3627
3628 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003629 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003630
Chia-I Wuf7458c52015-10-26 21:10:41 +08003631 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3632 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003633}
3634
Karl Schultz6addd812016-02-02 17:17:23 -07003635TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003636 // Attempt to clear Descriptor Pool with bad object.
3637 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003638
3639 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003641 uint64_t fake_pool_handle = 0xbaad6001;
3642 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3643 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003644 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003645}
3646
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003647TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003648 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3649 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003650 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003651 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003652
3653 uint64_t fake_set_handle = 0xbaad6001;
3654 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003655 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003657
3658 ASSERT_NO_FATAL_FAILURE(InitState());
3659
3660 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3661 layout_bindings[0].binding = 0;
3662 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3663 layout_bindings[0].descriptorCount = 1;
3664 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3665 layout_bindings[0].pImmutableSamplers = NULL;
3666
3667 VkDescriptorSetLayout descriptor_set_layout;
3668 VkDescriptorSetLayoutCreateInfo dslci = {};
3669 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3670 dslci.pNext = NULL;
3671 dslci.bindingCount = 1;
3672 dslci.pBindings = layout_bindings;
3673 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003674 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003675
3676 VkPipelineLayout pipeline_layout;
3677 VkPipelineLayoutCreateInfo plci = {};
3678 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3679 plci.pNext = NULL;
3680 plci.setLayoutCount = 1;
3681 plci.pSetLayouts = &descriptor_set_layout;
3682 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003683 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003684
3685 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003686 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3687 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003688 m_errorMonitor->VerifyFound();
3689 EndCommandBuffer();
3690 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3691 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003692}
3693
Karl Schultz6addd812016-02-02 17:17:23 -07003694TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003695 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3696 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003697 uint64_t fake_layout_handle = 0xbaad6001;
3698 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003700 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003701 VkPipelineLayout pipeline_layout;
3702 VkPipelineLayoutCreateInfo plci = {};
3703 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3704 plci.pNext = NULL;
3705 plci.setLayoutCount = 1;
3706 plci.pSetLayouts = &bad_layout;
3707 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3708
3709 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003710}
3711
Mark Muellerd4914412016-06-13 17:52:06 -06003712TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3713 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3714 "1) A uniform buffer update must have a valid buffer index."
3715 "2) When using an array of descriptors in a single WriteDescriptor,"
3716 " the descriptor types and stageflags must all be the same."
3717 "3) Immutable Sampler state must match across descriptors");
3718
3719 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003720 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3721 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3722 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3723 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3724 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003725
Mark Muellerd4914412016-06-13 17:52:06 -06003726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3727
3728 ASSERT_NO_FATAL_FAILURE(InitState());
3729 VkDescriptorPoolSize ds_type_count[4] = {};
3730 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3731 ds_type_count[0].descriptorCount = 1;
3732 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3733 ds_type_count[1].descriptorCount = 1;
3734 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3735 ds_type_count[2].descriptorCount = 1;
3736 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3737 ds_type_count[3].descriptorCount = 1;
3738
3739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3741 ds_pool_ci.maxSets = 1;
3742 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3743 ds_pool_ci.pPoolSizes = ds_type_count;
3744
3745 VkDescriptorPool ds_pool;
3746 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3747 ASSERT_VK_SUCCESS(err);
3748
Mark Muellerb9896722016-06-16 09:54:29 -06003749 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003750 layout_binding[0].binding = 0;
3751 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3752 layout_binding[0].descriptorCount = 1;
3753 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3754 layout_binding[0].pImmutableSamplers = NULL;
3755
3756 layout_binding[1].binding = 1;
3757 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3758 layout_binding[1].descriptorCount = 1;
3759 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3760 layout_binding[1].pImmutableSamplers = NULL;
3761
3762 VkSamplerCreateInfo sampler_ci = {};
3763 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3764 sampler_ci.pNext = NULL;
3765 sampler_ci.magFilter = VK_FILTER_NEAREST;
3766 sampler_ci.minFilter = VK_FILTER_NEAREST;
3767 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3768 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3769 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3770 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3771 sampler_ci.mipLodBias = 1.0;
3772 sampler_ci.anisotropyEnable = VK_FALSE;
3773 sampler_ci.maxAnisotropy = 1;
3774 sampler_ci.compareEnable = VK_FALSE;
3775 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3776 sampler_ci.minLod = 1.0;
3777 sampler_ci.maxLod = 1.0;
3778 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3779 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3780 VkSampler sampler;
3781
3782 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3783 ASSERT_VK_SUCCESS(err);
3784
3785 layout_binding[2].binding = 2;
3786 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3787 layout_binding[2].descriptorCount = 1;
3788 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3789 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3790
Mark Muellerd4914412016-06-13 17:52:06 -06003791 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3792 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3793 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3794 ds_layout_ci.pBindings = layout_binding;
3795 VkDescriptorSetLayout ds_layout;
3796 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3797 ASSERT_VK_SUCCESS(err);
3798
3799 VkDescriptorSetAllocateInfo alloc_info = {};
3800 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3801 alloc_info.descriptorSetCount = 1;
3802 alloc_info.descriptorPool = ds_pool;
3803 alloc_info.pSetLayouts = &ds_layout;
3804 VkDescriptorSet descriptorSet;
3805 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3806 ASSERT_VK_SUCCESS(err);
3807
3808 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3809 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3810 pipeline_layout_ci.pNext = NULL;
3811 pipeline_layout_ci.setLayoutCount = 1;
3812 pipeline_layout_ci.pSetLayouts = &ds_layout;
3813
3814 VkPipelineLayout pipeline_layout;
3815 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3816 ASSERT_VK_SUCCESS(err);
3817
Mark Mueller5c838ce2016-06-16 09:54:29 -06003818 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003819 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3820 descriptor_write.dstSet = descriptorSet;
3821 descriptor_write.dstBinding = 0;
3822 descriptor_write.descriptorCount = 1;
3823 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3824
Mark Mueller5c838ce2016-06-16 09:54:29 -06003825 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003826 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3827 m_errorMonitor->VerifyFound();
3828
3829 // Create a buffer to update the descriptor with
3830 uint32_t qfi = 0;
3831 VkBufferCreateInfo buffCI = {};
3832 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3833 buffCI.size = 1024;
3834 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3835 buffCI.queueFamilyIndexCount = 1;
3836 buffCI.pQueueFamilyIndices = &qfi;
3837
3838 VkBuffer dyub;
3839 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3840 ASSERT_VK_SUCCESS(err);
3841 VkDescriptorBufferInfo buffInfo = {};
3842 buffInfo.buffer = dyub;
3843 buffInfo.offset = 0;
3844 buffInfo.range = 1024;
3845
3846 descriptor_write.pBufferInfo = &buffInfo;
3847 descriptor_write.descriptorCount = 2;
3848
Mark Mueller5c838ce2016-06-16 09:54:29 -06003849 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3851 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3852 m_errorMonitor->VerifyFound();
3853
Mark Mueller5c838ce2016-06-16 09:54:29 -06003854 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3855 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003856 descriptor_write.dstBinding = 1;
3857 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003858
Mark Mueller5c838ce2016-06-16 09:54:29 -06003859 // Make pImageInfo index non-null to avoid complaints of it missing
3860 VkDescriptorImageInfo imageInfo = {};
3861 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3862 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3864 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3865 m_errorMonitor->VerifyFound();
3866
Mark Muellerd4914412016-06-13 17:52:06 -06003867 vkDestroyBuffer(m_device->device(), dyub, NULL);
3868 vkDestroySampler(m_device->device(), sampler, NULL);
3869 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3870 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3871 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3872}
3873
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003874TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3875 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3876 "due to a buffer dependency being destroyed.");
3877 ASSERT_NO_FATAL_FAILURE(InitState());
3878
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003879 VkBuffer buffer;
3880 VkDeviceMemory mem;
3881 VkMemoryRequirements mem_reqs;
3882
3883 VkBufferCreateInfo buf_info = {};
3884 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12003885 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003886 buf_info.size = 256;
3887 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3888 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
3889 ASSERT_VK_SUCCESS(err);
3890
3891 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
3892
3893 VkMemoryAllocateInfo alloc_info = {};
3894 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3895 alloc_info.allocationSize = 256;
3896 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003897 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 -06003898 if (!pass) {
3899 vkDestroyBuffer(m_device->device(), buffer, NULL);
3900 return;
3901 }
3902 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
3903 ASSERT_VK_SUCCESS(err);
3904
3905 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3906 ASSERT_VK_SUCCESS(err);
3907
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003908 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12003909 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003910 m_commandBuffer->EndCommandBuffer();
3911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003913 // Destroy buffer dependency prior to submit to cause ERROR
3914 vkDestroyBuffer(m_device->device(), buffer, NULL);
3915
3916 VkSubmitInfo submit_info = {};
3917 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3918 submit_info.commandBufferCount = 1;
3919 submit_info.pCommandBuffers = &m_commandBuffer->handle();
3920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3921
3922 m_errorMonitor->VerifyFound();
3923 vkFreeMemory(m_device->handle(), mem, NULL);
3924}
3925
Tobin Ehlisea413442016-09-28 10:23:59 -06003926TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
3927 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
3928
3929 ASSERT_NO_FATAL_FAILURE(InitState());
3930 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3931
3932 VkDescriptorPoolSize ds_type_count;
3933 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3934 ds_type_count.descriptorCount = 1;
3935
3936 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3937 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3938 ds_pool_ci.maxSets = 1;
3939 ds_pool_ci.poolSizeCount = 1;
3940 ds_pool_ci.pPoolSizes = &ds_type_count;
3941
3942 VkDescriptorPool ds_pool;
3943 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3944 ASSERT_VK_SUCCESS(err);
3945
3946 VkDescriptorSetLayoutBinding layout_binding;
3947 layout_binding.binding = 0;
3948 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3949 layout_binding.descriptorCount = 1;
3950 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3951 layout_binding.pImmutableSamplers = NULL;
3952
3953 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3954 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3955 ds_layout_ci.bindingCount = 1;
3956 ds_layout_ci.pBindings = &layout_binding;
3957 VkDescriptorSetLayout ds_layout;
3958 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3959 ASSERT_VK_SUCCESS(err);
3960
3961 VkDescriptorSetAllocateInfo alloc_info = {};
3962 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3963 alloc_info.descriptorSetCount = 1;
3964 alloc_info.descriptorPool = ds_pool;
3965 alloc_info.pSetLayouts = &ds_layout;
3966 VkDescriptorSet descriptor_set;
3967 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
3968 ASSERT_VK_SUCCESS(err);
3969
3970 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3971 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3972 pipeline_layout_ci.pNext = NULL;
3973 pipeline_layout_ci.setLayoutCount = 1;
3974 pipeline_layout_ci.pSetLayouts = &ds_layout;
3975
3976 VkPipelineLayout pipeline_layout;
3977 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3978 ASSERT_VK_SUCCESS(err);
3979
3980 VkBuffer buffer;
3981 uint32_t queue_family_index = 0;
3982 VkBufferCreateInfo buffer_create_info = {};
3983 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3984 buffer_create_info.size = 1024;
3985 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
3986 buffer_create_info.queueFamilyIndexCount = 1;
3987 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
3988
3989 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
3990 ASSERT_VK_SUCCESS(err);
3991
3992 VkMemoryRequirements memory_reqs;
3993 VkDeviceMemory buffer_memory;
3994
3995 VkMemoryAllocateInfo memory_info = {};
3996 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3997 memory_info.allocationSize = 0;
3998 memory_info.memoryTypeIndex = 0;
3999
4000 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4001 memory_info.allocationSize = memory_reqs.size;
4002 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4003 ASSERT_TRUE(pass);
4004
4005 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4006 ASSERT_VK_SUCCESS(err);
4007 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4008 ASSERT_VK_SUCCESS(err);
4009
4010 VkBufferView view;
4011 VkBufferViewCreateInfo bvci = {};
4012 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4013 bvci.buffer = buffer;
4014 bvci.format = VK_FORMAT_R8_UNORM;
4015 bvci.range = VK_WHOLE_SIZE;
4016
4017 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4018 ASSERT_VK_SUCCESS(err);
4019
4020 VkWriteDescriptorSet descriptor_write = {};
4021 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4022 descriptor_write.dstSet = descriptor_set;
4023 descriptor_write.dstBinding = 0;
4024 descriptor_write.descriptorCount = 1;
4025 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4026 descriptor_write.pTexelBufferView = &view;
4027
4028 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4029
4030 char const *vsSource = "#version 450\n"
4031 "\n"
4032 "out gl_PerVertex { \n"
4033 " vec4 gl_Position;\n"
4034 "};\n"
4035 "void main(){\n"
4036 " gl_Position = vec4(1);\n"
4037 "}\n";
4038 char const *fsSource = "#version 450\n"
4039 "\n"
4040 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4041 "layout(location=0) out vec4 x;\n"
4042 "void main(){\n"
4043 " x = imageLoad(s, 0);\n"
4044 "}\n";
4045 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4046 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4047 VkPipelineObj pipe(m_device);
4048 pipe.AddShader(&vs);
4049 pipe.AddShader(&fs);
4050 pipe.AddColorAttachment();
4051 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4052
4053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4055
4056 BeginCommandBuffer();
4057 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4058 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4059 VkRect2D scissor = {{0, 0}, {16, 16}};
4060 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4061 // Bind pipeline to cmd buffer
4062 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4063 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4064 &descriptor_set, 0, nullptr);
4065 Draw(1, 0, 0, 0);
4066 EndCommandBuffer();
4067
4068 // Delete BufferView in order to invalidate cmd buffer
4069 vkDestroyBufferView(m_device->device(), view, NULL);
4070 // Now attempt submit of cmd buffer
4071 VkSubmitInfo submit_info = {};
4072 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4073 submit_info.commandBufferCount = 1;
4074 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4075 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4076 m_errorMonitor->VerifyFound();
4077
4078 // Clean-up
4079 vkDestroyBuffer(m_device->device(), buffer, NULL);
4080 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4081 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4082 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4083 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4084}
4085
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004086TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4087 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4088 "due to an image dependency being destroyed.");
4089 ASSERT_NO_FATAL_FAILURE(InitState());
4090
4091 VkImage image;
4092 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4093 VkImageCreateInfo image_create_info = {};
4094 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4095 image_create_info.pNext = NULL;
4096 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4097 image_create_info.format = tex_format;
4098 image_create_info.extent.width = 32;
4099 image_create_info.extent.height = 32;
4100 image_create_info.extent.depth = 1;
4101 image_create_info.mipLevels = 1;
4102 image_create_info.arrayLayers = 1;
4103 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4104 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004105 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004106 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004107 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004108 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004109 // Have to bind memory to image before recording cmd in cmd buffer using it
4110 VkMemoryRequirements mem_reqs;
4111 VkDeviceMemory image_mem;
4112 bool pass;
4113 VkMemoryAllocateInfo mem_alloc = {};
4114 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4115 mem_alloc.pNext = NULL;
4116 mem_alloc.memoryTypeIndex = 0;
4117 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4118 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004119 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004120 ASSERT_TRUE(pass);
4121 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4122 ASSERT_VK_SUCCESS(err);
4123 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4124 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004125
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004126 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004127 VkClearColorValue ccv;
4128 ccv.float32[0] = 1.0f;
4129 ccv.float32[1] = 1.0f;
4130 ccv.float32[2] = 1.0f;
4131 ccv.float32[3] = 1.0f;
4132 VkImageSubresourceRange isr = {};
4133 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004134 isr.baseArrayLayer = 0;
4135 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004136 isr.layerCount = 1;
4137 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004138 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004139 m_commandBuffer->EndCommandBuffer();
4140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004142 // Destroy image dependency prior to submit to cause ERROR
4143 vkDestroyImage(m_device->device(), image, NULL);
4144
4145 VkSubmitInfo submit_info = {};
4146 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4147 submit_info.commandBufferCount = 1;
4148 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4149 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4150
4151 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004152 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004153}
4154
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004155TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4156 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4157 "due to a framebuffer image dependency being destroyed.");
4158 VkFormatProperties format_properties;
4159 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004160 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4161 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004162 return;
4163 }
4164
4165 ASSERT_NO_FATAL_FAILURE(InitState());
4166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4167
4168 VkImageCreateInfo image_ci = {};
4169 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4170 image_ci.pNext = NULL;
4171 image_ci.imageType = VK_IMAGE_TYPE_2D;
4172 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4173 image_ci.extent.width = 32;
4174 image_ci.extent.height = 32;
4175 image_ci.extent.depth = 1;
4176 image_ci.mipLevels = 1;
4177 image_ci.arrayLayers = 1;
4178 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4179 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004180 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004181 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4182 image_ci.flags = 0;
4183 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004184 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004185
4186 VkMemoryRequirements memory_reqs;
4187 VkDeviceMemory image_memory;
4188 bool pass;
4189 VkMemoryAllocateInfo memory_info = {};
4190 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4191 memory_info.pNext = NULL;
4192 memory_info.allocationSize = 0;
4193 memory_info.memoryTypeIndex = 0;
4194 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4195 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004196 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004197 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004198 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004199 ASSERT_VK_SUCCESS(err);
4200 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4201 ASSERT_VK_SUCCESS(err);
4202
4203 VkImageViewCreateInfo ivci = {
4204 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4205 nullptr,
4206 0,
4207 image,
4208 VK_IMAGE_VIEW_TYPE_2D,
4209 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004210 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004211 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4212 };
4213 VkImageView view;
4214 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4215 ASSERT_VK_SUCCESS(err);
4216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004217 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004218 VkFramebuffer fb;
4219 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4220 ASSERT_VK_SUCCESS(err);
4221
4222 // Just use default renderpass with our framebuffer
4223 m_renderPassBeginInfo.framebuffer = fb;
4224 // Create Null cmd buffer for submit
4225 BeginCommandBuffer();
4226 EndCommandBuffer();
4227 // Destroy image attached to framebuffer to invalidate cmd buffer
4228 vkDestroyImage(m_device->device(), image, NULL);
4229 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004231 QueueCommandBuffer(false);
4232 m_errorMonitor->VerifyFound();
4233
4234 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4235 vkDestroyImageView(m_device->device(), view, nullptr);
4236 vkFreeMemory(m_device->device(), image_memory, nullptr);
4237}
4238
Tobin Ehlisb329f992016-10-12 13:20:29 -06004239TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4240 TEST_DESCRIPTION("Delete in-use framebuffer.");
4241 VkFormatProperties format_properties;
4242 VkResult err = VK_SUCCESS;
4243 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4244
4245 ASSERT_NO_FATAL_FAILURE(InitState());
4246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4247
4248 VkImageObj image(m_device);
4249 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4250 ASSERT_TRUE(image.initialized());
4251 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4252
4253 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4254 VkFramebuffer fb;
4255 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4256 ASSERT_VK_SUCCESS(err);
4257
4258 // Just use default renderpass with our framebuffer
4259 m_renderPassBeginInfo.framebuffer = fb;
4260 // Create Null cmd buffer for submit
4261 BeginCommandBuffer();
4262 EndCommandBuffer();
4263 // Submit cmd buffer to put it in-flight
4264 VkSubmitInfo submit_info = {};
4265 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4266 submit_info.commandBufferCount = 1;
4267 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4268 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4269 // Destroy framebuffer while in-flight
4270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4271 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4272 m_errorMonitor->VerifyFound();
4273 // Wait for queue to complete so we can safely destroy everything
4274 vkQueueWaitIdle(m_device->m_queue);
4275 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4276}
4277
Tobin Ehlis88becd72016-09-21 14:33:41 -06004278TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4279 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4280 VkFormatProperties format_properties;
4281 VkResult err = VK_SUCCESS;
4282 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004283
4284 ASSERT_NO_FATAL_FAILURE(InitState());
4285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4286
4287 VkImageCreateInfo image_ci = {};
4288 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4289 image_ci.pNext = NULL;
4290 image_ci.imageType = VK_IMAGE_TYPE_2D;
4291 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4292 image_ci.extent.width = 256;
4293 image_ci.extent.height = 256;
4294 image_ci.extent.depth = 1;
4295 image_ci.mipLevels = 1;
4296 image_ci.arrayLayers = 1;
4297 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4298 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004299 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004300 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4301 image_ci.flags = 0;
4302 VkImage image;
4303 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4304
4305 VkMemoryRequirements memory_reqs;
4306 VkDeviceMemory image_memory;
4307 bool pass;
4308 VkMemoryAllocateInfo memory_info = {};
4309 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4310 memory_info.pNext = NULL;
4311 memory_info.allocationSize = 0;
4312 memory_info.memoryTypeIndex = 0;
4313 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4314 memory_info.allocationSize = memory_reqs.size;
4315 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4316 ASSERT_TRUE(pass);
4317 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4318 ASSERT_VK_SUCCESS(err);
4319 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4320 ASSERT_VK_SUCCESS(err);
4321
4322 VkImageViewCreateInfo ivci = {
4323 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4324 nullptr,
4325 0,
4326 image,
4327 VK_IMAGE_VIEW_TYPE_2D,
4328 VK_FORMAT_B8G8R8A8_UNORM,
4329 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4330 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4331 };
4332 VkImageView view;
4333 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4334 ASSERT_VK_SUCCESS(err);
4335
4336 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4337 VkFramebuffer fb;
4338 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4339 ASSERT_VK_SUCCESS(err);
4340
4341 // Just use default renderpass with our framebuffer
4342 m_renderPassBeginInfo.framebuffer = fb;
4343 // Create Null cmd buffer for submit
4344 BeginCommandBuffer();
4345 EndCommandBuffer();
4346 // Submit cmd buffer to put it (and attached imageView) in-flight
4347 VkSubmitInfo submit_info = {};
4348 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4349 submit_info.commandBufferCount = 1;
4350 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4351 // Submit cmd buffer to put framebuffer and children in-flight
4352 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4353 // Destroy image attached to framebuffer while in-flight
4354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4355 vkDestroyImage(m_device->device(), image, NULL);
4356 m_errorMonitor->VerifyFound();
4357 // Wait for queue to complete so we can safely destroy image and other objects
4358 vkQueueWaitIdle(m_device->m_queue);
4359 vkDestroyImage(m_device->device(), image, NULL);
4360 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4361 vkDestroyImageView(m_device->device(), view, nullptr);
4362 vkFreeMemory(m_device->device(), image_memory, nullptr);
4363}
4364
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004365TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4366 TEST_DESCRIPTION("Delete in-use renderPass.");
4367
4368 ASSERT_NO_FATAL_FAILURE(InitState());
4369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4370
4371 // Create simple renderpass
4372 VkAttachmentReference attach = {};
4373 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4374 VkSubpassDescription subpass = {};
4375 subpass.pColorAttachments = &attach;
4376 VkRenderPassCreateInfo rpci = {};
4377 rpci.subpassCount = 1;
4378 rpci.pSubpasses = &subpass;
4379 rpci.attachmentCount = 1;
4380 VkAttachmentDescription attach_desc = {};
4381 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4382 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4383 rpci.pAttachments = &attach_desc;
4384 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4385 VkRenderPass rp;
4386 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4387 ASSERT_VK_SUCCESS(err);
4388
4389 // Create a pipeline that uses the given renderpass
4390 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4391 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4392
4393 VkPipelineLayout pipeline_layout;
4394 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4395 ASSERT_VK_SUCCESS(err);
4396
4397 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4398 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4399 vp_state_ci.viewportCount = 1;
4400 VkViewport vp = {}; // Just need dummy vp to point to
4401 vp_state_ci.pViewports = &vp;
4402 vp_state_ci.scissorCount = 1;
4403 VkRect2D scissors = {}; // Dummy scissors to point to
4404 vp_state_ci.pScissors = &scissors;
4405
4406 VkPipelineShaderStageCreateInfo shaderStages[2];
4407 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4408
4409 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4410 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4411 // but add it to be able to run on more devices
4412 shaderStages[0] = vs.GetStageCreateInfo();
4413 shaderStages[1] = fs.GetStageCreateInfo();
4414
4415 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4416 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4417
4418 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4419 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4420 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4421
4422 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4423 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4424 rs_ci.rasterizerDiscardEnable = true;
4425 rs_ci.lineWidth = 1.0f;
4426
4427 VkPipelineColorBlendAttachmentState att = {};
4428 att.blendEnable = VK_FALSE;
4429 att.colorWriteMask = 0xf;
4430
4431 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4432 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4433 cb_ci.attachmentCount = 1;
4434 cb_ci.pAttachments = &att;
4435
4436 VkGraphicsPipelineCreateInfo gp_ci = {};
4437 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4438 gp_ci.stageCount = 2;
4439 gp_ci.pStages = shaderStages;
4440 gp_ci.pVertexInputState = &vi_ci;
4441 gp_ci.pInputAssemblyState = &ia_ci;
4442 gp_ci.pViewportState = &vp_state_ci;
4443 gp_ci.pRasterizationState = &rs_ci;
4444 gp_ci.pColorBlendState = &cb_ci;
4445 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4446 gp_ci.layout = pipeline_layout;
4447 gp_ci.renderPass = rp;
4448
4449 VkPipelineCacheCreateInfo pc_ci = {};
4450 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4451
4452 VkPipeline pipeline;
4453 VkPipelineCache pipe_cache;
4454 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4455 ASSERT_VK_SUCCESS(err);
4456
4457 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4458 ASSERT_VK_SUCCESS(err);
4459 // Bind pipeline to cmd buffer, will also bind renderpass
4460 m_commandBuffer->BeginCommandBuffer();
4461 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4462 m_commandBuffer->EndCommandBuffer();
4463
4464 VkSubmitInfo submit_info = {};
4465 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4466 submit_info.commandBufferCount = 1;
4467 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4468 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4469
4470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4471 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4472 m_errorMonitor->VerifyFound();
4473
4474 // Wait for queue to complete so we can safely destroy everything
4475 vkQueueWaitIdle(m_device->m_queue);
4476 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4477 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4478 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4479 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4480}
4481
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004482TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004483 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004484 ASSERT_NO_FATAL_FAILURE(InitState());
4485
4486 VkImage image;
4487 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4488 VkImageCreateInfo image_create_info = {};
4489 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4490 image_create_info.pNext = NULL;
4491 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4492 image_create_info.format = tex_format;
4493 image_create_info.extent.width = 32;
4494 image_create_info.extent.height = 32;
4495 image_create_info.extent.depth = 1;
4496 image_create_info.mipLevels = 1;
4497 image_create_info.arrayLayers = 1;
4498 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4499 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004500 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004501 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004502 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004503 ASSERT_VK_SUCCESS(err);
4504 // Have to bind memory to image before recording cmd in cmd buffer using it
4505 VkMemoryRequirements mem_reqs;
4506 VkDeviceMemory image_mem;
4507 bool pass;
4508 VkMemoryAllocateInfo mem_alloc = {};
4509 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4510 mem_alloc.pNext = NULL;
4511 mem_alloc.memoryTypeIndex = 0;
4512 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4513 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004514 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004515 ASSERT_TRUE(pass);
4516 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4517 ASSERT_VK_SUCCESS(err);
4518
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004519 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004521 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004522
4523 m_commandBuffer->BeginCommandBuffer();
4524 VkClearColorValue ccv;
4525 ccv.float32[0] = 1.0f;
4526 ccv.float32[1] = 1.0f;
4527 ccv.float32[2] = 1.0f;
4528 ccv.float32[3] = 1.0f;
4529 VkImageSubresourceRange isr = {};
4530 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4531 isr.baseArrayLayer = 0;
4532 isr.baseMipLevel = 0;
4533 isr.layerCount = 1;
4534 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004535 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004536 m_commandBuffer->EndCommandBuffer();
4537
4538 m_errorMonitor->VerifyFound();
4539 vkDestroyImage(m_device->device(), image, NULL);
4540 vkFreeMemory(m_device->device(), image_mem, nullptr);
4541}
4542
4543TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004544 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004545 ASSERT_NO_FATAL_FAILURE(InitState());
4546
4547 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004548 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 -06004549 VK_IMAGE_TILING_OPTIMAL, 0);
4550 ASSERT_TRUE(image.initialized());
4551
4552 VkBuffer buffer;
4553 VkDeviceMemory mem;
4554 VkMemoryRequirements mem_reqs;
4555
4556 VkBufferCreateInfo buf_info = {};
4557 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004558 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004559 buf_info.size = 256;
4560 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4561 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4562 ASSERT_VK_SUCCESS(err);
4563
4564 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4565
4566 VkMemoryAllocateInfo alloc_info = {};
4567 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4568 alloc_info.allocationSize = 256;
4569 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004570 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 -06004571 if (!pass) {
4572 vkDestroyBuffer(m_device->device(), buffer, NULL);
4573 return;
4574 }
4575 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4576 ASSERT_VK_SUCCESS(err);
4577
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004578 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004580 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004581 VkBufferImageCopy region = {};
4582 region.bufferRowLength = 128;
4583 region.bufferImageHeight = 128;
4584 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4585
4586 region.imageSubresource.layerCount = 1;
4587 region.imageExtent.height = 4;
4588 region.imageExtent.width = 4;
4589 region.imageExtent.depth = 1;
4590 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004591 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4592 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004593 m_commandBuffer->EndCommandBuffer();
4594
4595 m_errorMonitor->VerifyFound();
4596
4597 vkDestroyBuffer(m_device->device(), buffer, NULL);
4598 vkFreeMemory(m_device->handle(), mem, NULL);
4599}
4600
Tobin Ehlis85940f52016-07-07 16:57:21 -06004601TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4602 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4603 "due to an event dependency being destroyed.");
4604 ASSERT_NO_FATAL_FAILURE(InitState());
4605
4606 VkEvent event;
4607 VkEventCreateInfo evci = {};
4608 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4609 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4610 ASSERT_VK_SUCCESS(result);
4611
4612 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004613 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004614 m_commandBuffer->EndCommandBuffer();
4615
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004617 // Destroy event dependency prior to submit to cause ERROR
4618 vkDestroyEvent(m_device->device(), event, NULL);
4619
4620 VkSubmitInfo submit_info = {};
4621 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4622 submit_info.commandBufferCount = 1;
4623 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4625
4626 m_errorMonitor->VerifyFound();
4627}
4628
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004629TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4630 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4631 "due to a query pool dependency being destroyed.");
4632 ASSERT_NO_FATAL_FAILURE(InitState());
4633
4634 VkQueryPool query_pool;
4635 VkQueryPoolCreateInfo qpci{};
4636 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4637 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4638 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004639 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004640 ASSERT_VK_SUCCESS(result);
4641
4642 m_commandBuffer->BeginCommandBuffer();
4643 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4644 m_commandBuffer->EndCommandBuffer();
4645
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004647 // Destroy query pool dependency prior to submit to cause ERROR
4648 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4649
4650 VkSubmitInfo submit_info = {};
4651 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4652 submit_info.commandBufferCount = 1;
4653 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4654 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4655
4656 m_errorMonitor->VerifyFound();
4657}
4658
Tobin Ehlis24130d92016-07-08 15:50:53 -06004659TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4660 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4661 "due to a pipeline dependency being destroyed.");
4662 ASSERT_NO_FATAL_FAILURE(InitState());
4663 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4664
4665 VkResult err;
4666
4667 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4668 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4669
4670 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004671 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004672 ASSERT_VK_SUCCESS(err);
4673
4674 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4675 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4676 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004677 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004678 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004679 vp_state_ci.scissorCount = 1;
4680 VkRect2D scissors = {}; // Dummy scissors to point to
4681 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004682
4683 VkPipelineShaderStageCreateInfo shaderStages[2];
4684 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4685
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004686 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4687 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4688 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004689 shaderStages[0] = vs.GetStageCreateInfo();
4690 shaderStages[1] = fs.GetStageCreateInfo();
4691
4692 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4693 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4694
4695 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4696 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4697 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4698
4699 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4700 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004701 rs_ci.rasterizerDiscardEnable = true;
4702 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004703
4704 VkPipelineColorBlendAttachmentState att = {};
4705 att.blendEnable = VK_FALSE;
4706 att.colorWriteMask = 0xf;
4707
4708 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4709 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4710 cb_ci.attachmentCount = 1;
4711 cb_ci.pAttachments = &att;
4712
4713 VkGraphicsPipelineCreateInfo gp_ci = {};
4714 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4715 gp_ci.stageCount = 2;
4716 gp_ci.pStages = shaderStages;
4717 gp_ci.pVertexInputState = &vi_ci;
4718 gp_ci.pInputAssemblyState = &ia_ci;
4719 gp_ci.pViewportState = &vp_state_ci;
4720 gp_ci.pRasterizationState = &rs_ci;
4721 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004722 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4723 gp_ci.layout = pipeline_layout;
4724 gp_ci.renderPass = renderPass();
4725
4726 VkPipelineCacheCreateInfo pc_ci = {};
4727 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4728
4729 VkPipeline pipeline;
4730 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004731 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004732 ASSERT_VK_SUCCESS(err);
4733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004734 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004735 ASSERT_VK_SUCCESS(err);
4736
4737 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004738 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004739 m_commandBuffer->EndCommandBuffer();
4740 // Now destroy pipeline in order to cause error when submitting
4741 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4742
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004744
4745 VkSubmitInfo submit_info = {};
4746 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4747 submit_info.commandBufferCount = 1;
4748 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4749 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4750
4751 m_errorMonitor->VerifyFound();
4752 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4753 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4754}
4755
Tobin Ehlis31289162016-08-17 14:57:58 -06004756TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4757 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4758 "due to a bound descriptor set with a buffer dependency "
4759 "being destroyed.");
4760 ASSERT_NO_FATAL_FAILURE(InitState());
4761 ASSERT_NO_FATAL_FAILURE(InitViewport());
4762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4763
4764 VkDescriptorPoolSize ds_type_count = {};
4765 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4766 ds_type_count.descriptorCount = 1;
4767
4768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4770 ds_pool_ci.pNext = NULL;
4771 ds_pool_ci.maxSets = 1;
4772 ds_pool_ci.poolSizeCount = 1;
4773 ds_pool_ci.pPoolSizes = &ds_type_count;
4774
4775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004776 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004777 ASSERT_VK_SUCCESS(err);
4778
4779 VkDescriptorSetLayoutBinding dsl_binding = {};
4780 dsl_binding.binding = 0;
4781 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4782 dsl_binding.descriptorCount = 1;
4783 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4784 dsl_binding.pImmutableSamplers = NULL;
4785
4786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4788 ds_layout_ci.pNext = NULL;
4789 ds_layout_ci.bindingCount = 1;
4790 ds_layout_ci.pBindings = &dsl_binding;
4791 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004792 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004793 ASSERT_VK_SUCCESS(err);
4794
4795 VkDescriptorSet descriptorSet;
4796 VkDescriptorSetAllocateInfo alloc_info = {};
4797 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4798 alloc_info.descriptorSetCount = 1;
4799 alloc_info.descriptorPool = ds_pool;
4800 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004801 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004802 ASSERT_VK_SUCCESS(err);
4803
4804 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4805 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4806 pipeline_layout_ci.pNext = NULL;
4807 pipeline_layout_ci.setLayoutCount = 1;
4808 pipeline_layout_ci.pSetLayouts = &ds_layout;
4809
4810 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004811 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004812 ASSERT_VK_SUCCESS(err);
4813
4814 // Create a buffer to update the descriptor with
4815 uint32_t qfi = 0;
4816 VkBufferCreateInfo buffCI = {};
4817 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4818 buffCI.size = 1024;
4819 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4820 buffCI.queueFamilyIndexCount = 1;
4821 buffCI.pQueueFamilyIndices = &qfi;
4822
4823 VkBuffer buffer;
4824 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4825 ASSERT_VK_SUCCESS(err);
4826 // Allocate memory and bind to buffer so we can make it to the appropriate
4827 // error
4828 VkMemoryAllocateInfo mem_alloc = {};
4829 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4830 mem_alloc.pNext = NULL;
4831 mem_alloc.allocationSize = 1024;
4832 mem_alloc.memoryTypeIndex = 0;
4833
4834 VkMemoryRequirements memReqs;
4835 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004836 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004837 if (!pass) {
4838 vkDestroyBuffer(m_device->device(), buffer, NULL);
4839 return;
4840 }
4841
4842 VkDeviceMemory mem;
4843 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4844 ASSERT_VK_SUCCESS(err);
4845 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4846 ASSERT_VK_SUCCESS(err);
4847 // Correctly update descriptor to avoid "NOT_UPDATED" error
4848 VkDescriptorBufferInfo buffInfo = {};
4849 buffInfo.buffer = buffer;
4850 buffInfo.offset = 0;
4851 buffInfo.range = 1024;
4852
4853 VkWriteDescriptorSet descriptor_write;
4854 memset(&descriptor_write, 0, sizeof(descriptor_write));
4855 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4856 descriptor_write.dstSet = descriptorSet;
4857 descriptor_write.dstBinding = 0;
4858 descriptor_write.descriptorCount = 1;
4859 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4860 descriptor_write.pBufferInfo = &buffInfo;
4861
4862 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4863
4864 // Create PSO to be used for draw-time errors below
4865 char const *vsSource = "#version 450\n"
4866 "\n"
4867 "out gl_PerVertex { \n"
4868 " vec4 gl_Position;\n"
4869 "};\n"
4870 "void main(){\n"
4871 " gl_Position = vec4(1);\n"
4872 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004873 char const *fsSource = "#version 450\n"
4874 "\n"
4875 "layout(location=0) out vec4 x;\n"
4876 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4877 "void main(){\n"
4878 " x = vec4(bar.y);\n"
4879 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004880 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4881 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4882 VkPipelineObj pipe(m_device);
4883 pipe.AddShader(&vs);
4884 pipe.AddShader(&fs);
4885 pipe.AddColorAttachment();
4886 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4887
4888 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004889 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4890 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4891 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06004892 Draw(1, 0, 0, 0);
4893 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06004895 // Destroy buffer should invalidate the cmd buffer, causing error on submit
4896 vkDestroyBuffer(m_device->device(), buffer, NULL);
4897 // Attempt to submit cmd buffer
4898 VkSubmitInfo submit_info = {};
4899 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4900 submit_info.commandBufferCount = 1;
4901 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4902 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4903 m_errorMonitor->VerifyFound();
4904 // Cleanup
4905 vkFreeMemory(m_device->device(), mem, NULL);
4906
4907 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4908 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4909 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4910}
4911
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004912TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
4913 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4914 "due to a bound descriptor sets with a combined image "
4915 "sampler having their image, sampler, and descriptor set "
4916 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06004917 "submit associated cmd buffers. Attempt to destroy a "
4918 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004919 ASSERT_NO_FATAL_FAILURE(InitState());
4920 ASSERT_NO_FATAL_FAILURE(InitViewport());
4921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4922
4923 VkDescriptorPoolSize ds_type_count = {};
4924 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4925 ds_type_count.descriptorCount = 1;
4926
4927 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4928 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4929 ds_pool_ci.pNext = NULL;
4930 ds_pool_ci.maxSets = 1;
4931 ds_pool_ci.poolSizeCount = 1;
4932 ds_pool_ci.pPoolSizes = &ds_type_count;
4933
4934 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004935 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004936 ASSERT_VK_SUCCESS(err);
4937
4938 VkDescriptorSetLayoutBinding dsl_binding = {};
4939 dsl_binding.binding = 0;
4940 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4941 dsl_binding.descriptorCount = 1;
4942 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4943 dsl_binding.pImmutableSamplers = NULL;
4944
4945 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4946 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4947 ds_layout_ci.pNext = NULL;
4948 ds_layout_ci.bindingCount = 1;
4949 ds_layout_ci.pBindings = &dsl_binding;
4950 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004951 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004952 ASSERT_VK_SUCCESS(err);
4953
4954 VkDescriptorSet descriptorSet;
4955 VkDescriptorSetAllocateInfo alloc_info = {};
4956 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4957 alloc_info.descriptorSetCount = 1;
4958 alloc_info.descriptorPool = ds_pool;
4959 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004960 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004961 ASSERT_VK_SUCCESS(err);
4962
4963 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4964 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4965 pipeline_layout_ci.pNext = NULL;
4966 pipeline_layout_ci.setLayoutCount = 1;
4967 pipeline_layout_ci.pSetLayouts = &ds_layout;
4968
4969 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004970 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004971 ASSERT_VK_SUCCESS(err);
4972
4973 // Create images to update the descriptor with
4974 VkImage image;
4975 VkImage image2;
4976 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4977 const int32_t tex_width = 32;
4978 const int32_t tex_height = 32;
4979 VkImageCreateInfo image_create_info = {};
4980 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4981 image_create_info.pNext = NULL;
4982 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4983 image_create_info.format = tex_format;
4984 image_create_info.extent.width = tex_width;
4985 image_create_info.extent.height = tex_height;
4986 image_create_info.extent.depth = 1;
4987 image_create_info.mipLevels = 1;
4988 image_create_info.arrayLayers = 1;
4989 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4990 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
4991 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4992 image_create_info.flags = 0;
4993 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
4994 ASSERT_VK_SUCCESS(err);
4995 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
4996 ASSERT_VK_SUCCESS(err);
4997
4998 VkMemoryRequirements memory_reqs;
4999 VkDeviceMemory image_memory;
5000 bool pass;
5001 VkMemoryAllocateInfo memory_info = {};
5002 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5003 memory_info.pNext = NULL;
5004 memory_info.allocationSize = 0;
5005 memory_info.memoryTypeIndex = 0;
5006 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5007 // Allocate enough memory for both images
5008 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005009 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005010 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005011 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005012 ASSERT_VK_SUCCESS(err);
5013 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5014 ASSERT_VK_SUCCESS(err);
5015 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005016 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005017 ASSERT_VK_SUCCESS(err);
5018
5019 VkImageViewCreateInfo image_view_create_info = {};
5020 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5021 image_view_create_info.image = image;
5022 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5023 image_view_create_info.format = tex_format;
5024 image_view_create_info.subresourceRange.layerCount = 1;
5025 image_view_create_info.subresourceRange.baseMipLevel = 0;
5026 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005027 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005028
5029 VkImageView view;
5030 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005031 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005032 ASSERT_VK_SUCCESS(err);
5033 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005034 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005035 ASSERT_VK_SUCCESS(err);
5036 // Create Samplers
5037 VkSamplerCreateInfo sampler_ci = {};
5038 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5039 sampler_ci.pNext = NULL;
5040 sampler_ci.magFilter = VK_FILTER_NEAREST;
5041 sampler_ci.minFilter = VK_FILTER_NEAREST;
5042 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5043 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5044 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5045 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5046 sampler_ci.mipLodBias = 1.0;
5047 sampler_ci.anisotropyEnable = VK_FALSE;
5048 sampler_ci.maxAnisotropy = 1;
5049 sampler_ci.compareEnable = VK_FALSE;
5050 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5051 sampler_ci.minLod = 1.0;
5052 sampler_ci.maxLod = 1.0;
5053 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5054 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5055 VkSampler sampler;
5056 VkSampler sampler2;
5057 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5058 ASSERT_VK_SUCCESS(err);
5059 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5060 ASSERT_VK_SUCCESS(err);
5061 // Update descriptor with image and sampler
5062 VkDescriptorImageInfo img_info = {};
5063 img_info.sampler = sampler;
5064 img_info.imageView = view;
5065 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5066
5067 VkWriteDescriptorSet descriptor_write;
5068 memset(&descriptor_write, 0, sizeof(descriptor_write));
5069 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5070 descriptor_write.dstSet = descriptorSet;
5071 descriptor_write.dstBinding = 0;
5072 descriptor_write.descriptorCount = 1;
5073 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5074 descriptor_write.pImageInfo = &img_info;
5075
5076 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5077
5078 // Create PSO to be used for draw-time errors below
5079 char const *vsSource = "#version 450\n"
5080 "\n"
5081 "out gl_PerVertex { \n"
5082 " vec4 gl_Position;\n"
5083 "};\n"
5084 "void main(){\n"
5085 " gl_Position = vec4(1);\n"
5086 "}\n";
5087 char const *fsSource = "#version 450\n"
5088 "\n"
5089 "layout(set=0, binding=0) uniform sampler2D s;\n"
5090 "layout(location=0) out vec4 x;\n"
5091 "void main(){\n"
5092 " x = texture(s, vec2(1));\n"
5093 "}\n";
5094 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5095 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5096 VkPipelineObj pipe(m_device);
5097 pipe.AddShader(&vs);
5098 pipe.AddShader(&fs);
5099 pipe.AddColorAttachment();
5100 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5101
5102 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005104 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005105 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5106 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5107 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005108 Draw(1, 0, 0, 0);
5109 EndCommandBuffer();
5110 // Destroy sampler invalidates the cmd buffer, causing error on submit
5111 vkDestroySampler(m_device->device(), sampler, NULL);
5112 // Attempt to submit cmd buffer
5113 VkSubmitInfo submit_info = {};
5114 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5115 submit_info.commandBufferCount = 1;
5116 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5117 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5118 m_errorMonitor->VerifyFound();
5119 // Now re-update descriptor with valid sampler and delete image
5120 img_info.sampler = sampler2;
5121 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005123 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005124 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5125 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5126 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005127 Draw(1, 0, 0, 0);
5128 EndCommandBuffer();
5129 // Destroy image invalidates the cmd buffer, causing error on submit
5130 vkDestroyImage(m_device->device(), image, NULL);
5131 // Attempt to submit cmd buffer
5132 submit_info = {};
5133 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5134 submit_info.commandBufferCount = 1;
5135 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5136 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5137 m_errorMonitor->VerifyFound();
5138 // Now update descriptor to be valid, but then free descriptor
5139 img_info.imageView = view2;
5140 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005142 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005143 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5144 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5145 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005146 Draw(1, 0, 0, 0);
5147 EndCommandBuffer();
5148 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005150 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005151 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005152 // Attempt to submit cmd buffer
5153 submit_info = {};
5154 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5155 submit_info.commandBufferCount = 1;
5156 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5157 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5158 m_errorMonitor->VerifyFound();
5159 // Cleanup
5160 vkFreeMemory(m_device->device(), image_memory, NULL);
5161 vkDestroySampler(m_device->device(), sampler2, NULL);
5162 vkDestroyImage(m_device->device(), image2, NULL);
5163 vkDestroyImageView(m_device->device(), view, NULL);
5164 vkDestroyImageView(m_device->device(), view2, NULL);
5165 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5166 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5167 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5168}
5169
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005170TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5171 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5172 ASSERT_NO_FATAL_FAILURE(InitState());
5173 ASSERT_NO_FATAL_FAILURE(InitViewport());
5174 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5175
5176 VkDescriptorPoolSize ds_type_count = {};
5177 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5178 ds_type_count.descriptorCount = 1;
5179
5180 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5181 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5182 ds_pool_ci.pNext = NULL;
5183 ds_pool_ci.maxSets = 1;
5184 ds_pool_ci.poolSizeCount = 1;
5185 ds_pool_ci.pPoolSizes = &ds_type_count;
5186
5187 VkDescriptorPool ds_pool;
5188 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5189 ASSERT_VK_SUCCESS(err);
5190
5191 VkDescriptorSetLayoutBinding dsl_binding = {};
5192 dsl_binding.binding = 0;
5193 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5194 dsl_binding.descriptorCount = 1;
5195 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5196 dsl_binding.pImmutableSamplers = NULL;
5197
5198 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5199 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5200 ds_layout_ci.pNext = NULL;
5201 ds_layout_ci.bindingCount = 1;
5202 ds_layout_ci.pBindings = &dsl_binding;
5203 VkDescriptorSetLayout ds_layout;
5204 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5205 ASSERT_VK_SUCCESS(err);
5206
5207 VkDescriptorSet descriptor_set;
5208 VkDescriptorSetAllocateInfo alloc_info = {};
5209 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5210 alloc_info.descriptorSetCount = 1;
5211 alloc_info.descriptorPool = ds_pool;
5212 alloc_info.pSetLayouts = &ds_layout;
5213 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5214 ASSERT_VK_SUCCESS(err);
5215
5216 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5217 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5218 pipeline_layout_ci.pNext = NULL;
5219 pipeline_layout_ci.setLayoutCount = 1;
5220 pipeline_layout_ci.pSetLayouts = &ds_layout;
5221
5222 VkPipelineLayout pipeline_layout;
5223 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5224 ASSERT_VK_SUCCESS(err);
5225
5226 // Create image to update the descriptor with
5227 VkImageObj image(m_device);
5228 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5229 ASSERT_TRUE(image.initialized());
5230
5231 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5232 // Create Sampler
5233 VkSamplerCreateInfo sampler_ci = {};
5234 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5235 sampler_ci.pNext = NULL;
5236 sampler_ci.magFilter = VK_FILTER_NEAREST;
5237 sampler_ci.minFilter = VK_FILTER_NEAREST;
5238 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5239 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5240 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5241 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5242 sampler_ci.mipLodBias = 1.0;
5243 sampler_ci.anisotropyEnable = VK_FALSE;
5244 sampler_ci.maxAnisotropy = 1;
5245 sampler_ci.compareEnable = VK_FALSE;
5246 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5247 sampler_ci.minLod = 1.0;
5248 sampler_ci.maxLod = 1.0;
5249 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5250 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5251 VkSampler sampler;
5252 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5253 ASSERT_VK_SUCCESS(err);
5254 // Update descriptor with image and sampler
5255 VkDescriptorImageInfo img_info = {};
5256 img_info.sampler = sampler;
5257 img_info.imageView = view;
5258 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5259
5260 VkWriteDescriptorSet descriptor_write;
5261 memset(&descriptor_write, 0, sizeof(descriptor_write));
5262 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5263 descriptor_write.dstSet = descriptor_set;
5264 descriptor_write.dstBinding = 0;
5265 descriptor_write.descriptorCount = 1;
5266 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5267 descriptor_write.pImageInfo = &img_info;
5268
5269 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5270
5271 // Create PSO to be used for draw-time errors below
5272 char const *vsSource = "#version 450\n"
5273 "\n"
5274 "out gl_PerVertex { \n"
5275 " vec4 gl_Position;\n"
5276 "};\n"
5277 "void main(){\n"
5278 " gl_Position = vec4(1);\n"
5279 "}\n";
5280 char const *fsSource = "#version 450\n"
5281 "\n"
5282 "layout(set=0, binding=0) uniform sampler2D s;\n"
5283 "layout(location=0) out vec4 x;\n"
5284 "void main(){\n"
5285 " x = texture(s, vec2(1));\n"
5286 "}\n";
5287 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5288 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5289 VkPipelineObj pipe(m_device);
5290 pipe.AddShader(&vs);
5291 pipe.AddShader(&fs);
5292 pipe.AddColorAttachment();
5293 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5294
5295 BeginCommandBuffer();
5296 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5297 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5298 &descriptor_set, 0, NULL);
5299 Draw(1, 0, 0, 0);
5300 EndCommandBuffer();
5301 // Submit cmd buffer to put pool in-flight
5302 VkSubmitInfo submit_info = {};
5303 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5304 submit_info.commandBufferCount = 1;
5305 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5306 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5307 // Destroy pool while in-flight, causing error
5308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5309 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5310 m_errorMonitor->VerifyFound();
5311 vkQueueWaitIdle(m_device->m_queue);
5312 // Cleanup
5313 vkDestroySampler(m_device->device(), sampler, NULL);
5314 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5315 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5316 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5317}
5318
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005319TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5320 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5321 ASSERT_NO_FATAL_FAILURE(InitState());
5322 ASSERT_NO_FATAL_FAILURE(InitViewport());
5323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5324
5325 VkDescriptorPoolSize ds_type_count = {};
5326 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5327 ds_type_count.descriptorCount = 1;
5328
5329 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5330 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5331 ds_pool_ci.pNext = NULL;
5332 ds_pool_ci.maxSets = 1;
5333 ds_pool_ci.poolSizeCount = 1;
5334 ds_pool_ci.pPoolSizes = &ds_type_count;
5335
5336 VkDescriptorPool ds_pool;
5337 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5338 ASSERT_VK_SUCCESS(err);
5339
5340 VkDescriptorSetLayoutBinding dsl_binding = {};
5341 dsl_binding.binding = 0;
5342 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5343 dsl_binding.descriptorCount = 1;
5344 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5345 dsl_binding.pImmutableSamplers = NULL;
5346
5347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5349 ds_layout_ci.pNext = NULL;
5350 ds_layout_ci.bindingCount = 1;
5351 ds_layout_ci.pBindings = &dsl_binding;
5352 VkDescriptorSetLayout ds_layout;
5353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5354 ASSERT_VK_SUCCESS(err);
5355
5356 VkDescriptorSet descriptorSet;
5357 VkDescriptorSetAllocateInfo alloc_info = {};
5358 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5359 alloc_info.descriptorSetCount = 1;
5360 alloc_info.descriptorPool = ds_pool;
5361 alloc_info.pSetLayouts = &ds_layout;
5362 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5363 ASSERT_VK_SUCCESS(err);
5364
5365 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5366 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5367 pipeline_layout_ci.pNext = NULL;
5368 pipeline_layout_ci.setLayoutCount = 1;
5369 pipeline_layout_ci.pSetLayouts = &ds_layout;
5370
5371 VkPipelineLayout pipeline_layout;
5372 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5373 ASSERT_VK_SUCCESS(err);
5374
5375 // Create images to update the descriptor with
5376 VkImage image;
5377 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5378 const int32_t tex_width = 32;
5379 const int32_t tex_height = 32;
5380 VkImageCreateInfo image_create_info = {};
5381 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5382 image_create_info.pNext = NULL;
5383 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5384 image_create_info.format = tex_format;
5385 image_create_info.extent.width = tex_width;
5386 image_create_info.extent.height = tex_height;
5387 image_create_info.extent.depth = 1;
5388 image_create_info.mipLevels = 1;
5389 image_create_info.arrayLayers = 1;
5390 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5391 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5392 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5393 image_create_info.flags = 0;
5394 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5395 ASSERT_VK_SUCCESS(err);
5396 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5397 VkMemoryRequirements memory_reqs;
5398 VkDeviceMemory image_memory;
5399 bool pass;
5400 VkMemoryAllocateInfo memory_info = {};
5401 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5402 memory_info.pNext = NULL;
5403 memory_info.allocationSize = 0;
5404 memory_info.memoryTypeIndex = 0;
5405 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5406 // Allocate enough memory for image
5407 memory_info.allocationSize = memory_reqs.size;
5408 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5409 ASSERT_TRUE(pass);
5410 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5411 ASSERT_VK_SUCCESS(err);
5412 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5413 ASSERT_VK_SUCCESS(err);
5414
5415 VkImageViewCreateInfo image_view_create_info = {};
5416 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5417 image_view_create_info.image = image;
5418 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5419 image_view_create_info.format = tex_format;
5420 image_view_create_info.subresourceRange.layerCount = 1;
5421 image_view_create_info.subresourceRange.baseMipLevel = 0;
5422 image_view_create_info.subresourceRange.levelCount = 1;
5423 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5424
5425 VkImageView view;
5426 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5427 ASSERT_VK_SUCCESS(err);
5428 // Create Samplers
5429 VkSamplerCreateInfo sampler_ci = {};
5430 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5431 sampler_ci.pNext = NULL;
5432 sampler_ci.magFilter = VK_FILTER_NEAREST;
5433 sampler_ci.minFilter = VK_FILTER_NEAREST;
5434 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5435 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5436 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5437 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5438 sampler_ci.mipLodBias = 1.0;
5439 sampler_ci.anisotropyEnable = VK_FALSE;
5440 sampler_ci.maxAnisotropy = 1;
5441 sampler_ci.compareEnable = VK_FALSE;
5442 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5443 sampler_ci.minLod = 1.0;
5444 sampler_ci.maxLod = 1.0;
5445 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5446 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5447 VkSampler sampler;
5448 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5449 ASSERT_VK_SUCCESS(err);
5450 // Update descriptor with image and sampler
5451 VkDescriptorImageInfo img_info = {};
5452 img_info.sampler = sampler;
5453 img_info.imageView = view;
5454 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5455
5456 VkWriteDescriptorSet descriptor_write;
5457 memset(&descriptor_write, 0, sizeof(descriptor_write));
5458 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5459 descriptor_write.dstSet = descriptorSet;
5460 descriptor_write.dstBinding = 0;
5461 descriptor_write.descriptorCount = 1;
5462 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5463 descriptor_write.pImageInfo = &img_info;
5464 // Break memory binding and attempt update
5465 vkFreeMemory(m_device->device(), image_memory, nullptr);
5466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005467 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5469 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5470 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5471 m_errorMonitor->VerifyFound();
5472 // Cleanup
5473 vkDestroyImage(m_device->device(), image, NULL);
5474 vkDestroySampler(m_device->device(), sampler, NULL);
5475 vkDestroyImageView(m_device->device(), view, NULL);
5476 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5477 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5478 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5479}
5480
Karl Schultz6addd812016-02-02 17:17:23 -07005481TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005482 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5483 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005484 // Create a valid cmd buffer
5485 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005486 uint64_t fake_pipeline_handle = 0xbaad6001;
5487 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005488 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5490
5491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005492 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005493 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005494 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005495
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005496 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005497 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 -06005498 Draw(1, 0, 0, 0);
5499 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005500
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005501 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005502 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 +12005503 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005504 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5505 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005506}
5507
Karl Schultz6addd812016-02-02 17:17:23 -07005508TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005509 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005510 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005511
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005513
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005514 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005515 ASSERT_NO_FATAL_FAILURE(InitViewport());
5516 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005517 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005518 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5519 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005520
5521 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005522 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5523 ds_pool_ci.pNext = NULL;
5524 ds_pool_ci.maxSets = 1;
5525 ds_pool_ci.poolSizeCount = 1;
5526 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005527
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005528 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005529 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005530 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005531
Tony Barboureb254902015-07-15 12:50:33 -06005532 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005533 dsl_binding.binding = 0;
5534 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5535 dsl_binding.descriptorCount = 1;
5536 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5537 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005538
Tony Barboureb254902015-07-15 12:50:33 -06005539 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005540 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5541 ds_layout_ci.pNext = NULL;
5542 ds_layout_ci.bindingCount = 1;
5543 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005544 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005545 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005546 ASSERT_VK_SUCCESS(err);
5547
5548 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005549 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005550 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005551 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005552 alloc_info.descriptorPool = ds_pool;
5553 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005554 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005555 ASSERT_VK_SUCCESS(err);
5556
Tony Barboureb254902015-07-15 12:50:33 -06005557 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005558 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5559 pipeline_layout_ci.pNext = NULL;
5560 pipeline_layout_ci.setLayoutCount = 1;
5561 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005562
5563 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005564 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005565 ASSERT_VK_SUCCESS(err);
5566
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005567 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005568 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005569 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005570 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005571
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005572 VkPipelineObj pipe(m_device);
5573 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005574 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005575 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005576 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005577
5578 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005579 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5580 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5581 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005582
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005583 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005584
Chia-I Wuf7458c52015-10-26 21:10:41 +08005585 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5586 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5587 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005588}
5589
Karl Schultz6addd812016-02-02 17:17:23 -07005590TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005591 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005592 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005593
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5595 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005596
5597 ASSERT_NO_FATAL_FAILURE(InitState());
5598 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005599 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5600 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005601
5602 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005603 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5604 ds_pool_ci.pNext = NULL;
5605 ds_pool_ci.maxSets = 1;
5606 ds_pool_ci.poolSizeCount = 1;
5607 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005608
5609 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005610 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005611 ASSERT_VK_SUCCESS(err);
5612
5613 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005614 dsl_binding.binding = 0;
5615 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5616 dsl_binding.descriptorCount = 1;
5617 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5618 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005619
5620 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005621 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5622 ds_layout_ci.pNext = NULL;
5623 ds_layout_ci.bindingCount = 1;
5624 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005625 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005626 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005627 ASSERT_VK_SUCCESS(err);
5628
5629 VkDescriptorSet descriptorSet;
5630 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005631 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005632 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005633 alloc_info.descriptorPool = ds_pool;
5634 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005635 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005636 ASSERT_VK_SUCCESS(err);
5637
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005638 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005639 VkWriteDescriptorSet descriptor_write;
5640 memset(&descriptor_write, 0, sizeof(descriptor_write));
5641 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5642 descriptor_write.dstSet = descriptorSet;
5643 descriptor_write.dstBinding = 0;
5644 descriptor_write.descriptorCount = 1;
5645 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5646 descriptor_write.pTexelBufferView = &view;
5647
5648 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5649
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005650 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005651
5652 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5653 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5654}
5655
Mark Youngd339ba32016-05-30 13:28:35 -06005656TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005657 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 -06005658
5659 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005661 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005662
5663 ASSERT_NO_FATAL_FAILURE(InitState());
5664
5665 // Create a buffer with no bound memory and then attempt to create
5666 // a buffer view.
5667 VkBufferCreateInfo buff_ci = {};
5668 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005669 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005670 buff_ci.size = 256;
5671 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5672 VkBuffer buffer;
5673 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5674 ASSERT_VK_SUCCESS(err);
5675
5676 VkBufferViewCreateInfo buff_view_ci = {};
5677 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5678 buff_view_ci.buffer = buffer;
5679 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5680 buff_view_ci.range = VK_WHOLE_SIZE;
5681 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005682 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005683
5684 m_errorMonitor->VerifyFound();
5685 vkDestroyBuffer(m_device->device(), buffer, NULL);
5686 // If last error is success, it still created the view, so delete it.
5687 if (err == VK_SUCCESS) {
5688 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5689 }
5690}
5691
Karl Schultz6addd812016-02-02 17:17:23 -07005692TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5693 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5694 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005695 // 1. No dynamicOffset supplied
5696 // 2. Too many dynamicOffsets supplied
5697 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005698 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5700 "0 dynamicOffsets are left in "
5701 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005702
5703 ASSERT_NO_FATAL_FAILURE(InitState());
5704 ASSERT_NO_FATAL_FAILURE(InitViewport());
5705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5706
5707 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005708 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5709 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005710
5711 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005712 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5713 ds_pool_ci.pNext = NULL;
5714 ds_pool_ci.maxSets = 1;
5715 ds_pool_ci.poolSizeCount = 1;
5716 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005717
5718 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005719 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005720 ASSERT_VK_SUCCESS(err);
5721
5722 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005723 dsl_binding.binding = 0;
5724 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5725 dsl_binding.descriptorCount = 1;
5726 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5727 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005728
5729 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005730 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5731 ds_layout_ci.pNext = NULL;
5732 ds_layout_ci.bindingCount = 1;
5733 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005734 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005735 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005736 ASSERT_VK_SUCCESS(err);
5737
5738 VkDescriptorSet descriptorSet;
5739 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005740 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005741 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005742 alloc_info.descriptorPool = ds_pool;
5743 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005744 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005745 ASSERT_VK_SUCCESS(err);
5746
5747 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005748 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5749 pipeline_layout_ci.pNext = NULL;
5750 pipeline_layout_ci.setLayoutCount = 1;
5751 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005752
5753 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005754 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005755 ASSERT_VK_SUCCESS(err);
5756
5757 // Create a buffer to update the descriptor with
5758 uint32_t qfi = 0;
5759 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005760 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5761 buffCI.size = 1024;
5762 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5763 buffCI.queueFamilyIndexCount = 1;
5764 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005765
5766 VkBuffer dyub;
5767 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5768 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005769 // Allocate memory and bind to buffer so we can make it to the appropriate
5770 // error
5771 VkMemoryAllocateInfo mem_alloc = {};
5772 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5773 mem_alloc.pNext = NULL;
5774 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005775 mem_alloc.memoryTypeIndex = 0;
5776
5777 VkMemoryRequirements memReqs;
5778 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005779 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005780 if (!pass) {
5781 vkDestroyBuffer(m_device->device(), dyub, NULL);
5782 return;
5783 }
5784
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005785 VkDeviceMemory mem;
5786 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5787 ASSERT_VK_SUCCESS(err);
5788 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5789 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005790 // Correctly update descriptor to avoid "NOT_UPDATED" error
5791 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005792 buffInfo.buffer = dyub;
5793 buffInfo.offset = 0;
5794 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005795
5796 VkWriteDescriptorSet descriptor_write;
5797 memset(&descriptor_write, 0, sizeof(descriptor_write));
5798 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5799 descriptor_write.dstSet = descriptorSet;
5800 descriptor_write.dstBinding = 0;
5801 descriptor_write.descriptorCount = 1;
5802 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5803 descriptor_write.pBufferInfo = &buffInfo;
5804
5805 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5806
5807 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005808 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5809 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005810 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005811 uint32_t pDynOff[2] = {512, 756};
5812 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5814 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5815 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5816 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005817 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005818 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5820 "offset 0 and range 1024 that "
5821 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005822 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005823 char const *vsSource = "#version 450\n"
5824 "\n"
5825 "out gl_PerVertex { \n"
5826 " vec4 gl_Position;\n"
5827 "};\n"
5828 "void main(){\n"
5829 " gl_Position = vec4(1);\n"
5830 "}\n";
5831 char const *fsSource = "#version 450\n"
5832 "\n"
5833 "layout(location=0) out vec4 x;\n"
5834 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5835 "void main(){\n"
5836 " x = vec4(bar.y);\n"
5837 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005838 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5839 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5840 VkPipelineObj pipe(m_device);
5841 pipe.AddShader(&vs);
5842 pipe.AddShader(&fs);
5843 pipe.AddColorAttachment();
5844 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5845
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005846 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005847 // This update should succeed, but offset size of 512 will overstep buffer
5848 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005849 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5850 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005851 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005852 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005853
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005854 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005855 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005856
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005857 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005858 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005859 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5860}
5861
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005862TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5863 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5864 "that doesn't have memory bound");
5865 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005867 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5869 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005870
5871 ASSERT_NO_FATAL_FAILURE(InitState());
5872 ASSERT_NO_FATAL_FAILURE(InitViewport());
5873 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5874
5875 VkDescriptorPoolSize ds_type_count = {};
5876 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5877 ds_type_count.descriptorCount = 1;
5878
5879 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5880 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5881 ds_pool_ci.pNext = NULL;
5882 ds_pool_ci.maxSets = 1;
5883 ds_pool_ci.poolSizeCount = 1;
5884 ds_pool_ci.pPoolSizes = &ds_type_count;
5885
5886 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005887 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005888 ASSERT_VK_SUCCESS(err);
5889
5890 VkDescriptorSetLayoutBinding dsl_binding = {};
5891 dsl_binding.binding = 0;
5892 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5893 dsl_binding.descriptorCount = 1;
5894 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5895 dsl_binding.pImmutableSamplers = NULL;
5896
5897 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5898 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5899 ds_layout_ci.pNext = NULL;
5900 ds_layout_ci.bindingCount = 1;
5901 ds_layout_ci.pBindings = &dsl_binding;
5902 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005903 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005904 ASSERT_VK_SUCCESS(err);
5905
5906 VkDescriptorSet descriptorSet;
5907 VkDescriptorSetAllocateInfo alloc_info = {};
5908 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5909 alloc_info.descriptorSetCount = 1;
5910 alloc_info.descriptorPool = ds_pool;
5911 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005912 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005913 ASSERT_VK_SUCCESS(err);
5914
5915 // Create a buffer to update the descriptor with
5916 uint32_t qfi = 0;
5917 VkBufferCreateInfo buffCI = {};
5918 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5919 buffCI.size = 1024;
5920 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5921 buffCI.queueFamilyIndexCount = 1;
5922 buffCI.pQueueFamilyIndices = &qfi;
5923
5924 VkBuffer dyub;
5925 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5926 ASSERT_VK_SUCCESS(err);
5927
5928 // Attempt to update descriptor without binding memory to it
5929 VkDescriptorBufferInfo buffInfo = {};
5930 buffInfo.buffer = dyub;
5931 buffInfo.offset = 0;
5932 buffInfo.range = 1024;
5933
5934 VkWriteDescriptorSet descriptor_write;
5935 memset(&descriptor_write, 0, sizeof(descriptor_write));
5936 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5937 descriptor_write.dstSet = descriptorSet;
5938 descriptor_write.dstBinding = 0;
5939 descriptor_write.descriptorCount = 1;
5940 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5941 descriptor_write.pBufferInfo = &buffInfo;
5942
5943 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5944 m_errorMonitor->VerifyFound();
5945
5946 vkDestroyBuffer(m_device->device(), dyub, NULL);
5947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5949}
5950
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005951TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005952 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005953 ASSERT_NO_FATAL_FAILURE(InitState());
5954 ASSERT_NO_FATAL_FAILURE(InitViewport());
5955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5956
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005957 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005958 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005959 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5960 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5961 pipeline_layout_ci.pushConstantRangeCount = 1;
5962 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5963
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005964 //
5965 // Check for invalid push constant ranges in pipeline layouts.
5966 //
5967 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005968 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005969 char const *msg;
5970 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005971
Karl Schultzc81037d2016-05-12 08:11:23 -06005972 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5973 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5974 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5975 "vkCreatePipelineLayout() call has push constants index 0 with "
5976 "size 0."},
5977 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5978 "vkCreatePipelineLayout() call has push constants index 0 with "
5979 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005980 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06005981 "vkCreatePipelineLayout() call has push constants index 0 with "
5982 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005983 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06005984 "vkCreatePipelineLayout() call has push constants index 0 with "
5985 "size 0."},
5986 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5987 "vkCreatePipelineLayout() call has push constants index 0 with "
5988 "offset 1. Offset must"},
5989 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5990 "vkCreatePipelineLayout() call has push constants index 0 "
5991 "with offset "},
5992 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5993 "vkCreatePipelineLayout() call has push constants "
5994 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005995 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06005996 "vkCreatePipelineLayout() call has push constants index 0 "
5997 "with offset "},
5998 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5999 "vkCreatePipelineLayout() call has push "
6000 "constants index 0 with offset "},
6001 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6002 "vkCreatePipelineLayout() call has push "
6003 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006004 }};
6005
6006 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006007 for (const auto &iter : range_tests) {
6008 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6010 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006011 m_errorMonitor->VerifyFound();
6012 if (VK_SUCCESS == err) {
6013 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6014 }
6015 }
6016
6017 // Check for invalid stage flag
6018 pc_range.offset = 0;
6019 pc_range.size = 16;
6020 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006021 m_errorMonitor->SetDesiredFailureMsg(
6022 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6023 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006024 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006025 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006026 if (VK_SUCCESS == err) {
6027 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6028 }
6029
6030 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006031 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006032 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006033 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006034 char const *msg;
6035 };
6036
Karl Schultzc81037d2016-05-12 08:11:23 -06006037 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006038 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6039 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6040 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6041 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6042 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006043 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006044 {
6045 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6046 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6047 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6048 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6049 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006050 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006051 },
6052 {
6053 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6054 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6055 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6056 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6057 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006058 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006059 },
6060 {
6061 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6062 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6063 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6064 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6065 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006066 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006067 },
6068 {
6069 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6070 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6071 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6072 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6073 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006074 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006075 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006076
Karl Schultzc81037d2016-05-12 08:11:23 -06006077 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006078 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006079 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6081 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006082 m_errorMonitor->VerifyFound();
6083 if (VK_SUCCESS == err) {
6084 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6085 }
6086 }
6087
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006088 //
6089 // CmdPushConstants tests
6090 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006091 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006092
6093 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006094 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6095 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006096 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6097 "vkCmdPushConstants() call has push constants with size 1. Size "
6098 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006099 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006100 "vkCmdPushConstants() call has push constants with size 1. Size "
6101 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006102 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006103 "vkCmdPushConstants() call has push constants with offset 1. "
6104 "Offset must be a multiple of 4."},
6105 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6106 "vkCmdPushConstants() call has push constants with offset 1. "
6107 "Offset must be a multiple of 4."},
6108 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6109 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6110 "0x1 not within flag-matching ranges in pipeline layout"},
6111 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6112 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6113 "0x1 not within flag-matching ranges in pipeline layout"},
6114 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6115 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6116 "0x1 not within flag-matching ranges in pipeline layout"},
6117 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6118 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6119 "0x1 not within flag-matching ranges in pipeline layout"},
6120 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6121 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6122 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006123 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006124 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6125 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006126 }};
6127
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006128 BeginCommandBuffer();
6129
6130 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006131 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006132 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006133 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006134 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006135 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006136 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006137 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006138 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6140 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006141 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006142 m_errorMonitor->VerifyFound();
6143 }
6144
6145 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006147 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006148 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006149 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006150
Karl Schultzc81037d2016-05-12 08:11:23 -06006151 // overlapping range tests with cmd
6152 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6153 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6154 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6155 "0x1 not within flag-matching ranges in pipeline layout"},
6156 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6157 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6158 "0x1 not within flag-matching ranges in pipeline layout"},
6159 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6160 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6161 "0x1 not within flag-matching ranges in pipeline layout"},
6162 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006163 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006164 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006165 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6166 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006167 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006168 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006169 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006170 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006171 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006172 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6174 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006175 iter.range.size, dummy_values);
6176 m_errorMonitor->VerifyFound();
6177 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006178 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6179
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006180 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006181}
6182
Karl Schultz6addd812016-02-02 17:17:23 -07006183TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006184 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006185 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006186
6187 ASSERT_NO_FATAL_FAILURE(InitState());
6188 ASSERT_NO_FATAL_FAILURE(InitViewport());
6189 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6190
Mike Stroyanb8a61002016-06-20 16:00:28 -06006191 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6192 VkImageTiling tiling;
6193 VkFormatProperties format_properties;
6194 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006195 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006196 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006197 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006198 tiling = VK_IMAGE_TILING_OPTIMAL;
6199 } else {
6200 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6201 "skipped.\n");
6202 return;
6203 }
6204
Tobin Ehlis559c6382015-11-05 09:52:49 -07006205 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6206 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006207 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6208 ds_type_count[0].descriptorCount = 10;
6209 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6210 ds_type_count[1].descriptorCount = 2;
6211 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6212 ds_type_count[2].descriptorCount = 2;
6213 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6214 ds_type_count[3].descriptorCount = 5;
6215 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6216 // type
6217 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6218 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6219 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006220
6221 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006222 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6223 ds_pool_ci.pNext = NULL;
6224 ds_pool_ci.maxSets = 5;
6225 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6226 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006227
6228 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006229 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006230 ASSERT_VK_SUCCESS(err);
6231
6232 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6233 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006234 dsl_binding[0].binding = 0;
6235 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6236 dsl_binding[0].descriptorCount = 5;
6237 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6238 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006239
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006240 // Create layout identical to set0 layout but w/ different stageFlags
6241 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006242 dsl_fs_stage_only.binding = 0;
6243 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6244 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006245 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6246 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006247 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006248 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006249 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6250 ds_layout_ci.pNext = NULL;
6251 ds_layout_ci.bindingCount = 1;
6252 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006253 static const uint32_t NUM_LAYOUTS = 4;
6254 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006255 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006256 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6257 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006258 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006259 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006260 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006261 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006262 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006263 dsl_binding[0].binding = 0;
6264 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006265 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006266 dsl_binding[1].binding = 1;
6267 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6268 dsl_binding[1].descriptorCount = 2;
6269 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6270 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006271 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006272 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006273 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006274 ASSERT_VK_SUCCESS(err);
6275 dsl_binding[0].binding = 0;
6276 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006277 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006278 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006279 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006280 ASSERT_VK_SUCCESS(err);
6281 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006282 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006283 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006284 ASSERT_VK_SUCCESS(err);
6285
6286 static const uint32_t NUM_SETS = 4;
6287 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6288 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006289 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006290 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006291 alloc_info.descriptorPool = ds_pool;
6292 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006293 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006294 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006295 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006296 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006297 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006298 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006299 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006300
6301 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006302 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6303 pipeline_layout_ci.pNext = NULL;
6304 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6305 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006306
6307 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006308 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006309 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006310 // Create pipelineLayout with only one setLayout
6311 pipeline_layout_ci.setLayoutCount = 1;
6312 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006313 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006314 ASSERT_VK_SUCCESS(err);
6315 // Create pipelineLayout with 2 descriptor setLayout at index 0
6316 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6317 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006318 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006319 ASSERT_VK_SUCCESS(err);
6320 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6321 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6322 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006323 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006324 ASSERT_VK_SUCCESS(err);
6325 // Create pipelineLayout with UB type, but stageFlags for FS only
6326 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6327 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006328 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006329 ASSERT_VK_SUCCESS(err);
6330 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6331 VkDescriptorSetLayout pl_bad_s0[2] = {};
6332 pl_bad_s0[0] = ds_layout_fs_only;
6333 pl_bad_s0[1] = ds_layout[1];
6334 pipeline_layout_ci.setLayoutCount = 2;
6335 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6336 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006337 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006338 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006339
6340 // Create a buffer to update the descriptor with
6341 uint32_t qfi = 0;
6342 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006343 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6344 buffCI.size = 1024;
6345 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6346 buffCI.queueFamilyIndexCount = 1;
6347 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006348
6349 VkBuffer dyub;
6350 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6351 ASSERT_VK_SUCCESS(err);
6352 // Correctly update descriptor to avoid "NOT_UPDATED" error
6353 static const uint32_t NUM_BUFFS = 5;
6354 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006355 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006356 buffInfo[i].buffer = dyub;
6357 buffInfo[i].offset = 0;
6358 buffInfo[i].range = 1024;
6359 }
Karl Schultz6addd812016-02-02 17:17:23 -07006360 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006361 const int32_t tex_width = 32;
6362 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006363 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6365 image_create_info.pNext = NULL;
6366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6367 image_create_info.format = tex_format;
6368 image_create_info.extent.width = tex_width;
6369 image_create_info.extent.height = tex_height;
6370 image_create_info.extent.depth = 1;
6371 image_create_info.mipLevels = 1;
6372 image_create_info.arrayLayers = 1;
6373 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006374 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006375 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006376 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006377 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6378 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006379
Karl Schultz6addd812016-02-02 17:17:23 -07006380 VkMemoryRequirements memReqs;
6381 VkDeviceMemory imageMem;
6382 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006383 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006384 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6385 memAlloc.pNext = NULL;
6386 memAlloc.allocationSize = 0;
6387 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006388 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6389 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006390 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006391 ASSERT_TRUE(pass);
6392 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6393 ASSERT_VK_SUCCESS(err);
6394 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6395 ASSERT_VK_SUCCESS(err);
6396
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006397 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006398 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6399 image_view_create_info.image = image;
6400 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6401 image_view_create_info.format = tex_format;
6402 image_view_create_info.subresourceRange.layerCount = 1;
6403 image_view_create_info.subresourceRange.baseMipLevel = 0;
6404 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006405 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006406
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006407 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006409 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006410 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006411 imageInfo[0].imageView = view;
6412 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6413 imageInfo[1].imageView = view;
6414 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006415 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006416 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006417 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006418 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006419
6420 static const uint32_t NUM_SET_UPDATES = 3;
6421 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6422 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6423 descriptor_write[0].dstSet = descriptorSet[0];
6424 descriptor_write[0].dstBinding = 0;
6425 descriptor_write[0].descriptorCount = 5;
6426 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6427 descriptor_write[0].pBufferInfo = buffInfo;
6428 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6429 descriptor_write[1].dstSet = descriptorSet[1];
6430 descriptor_write[1].dstBinding = 0;
6431 descriptor_write[1].descriptorCount = 2;
6432 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6433 descriptor_write[1].pImageInfo = imageInfo;
6434 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6435 descriptor_write[2].dstSet = descriptorSet[1];
6436 descriptor_write[2].dstBinding = 1;
6437 descriptor_write[2].descriptorCount = 2;
6438 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006439 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006440
6441 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006442
Tobin Ehlis88452832015-12-03 09:40:56 -07006443 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006444 char const *vsSource = "#version 450\n"
6445 "\n"
6446 "out gl_PerVertex {\n"
6447 " vec4 gl_Position;\n"
6448 "};\n"
6449 "void main(){\n"
6450 " gl_Position = vec4(1);\n"
6451 "}\n";
6452 char const *fsSource = "#version 450\n"
6453 "\n"
6454 "layout(location=0) out vec4 x;\n"
6455 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6456 "void main(){\n"
6457 " x = vec4(bar.y);\n"
6458 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006459 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6460 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006461 VkPipelineObj pipe(m_device);
6462 pipe.AddShader(&vs);
6463 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006464 pipe.AddColorAttachment();
6465 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006466
6467 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006468
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006469 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006470 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6471 // of PSO
6472 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6473 // cmd_pipeline.c
6474 // due to the fact that cmd_alloc_dset_data() has not been called in
6475 // cmd_bind_graphics_pipeline()
6476 // TODO : Want to cause various binding incompatibility issues here to test
6477 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006478 // First cause various verify_layout_compatibility() fails
6479 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006480 // verify_set_layout_compatibility fail cases:
6481 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6483 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6484 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006485 m_errorMonitor->VerifyFound();
6486
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006487 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6489 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6490 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006491 m_errorMonitor->VerifyFound();
6492
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006493 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006494 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6495 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6497 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6498 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006499 m_errorMonitor->VerifyFound();
6500
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006501 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6502 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6504 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6505 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006506 m_errorMonitor->VerifyFound();
6507
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006508 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6509 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6511 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6512 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6513 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006514 m_errorMonitor->VerifyFound();
6515
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006516 // Cause INFO messages due to disturbing previously bound Sets
6517 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006518 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6519 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006520 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6522 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6523 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006524 m_errorMonitor->VerifyFound();
6525
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006526 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6527 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006528 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6530 "any subsequent sets were disturbed ");
6531 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6532 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006533 m_errorMonitor->VerifyFound();
6534
Tobin Ehlis10fad692016-07-07 12:00:36 -06006535 // Now that we're done actively using the pipelineLayout that gfx pipeline
6536 // was created with, we should be able to delete it. Do that now to verify
6537 // that validation obeys pipelineLayout lifetime
6538 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6539
Tobin Ehlis88452832015-12-03 09:40:56 -07006540 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006541 // 1. Error due to not binding required set (we actually use same code as
6542 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006543 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6544 &descriptorSet[0], 0, NULL);
6545 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6546 &descriptorSet[1], 0, NULL);
6547 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 -07006548 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006549 m_errorMonitor->VerifyFound();
6550
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006551 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006552 // 2. Error due to bound set not being compatible with PSO's
6553 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006554 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6555 &descriptorSet[0], 0, NULL);
6556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006557 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006558 m_errorMonitor->VerifyFound();
6559
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006560 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006561 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006562 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6563 }
6564 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006565 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006566 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6567 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006568 vkFreeMemory(m_device->device(), imageMem, NULL);
6569 vkDestroyImage(m_device->device(), image, NULL);
6570 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006571}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006572
Karl Schultz6addd812016-02-02 17:17:23 -07006573TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6576 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006577
6578 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006579 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006580 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006581 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006582
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006583 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006584}
6585
Karl Schultz6addd812016-02-02 17:17:23 -07006586TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6587 VkResult err;
6588 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006589
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006591
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006592 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006593
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006594 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006595 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006596 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006597 cmd.commandPool = m_commandPool;
6598 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006599 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006600
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006601 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006602 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006603
6604 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006605 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006606 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006607 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006608 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006609 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 -07006610 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006611
6612 // The error should be caught by validation of the BeginCommandBuffer call
6613 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6614
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006615 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006616 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006617}
6618
Karl Schultz6addd812016-02-02 17:17:23 -07006619TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006620 // Cause error due to Begin while recording CB
6621 // Then cause 2 errors for attempting to reset CB w/o having
6622 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6623 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006625
6626 ASSERT_NO_FATAL_FAILURE(InitState());
6627
6628 // Calls AllocateCommandBuffers
6629 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6630
Karl Schultz6addd812016-02-02 17:17:23 -07006631 // Force the failure by setting the Renderpass and Framebuffer fields with
6632 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006633 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006634 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006635 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6636 cmd_buf_info.pNext = NULL;
6637 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006638 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006639
6640 // Begin CB to transition to recording state
6641 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6642 // Can't re-begin. This should trigger error
6643 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006644 m_errorMonitor->VerifyFound();
6645
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006647 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6648 // Reset attempt will trigger error due to incorrect CommandPool state
6649 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006650 m_errorMonitor->VerifyFound();
6651
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006653 // Transition CB to RECORDED state
6654 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6655 // Now attempting to Begin will implicitly reset, which triggers error
6656 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006657 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006658}
6659
Karl Schultz6addd812016-02-02 17:17:23 -07006660TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006661 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006662 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006663
Mike Weiblencce7ec72016-10-17 19:33:05 -06006664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006665
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006666 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006667 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006668
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006669 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006670 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6671 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006672
6673 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006674 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6675 ds_pool_ci.pNext = NULL;
6676 ds_pool_ci.maxSets = 1;
6677 ds_pool_ci.poolSizeCount = 1;
6678 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006679
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006680 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006681 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006682 ASSERT_VK_SUCCESS(err);
6683
Tony Barboureb254902015-07-15 12:50:33 -06006684 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006685 dsl_binding.binding = 0;
6686 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6687 dsl_binding.descriptorCount = 1;
6688 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6689 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006690
Tony Barboureb254902015-07-15 12:50:33 -06006691 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006692 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6693 ds_layout_ci.pNext = NULL;
6694 ds_layout_ci.bindingCount = 1;
6695 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006696
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006697 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006698 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006699 ASSERT_VK_SUCCESS(err);
6700
6701 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006702 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006703 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006704 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006705 alloc_info.descriptorPool = ds_pool;
6706 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006707 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006708 ASSERT_VK_SUCCESS(err);
6709
Tony Barboureb254902015-07-15 12:50:33 -06006710 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006711 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6712 pipeline_layout_ci.setLayoutCount = 1;
6713 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006714
6715 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006716 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006717 ASSERT_VK_SUCCESS(err);
6718
Tobin Ehlise68360f2015-10-01 11:15:13 -06006719 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006720 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006721
6722 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006723 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6724 vp_state_ci.scissorCount = 1;
6725 vp_state_ci.pScissors = &sc;
6726 vp_state_ci.viewportCount = 1;
6727 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006728
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006729 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6730 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6731 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6732 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6733 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6734 rs_state_ci.depthClampEnable = VK_FALSE;
6735 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6736 rs_state_ci.depthBiasEnable = VK_FALSE;
6737
Tony Barboureb254902015-07-15 12:50:33 -06006738 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006739 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6740 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006741 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006742 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6743 gp_ci.layout = pipeline_layout;
6744 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006745
6746 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006747 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6748 pc_ci.initialDataSize = 0;
6749 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006750
6751 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006752 VkPipelineCache pipelineCache;
6753
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006754 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006755 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006756 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006757
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006758 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006759
Chia-I Wuf7458c52015-10-26 21:10:41 +08006760 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6761 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6762 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6763 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006764}
Tobin Ehlis912df022015-09-17 08:46:18 -06006765/*// TODO : This test should be good, but needs Tess support in compiler to run
6766TEST_F(VkLayerTest, InvalidPatchControlPoints)
6767{
6768 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006769 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006770
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006772 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6773primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006774
Tobin Ehlis912df022015-09-17 08:46:18 -06006775 ASSERT_NO_FATAL_FAILURE(InitState());
6776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006777
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006778 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006779 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006780 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006781
6782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6784 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006785 ds_pool_ci.poolSizeCount = 1;
6786 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006787
6788 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006789 err = vkCreateDescriptorPool(m_device->device(),
6790VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006791 ASSERT_VK_SUCCESS(err);
6792
6793 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006794 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006796 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6798 dsl_binding.pImmutableSamplers = NULL;
6799
6800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006801 ds_layout_ci.sType =
6802VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006803 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006804 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006805 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006806
6807 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006808 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6809&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006810 ASSERT_VK_SUCCESS(err);
6811
6812 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006813 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6814VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006815 ASSERT_VK_SUCCESS(err);
6816
6817 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006818 pipeline_layout_ci.sType =
6819VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006820 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006821 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006822 pipeline_layout_ci.pSetLayouts = &ds_layout;
6823
6824 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006825 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6826&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006827 ASSERT_VK_SUCCESS(err);
6828
6829 VkPipelineShaderStageCreateInfo shaderStages[3];
6830 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6831
Karl Schultz6addd812016-02-02 17:17:23 -07006832 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6833this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006834 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006835 VkShaderObj
6836tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6837this);
6838 VkShaderObj
6839te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6840this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006841
Karl Schultz6addd812016-02-02 17:17:23 -07006842 shaderStages[0].sType =
6843VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006844 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006845 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006846 shaderStages[1].sType =
6847VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006848 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006849 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006850 shaderStages[2].sType =
6851VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006852 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006853 shaderStages[2].shader = te.handle();
6854
6855 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006856 iaCI.sType =
6857VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006858 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006859
6860 VkPipelineTessellationStateCreateInfo tsCI = {};
6861 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6862 tsCI.patchControlPoints = 0; // This will cause an error
6863
6864 VkGraphicsPipelineCreateInfo gp_ci = {};
6865 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6866 gp_ci.pNext = NULL;
6867 gp_ci.stageCount = 3;
6868 gp_ci.pStages = shaderStages;
6869 gp_ci.pVertexInputState = NULL;
6870 gp_ci.pInputAssemblyState = &iaCI;
6871 gp_ci.pTessellationState = &tsCI;
6872 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006873 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006874 gp_ci.pMultisampleState = NULL;
6875 gp_ci.pDepthStencilState = NULL;
6876 gp_ci.pColorBlendState = NULL;
6877 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6878 gp_ci.layout = pipeline_layout;
6879 gp_ci.renderPass = renderPass();
6880
6881 VkPipelineCacheCreateInfo pc_ci = {};
6882 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6883 pc_ci.pNext = NULL;
6884 pc_ci.initialSize = 0;
6885 pc_ci.initialData = 0;
6886 pc_ci.maxSize = 0;
6887
6888 VkPipeline pipeline;
6889 VkPipelineCache pipelineCache;
6890
Karl Schultz6addd812016-02-02 17:17:23 -07006891 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6892&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006893 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006894 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6895&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006896
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006897 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006898
Chia-I Wuf7458c52015-10-26 21:10:41 +08006899 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6900 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6901 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6902 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006903}
6904*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006905// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006906TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006907 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6910 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006911
Tobin Ehlise68360f2015-10-01 11:15:13 -06006912 ASSERT_NO_FATAL_FAILURE(InitState());
6913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006914
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006915 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006916 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6917 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006918
6919 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006920 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6921 ds_pool_ci.maxSets = 1;
6922 ds_pool_ci.poolSizeCount = 1;
6923 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006924
6925 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006926 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006927 ASSERT_VK_SUCCESS(err);
6928
6929 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006930 dsl_binding.binding = 0;
6931 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6932 dsl_binding.descriptorCount = 1;
6933 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006934
6935 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006936 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6937 ds_layout_ci.bindingCount = 1;
6938 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006939
6940 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006941 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006942 ASSERT_VK_SUCCESS(err);
6943
6944 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006945 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006946 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006947 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006948 alloc_info.descriptorPool = ds_pool;
6949 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006950 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006951 ASSERT_VK_SUCCESS(err);
6952
6953 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006954 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6955 pipeline_layout_ci.setLayoutCount = 1;
6956 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006957
6958 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006959 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006960 ASSERT_VK_SUCCESS(err);
6961
6962 VkViewport vp = {}; // Just need dummy vp to point to
6963
6964 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006965 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6966 vp_state_ci.scissorCount = 0;
6967 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6968 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006969
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006970 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6971 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6972 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6973 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6974 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6975 rs_state_ci.depthClampEnable = VK_FALSE;
6976 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6977 rs_state_ci.depthBiasEnable = VK_FALSE;
6978
Cody Northropeb3a6c12015-10-05 14:44:45 -06006979 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006980 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006982 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6983 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
6984 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006985 shaderStages[0] = vs.GetStageCreateInfo();
6986 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006987
6988 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006989 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6990 gp_ci.stageCount = 2;
6991 gp_ci.pStages = shaderStages;
6992 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006993 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006994 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6995 gp_ci.layout = pipeline_layout;
6996 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006997
6998 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006999 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007000
7001 VkPipeline pipeline;
7002 VkPipelineCache pipelineCache;
7003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007004 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007005 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007006 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007007
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007008 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007009
Chia-I Wuf7458c52015-10-26 21:10:41 +08007010 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7011 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7012 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7013 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007014}
Karl Schultz6addd812016-02-02 17:17:23 -07007015// Don't set viewport state in PSO. This is an error b/c we always need this
7016// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007017// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007018TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007019 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007020 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007023
Tobin Ehlise68360f2015-10-01 11:15:13 -06007024 ASSERT_NO_FATAL_FAILURE(InitState());
7025 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007026
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007027 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007028 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7029 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007030
7031 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007032 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7033 ds_pool_ci.maxSets = 1;
7034 ds_pool_ci.poolSizeCount = 1;
7035 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007036
7037 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007038 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007039 ASSERT_VK_SUCCESS(err);
7040
7041 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007042 dsl_binding.binding = 0;
7043 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7044 dsl_binding.descriptorCount = 1;
7045 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007046
7047 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007048 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7049 ds_layout_ci.bindingCount = 1;
7050 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007051
7052 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007053 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007054 ASSERT_VK_SUCCESS(err);
7055
7056 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007057 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007058 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007059 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007060 alloc_info.descriptorPool = ds_pool;
7061 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007062 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007063 ASSERT_VK_SUCCESS(err);
7064
7065 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007066 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7067 pipeline_layout_ci.setLayoutCount = 1;
7068 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007069
7070 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007071 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007072 ASSERT_VK_SUCCESS(err);
7073
7074 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7075 // Set scissor as dynamic to avoid second error
7076 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007077 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7078 dyn_state_ci.dynamicStateCount = 1;
7079 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007080
Cody Northropeb3a6c12015-10-05 14:44:45 -06007081 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007082 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007083
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007084 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7085 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7086 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007087 shaderStages[0] = vs.GetStageCreateInfo();
7088 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007089
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007090 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7091 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7092 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7093 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7094 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7095 rs_state_ci.depthClampEnable = VK_FALSE;
7096 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7097 rs_state_ci.depthBiasEnable = VK_FALSE;
7098
Tobin Ehlise68360f2015-10-01 11:15:13 -06007099 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007100 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7101 gp_ci.stageCount = 2;
7102 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007103 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007104 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7105 // should cause validation error
7106 gp_ci.pDynamicState = &dyn_state_ci;
7107 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7108 gp_ci.layout = pipeline_layout;
7109 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007110
7111 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007112 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007113
7114 VkPipeline pipeline;
7115 VkPipelineCache pipelineCache;
7116
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007117 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007118 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007119 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007120
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007121 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007122
Chia-I Wuf7458c52015-10-26 21:10:41 +08007123 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7124 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7125 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7126 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007127}
7128// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007129// Then run second test where dynamic scissor count doesn't match PSO scissor
7130// count
7131TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7132 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007133
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7135 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007136
Tobin Ehlise68360f2015-10-01 11:15:13 -06007137 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007138
7139 if (!m_device->phy().features().multiViewport) {
7140 printf("Device does not support multiple viewports/scissors; skipped.\n");
7141 return;
7142 }
7143
Tobin Ehlise68360f2015-10-01 11:15:13 -06007144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007145
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007146 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007147 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7148 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149
7150 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007151 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7152 ds_pool_ci.maxSets = 1;
7153 ds_pool_ci.poolSizeCount = 1;
7154 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007155
7156 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007157 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007158 ASSERT_VK_SUCCESS(err);
7159
7160 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007161 dsl_binding.binding = 0;
7162 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7163 dsl_binding.descriptorCount = 1;
7164 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007165
7166 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007167 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7168 ds_layout_ci.bindingCount = 1;
7169 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007170
7171 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007172 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007173 ASSERT_VK_SUCCESS(err);
7174
7175 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007176 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007177 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007178 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007179 alloc_info.descriptorPool = ds_pool;
7180 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007181 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007182 ASSERT_VK_SUCCESS(err);
7183
7184 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007185 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7186 pipeline_layout_ci.setLayoutCount = 1;
7187 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007188
7189 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007190 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007191 ASSERT_VK_SUCCESS(err);
7192
7193 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007194 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7195 vp_state_ci.viewportCount = 1;
7196 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7197 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007198 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007199
7200 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7201 // Set scissor as dynamic to avoid that error
7202 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007203 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7204 dyn_state_ci.dynamicStateCount = 1;
7205 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007206
Cody Northropeb3a6c12015-10-05 14:44:45 -06007207 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007208 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007210 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7211 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7212 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007213 shaderStages[0] = vs.GetStageCreateInfo();
7214 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007215
Cody Northropf6622dc2015-10-06 10:33:21 -06007216 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7217 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7218 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007219 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007220 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007221 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007222 vi_ci.pVertexAttributeDescriptions = nullptr;
7223
7224 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7225 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7226 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7227
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007228 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007229 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007230 rs_ci.pNext = nullptr;
7231
Mark Youngc89c6312016-03-31 16:03:20 -06007232 VkPipelineColorBlendAttachmentState att = {};
7233 att.blendEnable = VK_FALSE;
7234 att.colorWriteMask = 0xf;
7235
Cody Northropf6622dc2015-10-06 10:33:21 -06007236 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7237 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7238 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007239 cb_ci.attachmentCount = 1;
7240 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007241
Tobin Ehlise68360f2015-10-01 11:15:13 -06007242 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007243 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7244 gp_ci.stageCount = 2;
7245 gp_ci.pStages = shaderStages;
7246 gp_ci.pVertexInputState = &vi_ci;
7247 gp_ci.pInputAssemblyState = &ia_ci;
7248 gp_ci.pViewportState = &vp_state_ci;
7249 gp_ci.pRasterizationState = &rs_ci;
7250 gp_ci.pColorBlendState = &cb_ci;
7251 gp_ci.pDynamicState = &dyn_state_ci;
7252 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7253 gp_ci.layout = pipeline_layout;
7254 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007255
7256 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007257 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007258
7259 VkPipeline pipeline;
7260 VkPipelineCache pipelineCache;
7261
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007262 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007263 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007264 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007265
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007266 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007267
Tobin Ehlisd332f282015-10-02 11:00:56 -06007268 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007269 // First need to successfully create the PSO from above by setting
7270 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007271 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 -07007272
7273 VkViewport vp = {}; // Just need dummy vp to point to
7274 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007275 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007276 ASSERT_VK_SUCCESS(err);
7277 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007278 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007279 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007280 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007281 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007282 Draw(1, 0, 0, 0);
7283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007284 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007285
7286 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7287 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7288 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7289 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007290 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007291}
7292// Create PSO w/o non-zero scissorCount but no scissor data
7293// Then run second test where dynamic viewportCount doesn't match PSO
7294// viewportCount
7295TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7296 VkResult err;
7297
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007298 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 -07007299
7300 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007301
7302 if (!m_device->phy().features().multiViewport) {
7303 printf("Device does not support multiple viewports/scissors; skipped.\n");
7304 return;
7305 }
7306
Karl Schultz6addd812016-02-02 17:17:23 -07007307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7308
7309 VkDescriptorPoolSize ds_type_count = {};
7310 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7311 ds_type_count.descriptorCount = 1;
7312
7313 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7314 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7315 ds_pool_ci.maxSets = 1;
7316 ds_pool_ci.poolSizeCount = 1;
7317 ds_pool_ci.pPoolSizes = &ds_type_count;
7318
7319 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007320 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007321 ASSERT_VK_SUCCESS(err);
7322
7323 VkDescriptorSetLayoutBinding dsl_binding = {};
7324 dsl_binding.binding = 0;
7325 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7326 dsl_binding.descriptorCount = 1;
7327 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7328
7329 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7330 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7331 ds_layout_ci.bindingCount = 1;
7332 ds_layout_ci.pBindings = &dsl_binding;
7333
7334 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007335 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007336 ASSERT_VK_SUCCESS(err);
7337
7338 VkDescriptorSet descriptorSet;
7339 VkDescriptorSetAllocateInfo alloc_info = {};
7340 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7341 alloc_info.descriptorSetCount = 1;
7342 alloc_info.descriptorPool = ds_pool;
7343 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007344 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007345 ASSERT_VK_SUCCESS(err);
7346
7347 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7348 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7349 pipeline_layout_ci.setLayoutCount = 1;
7350 pipeline_layout_ci.pSetLayouts = &ds_layout;
7351
7352 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007353 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007354 ASSERT_VK_SUCCESS(err);
7355
7356 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7357 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7358 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007359 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007360 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007361 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007362
7363 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7364 // Set scissor as dynamic to avoid that error
7365 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7366 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7367 dyn_state_ci.dynamicStateCount = 1;
7368 dyn_state_ci.pDynamicStates = &vp_state;
7369
7370 VkPipelineShaderStageCreateInfo shaderStages[2];
7371 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7372
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007373 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7374 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7375 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007376 shaderStages[0] = vs.GetStageCreateInfo();
7377 shaderStages[1] = fs.GetStageCreateInfo();
7378
7379 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7380 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7381 vi_ci.pNext = nullptr;
7382 vi_ci.vertexBindingDescriptionCount = 0;
7383 vi_ci.pVertexBindingDescriptions = nullptr;
7384 vi_ci.vertexAttributeDescriptionCount = 0;
7385 vi_ci.pVertexAttributeDescriptions = nullptr;
7386
7387 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7388 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7389 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7390
7391 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7392 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7393 rs_ci.pNext = nullptr;
7394
Mark Youngc89c6312016-03-31 16:03:20 -06007395 VkPipelineColorBlendAttachmentState att = {};
7396 att.blendEnable = VK_FALSE;
7397 att.colorWriteMask = 0xf;
7398
Karl Schultz6addd812016-02-02 17:17:23 -07007399 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7400 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7401 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007402 cb_ci.attachmentCount = 1;
7403 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007404
7405 VkGraphicsPipelineCreateInfo gp_ci = {};
7406 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7407 gp_ci.stageCount = 2;
7408 gp_ci.pStages = shaderStages;
7409 gp_ci.pVertexInputState = &vi_ci;
7410 gp_ci.pInputAssemblyState = &ia_ci;
7411 gp_ci.pViewportState = &vp_state_ci;
7412 gp_ci.pRasterizationState = &rs_ci;
7413 gp_ci.pColorBlendState = &cb_ci;
7414 gp_ci.pDynamicState = &dyn_state_ci;
7415 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7416 gp_ci.layout = pipeline_layout;
7417 gp_ci.renderPass = renderPass();
7418
7419 VkPipelineCacheCreateInfo pc_ci = {};
7420 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7421
7422 VkPipeline pipeline;
7423 VkPipelineCache pipelineCache;
7424
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007425 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007426 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007427 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007428
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007429 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007430
7431 // Now hit second fail case where we set scissor w/ different count than PSO
7432 // First need to successfully create the PSO from above by setting
7433 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007434 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 -06007435
Tobin Ehlisd332f282015-10-02 11:00:56 -06007436 VkRect2D sc = {}; // Just need dummy vp to point to
7437 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007438 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007439 ASSERT_VK_SUCCESS(err);
7440 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007441 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007442 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007443 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007444 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007445 Draw(1, 0, 0, 0);
7446
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007447 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007448
Chia-I Wuf7458c52015-10-26 21:10:41 +08007449 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7450 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7451 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7452 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007453 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007454}
7455
Mark Young7394fdd2016-03-31 14:56:43 -06007456TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7457 VkResult err;
7458
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007460
7461 ASSERT_NO_FATAL_FAILURE(InitState());
7462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7463
7464 VkDescriptorPoolSize ds_type_count = {};
7465 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7466 ds_type_count.descriptorCount = 1;
7467
7468 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7469 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7470 ds_pool_ci.maxSets = 1;
7471 ds_pool_ci.poolSizeCount = 1;
7472 ds_pool_ci.pPoolSizes = &ds_type_count;
7473
7474 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007475 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007476 ASSERT_VK_SUCCESS(err);
7477
7478 VkDescriptorSetLayoutBinding dsl_binding = {};
7479 dsl_binding.binding = 0;
7480 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7481 dsl_binding.descriptorCount = 1;
7482 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7483
7484 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7485 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7486 ds_layout_ci.bindingCount = 1;
7487 ds_layout_ci.pBindings = &dsl_binding;
7488
7489 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007490 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007491 ASSERT_VK_SUCCESS(err);
7492
7493 VkDescriptorSet descriptorSet;
7494 VkDescriptorSetAllocateInfo alloc_info = {};
7495 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7496 alloc_info.descriptorSetCount = 1;
7497 alloc_info.descriptorPool = ds_pool;
7498 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007499 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007500 ASSERT_VK_SUCCESS(err);
7501
7502 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7503 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7504 pipeline_layout_ci.setLayoutCount = 1;
7505 pipeline_layout_ci.pSetLayouts = &ds_layout;
7506
7507 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007508 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007509 ASSERT_VK_SUCCESS(err);
7510
7511 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7512 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7513 vp_state_ci.scissorCount = 1;
7514 vp_state_ci.pScissors = NULL;
7515 vp_state_ci.viewportCount = 1;
7516 vp_state_ci.pViewports = NULL;
7517
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007518 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007519 // Set scissor as dynamic to avoid that error
7520 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7521 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7522 dyn_state_ci.dynamicStateCount = 2;
7523 dyn_state_ci.pDynamicStates = dynamic_states;
7524
7525 VkPipelineShaderStageCreateInfo shaderStages[2];
7526 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7527
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007528 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7529 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007530 this); // TODO - We shouldn't need a fragment shader
7531 // but add it to be able to run on more devices
7532 shaderStages[0] = vs.GetStageCreateInfo();
7533 shaderStages[1] = fs.GetStageCreateInfo();
7534
7535 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7536 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7537 vi_ci.pNext = nullptr;
7538 vi_ci.vertexBindingDescriptionCount = 0;
7539 vi_ci.pVertexBindingDescriptions = nullptr;
7540 vi_ci.vertexAttributeDescriptionCount = 0;
7541 vi_ci.pVertexAttributeDescriptions = nullptr;
7542
7543 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7544 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7545 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7546
7547 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7548 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7549 rs_ci.pNext = nullptr;
7550
Mark Young47107952016-05-02 15:59:55 -06007551 // Check too low (line width of -1.0f).
7552 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007553
7554 VkPipelineColorBlendAttachmentState att = {};
7555 att.blendEnable = VK_FALSE;
7556 att.colorWriteMask = 0xf;
7557
7558 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7559 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7560 cb_ci.pNext = nullptr;
7561 cb_ci.attachmentCount = 1;
7562 cb_ci.pAttachments = &att;
7563
7564 VkGraphicsPipelineCreateInfo gp_ci = {};
7565 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7566 gp_ci.stageCount = 2;
7567 gp_ci.pStages = shaderStages;
7568 gp_ci.pVertexInputState = &vi_ci;
7569 gp_ci.pInputAssemblyState = &ia_ci;
7570 gp_ci.pViewportState = &vp_state_ci;
7571 gp_ci.pRasterizationState = &rs_ci;
7572 gp_ci.pColorBlendState = &cb_ci;
7573 gp_ci.pDynamicState = &dyn_state_ci;
7574 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7575 gp_ci.layout = pipeline_layout;
7576 gp_ci.renderPass = renderPass();
7577
7578 VkPipelineCacheCreateInfo pc_ci = {};
7579 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7580
7581 VkPipeline pipeline;
7582 VkPipelineCache pipelineCache;
7583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007585 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007586 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007587
7588 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007589 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007590
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007592
7593 // Check too high (line width of 65536.0f).
7594 rs_ci.lineWidth = 65536.0f;
7595
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007596 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007597 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007598 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007599
7600 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007601 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007602
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007604
7605 dyn_state_ci.dynamicStateCount = 3;
7606
7607 rs_ci.lineWidth = 1.0f;
7608
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007609 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007610 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007611 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007612 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007613 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007614
7615 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007616 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007617 m_errorMonitor->VerifyFound();
7618
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007620
7621 // Check too high with dynamic setting.
7622 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7623 m_errorMonitor->VerifyFound();
7624 EndCommandBuffer();
7625
7626 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7627 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7628 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7629 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007630 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007631}
7632
Karl Schultz6addd812016-02-02 17:17:23 -07007633TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007634 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7636 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007637
7638 ASSERT_NO_FATAL_FAILURE(InitState());
7639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007640
Tony Barbourfe3351b2015-07-28 10:17:20 -06007641 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007642 // Don't care about RenderPass handle b/c error should be flagged before
7643 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007644 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007645
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007646 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007647}
7648
Karl Schultz6addd812016-02-02 17:17:23 -07007649TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007650 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7652 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007653
7654 ASSERT_NO_FATAL_FAILURE(InitState());
7655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007656
Tony Barbourfe3351b2015-07-28 10:17:20 -06007657 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007658 // Just create a dummy Renderpass that's non-NULL so we can get to the
7659 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007660 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007661
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007662 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007663}
7664
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007665TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7666 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7667 "the number of renderPass attachments that use loadOp"
7668 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7669
7670 ASSERT_NO_FATAL_FAILURE(InitState());
7671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7672
7673 // Create a renderPass with a single attachment that uses loadOp CLEAR
7674 VkAttachmentReference attach = {};
7675 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7676 VkSubpassDescription subpass = {};
7677 subpass.inputAttachmentCount = 1;
7678 subpass.pInputAttachments = &attach;
7679 VkRenderPassCreateInfo rpci = {};
7680 rpci.subpassCount = 1;
7681 rpci.pSubpasses = &subpass;
7682 rpci.attachmentCount = 1;
7683 VkAttachmentDescription attach_desc = {};
7684 attach_desc.format = VK_FORMAT_UNDEFINED;
7685 // Set loadOp to CLEAR
7686 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7687 rpci.pAttachments = &attach_desc;
7688 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7689 VkRenderPass rp;
7690 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7691
7692 VkCommandBufferInheritanceInfo hinfo = {};
7693 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7694 hinfo.renderPass = VK_NULL_HANDLE;
7695 hinfo.subpass = 0;
7696 hinfo.framebuffer = VK_NULL_HANDLE;
7697 hinfo.occlusionQueryEnable = VK_FALSE;
7698 hinfo.queryFlags = 0;
7699 hinfo.pipelineStatistics = 0;
7700 VkCommandBufferBeginInfo info = {};
7701 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7702 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7703 info.pInheritanceInfo = &hinfo;
7704
7705 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7706 VkRenderPassBeginInfo rp_begin = {};
7707 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7708 rp_begin.pNext = NULL;
7709 rp_begin.renderPass = renderPass();
7710 rp_begin.framebuffer = framebuffer();
7711 rp_begin.clearValueCount = 0; // Should be 1
7712
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7714 "there must be at least 1 entries in "
7715 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007717 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007718
7719 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007720
7721 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007722}
7723
Cody Northrop3bb4d962016-05-09 16:15:57 -06007724TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7725
7726 TEST_DESCRIPTION("End a command buffer with an active render pass");
7727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7729 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007730
7731 ASSERT_NO_FATAL_FAILURE(InitState());
7732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7733
7734 // The framework's BeginCommandBuffer calls CreateRenderPass
7735 BeginCommandBuffer();
7736
7737 // Call directly into vkEndCommandBuffer instead of the
7738 // the framework's EndCommandBuffer, which inserts a
7739 // vkEndRenderPass
7740 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7741
7742 m_errorMonitor->VerifyFound();
7743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007744 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7745 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007746}
7747
Karl Schultz6addd812016-02-02 17:17:23 -07007748TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007749 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7751 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007752
7753 ASSERT_NO_FATAL_FAILURE(InitState());
7754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007755
7756 // Renderpass is started here
7757 BeginCommandBuffer();
7758
7759 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007760 vk_testing::Buffer dstBuffer;
7761 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007762
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007763 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007764
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007765 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007766}
7767
Karl Schultz6addd812016-02-02 17:17:23 -07007768TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007769 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7771 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007772
7773 ASSERT_NO_FATAL_FAILURE(InitState());
7774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007775
7776 // Renderpass is started here
7777 BeginCommandBuffer();
7778
7779 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007780 vk_testing::Buffer dstBuffer;
7781 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007782
Karl Schultz6addd812016-02-02 17:17:23 -07007783 VkDeviceSize dstOffset = 0;
7784 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007785 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007786
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007787 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007788
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007789 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007790}
7791
Karl Schultz6addd812016-02-02 17:17:23 -07007792TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007793 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7795 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007796
7797 ASSERT_NO_FATAL_FAILURE(InitState());
7798 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007799
7800 // Renderpass is started here
7801 BeginCommandBuffer();
7802
Michael Lentine0a369f62016-02-03 16:51:46 -06007803 VkClearColorValue clear_color;
7804 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007805 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7806 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7807 const int32_t tex_width = 32;
7808 const int32_t tex_height = 32;
7809 VkImageCreateInfo image_create_info = {};
7810 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7811 image_create_info.pNext = NULL;
7812 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7813 image_create_info.format = tex_format;
7814 image_create_info.extent.width = tex_width;
7815 image_create_info.extent.height = tex_height;
7816 image_create_info.extent.depth = 1;
7817 image_create_info.mipLevels = 1;
7818 image_create_info.arrayLayers = 1;
7819 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7820 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7821 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007822
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007823 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007824 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007825
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007826 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007827
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007828 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007829
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007830 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007831}
7832
Karl Schultz6addd812016-02-02 17:17:23 -07007833TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007834 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7836 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007837
7838 ASSERT_NO_FATAL_FAILURE(InitState());
7839 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007840
7841 // Renderpass is started here
7842 BeginCommandBuffer();
7843
7844 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007845 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007846 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7847 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7848 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7849 image_create_info.extent.width = 64;
7850 image_create_info.extent.height = 64;
7851 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7852 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007853
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007854 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007855 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007857 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007859 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7860 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007861
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007862 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007863}
7864
Karl Schultz6addd812016-02-02 17:17:23 -07007865TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007866 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007867 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7870 "must be issued inside an active "
7871 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007872
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007873 ASSERT_NO_FATAL_FAILURE(InitState());
7874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007875
7876 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007877 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007878 ASSERT_VK_SUCCESS(err);
7879
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007880 VkClearAttachment color_attachment;
7881 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7882 color_attachment.clearValue.color.float32[0] = 0;
7883 color_attachment.clearValue.color.float32[1] = 0;
7884 color_attachment.clearValue.color.float32[2] = 0;
7885 color_attachment.clearValue.color.float32[3] = 0;
7886 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007887 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007888 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007889
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007890 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007891}
7892
Chris Forbes3b97e932016-09-07 11:29:24 +12007893TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
7894 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
7895 "called too many times in a renderpass instance");
7896
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
7898 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12007899
7900 ASSERT_NO_FATAL_FAILURE(InitState());
7901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7902
7903 BeginCommandBuffer();
7904
7905 // error here.
7906 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
7907 m_errorMonitor->VerifyFound();
7908
7909 EndCommandBuffer();
7910}
7911
Chris Forbes6d624702016-09-07 13:57:05 +12007912TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
7913 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
7914 "called before the final subpass has been reached");
7915
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
7917 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12007918
7919 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007920 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
7921 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12007922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12007924
7925 VkRenderPass rp;
7926 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
7927 ASSERT_VK_SUCCESS(err);
7928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007929 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12007930
7931 VkFramebuffer fb;
7932 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
7933 ASSERT_VK_SUCCESS(err);
7934
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007935 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12007936
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007937 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 +12007938
7939 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
7940
7941 // Error here.
7942 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7943 m_errorMonitor->VerifyFound();
7944
7945 // Clean up.
7946 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
7947 vkDestroyRenderPass(m_device->device(), rp, nullptr);
7948}
7949
Karl Schultz9e66a292016-04-21 15:57:51 -06007950TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7951 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7953 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06007954
7955 ASSERT_NO_FATAL_FAILURE(InitState());
7956 BeginCommandBuffer();
7957
7958 VkBufferMemoryBarrier buf_barrier = {};
7959 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7960 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7961 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7962 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7963 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7964 buf_barrier.buffer = VK_NULL_HANDLE;
7965 buf_barrier.offset = 0;
7966 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007967 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7968 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06007969
7970 m_errorMonitor->VerifyFound();
7971}
7972
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007973TEST_F(VkLayerTest, InvalidBarriers) {
7974 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7975
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007977
7978 ASSERT_NO_FATAL_FAILURE(InitState());
7979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7980
7981 VkMemoryBarrier mem_barrier = {};
7982 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7983 mem_barrier.pNext = NULL;
7984 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7985 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7986 BeginCommandBuffer();
7987 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007988 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007989 &mem_barrier, 0, nullptr, 0, nullptr);
7990 m_errorMonitor->VerifyFound();
7991
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007993 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007994 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 -06007995 ASSERT_TRUE(image.initialized());
7996 VkImageMemoryBarrier img_barrier = {};
7997 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7998 img_barrier.pNext = NULL;
7999 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8000 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8001 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8002 // New layout can't be UNDEFINED
8003 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8004 img_barrier.image = image.handle();
8005 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8006 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8007 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8008 img_barrier.subresourceRange.baseArrayLayer = 0;
8009 img_barrier.subresourceRange.baseMipLevel = 0;
8010 img_barrier.subresourceRange.layerCount = 1;
8011 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008012 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8013 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008014 m_errorMonitor->VerifyFound();
8015 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8018 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008019 // baseArrayLayer + layerCount must be <= image's arrayLayers
8020 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008021 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8022 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008023 m_errorMonitor->VerifyFound();
8024 img_barrier.subresourceRange.baseArrayLayer = 0;
8025
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008027 // baseMipLevel + levelCount must be <= image's mipLevels
8028 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008029 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8030 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008031 m_errorMonitor->VerifyFound();
8032 img_barrier.subresourceRange.baseMipLevel = 0;
8033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008034 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 -06008035 vk_testing::Buffer buffer;
8036 buffer.init(*m_device, 256);
8037 VkBufferMemoryBarrier buf_barrier = {};
8038 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8039 buf_barrier.pNext = NULL;
8040 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8041 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8042 buf_barrier.buffer = buffer.handle();
8043 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8044 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8045 buf_barrier.offset = 0;
8046 buf_barrier.size = VK_WHOLE_SIZE;
8047 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008048 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8049 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008050 m_errorMonitor->VerifyFound();
8051 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8052
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008054 buf_barrier.offset = 257;
8055 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008056 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8057 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008058 m_errorMonitor->VerifyFound();
8059 buf_barrier.offset = 0;
8060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008062 buf_barrier.size = 257;
8063 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008064 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8065 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008066 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008067
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008068 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008069 m_errorMonitor->SetDesiredFailureMsg(
8070 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8071 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8072 m_errorMonitor->SetDesiredFailureMsg(
8073 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8074 "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 -06008075 VkDepthStencilObj ds_image(m_device);
8076 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8077 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008078 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8079 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008080 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008081 // Use of COLOR aspect on DS image is error
8082 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008083 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8084 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008085 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008086 // Now test depth-only
8087 VkFormatProperties format_props;
8088
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008089 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8090 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8092 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8094 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008095 VkDepthStencilObj d_image(m_device);
8096 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8097 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008098 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008099 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008100 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008101 // Use of COLOR aspect on depth image is error
8102 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008103 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8104 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008105 m_errorMonitor->VerifyFound();
8106 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008107 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8108 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008109 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8111 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008112 VkDepthStencilObj s_image(m_device);
8113 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8114 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008115 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008116 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008117 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008118 // Use of COLOR aspect on depth image is error
8119 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008120 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8121 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008122 m_errorMonitor->VerifyFound();
8123 }
8124 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8126 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8128 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008129 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008130 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 -06008131 ASSERT_TRUE(c_image.initialized());
8132 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8133 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8134 img_barrier.image = c_image.handle();
8135 // Set aspect to depth (non-color)
8136 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008137 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8138 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008139 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008140}
8141
Tony Barbour18ba25c2016-09-29 13:42:40 -06008142TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8143 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8144
8145 m_errorMonitor->SetDesiredFailureMsg(
8146 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8147 "must have required access bit");
8148 ASSERT_NO_FATAL_FAILURE(InitState());
8149 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008150 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 -06008151 ASSERT_TRUE(image.initialized());
8152
8153 VkImageMemoryBarrier barrier = {};
8154 VkImageSubresourceRange range;
8155 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8156 barrier.srcAccessMask = 0;
8157 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8158 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8159 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8160 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8161 barrier.image = image.handle();
8162 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8163 range.baseMipLevel = 0;
8164 range.levelCount = 1;
8165 range.baseArrayLayer = 0;
8166 range.layerCount = 1;
8167 barrier.subresourceRange = range;
8168 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8169 cmdbuf.BeginCommandBuffer();
8170 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8171 &barrier);
8172 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8173 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8174 barrier.srcAccessMask = 0;
8175 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8176 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8177 &barrier);
8178
8179 m_errorMonitor->VerifyFound();
8180}
8181
Karl Schultz6addd812016-02-02 17:17:23 -07008182TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008183 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008184 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008187
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008188 ASSERT_NO_FATAL_FAILURE(InitState());
8189 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008190 uint32_t qfi = 0;
8191 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008192 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8193 buffCI.size = 1024;
8194 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8195 buffCI.queueFamilyIndexCount = 1;
8196 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008197
8198 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008199 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008200 ASSERT_VK_SUCCESS(err);
8201
8202 BeginCommandBuffer();
8203 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008204 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8205 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008206 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008207 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008208
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008209 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008210
Chia-I Wuf7458c52015-10-26 21:10:41 +08008211 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008212}
8213
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008214TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8215 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8217 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8218 "of the indices specified when the device was created, via the "
8219 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008220
8221 ASSERT_NO_FATAL_FAILURE(InitState());
8222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8223 VkBufferCreateInfo buffCI = {};
8224 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8225 buffCI.size = 1024;
8226 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8227 buffCI.queueFamilyIndexCount = 1;
8228 // Introduce failure by specifying invalid queue_family_index
8229 uint32_t qfi = 777;
8230 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008231 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008232
8233 VkBuffer ib;
8234 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8235
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008236 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008237 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008238}
8239
Karl Schultz6addd812016-02-02 17:17:23 -07008240TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008241TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008242 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008243
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008244 ASSERT_NO_FATAL_FAILURE(InitState());
8245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008246
Chris Forbesf29a84f2016-10-06 18:39:28 +13008247 // An empty primary command buffer
8248 VkCommandBufferObj cb(m_device, m_commandPool);
8249 cb.BeginCommandBuffer();
8250 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008251
Chris Forbesf29a84f2016-10-06 18:39:28 +13008252 m_commandBuffer->BeginCommandBuffer();
8253 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8254 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008255
Chris Forbesf29a84f2016-10-06 18:39:28 +13008256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8257 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008258 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008259}
8260
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008261TEST_F(VkLayerTest, DSUsageBitsErrors) {
8262 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8263 "that do not have correct usage bits sets.");
8264 VkResult err;
8265
8266 ASSERT_NO_FATAL_FAILURE(InitState());
8267 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8268 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8269 ds_type_count[i].type = VkDescriptorType(i);
8270 ds_type_count[i].descriptorCount = 1;
8271 }
8272 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8273 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8274 ds_pool_ci.pNext = NULL;
8275 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8276 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8277 ds_pool_ci.pPoolSizes = ds_type_count;
8278
8279 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008280 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008281 ASSERT_VK_SUCCESS(err);
8282
8283 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008284 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008285 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8286 dsl_binding[i].binding = 0;
8287 dsl_binding[i].descriptorType = VkDescriptorType(i);
8288 dsl_binding[i].descriptorCount = 1;
8289 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8290 dsl_binding[i].pImmutableSamplers = NULL;
8291 }
8292
8293 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8294 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8295 ds_layout_ci.pNext = NULL;
8296 ds_layout_ci.bindingCount = 1;
8297 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8298 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8299 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008300 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008301 ASSERT_VK_SUCCESS(err);
8302 }
8303 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8304 VkDescriptorSetAllocateInfo alloc_info = {};
8305 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8306 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8307 alloc_info.descriptorPool = ds_pool;
8308 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008309 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008310 ASSERT_VK_SUCCESS(err);
8311
8312 // Create a buffer & bufferView to be used for invalid updates
8313 VkBufferCreateInfo buff_ci = {};
8314 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8315 // This usage is not valid for any descriptor type
8316 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8317 buff_ci.size = 256;
8318 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8319 VkBuffer buffer;
8320 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8321 ASSERT_VK_SUCCESS(err);
8322
8323 VkBufferViewCreateInfo buff_view_ci = {};
8324 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8325 buff_view_ci.buffer = buffer;
8326 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8327 buff_view_ci.range = VK_WHOLE_SIZE;
8328 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008329 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008330 ASSERT_VK_SUCCESS(err);
8331
8332 // Create an image to be used for invalid updates
8333 VkImageCreateInfo image_ci = {};
8334 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8335 image_ci.imageType = VK_IMAGE_TYPE_2D;
8336 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8337 image_ci.extent.width = 64;
8338 image_ci.extent.height = 64;
8339 image_ci.extent.depth = 1;
8340 image_ci.mipLevels = 1;
8341 image_ci.arrayLayers = 1;
8342 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8343 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8344 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8345 // This usage is not valid for any descriptor type
8346 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8347 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8348 VkImage image;
8349 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8350 ASSERT_VK_SUCCESS(err);
8351 // Bind memory to image
8352 VkMemoryRequirements mem_reqs;
8353 VkDeviceMemory image_mem;
8354 bool pass;
8355 VkMemoryAllocateInfo mem_alloc = {};
8356 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8357 mem_alloc.pNext = NULL;
8358 mem_alloc.allocationSize = 0;
8359 mem_alloc.memoryTypeIndex = 0;
8360 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8361 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008362 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008363 ASSERT_TRUE(pass);
8364 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8365 ASSERT_VK_SUCCESS(err);
8366 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8367 ASSERT_VK_SUCCESS(err);
8368 // Now create view for image
8369 VkImageViewCreateInfo image_view_ci = {};
8370 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8371 image_view_ci.image = image;
8372 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8373 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8374 image_view_ci.subresourceRange.layerCount = 1;
8375 image_view_ci.subresourceRange.baseArrayLayer = 0;
8376 image_view_ci.subresourceRange.levelCount = 1;
8377 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8378 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008379 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008380 ASSERT_VK_SUCCESS(err);
8381
8382 VkDescriptorBufferInfo buff_info = {};
8383 buff_info.buffer = buffer;
8384 VkDescriptorImageInfo img_info = {};
8385 img_info.imageView = image_view;
8386 VkWriteDescriptorSet descriptor_write = {};
8387 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8388 descriptor_write.dstBinding = 0;
8389 descriptor_write.descriptorCount = 1;
8390 descriptor_write.pTexelBufferView = &buff_view;
8391 descriptor_write.pBufferInfo = &buff_info;
8392 descriptor_write.pImageInfo = &img_info;
8393
8394 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8396 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8397 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8398 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8399 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8400 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8401 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8402 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8403 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8404 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8405 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008406 // Start loop at 1 as SAMPLER desc type has no usage bit error
8407 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8408 descriptor_write.descriptorType = VkDescriptorType(i);
8409 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008412 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008413
8414 m_errorMonitor->VerifyFound();
8415 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8416 }
8417 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8418 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008419 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008420 vkDestroyImageView(m_device->device(), image_view, NULL);
8421 vkDestroyBuffer(m_device->device(), buffer, NULL);
8422 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008423 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008424 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8425}
8426
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008427TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008428 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8429 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8430 "1. offset value greater than buffer size\n"
8431 "2. range value of 0\n"
8432 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008433 VkResult err;
8434
8435 ASSERT_NO_FATAL_FAILURE(InitState());
8436 VkDescriptorPoolSize ds_type_count = {};
8437 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8438 ds_type_count.descriptorCount = 1;
8439
8440 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8441 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8442 ds_pool_ci.pNext = NULL;
8443 ds_pool_ci.maxSets = 1;
8444 ds_pool_ci.poolSizeCount = 1;
8445 ds_pool_ci.pPoolSizes = &ds_type_count;
8446
8447 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008448 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008449 ASSERT_VK_SUCCESS(err);
8450
8451 // Create layout with single uniform buffer descriptor
8452 VkDescriptorSetLayoutBinding dsl_binding = {};
8453 dsl_binding.binding = 0;
8454 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8455 dsl_binding.descriptorCount = 1;
8456 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8457 dsl_binding.pImmutableSamplers = NULL;
8458
8459 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8460 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8461 ds_layout_ci.pNext = NULL;
8462 ds_layout_ci.bindingCount = 1;
8463 ds_layout_ci.pBindings = &dsl_binding;
8464 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008465 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008466 ASSERT_VK_SUCCESS(err);
8467
8468 VkDescriptorSet descriptor_set = {};
8469 VkDescriptorSetAllocateInfo alloc_info = {};
8470 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8471 alloc_info.descriptorSetCount = 1;
8472 alloc_info.descriptorPool = ds_pool;
8473 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008475 ASSERT_VK_SUCCESS(err);
8476
8477 // Create a buffer to be used for invalid updates
8478 VkBufferCreateInfo buff_ci = {};
8479 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8480 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8481 buff_ci.size = 256;
8482 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8483 VkBuffer buffer;
8484 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8485 ASSERT_VK_SUCCESS(err);
8486 // Have to bind memory to buffer before descriptor update
8487 VkMemoryAllocateInfo mem_alloc = {};
8488 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8489 mem_alloc.pNext = NULL;
8490 mem_alloc.allocationSize = 256;
8491 mem_alloc.memoryTypeIndex = 0;
8492
8493 VkMemoryRequirements mem_reqs;
8494 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008495 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008496 if (!pass) {
8497 vkDestroyBuffer(m_device->device(), buffer, NULL);
8498 return;
8499 }
8500
8501 VkDeviceMemory mem;
8502 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8503 ASSERT_VK_SUCCESS(err);
8504 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8505 ASSERT_VK_SUCCESS(err);
8506
8507 VkDescriptorBufferInfo buff_info = {};
8508 buff_info.buffer = buffer;
8509 // First make offset 1 larger than buffer size
8510 buff_info.offset = 257;
8511 buff_info.range = VK_WHOLE_SIZE;
8512 VkWriteDescriptorSet descriptor_write = {};
8513 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8514 descriptor_write.dstBinding = 0;
8515 descriptor_write.descriptorCount = 1;
8516 descriptor_write.pTexelBufferView = nullptr;
8517 descriptor_write.pBufferInfo = &buff_info;
8518 descriptor_write.pImageInfo = nullptr;
8519
8520 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8521 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008523
8524 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8525
8526 m_errorMonitor->VerifyFound();
8527 // Now cause error due to range of 0
8528 buff_info.offset = 0;
8529 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8531 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008532
8533 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8534
8535 m_errorMonitor->VerifyFound();
8536 // Now cause error due to range exceeding buffer size - offset
8537 buff_info.offset = 128;
8538 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008539 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 -06008540
8541 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8542
8543 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008544 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008545 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8546 vkDestroyBuffer(m_device->device(), buffer, NULL);
8547 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8548 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8549}
8550
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008551TEST_F(VkLayerTest, DSAspectBitsErrors) {
8552 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8553 // are set, but could expand this test to hit more cases.
8554 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8555 "that do not have correct aspect bits sets.");
8556 VkResult err;
8557
8558 ASSERT_NO_FATAL_FAILURE(InitState());
8559 VkDescriptorPoolSize ds_type_count = {};
8560 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8561 ds_type_count.descriptorCount = 1;
8562
8563 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8564 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8565 ds_pool_ci.pNext = NULL;
8566 ds_pool_ci.maxSets = 5;
8567 ds_pool_ci.poolSizeCount = 1;
8568 ds_pool_ci.pPoolSizes = &ds_type_count;
8569
8570 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008571 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008572 ASSERT_VK_SUCCESS(err);
8573
8574 VkDescriptorSetLayoutBinding dsl_binding = {};
8575 dsl_binding.binding = 0;
8576 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8577 dsl_binding.descriptorCount = 1;
8578 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8579 dsl_binding.pImmutableSamplers = NULL;
8580
8581 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8582 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8583 ds_layout_ci.pNext = NULL;
8584 ds_layout_ci.bindingCount = 1;
8585 ds_layout_ci.pBindings = &dsl_binding;
8586 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008587 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008588 ASSERT_VK_SUCCESS(err);
8589
8590 VkDescriptorSet descriptor_set = {};
8591 VkDescriptorSetAllocateInfo alloc_info = {};
8592 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8593 alloc_info.descriptorSetCount = 1;
8594 alloc_info.descriptorPool = ds_pool;
8595 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008596 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008597 ASSERT_VK_SUCCESS(err);
8598
8599 // Create an image to be used for invalid updates
8600 VkImageCreateInfo image_ci = {};
8601 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8602 image_ci.imageType = VK_IMAGE_TYPE_2D;
8603 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8604 image_ci.extent.width = 64;
8605 image_ci.extent.height = 64;
8606 image_ci.extent.depth = 1;
8607 image_ci.mipLevels = 1;
8608 image_ci.arrayLayers = 1;
8609 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8610 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8611 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8612 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8613 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8614 VkImage image;
8615 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8616 ASSERT_VK_SUCCESS(err);
8617 // Bind memory to image
8618 VkMemoryRequirements mem_reqs;
8619 VkDeviceMemory image_mem;
8620 bool pass;
8621 VkMemoryAllocateInfo mem_alloc = {};
8622 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8623 mem_alloc.pNext = NULL;
8624 mem_alloc.allocationSize = 0;
8625 mem_alloc.memoryTypeIndex = 0;
8626 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8627 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008628 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008629 ASSERT_TRUE(pass);
8630 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8631 ASSERT_VK_SUCCESS(err);
8632 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8633 ASSERT_VK_SUCCESS(err);
8634 // Now create view for image
8635 VkImageViewCreateInfo image_view_ci = {};
8636 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8637 image_view_ci.image = image;
8638 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8639 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8640 image_view_ci.subresourceRange.layerCount = 1;
8641 image_view_ci.subresourceRange.baseArrayLayer = 0;
8642 image_view_ci.subresourceRange.levelCount = 1;
8643 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008644 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008645
8646 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008648 ASSERT_VK_SUCCESS(err);
8649
8650 VkDescriptorImageInfo img_info = {};
8651 img_info.imageView = image_view;
8652 VkWriteDescriptorSet descriptor_write = {};
8653 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8654 descriptor_write.dstBinding = 0;
8655 descriptor_write.descriptorCount = 1;
8656 descriptor_write.pTexelBufferView = NULL;
8657 descriptor_write.pBufferInfo = NULL;
8658 descriptor_write.pImageInfo = &img_info;
8659 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8660 descriptor_write.dstSet = descriptor_set;
8661 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8662 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008664
8665 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8666
8667 m_errorMonitor->VerifyFound();
8668 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8669 vkDestroyImage(m_device->device(), image, NULL);
8670 vkFreeMemory(m_device->device(), image_mem, NULL);
8671 vkDestroyImageView(m_device->device(), image_view, NULL);
8672 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8673 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8674}
8675
Karl Schultz6addd812016-02-02 17:17:23 -07008676TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008677 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008678 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8681 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8682 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008683
Tobin Ehlis3b780662015-05-28 12:11:26 -06008684 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008685 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008686 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008687 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8688 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008689
8690 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008691 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8692 ds_pool_ci.pNext = NULL;
8693 ds_pool_ci.maxSets = 1;
8694 ds_pool_ci.poolSizeCount = 1;
8695 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008696
Tobin Ehlis3b780662015-05-28 12:11:26 -06008697 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008698 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008699 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008700 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008701 dsl_binding.binding = 0;
8702 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8703 dsl_binding.descriptorCount = 1;
8704 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8705 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008706
Tony Barboureb254902015-07-15 12:50:33 -06008707 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008708 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8709 ds_layout_ci.pNext = NULL;
8710 ds_layout_ci.bindingCount = 1;
8711 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008712
Tobin Ehlis3b780662015-05-28 12:11:26 -06008713 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008714 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008715 ASSERT_VK_SUCCESS(err);
8716
8717 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008718 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008719 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008720 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008721 alloc_info.descriptorPool = ds_pool;
8722 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008723 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008724 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008725
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008726 VkSamplerCreateInfo sampler_ci = {};
8727 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8728 sampler_ci.pNext = NULL;
8729 sampler_ci.magFilter = VK_FILTER_NEAREST;
8730 sampler_ci.minFilter = VK_FILTER_NEAREST;
8731 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8732 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8733 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8734 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8735 sampler_ci.mipLodBias = 1.0;
8736 sampler_ci.anisotropyEnable = VK_FALSE;
8737 sampler_ci.maxAnisotropy = 1;
8738 sampler_ci.compareEnable = VK_FALSE;
8739 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8740 sampler_ci.minLod = 1.0;
8741 sampler_ci.maxLod = 1.0;
8742 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8743 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8744 VkSampler sampler;
8745 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8746 ASSERT_VK_SUCCESS(err);
8747
8748 VkDescriptorImageInfo info = {};
8749 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008750
8751 VkWriteDescriptorSet descriptor_write;
8752 memset(&descriptor_write, 0, sizeof(descriptor_write));
8753 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008754 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008755 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008756 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008757 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008758 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008759
8760 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8761
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008762 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008763
Chia-I Wuf7458c52015-10-26 21:10:41 +08008764 vkDestroySampler(m_device->device(), sampler, NULL);
8765 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8766 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008767}
8768
Karl Schultz6addd812016-02-02 17:17:23 -07008769TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008770 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008771 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008772
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8774 " binding #0 with 1 total descriptors but update of 1 descriptors "
8775 "starting at binding offset of 0 combined with update array element "
8776 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008777
Tobin Ehlis3b780662015-05-28 12:11:26 -06008778 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008779 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008780 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008781 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8782 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008783
8784 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008785 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8786 ds_pool_ci.pNext = NULL;
8787 ds_pool_ci.maxSets = 1;
8788 ds_pool_ci.poolSizeCount = 1;
8789 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008790
Tobin Ehlis3b780662015-05-28 12:11:26 -06008791 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008792 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008793 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008794
Tony Barboureb254902015-07-15 12:50:33 -06008795 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008796 dsl_binding.binding = 0;
8797 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8798 dsl_binding.descriptorCount = 1;
8799 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8800 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008801
8802 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008803 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8804 ds_layout_ci.pNext = NULL;
8805 ds_layout_ci.bindingCount = 1;
8806 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008807
Tobin Ehlis3b780662015-05-28 12:11:26 -06008808 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008809 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008810 ASSERT_VK_SUCCESS(err);
8811
8812 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008813 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008814 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008815 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008816 alloc_info.descriptorPool = ds_pool;
8817 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008818 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008819 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008820
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008821 // Correctly update descriptor to avoid "NOT_UPDATED" error
8822 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008824 buff_info.offset = 0;
8825 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008826
8827 VkWriteDescriptorSet descriptor_write;
8828 memset(&descriptor_write, 0, sizeof(descriptor_write));
8829 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008830 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008831 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008832 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008833 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8834 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008835
8836 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8837
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008838 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008839
Chia-I Wuf7458c52015-10-26 21:10:41 +08008840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008842}
8843
Karl Schultz6addd812016-02-02 17:17:23 -07008844TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8845 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8846 // index 2
8847 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008850
Tobin Ehlis3b780662015-05-28 12:11:26 -06008851 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008852 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008853 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008854 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8855 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008856
8857 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008858 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8859 ds_pool_ci.pNext = NULL;
8860 ds_pool_ci.maxSets = 1;
8861 ds_pool_ci.poolSizeCount = 1;
8862 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008863
Tobin Ehlis3b780662015-05-28 12:11:26 -06008864 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008865 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008866 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008867
Tony Barboureb254902015-07-15 12:50:33 -06008868 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008869 dsl_binding.binding = 0;
8870 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8871 dsl_binding.descriptorCount = 1;
8872 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8873 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008874
8875 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008876 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8877 ds_layout_ci.pNext = NULL;
8878 ds_layout_ci.bindingCount = 1;
8879 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008880 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008881 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008882 ASSERT_VK_SUCCESS(err);
8883
8884 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008885 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008886 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008887 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008888 alloc_info.descriptorPool = ds_pool;
8889 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008890 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008891 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008892
Tony Barboureb254902015-07-15 12:50:33 -06008893 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008894 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8895 sampler_ci.pNext = NULL;
8896 sampler_ci.magFilter = VK_FILTER_NEAREST;
8897 sampler_ci.minFilter = VK_FILTER_NEAREST;
8898 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8899 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8900 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8901 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8902 sampler_ci.mipLodBias = 1.0;
8903 sampler_ci.anisotropyEnable = VK_FALSE;
8904 sampler_ci.maxAnisotropy = 1;
8905 sampler_ci.compareEnable = VK_FALSE;
8906 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8907 sampler_ci.minLod = 1.0;
8908 sampler_ci.maxLod = 1.0;
8909 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8910 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008911
Tobin Ehlis3b780662015-05-28 12:11:26 -06008912 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008913 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008914 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008915
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008916 VkDescriptorImageInfo info = {};
8917 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008918
8919 VkWriteDescriptorSet descriptor_write;
8920 memset(&descriptor_write, 0, sizeof(descriptor_write));
8921 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008922 descriptor_write.dstSet = descriptorSet;
8923 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008924 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008925 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008926 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008927 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008928
8929 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8930
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008931 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008932
Chia-I Wuf7458c52015-10-26 21:10:41 +08008933 vkDestroySampler(m_device->device(), sampler, NULL);
8934 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8935 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008936}
8937
Karl Schultz6addd812016-02-02 17:17:23 -07008938TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8939 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8940 // types
8941 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008942
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008943 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 -06008944
Tobin Ehlis3b780662015-05-28 12:11:26 -06008945 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008946
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008947 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008948 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8949 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008950
8951 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008952 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8953 ds_pool_ci.pNext = NULL;
8954 ds_pool_ci.maxSets = 1;
8955 ds_pool_ci.poolSizeCount = 1;
8956 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008957
Tobin Ehlis3b780662015-05-28 12:11:26 -06008958 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008959 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008960 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008961 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008962 dsl_binding.binding = 0;
8963 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8964 dsl_binding.descriptorCount = 1;
8965 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8966 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008967
Tony Barboureb254902015-07-15 12:50:33 -06008968 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008969 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8970 ds_layout_ci.pNext = NULL;
8971 ds_layout_ci.bindingCount = 1;
8972 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008973
Tobin Ehlis3b780662015-05-28 12:11:26 -06008974 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008975 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008976 ASSERT_VK_SUCCESS(err);
8977
8978 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008979 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008980 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008981 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008982 alloc_info.descriptorPool = ds_pool;
8983 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008984 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008985 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008986
Tony Barboureb254902015-07-15 12:50:33 -06008987 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008988 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8989 sampler_ci.pNext = NULL;
8990 sampler_ci.magFilter = VK_FILTER_NEAREST;
8991 sampler_ci.minFilter = VK_FILTER_NEAREST;
8992 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8993 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8994 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8995 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8996 sampler_ci.mipLodBias = 1.0;
8997 sampler_ci.anisotropyEnable = VK_FALSE;
8998 sampler_ci.maxAnisotropy = 1;
8999 sampler_ci.compareEnable = VK_FALSE;
9000 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9001 sampler_ci.minLod = 1.0;
9002 sampler_ci.maxLod = 1.0;
9003 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9004 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009005 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009006 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009007 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009008
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009009 VkDescriptorImageInfo info = {};
9010 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009011
9012 VkWriteDescriptorSet descriptor_write;
9013 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009014 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009015 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009016 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009017 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009018 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009019 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009020
9021 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9022
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009023 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009024
Chia-I Wuf7458c52015-10-26 21:10:41 +08009025 vkDestroySampler(m_device->device(), sampler, NULL);
9026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009028}
9029
Karl Schultz6addd812016-02-02 17:17:23 -07009030TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009031 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009032 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9035 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009036
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009037 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009038 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9039 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009040 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009041 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9042 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009043
9044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9046 ds_pool_ci.pNext = NULL;
9047 ds_pool_ci.maxSets = 1;
9048 ds_pool_ci.poolSizeCount = 1;
9049 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009050
9051 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009052 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009053 ASSERT_VK_SUCCESS(err);
9054
9055 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009056 dsl_binding.binding = 0;
9057 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9058 dsl_binding.descriptorCount = 1;
9059 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9060 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009061
9062 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009063 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9064 ds_layout_ci.pNext = NULL;
9065 ds_layout_ci.bindingCount = 1;
9066 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009067 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009068 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009069 ASSERT_VK_SUCCESS(err);
9070
9071 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009072 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009073 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009074 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009075 alloc_info.descriptorPool = ds_pool;
9076 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009077 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009078 ASSERT_VK_SUCCESS(err);
9079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009080 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009081
9082 VkDescriptorImageInfo descriptor_info;
9083 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9084 descriptor_info.sampler = sampler;
9085
9086 VkWriteDescriptorSet descriptor_write;
9087 memset(&descriptor_write, 0, sizeof(descriptor_write));
9088 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009089 descriptor_write.dstSet = descriptorSet;
9090 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009091 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009092 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9093 descriptor_write.pImageInfo = &descriptor_info;
9094
9095 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9096
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009097 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009098
Chia-I Wuf7458c52015-10-26 21:10:41 +08009099 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9100 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009101}
9102
Karl Schultz6addd812016-02-02 17:17:23 -07009103TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9104 // Create a single combined Image/Sampler descriptor and send it an invalid
9105 // imageView
9106 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009107
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9109 "image sampler descriptor failed due "
9110 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009111
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009112 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009113 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009114 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9115 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009116
9117 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009118 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9119 ds_pool_ci.pNext = NULL;
9120 ds_pool_ci.maxSets = 1;
9121 ds_pool_ci.poolSizeCount = 1;
9122 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009123
9124 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009125 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009126 ASSERT_VK_SUCCESS(err);
9127
9128 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009129 dsl_binding.binding = 0;
9130 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9131 dsl_binding.descriptorCount = 1;
9132 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9133 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009134
9135 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009136 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9137 ds_layout_ci.pNext = NULL;
9138 ds_layout_ci.bindingCount = 1;
9139 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009140 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009141 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009142 ASSERT_VK_SUCCESS(err);
9143
9144 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009145 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009146 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009147 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009148 alloc_info.descriptorPool = ds_pool;
9149 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009150 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009151 ASSERT_VK_SUCCESS(err);
9152
9153 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009154 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9155 sampler_ci.pNext = NULL;
9156 sampler_ci.magFilter = VK_FILTER_NEAREST;
9157 sampler_ci.minFilter = VK_FILTER_NEAREST;
9158 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9159 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9160 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9161 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9162 sampler_ci.mipLodBias = 1.0;
9163 sampler_ci.anisotropyEnable = VK_FALSE;
9164 sampler_ci.maxAnisotropy = 1;
9165 sampler_ci.compareEnable = VK_FALSE;
9166 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9167 sampler_ci.minLod = 1.0;
9168 sampler_ci.maxLod = 1.0;
9169 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9170 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009171
9172 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009173 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009174 ASSERT_VK_SUCCESS(err);
9175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009176 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009177
9178 VkDescriptorImageInfo descriptor_info;
9179 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9180 descriptor_info.sampler = sampler;
9181 descriptor_info.imageView = view;
9182
9183 VkWriteDescriptorSet descriptor_write;
9184 memset(&descriptor_write, 0, sizeof(descriptor_write));
9185 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009186 descriptor_write.dstSet = descriptorSet;
9187 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009188 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009189 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9190 descriptor_write.pImageInfo = &descriptor_info;
9191
9192 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9193
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009194 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009195
Chia-I Wuf7458c52015-10-26 21:10:41 +08009196 vkDestroySampler(m_device->device(), sampler, NULL);
9197 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9198 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009199}
9200
Karl Schultz6addd812016-02-02 17:17:23 -07009201TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9202 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9203 // into the other
9204 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009205
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9207 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9208 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009209
Tobin Ehlis04356f92015-10-27 16:35:27 -06009210 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009211 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009212 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009213 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9214 ds_type_count[0].descriptorCount = 1;
9215 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9216 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009217
9218 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009219 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9220 ds_pool_ci.pNext = NULL;
9221 ds_pool_ci.maxSets = 1;
9222 ds_pool_ci.poolSizeCount = 2;
9223 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009224
9225 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009226 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009227 ASSERT_VK_SUCCESS(err);
9228 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009229 dsl_binding[0].binding = 0;
9230 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9231 dsl_binding[0].descriptorCount = 1;
9232 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9233 dsl_binding[0].pImmutableSamplers = NULL;
9234 dsl_binding[1].binding = 1;
9235 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9236 dsl_binding[1].descriptorCount = 1;
9237 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9238 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009239
9240 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009241 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9242 ds_layout_ci.pNext = NULL;
9243 ds_layout_ci.bindingCount = 2;
9244 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009245
9246 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009247 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009248 ASSERT_VK_SUCCESS(err);
9249
9250 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009251 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009252 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009253 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009254 alloc_info.descriptorPool = ds_pool;
9255 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009256 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009257 ASSERT_VK_SUCCESS(err);
9258
9259 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009260 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9261 sampler_ci.pNext = NULL;
9262 sampler_ci.magFilter = VK_FILTER_NEAREST;
9263 sampler_ci.minFilter = VK_FILTER_NEAREST;
9264 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9265 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9266 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9267 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9268 sampler_ci.mipLodBias = 1.0;
9269 sampler_ci.anisotropyEnable = VK_FALSE;
9270 sampler_ci.maxAnisotropy = 1;
9271 sampler_ci.compareEnable = VK_FALSE;
9272 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9273 sampler_ci.minLod = 1.0;
9274 sampler_ci.maxLod = 1.0;
9275 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9276 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009277
9278 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009279 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009280 ASSERT_VK_SUCCESS(err);
9281
9282 VkDescriptorImageInfo info = {};
9283 info.sampler = sampler;
9284
9285 VkWriteDescriptorSet descriptor_write;
9286 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9287 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009288 descriptor_write.dstSet = descriptorSet;
9289 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009290 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009291 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9292 descriptor_write.pImageInfo = &info;
9293 // This write update should succeed
9294 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9295 // Now perform a copy update that fails due to type mismatch
9296 VkCopyDescriptorSet copy_ds_update;
9297 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9298 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9299 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009300 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009301 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009302 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009303 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009304 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9305
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009306 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009307 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009308 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 -06009309 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9310 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9311 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009312 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009313 copy_ds_update.dstSet = descriptorSet;
9314 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009315 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009316 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9317
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009318 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009319
Tobin Ehlis04356f92015-10-27 16:35:27 -06009320 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9322 "update array offset of 0 and update of "
9323 "5 descriptors oversteps total number "
9324 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009325
Tobin Ehlis04356f92015-10-27 16:35:27 -06009326 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9327 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9328 copy_ds_update.srcSet = descriptorSet;
9329 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009330 copy_ds_update.dstSet = descriptorSet;
9331 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009332 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009333 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9334
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009335 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009336
Chia-I Wuf7458c52015-10-26 21:10:41 +08009337 vkDestroySampler(m_device->device(), sampler, NULL);
9338 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9339 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009340}
9341
Karl Schultz6addd812016-02-02 17:17:23 -07009342TEST_F(VkLayerTest, NumSamplesMismatch) {
9343 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9344 // sampleCount
9345 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009346
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009348
Tobin Ehlis3b780662015-05-28 12:11:26 -06009349 ASSERT_NO_FATAL_FAILURE(InitState());
9350 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009351 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009352 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009353 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009354
9355 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009356 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9357 ds_pool_ci.pNext = NULL;
9358 ds_pool_ci.maxSets = 1;
9359 ds_pool_ci.poolSizeCount = 1;
9360 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009361
Tobin Ehlis3b780662015-05-28 12:11:26 -06009362 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009363 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009364 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009365
Tony Barboureb254902015-07-15 12:50:33 -06009366 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009367 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009368 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009369 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009370 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9371 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009372
Tony Barboureb254902015-07-15 12:50:33 -06009373 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9374 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9375 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009376 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009377 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009378
Tobin Ehlis3b780662015-05-28 12:11:26 -06009379 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009380 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009381 ASSERT_VK_SUCCESS(err);
9382
9383 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009384 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009385 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009386 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009387 alloc_info.descriptorPool = ds_pool;
9388 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009389 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009390 ASSERT_VK_SUCCESS(err);
9391
Tony Barboureb254902015-07-15 12:50:33 -06009392 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009393 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009394 pipe_ms_state_ci.pNext = NULL;
9395 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9396 pipe_ms_state_ci.sampleShadingEnable = 0;
9397 pipe_ms_state_ci.minSampleShading = 1.0;
9398 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009399
Tony Barboureb254902015-07-15 12:50:33 -06009400 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009401 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9402 pipeline_layout_ci.pNext = NULL;
9403 pipeline_layout_ci.setLayoutCount = 1;
9404 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009405
9406 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009407 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009408 ASSERT_VK_SUCCESS(err);
9409
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009410 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9411 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9412 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009413 VkPipelineObj pipe(m_device);
9414 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009415 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009416 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009417 pipe.SetMSAA(&pipe_ms_state_ci);
9418 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009419
Tony Barbourfe3351b2015-07-28 10:17:20 -06009420 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009421 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009422
Mark Young29927482016-05-04 14:38:51 -06009423 // Render triangle (the error should trigger on the attempt to draw).
9424 Draw(3, 1, 0, 0);
9425
9426 // Finalize recording of the command buffer
9427 EndCommandBuffer();
9428
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009429 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009430
Chia-I Wuf7458c52015-10-26 21:10:41 +08009431 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9432 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9433 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009434}
Mark Young29927482016-05-04 14:38:51 -06009435
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009436TEST_F(VkLayerTest, RenderPassIncompatible) {
9437 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9438 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009439 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009440 VkResult err;
9441
9442 ASSERT_NO_FATAL_FAILURE(InitState());
9443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9444
9445 VkDescriptorSetLayoutBinding dsl_binding = {};
9446 dsl_binding.binding = 0;
9447 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9448 dsl_binding.descriptorCount = 1;
9449 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9450 dsl_binding.pImmutableSamplers = NULL;
9451
9452 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9453 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9454 ds_layout_ci.pNext = NULL;
9455 ds_layout_ci.bindingCount = 1;
9456 ds_layout_ci.pBindings = &dsl_binding;
9457
9458 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009459 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009460 ASSERT_VK_SUCCESS(err);
9461
9462 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9463 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9464 pipeline_layout_ci.pNext = NULL;
9465 pipeline_layout_ci.setLayoutCount = 1;
9466 pipeline_layout_ci.pSetLayouts = &ds_layout;
9467
9468 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009469 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009470 ASSERT_VK_SUCCESS(err);
9471
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009472 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9473 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9474 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009475 // Create a renderpass that will be incompatible with default renderpass
9476 VkAttachmentReference attach = {};
9477 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9478 VkAttachmentReference color_att = {};
9479 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9480 VkSubpassDescription subpass = {};
9481 subpass.inputAttachmentCount = 1;
9482 subpass.pInputAttachments = &attach;
9483 subpass.colorAttachmentCount = 1;
9484 subpass.pColorAttachments = &color_att;
9485 VkRenderPassCreateInfo rpci = {};
9486 rpci.subpassCount = 1;
9487 rpci.pSubpasses = &subpass;
9488 rpci.attachmentCount = 1;
9489 VkAttachmentDescription attach_desc = {};
9490 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009491 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9492 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009493 rpci.pAttachments = &attach_desc;
9494 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9495 VkRenderPass rp;
9496 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9497 VkPipelineObj pipe(m_device);
9498 pipe.AddShader(&vs);
9499 pipe.AddShader(&fs);
9500 pipe.AddColorAttachment();
9501 VkViewport view_port = {};
9502 m_viewports.push_back(view_port);
9503 pipe.SetViewport(m_viewports);
9504 VkRect2D rect = {};
9505 m_scissors.push_back(rect);
9506 pipe.SetScissor(m_scissors);
9507 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9508
9509 VkCommandBufferInheritanceInfo cbii = {};
9510 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9511 cbii.renderPass = rp;
9512 cbii.subpass = 0;
9513 VkCommandBufferBeginInfo cbbi = {};
9514 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9515 cbbi.pInheritanceInfo = &cbii;
9516 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9517 VkRenderPassBeginInfo rpbi = {};
9518 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9519 rpbi.framebuffer = m_framebuffer;
9520 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009521 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9522 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009523
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009525 // Render triangle (the error should trigger on the attempt to draw).
9526 Draw(3, 1, 0, 0);
9527
9528 // Finalize recording of the command buffer
9529 EndCommandBuffer();
9530
9531 m_errorMonitor->VerifyFound();
9532
9533 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9534 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9535 vkDestroyRenderPass(m_device->device(), rp, NULL);
9536}
9537
Mark Youngc89c6312016-03-31 16:03:20 -06009538TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9539 // Create Pipeline where the number of blend attachments doesn't match the
9540 // number of color attachments. In this case, we don't add any color
9541 // blend attachments even though we have a color attachment.
9542 VkResult err;
9543
9544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009545 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009546
9547 ASSERT_NO_FATAL_FAILURE(InitState());
9548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9549 VkDescriptorPoolSize ds_type_count = {};
9550 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9551 ds_type_count.descriptorCount = 1;
9552
9553 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9554 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9555 ds_pool_ci.pNext = NULL;
9556 ds_pool_ci.maxSets = 1;
9557 ds_pool_ci.poolSizeCount = 1;
9558 ds_pool_ci.pPoolSizes = &ds_type_count;
9559
9560 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009561 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009562 ASSERT_VK_SUCCESS(err);
9563
9564 VkDescriptorSetLayoutBinding dsl_binding = {};
9565 dsl_binding.binding = 0;
9566 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9567 dsl_binding.descriptorCount = 1;
9568 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9569 dsl_binding.pImmutableSamplers = NULL;
9570
9571 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9572 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9573 ds_layout_ci.pNext = NULL;
9574 ds_layout_ci.bindingCount = 1;
9575 ds_layout_ci.pBindings = &dsl_binding;
9576
9577 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009578 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009579 ASSERT_VK_SUCCESS(err);
9580
9581 VkDescriptorSet descriptorSet;
9582 VkDescriptorSetAllocateInfo alloc_info = {};
9583 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9584 alloc_info.descriptorSetCount = 1;
9585 alloc_info.descriptorPool = ds_pool;
9586 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009587 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009588 ASSERT_VK_SUCCESS(err);
9589
9590 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009591 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009592 pipe_ms_state_ci.pNext = NULL;
9593 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9594 pipe_ms_state_ci.sampleShadingEnable = 0;
9595 pipe_ms_state_ci.minSampleShading = 1.0;
9596 pipe_ms_state_ci.pSampleMask = NULL;
9597
9598 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9599 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9600 pipeline_layout_ci.pNext = NULL;
9601 pipeline_layout_ci.setLayoutCount = 1;
9602 pipeline_layout_ci.pSetLayouts = &ds_layout;
9603
9604 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009605 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009606 ASSERT_VK_SUCCESS(err);
9607
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009608 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9609 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9610 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009611 VkPipelineObj pipe(m_device);
9612 pipe.AddShader(&vs);
9613 pipe.AddShader(&fs);
9614 pipe.SetMSAA(&pipe_ms_state_ci);
9615 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9616
9617 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009618 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009619
Mark Young29927482016-05-04 14:38:51 -06009620 // Render triangle (the error should trigger on the attempt to draw).
9621 Draw(3, 1, 0, 0);
9622
9623 // Finalize recording of the command buffer
9624 EndCommandBuffer();
9625
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009626 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009627
9628 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9629 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9630 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9631}
Mark Young29927482016-05-04 14:38:51 -06009632
Mark Muellerd4914412016-06-13 17:52:06 -06009633TEST_F(VkLayerTest, MissingClearAttachment) {
9634 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9635 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009636 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009638 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009639
9640 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9641 m_errorMonitor->VerifyFound();
9642}
9643
Karl Schultz6addd812016-02-02 17:17:23 -07009644TEST_F(VkLayerTest, ClearCmdNoDraw) {
9645 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9646 // to issuing a Draw
9647 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009648
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009650 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009651
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009652 ASSERT_NO_FATAL_FAILURE(InitState());
9653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009654
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009655 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009656 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9657 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009658
9659 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009660 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9661 ds_pool_ci.pNext = NULL;
9662 ds_pool_ci.maxSets = 1;
9663 ds_pool_ci.poolSizeCount = 1;
9664 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009665
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009666 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009667 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009668 ASSERT_VK_SUCCESS(err);
9669
Tony Barboureb254902015-07-15 12:50:33 -06009670 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009671 dsl_binding.binding = 0;
9672 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9673 dsl_binding.descriptorCount = 1;
9674 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9675 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009676
Tony Barboureb254902015-07-15 12:50:33 -06009677 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009678 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9679 ds_layout_ci.pNext = NULL;
9680 ds_layout_ci.bindingCount = 1;
9681 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009682
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009683 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009684 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009685 ASSERT_VK_SUCCESS(err);
9686
9687 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009688 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009689 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009690 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009691 alloc_info.descriptorPool = ds_pool;
9692 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009693 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009694 ASSERT_VK_SUCCESS(err);
9695
Tony Barboureb254902015-07-15 12:50:33 -06009696 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009697 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009698 pipe_ms_state_ci.pNext = NULL;
9699 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9700 pipe_ms_state_ci.sampleShadingEnable = 0;
9701 pipe_ms_state_ci.minSampleShading = 1.0;
9702 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009703
Tony Barboureb254902015-07-15 12:50:33 -06009704 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009705 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9706 pipeline_layout_ci.pNext = NULL;
9707 pipeline_layout_ci.setLayoutCount = 1;
9708 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009709
9710 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009711 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009712 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009714 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009715 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009716 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009717 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009718
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009719 VkPipelineObj pipe(m_device);
9720 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009721 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009722 pipe.SetMSAA(&pipe_ms_state_ci);
9723 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009724
9725 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009726
Karl Schultz6addd812016-02-02 17:17:23 -07009727 // Main thing we care about for this test is that the VkImage obj we're
9728 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009729 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009730 VkClearAttachment color_attachment;
9731 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9732 color_attachment.clearValue.color.float32[0] = 1.0;
9733 color_attachment.clearValue.color.float32[1] = 1.0;
9734 color_attachment.clearValue.color.float32[2] = 1.0;
9735 color_attachment.clearValue.color.float32[3] = 1.0;
9736 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009737 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009738
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009739 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009740
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009741 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009742
Chia-I Wuf7458c52015-10-26 21:10:41 +08009743 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9744 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9745 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009746}
9747
Karl Schultz6addd812016-02-02 17:17:23 -07009748TEST_F(VkLayerTest, VtxBufferBadIndex) {
9749 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009750
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9752 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009753
Tobin Ehlis502480b2015-06-24 15:53:07 -06009754 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009755 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009756 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009757
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009758 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009759 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9760 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009761
9762 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009763 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9764 ds_pool_ci.pNext = NULL;
9765 ds_pool_ci.maxSets = 1;
9766 ds_pool_ci.poolSizeCount = 1;
9767 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009768
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009769 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009770 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009771 ASSERT_VK_SUCCESS(err);
9772
Tony Barboureb254902015-07-15 12:50:33 -06009773 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009774 dsl_binding.binding = 0;
9775 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9776 dsl_binding.descriptorCount = 1;
9777 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9778 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009779
Tony Barboureb254902015-07-15 12:50:33 -06009780 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009781 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9782 ds_layout_ci.pNext = NULL;
9783 ds_layout_ci.bindingCount = 1;
9784 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009785
Tobin Ehlis502480b2015-06-24 15:53:07 -06009786 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009787 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009788 ASSERT_VK_SUCCESS(err);
9789
9790 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009791 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009792 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009793 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009794 alloc_info.descriptorPool = ds_pool;
9795 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009796 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009797 ASSERT_VK_SUCCESS(err);
9798
Tony Barboureb254902015-07-15 12:50:33 -06009799 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009800 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009801 pipe_ms_state_ci.pNext = NULL;
9802 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9803 pipe_ms_state_ci.sampleShadingEnable = 0;
9804 pipe_ms_state_ci.minSampleShading = 1.0;
9805 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009806
Tony Barboureb254902015-07-15 12:50:33 -06009807 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009808 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9809 pipeline_layout_ci.pNext = NULL;
9810 pipeline_layout_ci.setLayoutCount = 1;
9811 pipeline_layout_ci.pSetLayouts = &ds_layout;
9812 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009814 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009815 ASSERT_VK_SUCCESS(err);
9816
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009817 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9818 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9819 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009820 VkPipelineObj pipe(m_device);
9821 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009822 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009823 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009824 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009825 pipe.SetViewport(m_viewports);
9826 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009827 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009828
9829 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009830 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009831 // Don't care about actual data, just need to get to draw to flag error
9832 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009833 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009834 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009835 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009836
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009837 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009838
Chia-I Wuf7458c52015-10-26 21:10:41 +08009839 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009842}
Mark Muellerdfe37552016-07-07 14:47:42 -06009843
Mark Mueller2ee294f2016-08-04 12:59:48 -06009844TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9845 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9846 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009847 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009849 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9850 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009851
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009852 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9853 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009855 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009858 // The following test fails with recent NVidia drivers.
9859 // By the time core_validation is reached, the NVidia
9860 // driver has sanitized the invalid condition and core_validation
9861 // is not introduced to the failure condition. This is not the case
9862 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009863 // uint32_t count = static_cast<uint32_t>(~0);
9864 // VkPhysicalDevice physical_device;
9865 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9866 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009869 float queue_priority = 0.0;
9870
9871 VkDeviceQueueCreateInfo queue_create_info = {};
9872 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9873 queue_create_info.queueCount = 1;
9874 queue_create_info.pQueuePriorities = &queue_priority;
9875 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9876
9877 VkPhysicalDeviceFeatures features = m_device->phy().features();
9878 VkDevice testDevice;
9879 VkDeviceCreateInfo device_create_info = {};
9880 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9881 device_create_info.queueCreateInfoCount = 1;
9882 device_create_info.pQueueCreateInfos = &queue_create_info;
9883 device_create_info.pEnabledFeatures = &features;
9884 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9885 m_errorMonitor->VerifyFound();
9886
9887 queue_create_info.queueFamilyIndex = 1;
9888
9889 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
9890 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
9891 for (unsigned i = 0; i < feature_count; i++) {
9892 if (VK_FALSE == feature_array[i]) {
9893 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009895 device_create_info.pEnabledFeatures = &features;
9896 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9897 m_errorMonitor->VerifyFound();
9898 break;
9899 }
9900 }
9901}
9902
9903TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
9904 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
9905 "End a command buffer with a query still in progress.");
9906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009907 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
9908 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
9909 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009910
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009911 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009912
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009914
9915 ASSERT_NO_FATAL_FAILURE(InitState());
9916
9917 VkEvent event;
9918 VkEventCreateInfo event_create_info{};
9919 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9920 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9921
Mark Mueller2ee294f2016-08-04 12:59:48 -06009922 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009923 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009924
9925 BeginCommandBuffer();
9926
9927 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009928 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 -06009929 ASSERT_TRUE(image.initialized());
9930 VkImageMemoryBarrier img_barrier = {};
9931 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9932 img_barrier.pNext = NULL;
9933 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9934 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9935 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9936 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9937 img_barrier.image = image.handle();
9938 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -06009939
9940 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
9941 // that layer validation catches the case when it is not.
9942 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -06009943 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9944 img_barrier.subresourceRange.baseArrayLayer = 0;
9945 img_barrier.subresourceRange.baseMipLevel = 0;
9946 img_barrier.subresourceRange.layerCount = 1;
9947 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009948 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
9949 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009950 m_errorMonitor->VerifyFound();
9951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009953
9954 VkQueryPool query_pool;
9955 VkQueryPoolCreateInfo query_pool_create_info = {};
9956 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
9957 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
9958 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009959 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009961 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009962 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
9963
9964 vkEndCommandBuffer(m_commandBuffer->handle());
9965 m_errorMonitor->VerifyFound();
9966
9967 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
9968 vkDestroyEvent(m_device->device(), event, nullptr);
9969}
9970
Mark Muellerdfe37552016-07-07 14:47:42 -06009971TEST_F(VkLayerTest, VertexBufferInvalid) {
9972 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
9973 "delete a buffer twice, use an invalid offset for each "
9974 "buffer type, and attempt to bind a null buffer");
9975
9976 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
9977 "using deleted buffer ";
9978 const char *double_destroy_message = "Cannot free buffer 0x";
9979 const char *invalid_offset_message = "vkBindBufferMemory(): "
9980 "memoryOffset is 0x";
9981 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
9982 "storage memoryOffset "
9983 "is 0x";
9984 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
9985 "texel memoryOffset "
9986 "is 0x";
9987 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
9988 "uniform memoryOffset "
9989 "is 0x";
9990 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
9991 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -06009992 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -06009993
9994 ASSERT_NO_FATAL_FAILURE(InitState());
9995 ASSERT_NO_FATAL_FAILURE(InitViewport());
9996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9997
9998 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009999 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010000 pipe_ms_state_ci.pNext = NULL;
10001 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10002 pipe_ms_state_ci.sampleShadingEnable = 0;
10003 pipe_ms_state_ci.minSampleShading = 1.0;
10004 pipe_ms_state_ci.pSampleMask = nullptr;
10005
10006 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10007 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10008 VkPipelineLayout pipeline_layout;
10009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010010 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010011 ASSERT_VK_SUCCESS(err);
10012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010013 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10014 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010015 VkPipelineObj pipe(m_device);
10016 pipe.AddShader(&vs);
10017 pipe.AddShader(&fs);
10018 pipe.AddColorAttachment();
10019 pipe.SetMSAA(&pipe_ms_state_ci);
10020 pipe.SetViewport(m_viewports);
10021 pipe.SetScissor(m_scissors);
10022 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10023
10024 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010025 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010026
10027 {
10028 // Create and bind a vertex buffer in a reduced scope, which will cause
10029 // it to be deleted upon leaving this scope
10030 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010031 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010032 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10033 draw_verticies.AddVertexInputToPipe(pipe);
10034 }
10035
10036 Draw(1, 0, 0, 0);
10037
10038 EndCommandBuffer();
10039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010041 QueueCommandBuffer(false);
10042 m_errorMonitor->VerifyFound();
10043
10044 {
10045 // Create and bind a vertex buffer in a reduced scope, and delete it
10046 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010047 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010049 buffer_test.TestDoubleDestroy();
10050 }
10051 m_errorMonitor->VerifyFound();
10052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010053 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010054 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10056 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10057 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010058 m_errorMonitor->VerifyFound();
10059 }
10060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010061 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10062 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010063 // Create and bind a memory buffer with an invalid offset again,
10064 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10066 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10067 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010068 m_errorMonitor->VerifyFound();
10069 }
10070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010071 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010072 // Create and bind a memory buffer with an invalid offset again, but
10073 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10075 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10076 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010077 m_errorMonitor->VerifyFound();
10078 }
10079
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010080 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010081 // Create and bind a memory buffer with an invalid offset again, but
10082 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10084 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10085 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010086 m_errorMonitor->VerifyFound();
10087 }
10088
10089 {
10090 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10092 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10093 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010094 m_errorMonitor->VerifyFound();
10095 }
10096
10097 {
10098 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10100 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10101 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010102 }
10103 m_errorMonitor->VerifyFound();
10104
10105 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10106}
10107
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010108// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10109TEST_F(VkLayerTest, InvalidImageLayout) {
10110 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010111 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10112 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010113 // 3 in ValidateCmdBufImageLayouts
10114 // * -1 Attempt to submit cmd buf w/ deleted image
10115 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10116 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10118 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010119
10120 ASSERT_NO_FATAL_FAILURE(InitState());
10121 // Create src & dst images to use for copy operations
10122 VkImage src_image;
10123 VkImage dst_image;
10124
10125 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10126 const int32_t tex_width = 32;
10127 const int32_t tex_height = 32;
10128
10129 VkImageCreateInfo image_create_info = {};
10130 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10131 image_create_info.pNext = NULL;
10132 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10133 image_create_info.format = tex_format;
10134 image_create_info.extent.width = tex_width;
10135 image_create_info.extent.height = tex_height;
10136 image_create_info.extent.depth = 1;
10137 image_create_info.mipLevels = 1;
10138 image_create_info.arrayLayers = 4;
10139 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10140 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10141 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10142 image_create_info.flags = 0;
10143
10144 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10145 ASSERT_VK_SUCCESS(err);
10146 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10147 ASSERT_VK_SUCCESS(err);
10148
10149 BeginCommandBuffer();
10150 VkImageCopy copyRegion;
10151 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10152 copyRegion.srcSubresource.mipLevel = 0;
10153 copyRegion.srcSubresource.baseArrayLayer = 0;
10154 copyRegion.srcSubresource.layerCount = 1;
10155 copyRegion.srcOffset.x = 0;
10156 copyRegion.srcOffset.y = 0;
10157 copyRegion.srcOffset.z = 0;
10158 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10159 copyRegion.dstSubresource.mipLevel = 0;
10160 copyRegion.dstSubresource.baseArrayLayer = 0;
10161 copyRegion.dstSubresource.layerCount = 1;
10162 copyRegion.dstOffset.x = 0;
10163 copyRegion.dstOffset.y = 0;
10164 copyRegion.dstOffset.z = 0;
10165 copyRegion.extent.width = 1;
10166 copyRegion.extent.height = 1;
10167 copyRegion.extent.depth = 1;
10168 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10169 m_errorMonitor->VerifyFound();
10170 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10172 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10173 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010174 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10175 m_errorMonitor->VerifyFound();
10176 // Final src error is due to bad layout type
10177 m_errorMonitor->SetDesiredFailureMsg(
10178 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10179 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10180 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10181 m_errorMonitor->VerifyFound();
10182 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10184 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010185 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10186 m_errorMonitor->VerifyFound();
10187 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10189 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10190 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010191 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10192 m_errorMonitor->VerifyFound();
10193 m_errorMonitor->SetDesiredFailureMsg(
10194 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10195 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10196 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10197 m_errorMonitor->VerifyFound();
10198 // Now cause error due to bad image layout transition in PipelineBarrier
10199 VkImageMemoryBarrier image_barrier[1] = {};
10200 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10201 image_barrier[0].image = src_image;
10202 image_barrier[0].subresourceRange.layerCount = 2;
10203 image_barrier[0].subresourceRange.levelCount = 2;
10204 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10206 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10207 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10208 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10209 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010210 m_errorMonitor->VerifyFound();
10211
10212 // Finally some layout errors at RenderPass create time
10213 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10214 VkAttachmentReference attach = {};
10215 // perf warning for GENERAL layout w/ non-DS input attachment
10216 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10217 VkSubpassDescription subpass = {};
10218 subpass.inputAttachmentCount = 1;
10219 subpass.pInputAttachments = &attach;
10220 VkRenderPassCreateInfo rpci = {};
10221 rpci.subpassCount = 1;
10222 rpci.pSubpasses = &subpass;
10223 rpci.attachmentCount = 1;
10224 VkAttachmentDescription attach_desc = {};
10225 attach_desc.format = VK_FORMAT_UNDEFINED;
10226 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010227 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010228 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10230 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010231 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10232 m_errorMonitor->VerifyFound();
10233 // error w/ non-general layout
10234 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10235
10236 m_errorMonitor->SetDesiredFailureMsg(
10237 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10238 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10239 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10240 m_errorMonitor->VerifyFound();
10241 subpass.inputAttachmentCount = 0;
10242 subpass.colorAttachmentCount = 1;
10243 subpass.pColorAttachments = &attach;
10244 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10245 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10247 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010248 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10249 m_errorMonitor->VerifyFound();
10250 // error w/ non-color opt or GENERAL layout for color attachment
10251 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10252 m_errorMonitor->SetDesiredFailureMsg(
10253 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10254 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10255 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10256 m_errorMonitor->VerifyFound();
10257 subpass.colorAttachmentCount = 0;
10258 subpass.pDepthStencilAttachment = &attach;
10259 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10260 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10262 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010263 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10264 m_errorMonitor->VerifyFound();
10265 // error w/ non-ds opt or GENERAL layout for color attachment
10266 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10268 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10269 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010270 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10271 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010272 // For this error we need a valid renderpass so create default one
10273 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10274 attach.attachment = 0;
10275 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10276 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10277 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10278 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10279 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10280 // Can't do a CLEAR load on READ_ONLY initialLayout
10281 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10282 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10283 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10285 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10286 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010287 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10288 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010289
10290 vkDestroyImage(m_device->device(), src_image, NULL);
10291 vkDestroyImage(m_device->device(), dst_image, NULL);
10292}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010293
Tobin Ehlise0936662016-10-11 08:10:51 -060010294TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10295 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10296 VkResult err;
10297
10298 ASSERT_NO_FATAL_FAILURE(InitState());
10299
10300 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10301 VkImageTiling tiling;
10302 VkFormatProperties format_properties;
10303 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10304 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10305 tiling = VK_IMAGE_TILING_LINEAR;
10306 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10307 tiling = VK_IMAGE_TILING_OPTIMAL;
10308 } else {
10309 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10310 "skipped.\n");
10311 return;
10312 }
10313
10314 VkDescriptorPoolSize ds_type = {};
10315 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10316 ds_type.descriptorCount = 1;
10317
10318 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10319 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10320 ds_pool_ci.maxSets = 1;
10321 ds_pool_ci.poolSizeCount = 1;
10322 ds_pool_ci.pPoolSizes = &ds_type;
10323 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10324
10325 VkDescriptorPool ds_pool;
10326 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10327 ASSERT_VK_SUCCESS(err);
10328
10329 VkDescriptorSetLayoutBinding dsl_binding = {};
10330 dsl_binding.binding = 0;
10331 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10332 dsl_binding.descriptorCount = 1;
10333 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10334 dsl_binding.pImmutableSamplers = NULL;
10335
10336 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10337 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10338 ds_layout_ci.pNext = NULL;
10339 ds_layout_ci.bindingCount = 1;
10340 ds_layout_ci.pBindings = &dsl_binding;
10341
10342 VkDescriptorSetLayout ds_layout;
10343 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10344 ASSERT_VK_SUCCESS(err);
10345
10346 VkDescriptorSetAllocateInfo alloc_info = {};
10347 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10348 alloc_info.descriptorSetCount = 1;
10349 alloc_info.descriptorPool = ds_pool;
10350 alloc_info.pSetLayouts = &ds_layout;
10351 VkDescriptorSet descriptor_set;
10352 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10353 ASSERT_VK_SUCCESS(err);
10354
10355 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10356 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10357 pipeline_layout_ci.pNext = NULL;
10358 pipeline_layout_ci.setLayoutCount = 1;
10359 pipeline_layout_ci.pSetLayouts = &ds_layout;
10360 VkPipelineLayout pipeline_layout;
10361 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10362 ASSERT_VK_SUCCESS(err);
10363
10364 VkImageObj image(m_device);
10365 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10366 ASSERT_TRUE(image.initialized());
10367 VkImageView view = image.targetView(tex_format);
10368
10369 VkDescriptorImageInfo image_info = {};
10370 image_info.imageView = view;
10371 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10372
10373 VkWriteDescriptorSet descriptor_write = {};
10374 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10375 descriptor_write.dstSet = descriptor_set;
10376 descriptor_write.dstBinding = 0;
10377 descriptor_write.descriptorCount = 1;
10378 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10379 descriptor_write.pImageInfo = &image_info;
10380
10381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10382 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10383 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10384 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10385 m_errorMonitor->VerifyFound();
10386
10387 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10388 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10389 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10390 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10391}
10392
Mark Mueller93b938f2016-08-18 10:27:40 -060010393TEST_F(VkLayerTest, SimultaneousUse) {
10394 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10395 "in primary and secondary command buffers.");
10396
10397 ASSERT_NO_FATAL_FAILURE(InitState());
10398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10399
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010400 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010401 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10402 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010403
10404 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010405 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010406 command_buffer_allocate_info.commandPool = m_commandPool;
10407 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10408 command_buffer_allocate_info.commandBufferCount = 1;
10409
10410 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010411 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010412 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10413 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010414 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010415 command_buffer_inheritance_info.renderPass = m_renderPass;
10416 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10417 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010418 command_buffer_begin_info.flags =
10419 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010420 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10421
10422 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010423 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10424 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010425 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010426 vkEndCommandBuffer(secondary_command_buffer);
10427
Mark Mueller93b938f2016-08-18 10:27:40 -060010428 VkSubmitInfo submit_info = {};
10429 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10430 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010431 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010432 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010433
Mark Mueller4042b652016-09-05 22:52:21 -060010434 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010435 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10437 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010438 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010439 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10440 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010441
10442 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010443 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10444
Mark Mueller4042b652016-09-05 22:52:21 -060010445 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010446 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010447 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10450 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010451 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010452 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10453 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010454}
10455
Mark Mueller917f6bc2016-08-30 10:57:19 -060010456TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10457 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10458 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010459 "Delete objects that are inuse. Call VkQueueSubmit "
10460 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010461
10462 ASSERT_NO_FATAL_FAILURE(InitState());
10463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10466 const char *cannot_delete_event_message = "Cannot delete event 0x";
10467 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10468 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010469
10470 BeginCommandBuffer();
10471
10472 VkEvent event;
10473 VkEventCreateInfo event_create_info = {};
10474 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10475 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010476 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010477
Mark Muellerc8d441e2016-08-23 17:36:00 -060010478 EndCommandBuffer();
10479 vkDestroyEvent(m_device->device(), event, nullptr);
10480
10481 VkSubmitInfo submit_info = {};
10482 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10483 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010484 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010486 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10487 m_errorMonitor->VerifyFound();
10488
10489 m_errorMonitor->SetDesiredFailureMsg(0, "");
10490 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10491
10492 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10493
Mark Mueller917f6bc2016-08-30 10:57:19 -060010494 VkSemaphoreCreateInfo semaphore_create_info = {};
10495 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10496 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010497 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010498 VkFenceCreateInfo fence_create_info = {};
10499 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10500 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010501 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010502
10503 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010504 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010505 descriptor_pool_type_count.descriptorCount = 1;
10506
10507 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10508 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10509 descriptor_pool_create_info.maxSets = 1;
10510 descriptor_pool_create_info.poolSizeCount = 1;
10511 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010512 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010513
10514 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010515 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010516
10517 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010518 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010519 descriptorset_layout_binding.descriptorCount = 1;
10520 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10521
10522 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010523 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010524 descriptorset_layout_create_info.bindingCount = 1;
10525 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10526
10527 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010528 ASSERT_VK_SUCCESS(
10529 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010530
10531 VkDescriptorSet descriptorset;
10532 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010533 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010534 descriptorset_allocate_info.descriptorSetCount = 1;
10535 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10536 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010537 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010538
Mark Mueller4042b652016-09-05 22:52:21 -060010539 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10540
10541 VkDescriptorBufferInfo buffer_info = {};
10542 buffer_info.buffer = buffer_test.GetBuffer();
10543 buffer_info.offset = 0;
10544 buffer_info.range = 1024;
10545
10546 VkWriteDescriptorSet write_descriptor_set = {};
10547 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10548 write_descriptor_set.dstSet = descriptorset;
10549 write_descriptor_set.descriptorCount = 1;
10550 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10551 write_descriptor_set.pBufferInfo = &buffer_info;
10552
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010553 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010554
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010555 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10556 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010557
10558 VkPipelineObj pipe(m_device);
10559 pipe.AddColorAttachment();
10560 pipe.AddShader(&vs);
10561 pipe.AddShader(&fs);
10562
10563 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010564 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010565 pipeline_layout_create_info.setLayoutCount = 1;
10566 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10567
10568 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010569 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010570
10571 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10572
Mark Muellerc8d441e2016-08-23 17:36:00 -060010573 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010574 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010575
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010576 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10577 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10578 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010579
Mark Muellerc8d441e2016-08-23 17:36:00 -060010580 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010581
Mark Mueller917f6bc2016-08-30 10:57:19 -060010582 submit_info.signalSemaphoreCount = 1;
10583 submit_info.pSignalSemaphores = &semaphore;
10584 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010587 vkDestroyEvent(m_device->device(), event, nullptr);
10588 m_errorMonitor->VerifyFound();
10589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010591 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10592 m_errorMonitor->VerifyFound();
10593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010595 vkDestroyFence(m_device->device(), fence, nullptr);
10596 m_errorMonitor->VerifyFound();
10597
Tobin Ehlis122207b2016-09-01 08:50:06 -070010598 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010599 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10600 vkDestroyFence(m_device->device(), fence, nullptr);
10601 vkDestroyEvent(m_device->device(), event, nullptr);
10602 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010604 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10605}
10606
Tobin Ehlis2adda372016-09-01 08:51:06 -070010607TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10608 TEST_DESCRIPTION("Delete in-use query pool.");
10609
10610 ASSERT_NO_FATAL_FAILURE(InitState());
10611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10612
10613 VkQueryPool query_pool;
10614 VkQueryPoolCreateInfo query_pool_ci{};
10615 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10616 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10617 query_pool_ci.queryCount = 1;
10618 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10619 BeginCommandBuffer();
10620 // Reset query pool to create binding with cmd buffer
10621 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10622
10623 EndCommandBuffer();
10624
10625 VkSubmitInfo submit_info = {};
10626 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10627 submit_info.commandBufferCount = 1;
10628 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10629 // Submit cmd buffer and then destroy query pool while in-flight
10630 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010633 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10634 m_errorMonitor->VerifyFound();
10635
10636 vkQueueWaitIdle(m_device->m_queue);
10637 // Now that cmd buffer done we can safely destroy query_pool
10638 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10639}
10640
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010641TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10642 TEST_DESCRIPTION("Delete in-use pipeline.");
10643
10644 ASSERT_NO_FATAL_FAILURE(InitState());
10645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10646
10647 // Empty pipeline layout used for binding PSO
10648 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10649 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10650 pipeline_layout_ci.setLayoutCount = 0;
10651 pipeline_layout_ci.pSetLayouts = NULL;
10652
10653 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010654 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010655 ASSERT_VK_SUCCESS(err);
10656
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010658 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010659 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10660 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010661 // Store pipeline handle so we can actually delete it before test finishes
10662 VkPipeline delete_this_pipeline;
10663 { // Scope pipeline so it will be auto-deleted
10664 VkPipelineObj pipe(m_device);
10665 pipe.AddShader(&vs);
10666 pipe.AddShader(&fs);
10667 pipe.AddColorAttachment();
10668 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10669 delete_this_pipeline = pipe.handle();
10670
10671 BeginCommandBuffer();
10672 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010673 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010674
10675 EndCommandBuffer();
10676
10677 VkSubmitInfo submit_info = {};
10678 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10679 submit_info.commandBufferCount = 1;
10680 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10681 // Submit cmd buffer and then pipeline destroyed while in-flight
10682 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10683 } // Pipeline deletion triggered here
10684 m_errorMonitor->VerifyFound();
10685 // Make sure queue finished and then actually delete pipeline
10686 vkQueueWaitIdle(m_device->m_queue);
10687 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10688 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10689}
10690
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010691TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10692 TEST_DESCRIPTION("Delete in-use imageView.");
10693
10694 ASSERT_NO_FATAL_FAILURE(InitState());
10695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10696
10697 VkDescriptorPoolSize ds_type_count;
10698 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10699 ds_type_count.descriptorCount = 1;
10700
10701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10703 ds_pool_ci.maxSets = 1;
10704 ds_pool_ci.poolSizeCount = 1;
10705 ds_pool_ci.pPoolSizes = &ds_type_count;
10706
10707 VkDescriptorPool ds_pool;
10708 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10709 ASSERT_VK_SUCCESS(err);
10710
10711 VkSamplerCreateInfo sampler_ci = {};
10712 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10713 sampler_ci.pNext = NULL;
10714 sampler_ci.magFilter = VK_FILTER_NEAREST;
10715 sampler_ci.minFilter = VK_FILTER_NEAREST;
10716 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10717 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10718 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10719 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10720 sampler_ci.mipLodBias = 1.0;
10721 sampler_ci.anisotropyEnable = VK_FALSE;
10722 sampler_ci.maxAnisotropy = 1;
10723 sampler_ci.compareEnable = VK_FALSE;
10724 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10725 sampler_ci.minLod = 1.0;
10726 sampler_ci.maxLod = 1.0;
10727 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10728 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10729 VkSampler sampler;
10730
10731 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10732 ASSERT_VK_SUCCESS(err);
10733
10734 VkDescriptorSetLayoutBinding layout_binding;
10735 layout_binding.binding = 0;
10736 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10737 layout_binding.descriptorCount = 1;
10738 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10739 layout_binding.pImmutableSamplers = NULL;
10740
10741 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10742 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10743 ds_layout_ci.bindingCount = 1;
10744 ds_layout_ci.pBindings = &layout_binding;
10745 VkDescriptorSetLayout ds_layout;
10746 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10747 ASSERT_VK_SUCCESS(err);
10748
10749 VkDescriptorSetAllocateInfo alloc_info = {};
10750 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10751 alloc_info.descriptorSetCount = 1;
10752 alloc_info.descriptorPool = ds_pool;
10753 alloc_info.pSetLayouts = &ds_layout;
10754 VkDescriptorSet descriptor_set;
10755 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10756 ASSERT_VK_SUCCESS(err);
10757
10758 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10759 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10760 pipeline_layout_ci.pNext = NULL;
10761 pipeline_layout_ci.setLayoutCount = 1;
10762 pipeline_layout_ci.pSetLayouts = &ds_layout;
10763
10764 VkPipelineLayout pipeline_layout;
10765 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10766 ASSERT_VK_SUCCESS(err);
10767
10768 VkImageObj image(m_device);
10769 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10770 ASSERT_TRUE(image.initialized());
10771
10772 VkImageView view;
10773 VkImageViewCreateInfo ivci = {};
10774 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10775 ivci.image = image.handle();
10776 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10777 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10778 ivci.subresourceRange.layerCount = 1;
10779 ivci.subresourceRange.baseMipLevel = 0;
10780 ivci.subresourceRange.levelCount = 1;
10781 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10782
10783 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10784 ASSERT_VK_SUCCESS(err);
10785
10786 VkDescriptorImageInfo image_info{};
10787 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10788 image_info.imageView = view;
10789 image_info.sampler = sampler;
10790
10791 VkWriteDescriptorSet descriptor_write = {};
10792 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10793 descriptor_write.dstSet = descriptor_set;
10794 descriptor_write.dstBinding = 0;
10795 descriptor_write.descriptorCount = 1;
10796 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10797 descriptor_write.pImageInfo = &image_info;
10798
10799 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10800
10801 // Create PSO to use the sampler
10802 char const *vsSource = "#version 450\n"
10803 "\n"
10804 "out gl_PerVertex { \n"
10805 " vec4 gl_Position;\n"
10806 "};\n"
10807 "void main(){\n"
10808 " gl_Position = vec4(1);\n"
10809 "}\n";
10810 char const *fsSource = "#version 450\n"
10811 "\n"
10812 "layout(set=0, binding=0) uniform sampler2D s;\n"
10813 "layout(location=0) out vec4 x;\n"
10814 "void main(){\n"
10815 " x = texture(s, vec2(1));\n"
10816 "}\n";
10817 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10818 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10819 VkPipelineObj pipe(m_device);
10820 pipe.AddShader(&vs);
10821 pipe.AddShader(&fs);
10822 pipe.AddColorAttachment();
10823 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10824
10825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10826
10827 BeginCommandBuffer();
10828 // Bind pipeline to cmd buffer
10829 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10830 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10831 &descriptor_set, 0, nullptr);
10832 Draw(1, 0, 0, 0);
10833 EndCommandBuffer();
10834 // Submit cmd buffer then destroy sampler
10835 VkSubmitInfo submit_info = {};
10836 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10837 submit_info.commandBufferCount = 1;
10838 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10839 // Submit cmd buffer and then destroy imageView while in-flight
10840 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10841
10842 vkDestroyImageView(m_device->device(), view, nullptr);
10843 m_errorMonitor->VerifyFound();
10844 vkQueueWaitIdle(m_device->m_queue);
10845 // Now we can actually destroy imageView
10846 vkDestroyImageView(m_device->device(), view, NULL);
10847 vkDestroySampler(m_device->device(), sampler, nullptr);
10848 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10849 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10850 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10851}
10852
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010853TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10854 TEST_DESCRIPTION("Delete in-use bufferView.");
10855
10856 ASSERT_NO_FATAL_FAILURE(InitState());
10857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10858
10859 VkDescriptorPoolSize ds_type_count;
10860 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10861 ds_type_count.descriptorCount = 1;
10862
10863 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10864 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10865 ds_pool_ci.maxSets = 1;
10866 ds_pool_ci.poolSizeCount = 1;
10867 ds_pool_ci.pPoolSizes = &ds_type_count;
10868
10869 VkDescriptorPool ds_pool;
10870 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10871 ASSERT_VK_SUCCESS(err);
10872
10873 VkDescriptorSetLayoutBinding layout_binding;
10874 layout_binding.binding = 0;
10875 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10876 layout_binding.descriptorCount = 1;
10877 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10878 layout_binding.pImmutableSamplers = NULL;
10879
10880 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10881 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10882 ds_layout_ci.bindingCount = 1;
10883 ds_layout_ci.pBindings = &layout_binding;
10884 VkDescriptorSetLayout ds_layout;
10885 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10886 ASSERT_VK_SUCCESS(err);
10887
10888 VkDescriptorSetAllocateInfo alloc_info = {};
10889 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10890 alloc_info.descriptorSetCount = 1;
10891 alloc_info.descriptorPool = ds_pool;
10892 alloc_info.pSetLayouts = &ds_layout;
10893 VkDescriptorSet descriptor_set;
10894 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10895 ASSERT_VK_SUCCESS(err);
10896
10897 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10898 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10899 pipeline_layout_ci.pNext = NULL;
10900 pipeline_layout_ci.setLayoutCount = 1;
10901 pipeline_layout_ci.pSetLayouts = &ds_layout;
10902
10903 VkPipelineLayout pipeline_layout;
10904 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10905 ASSERT_VK_SUCCESS(err);
10906
10907 VkBuffer buffer;
10908 uint32_t queue_family_index = 0;
10909 VkBufferCreateInfo buffer_create_info = {};
10910 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10911 buffer_create_info.size = 1024;
10912 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10913 buffer_create_info.queueFamilyIndexCount = 1;
10914 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
10915
10916 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
10917 ASSERT_VK_SUCCESS(err);
10918
10919 VkMemoryRequirements memory_reqs;
10920 VkDeviceMemory buffer_memory;
10921
10922 VkMemoryAllocateInfo memory_info = {};
10923 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10924 memory_info.allocationSize = 0;
10925 memory_info.memoryTypeIndex = 0;
10926
10927 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
10928 memory_info.allocationSize = memory_reqs.size;
10929 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
10930 ASSERT_TRUE(pass);
10931
10932 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
10933 ASSERT_VK_SUCCESS(err);
10934 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
10935 ASSERT_VK_SUCCESS(err);
10936
10937 VkBufferView view;
10938 VkBufferViewCreateInfo bvci = {};
10939 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10940 bvci.buffer = buffer;
10941 bvci.format = VK_FORMAT_R8_UNORM;
10942 bvci.range = VK_WHOLE_SIZE;
10943
10944 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
10945 ASSERT_VK_SUCCESS(err);
10946
10947 VkWriteDescriptorSet descriptor_write = {};
10948 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10949 descriptor_write.dstSet = descriptor_set;
10950 descriptor_write.dstBinding = 0;
10951 descriptor_write.descriptorCount = 1;
10952 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10953 descriptor_write.pTexelBufferView = &view;
10954
10955 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10956
10957 char const *vsSource = "#version 450\n"
10958 "\n"
10959 "out gl_PerVertex { \n"
10960 " vec4 gl_Position;\n"
10961 "};\n"
10962 "void main(){\n"
10963 " gl_Position = vec4(1);\n"
10964 "}\n";
10965 char const *fsSource = "#version 450\n"
10966 "\n"
10967 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
10968 "layout(location=0) out vec4 x;\n"
10969 "void main(){\n"
10970 " x = imageLoad(s, 0);\n"
10971 "}\n";
10972 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10973 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10974 VkPipelineObj pipe(m_device);
10975 pipe.AddShader(&vs);
10976 pipe.AddShader(&fs);
10977 pipe.AddColorAttachment();
10978 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10979
10980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
10981
10982 BeginCommandBuffer();
10983 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10984 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10985 VkRect2D scissor = {{0, 0}, {16, 16}};
10986 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10987 // Bind pipeline to cmd buffer
10988 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10989 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10990 &descriptor_set, 0, nullptr);
10991 Draw(1, 0, 0, 0);
10992 EndCommandBuffer();
10993
10994 VkSubmitInfo submit_info = {};
10995 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10996 submit_info.commandBufferCount = 1;
10997 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10998 // Submit cmd buffer and then destroy bufferView while in-flight
10999 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11000
11001 vkDestroyBufferView(m_device->device(), view, nullptr);
11002 m_errorMonitor->VerifyFound();
11003 vkQueueWaitIdle(m_device->m_queue);
11004 // Now we can actually destroy bufferView
11005 vkDestroyBufferView(m_device->device(), view, NULL);
11006 vkDestroyBuffer(m_device->device(), buffer, NULL);
11007 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11008 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11009 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11010 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11011}
11012
Tobin Ehlis209532e2016-09-07 13:52:18 -060011013TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11014 TEST_DESCRIPTION("Delete in-use sampler.");
11015
11016 ASSERT_NO_FATAL_FAILURE(InitState());
11017 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11018
11019 VkDescriptorPoolSize ds_type_count;
11020 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11021 ds_type_count.descriptorCount = 1;
11022
11023 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11024 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11025 ds_pool_ci.maxSets = 1;
11026 ds_pool_ci.poolSizeCount = 1;
11027 ds_pool_ci.pPoolSizes = &ds_type_count;
11028
11029 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011030 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011031 ASSERT_VK_SUCCESS(err);
11032
11033 VkSamplerCreateInfo sampler_ci = {};
11034 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11035 sampler_ci.pNext = NULL;
11036 sampler_ci.magFilter = VK_FILTER_NEAREST;
11037 sampler_ci.minFilter = VK_FILTER_NEAREST;
11038 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11039 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11040 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11041 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11042 sampler_ci.mipLodBias = 1.0;
11043 sampler_ci.anisotropyEnable = VK_FALSE;
11044 sampler_ci.maxAnisotropy = 1;
11045 sampler_ci.compareEnable = VK_FALSE;
11046 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11047 sampler_ci.minLod = 1.0;
11048 sampler_ci.maxLod = 1.0;
11049 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11050 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11051 VkSampler sampler;
11052
11053 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11054 ASSERT_VK_SUCCESS(err);
11055
11056 VkDescriptorSetLayoutBinding layout_binding;
11057 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011058 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011059 layout_binding.descriptorCount = 1;
11060 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11061 layout_binding.pImmutableSamplers = NULL;
11062
11063 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11064 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11065 ds_layout_ci.bindingCount = 1;
11066 ds_layout_ci.pBindings = &layout_binding;
11067 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011068 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011069 ASSERT_VK_SUCCESS(err);
11070
11071 VkDescriptorSetAllocateInfo alloc_info = {};
11072 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11073 alloc_info.descriptorSetCount = 1;
11074 alloc_info.descriptorPool = ds_pool;
11075 alloc_info.pSetLayouts = &ds_layout;
11076 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011077 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011078 ASSERT_VK_SUCCESS(err);
11079
11080 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11081 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11082 pipeline_layout_ci.pNext = NULL;
11083 pipeline_layout_ci.setLayoutCount = 1;
11084 pipeline_layout_ci.pSetLayouts = &ds_layout;
11085
11086 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011087 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011088 ASSERT_VK_SUCCESS(err);
11089
11090 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011091 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 -060011092 ASSERT_TRUE(image.initialized());
11093
11094 VkImageView view;
11095 VkImageViewCreateInfo ivci = {};
11096 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11097 ivci.image = image.handle();
11098 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11099 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11100 ivci.subresourceRange.layerCount = 1;
11101 ivci.subresourceRange.baseMipLevel = 0;
11102 ivci.subresourceRange.levelCount = 1;
11103 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11104
11105 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11106 ASSERT_VK_SUCCESS(err);
11107
11108 VkDescriptorImageInfo image_info{};
11109 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11110 image_info.imageView = view;
11111 image_info.sampler = sampler;
11112
11113 VkWriteDescriptorSet descriptor_write = {};
11114 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11115 descriptor_write.dstSet = descriptor_set;
11116 descriptor_write.dstBinding = 0;
11117 descriptor_write.descriptorCount = 1;
11118 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11119 descriptor_write.pImageInfo = &image_info;
11120
11121 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11122
11123 // Create PSO to use the sampler
11124 char const *vsSource = "#version 450\n"
11125 "\n"
11126 "out gl_PerVertex { \n"
11127 " vec4 gl_Position;\n"
11128 "};\n"
11129 "void main(){\n"
11130 " gl_Position = vec4(1);\n"
11131 "}\n";
11132 char const *fsSource = "#version 450\n"
11133 "\n"
11134 "layout(set=0, binding=0) uniform sampler2D s;\n"
11135 "layout(location=0) out vec4 x;\n"
11136 "void main(){\n"
11137 " x = texture(s, vec2(1));\n"
11138 "}\n";
11139 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11140 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11141 VkPipelineObj pipe(m_device);
11142 pipe.AddShader(&vs);
11143 pipe.AddShader(&fs);
11144 pipe.AddColorAttachment();
11145 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011148
11149 BeginCommandBuffer();
11150 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011151 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11152 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11153 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011154 Draw(1, 0, 0, 0);
11155 EndCommandBuffer();
11156 // Submit cmd buffer then destroy sampler
11157 VkSubmitInfo submit_info = {};
11158 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11159 submit_info.commandBufferCount = 1;
11160 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11161 // Submit cmd buffer and then destroy sampler while in-flight
11162 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11163
11164 vkDestroySampler(m_device->device(), sampler, nullptr);
11165 m_errorMonitor->VerifyFound();
11166 vkQueueWaitIdle(m_device->m_queue);
11167 // Now we can actually destroy sampler
11168 vkDestroySampler(m_device->device(), sampler, nullptr);
11169 vkDestroyImageView(m_device->device(), view, NULL);
11170 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11171 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11172 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11173}
11174
Mark Mueller1cd9f412016-08-25 13:23:52 -060011175TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011176 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011177 "signaled but not waited on by the queue. Wait on a "
11178 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011179
11180 ASSERT_NO_FATAL_FAILURE(InitState());
11181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011183 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11184 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11185 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011186
11187 BeginCommandBuffer();
11188 EndCommandBuffer();
11189
11190 VkSemaphoreCreateInfo semaphore_create_info = {};
11191 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11192 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011193 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011194 VkSubmitInfo submit_info = {};
11195 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11196 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011197 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011198 submit_info.signalSemaphoreCount = 1;
11199 submit_info.pSignalSemaphores = &semaphore;
11200 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11201 m_errorMonitor->SetDesiredFailureMsg(0, "");
11202 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11203 BeginCommandBuffer();
11204 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011206 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11207 m_errorMonitor->VerifyFound();
11208
Mark Mueller1cd9f412016-08-25 13:23:52 -060011209 VkFenceCreateInfo fence_create_info = {};
11210 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11211 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011215 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11216 m_errorMonitor->VerifyFound();
11217
Mark Mueller4042b652016-09-05 22:52:21 -060011218 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011219 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011220 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11221}
11222
Tobin Ehlis4af23302016-07-19 10:50:30 -060011223TEST_F(VkLayerTest, FramebufferIncompatible) {
11224 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11225 "that does not match the framebuffer for the active "
11226 "renderpass.");
11227 ASSERT_NO_FATAL_FAILURE(InitState());
11228 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11229
11230 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 VkAttachmentDescription attachment = {0,
11232 VK_FORMAT_B8G8R8A8_UNORM,
11233 VK_SAMPLE_COUNT_1_BIT,
11234 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11235 VK_ATTACHMENT_STORE_OP_STORE,
11236 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11237 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11238 VK_IMAGE_LAYOUT_UNDEFINED,
11239 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011241 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011243 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011245 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011246
11247 VkRenderPass rp;
11248 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11249 ASSERT_VK_SUCCESS(err);
11250
11251 // A compatible framebuffer.
11252 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011253 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 -060011254 ASSERT_TRUE(image.initialized());
11255
11256 VkImageViewCreateInfo ivci = {
11257 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11258 nullptr,
11259 0,
11260 image.handle(),
11261 VK_IMAGE_VIEW_TYPE_2D,
11262 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011263 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11264 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011265 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11266 };
11267 VkImageView view;
11268 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11269 ASSERT_VK_SUCCESS(err);
11270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011271 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011272 VkFramebuffer fb;
11273 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11274 ASSERT_VK_SUCCESS(err);
11275
11276 VkCommandBufferAllocateInfo cbai = {};
11277 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11278 cbai.commandPool = m_commandPool;
11279 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11280 cbai.commandBufferCount = 1;
11281
11282 VkCommandBuffer sec_cb;
11283 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11284 ASSERT_VK_SUCCESS(err);
11285 VkCommandBufferBeginInfo cbbi = {};
11286 VkCommandBufferInheritanceInfo cbii = {};
11287 cbii.renderPass = renderPass();
11288 cbii.framebuffer = fb;
11289 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11290 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011291 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 -060011292 cbbi.pInheritanceInfo = &cbii;
11293 vkBeginCommandBuffer(sec_cb, &cbbi);
11294 vkEndCommandBuffer(sec_cb);
11295
Chris Forbes3400bc52016-09-13 18:10:34 +120011296 VkCommandBufferBeginInfo cbbi2 = {
11297 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11298 0, nullptr
11299 };
11300 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11301 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011304 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011305 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11306 m_errorMonitor->VerifyFound();
11307 // Cleanup
11308 vkDestroyImageView(m_device->device(), view, NULL);
11309 vkDestroyRenderPass(m_device->device(), rp, NULL);
11310 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11311}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011312
11313TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11314 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11315 "invalid value. If logicOp is not available, attempt to "
11316 "use it and verify that we see the correct error.");
11317 ASSERT_NO_FATAL_FAILURE(InitState());
11318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11319
11320 auto features = m_device->phy().features();
11321 // Set the expected error depending on whether or not logicOp available
11322 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11324 "enabled, logicOpEnable must be "
11325 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011326 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011328 }
11329 // Create a pipeline using logicOp
11330 VkResult err;
11331
11332 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11333 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11334
11335 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011336 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011337 ASSERT_VK_SUCCESS(err);
11338
11339 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11340 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11341 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011342 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011343 vp_state_ci.pViewports = &vp;
11344 vp_state_ci.scissorCount = 1;
11345 VkRect2D scissors = {}; // Dummy scissors to point to
11346 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011347
11348 VkPipelineShaderStageCreateInfo shaderStages[2];
11349 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011351 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11352 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011353 shaderStages[0] = vs.GetStageCreateInfo();
11354 shaderStages[1] = fs.GetStageCreateInfo();
11355
11356 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11357 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11358
11359 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11360 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11361 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11362
11363 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11364 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011365 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011366
11367 VkPipelineColorBlendAttachmentState att = {};
11368 att.blendEnable = VK_FALSE;
11369 att.colorWriteMask = 0xf;
11370
11371 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11372 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11373 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11374 cb_ci.logicOpEnable = VK_TRUE;
11375 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11376 cb_ci.attachmentCount = 1;
11377 cb_ci.pAttachments = &att;
11378
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011379 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11380 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11381 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11382
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011383 VkGraphicsPipelineCreateInfo gp_ci = {};
11384 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11385 gp_ci.stageCount = 2;
11386 gp_ci.pStages = shaderStages;
11387 gp_ci.pVertexInputState = &vi_ci;
11388 gp_ci.pInputAssemblyState = &ia_ci;
11389 gp_ci.pViewportState = &vp_state_ci;
11390 gp_ci.pRasterizationState = &rs_ci;
11391 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011392 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011393 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11394 gp_ci.layout = pipeline_layout;
11395 gp_ci.renderPass = renderPass();
11396
11397 VkPipelineCacheCreateInfo pc_ci = {};
11398 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11399
11400 VkPipeline pipeline;
11401 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011402 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011403 ASSERT_VK_SUCCESS(err);
11404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011405 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011406 m_errorMonitor->VerifyFound();
11407 if (VK_SUCCESS == err) {
11408 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11409 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011410 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11411 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11412}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011413#endif // DRAW_STATE_TESTS
11414
Tobin Ehlis0788f522015-05-26 16:11:58 -060011415#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011416#if GTEST_IS_THREADSAFE
11417struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011418 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011419 VkEvent event;
11420 bool bailout;
11421};
11422
Karl Schultz6addd812016-02-02 17:17:23 -070011423extern "C" void *AddToCommandBuffer(void *arg) {
11424 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011425
Mike Stroyana6d14942016-07-13 15:10:05 -060011426 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011427 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011428 if (data->bailout) {
11429 break;
11430 }
11431 }
11432 return NULL;
11433}
11434
Karl Schultz6addd812016-02-02 17:17:23 -070011435TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011436 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011439
Mike Stroyanaccf7692015-05-12 16:00:45 -060011440 ASSERT_NO_FATAL_FAILURE(InitState());
11441 ASSERT_NO_FATAL_FAILURE(InitViewport());
11442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11443
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011444 // Calls AllocateCommandBuffers
11445 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011446
11447 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011448 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011449
11450 VkEventCreateInfo event_info;
11451 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011452 VkResult err;
11453
11454 memset(&event_info, 0, sizeof(event_info));
11455 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11456
Chia-I Wuf7458c52015-10-26 21:10:41 +080011457 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011458 ASSERT_VK_SUCCESS(err);
11459
Mike Stroyanaccf7692015-05-12 16:00:45 -060011460 err = vkResetEvent(device(), event);
11461 ASSERT_VK_SUCCESS(err);
11462
11463 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011464 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011465 data.event = event;
11466 data.bailout = false;
11467 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011468
11469 // First do some correct operations using multiple threads.
11470 // Add many entries to command buffer from another thread.
11471 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11472 // Make non-conflicting calls from this thread at the same time.
11473 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011474 uint32_t count;
11475 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011476 }
11477 test_platform_thread_join(thread, NULL);
11478
11479 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011480 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011481 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011482 // Add many entries to command buffer from this thread at the same time.
11483 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011484
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011485 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011486 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011487
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011488 m_errorMonitor->SetBailout(NULL);
11489
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011490 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011491
Chia-I Wuf7458c52015-10-26 21:10:41 +080011492 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011493}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011494#endif // GTEST_IS_THREADSAFE
11495#endif // THREADING_TESTS
11496
Chris Forbes9f7ff632015-05-25 11:13:08 +120011497#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011498TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011499 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11500 "with an impossible code size");
11501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011503
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011504 ASSERT_NO_FATAL_FAILURE(InitState());
11505 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11506
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011507 VkShaderModule module;
11508 VkShaderModuleCreateInfo moduleCreateInfo;
11509 struct icd_spv_header spv;
11510
11511 spv.magic = ICD_SPV_MAGIC;
11512 spv.version = ICD_SPV_VERSION;
11513 spv.gen_magic = 0;
11514
11515 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11516 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011517 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011518 moduleCreateInfo.codeSize = 4;
11519 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011520 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011521
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011522 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011523}
11524
Karl Schultz6addd812016-02-02 17:17:23 -070011525TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011526 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11527 "with a bad magic number");
11528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011530
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011531 ASSERT_NO_FATAL_FAILURE(InitState());
11532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11533
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011534 VkShaderModule module;
11535 VkShaderModuleCreateInfo moduleCreateInfo;
11536 struct icd_spv_header spv;
11537
11538 spv.magic = ~ICD_SPV_MAGIC;
11539 spv.version = ICD_SPV_VERSION;
11540 spv.gen_magic = 0;
11541
11542 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11543 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011544 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011545 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11546 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011547 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011548
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011549 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011550}
11551
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011552#if 0
11553// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011554TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011556 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011557
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011558 ASSERT_NO_FATAL_FAILURE(InitState());
11559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11560
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011561 VkShaderModule module;
11562 VkShaderModuleCreateInfo moduleCreateInfo;
11563 struct icd_spv_header spv;
11564
11565 spv.magic = ICD_SPV_MAGIC;
11566 spv.version = ~ICD_SPV_VERSION;
11567 spv.gen_magic = 0;
11568
11569 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11570 moduleCreateInfo.pNext = NULL;
11571
Karl Schultz6addd812016-02-02 17:17:23 -070011572 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011573 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11574 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011575 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011576
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011577 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011578}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011579#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011580
Karl Schultz6addd812016-02-02 17:17:23 -070011581TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011582 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11583 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011585
Chris Forbes9f7ff632015-05-25 11:13:08 +120011586 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011589 char const *vsSource = "#version 450\n"
11590 "\n"
11591 "layout(location=0) out float x;\n"
11592 "out gl_PerVertex {\n"
11593 " vec4 gl_Position;\n"
11594 "};\n"
11595 "void main(){\n"
11596 " gl_Position = vec4(1);\n"
11597 " x = 0;\n"
11598 "}\n";
11599 char const *fsSource = "#version 450\n"
11600 "\n"
11601 "layout(location=0) out vec4 color;\n"
11602 "void main(){\n"
11603 " color = vec4(1);\n"
11604 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011605
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11607 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011608
11609 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011610 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011611 pipe.AddShader(&vs);
11612 pipe.AddShader(&fs);
11613
Chris Forbes9f7ff632015-05-25 11:13:08 +120011614 VkDescriptorSetObj descriptorSet(m_device);
11615 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011616 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011617
Tony Barbour5781e8f2015-08-04 16:23:11 -060011618 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011619
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011620 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011621}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011622
Mark Mueller098c9cb2016-09-08 09:01:57 -060011623TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11624 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11625
11626 ASSERT_NO_FATAL_FAILURE(InitState());
11627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11628
11629 const char *bad_specialization_message =
11630 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11631
11632 char const *vsSource =
11633 "#version 450\n"
11634 "\n"
11635 "out gl_PerVertex {\n"
11636 " vec4 gl_Position;\n"
11637 "};\n"
11638 "void main(){\n"
11639 " gl_Position = vec4(1);\n"
11640 "}\n";
11641
11642 char const *fsSource =
11643 "#version 450\n"
11644 "\n"
11645 "layout (constant_id = 0) const float r = 0.0f;\n"
11646 "layout(location = 0) out vec4 uFragColor;\n"
11647 "void main(){\n"
11648 " uFragColor = vec4(r,1,0,1);\n"
11649 "}\n";
11650
11651 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11653
11654 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11655 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11656
11657 VkPipelineLayout pipeline_layout;
11658 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11659
11660 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11661 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11662 vp_state_create_info.viewportCount = 1;
11663 VkViewport viewport = {};
11664 vp_state_create_info.pViewports = &viewport;
11665 vp_state_create_info.scissorCount = 1;
11666 VkRect2D scissors = {};
11667 vp_state_create_info.pScissors = &scissors;
11668
11669 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11670
11671 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11672 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11673 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11674 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11675
11676 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11677 vs.GetStageCreateInfo(),
11678 fs.GetStageCreateInfo()
11679 };
11680
11681 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11682 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11683
11684 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11685 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11686 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11687
11688 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11689 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11690 rasterization_state_create_info.pNext = nullptr;
11691 rasterization_state_create_info.lineWidth = 1.0f;
11692 rasterization_state_create_info.rasterizerDiscardEnable = true;
11693
11694 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11695 color_blend_attachment_state.blendEnable = VK_FALSE;
11696 color_blend_attachment_state.colorWriteMask = 0xf;
11697
11698 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11699 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11700 color_blend_state_create_info.attachmentCount = 1;
11701 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11702
11703 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11704 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11705 graphicspipe_create_info.stageCount = 2;
11706 graphicspipe_create_info.pStages = shader_stage_create_info;
11707 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11708 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11709 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11710 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11711 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11712 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11713 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11714 graphicspipe_create_info.layout = pipeline_layout;
11715 graphicspipe_create_info.renderPass = renderPass();
11716
11717 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11718 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11719
11720 VkPipelineCache pipelineCache;
11721 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11722
11723 // This structure maps constant ids to data locations.
11724 const VkSpecializationMapEntry entry =
11725 // id, offset, size
11726 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11727
11728 uint32_t data = 1;
11729
11730 // Set up the info describing spec map and data
11731 const VkSpecializationInfo specialization_info = {
11732 1,
11733 &entry,
11734 1 * sizeof(float),
11735 &data,
11736 };
11737 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11738
11739 VkPipeline pipeline;
11740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11741 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11742 m_errorMonitor->VerifyFound();
11743
11744 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11745 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11746}
11747
11748TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11749 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11750
11751 ASSERT_NO_FATAL_FAILURE(InitState());
11752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11753
11754 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11755
11756 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11757 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11758 descriptor_pool_type_count[0].descriptorCount = 1;
11759 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11760 descriptor_pool_type_count[1].descriptorCount = 1;
11761
11762 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11763 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11764 descriptor_pool_create_info.maxSets = 1;
11765 descriptor_pool_create_info.poolSizeCount = 2;
11766 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11767 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11768
11769 VkDescriptorPool descriptorset_pool;
11770 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11771
11772 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11773 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11774 descriptorset_layout_binding.descriptorCount = 1;
11775 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11776
11777 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11778 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11779 descriptorset_layout_create_info.bindingCount = 1;
11780 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11781
11782 VkDescriptorSetLayout descriptorset_layout;
11783 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11784
11785 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11786 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11787 descriptorset_allocate_info.descriptorSetCount = 1;
11788 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11789 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11790 VkDescriptorSet descriptorset;
11791 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11792
11793 // Challenge core_validation with a non uniform buffer type.
11794 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11795
Mark Mueller098c9cb2016-09-08 09:01:57 -060011796 char const *vsSource =
11797 "#version 450\n"
11798 "\n"
11799 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11800 " mat4 mvp;\n"
11801 "} ubuf;\n"
11802 "out gl_PerVertex {\n"
11803 " vec4 gl_Position;\n"
11804 "};\n"
11805 "void main(){\n"
11806 " gl_Position = ubuf.mvp * vec4(1);\n"
11807 "}\n";
11808
11809 char const *fsSource =
11810 "#version 450\n"
11811 "\n"
11812 "layout(location = 0) out vec4 uFragColor;\n"
11813 "void main(){\n"
11814 " uFragColor = vec4(0,1,0,1);\n"
11815 "}\n";
11816
11817 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11818 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11819
11820 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11821 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11822 pipeline_layout_create_info.setLayoutCount = 1;
11823 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11824
11825 VkPipelineLayout pipeline_layout;
11826 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11827
11828 VkPipelineObj pipe(m_device);
11829 pipe.AddColorAttachment();
11830 pipe.AddShader(&vs);
11831 pipe.AddShader(&fs);
11832
11833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11834 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11835 m_errorMonitor->VerifyFound();
11836
11837 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11838 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11839 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11840}
11841
11842TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11843 TEST_DESCRIPTION(
11844 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11845
11846 ASSERT_NO_FATAL_FAILURE(InitState());
11847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11848
11849 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11850
11851 VkDescriptorPoolSize descriptor_pool_type_count = {};
11852 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11853 descriptor_pool_type_count.descriptorCount = 1;
11854
11855 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11856 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11857 descriptor_pool_create_info.maxSets = 1;
11858 descriptor_pool_create_info.poolSizeCount = 1;
11859 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11860 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11861
11862 VkDescriptorPool descriptorset_pool;
11863 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11864
11865 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11866 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11867 descriptorset_layout_binding.descriptorCount = 1;
11868 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11869 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11870
11871 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11872 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11873 descriptorset_layout_create_info.bindingCount = 1;
11874 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11875
11876 VkDescriptorSetLayout descriptorset_layout;
11877 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11878 nullptr, &descriptorset_layout));
11879
11880 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11881 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11882 descriptorset_allocate_info.descriptorSetCount = 1;
11883 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11884 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11885 VkDescriptorSet descriptorset;
11886 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11887
11888 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11889
Mark Mueller098c9cb2016-09-08 09:01:57 -060011890 char const *vsSource =
11891 "#version 450\n"
11892 "\n"
11893 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11894 " mat4 mvp;\n"
11895 "} ubuf;\n"
11896 "out gl_PerVertex {\n"
11897 " vec4 gl_Position;\n"
11898 "};\n"
11899 "void main(){\n"
11900 " gl_Position = ubuf.mvp * vec4(1);\n"
11901 "}\n";
11902
11903 char const *fsSource =
11904 "#version 450\n"
11905 "\n"
11906 "layout(location = 0) out vec4 uFragColor;\n"
11907 "void main(){\n"
11908 " uFragColor = vec4(0,1,0,1);\n"
11909 "}\n";
11910
11911 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11912 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11913
11914 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11915 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11916 pipeline_layout_create_info.setLayoutCount = 1;
11917 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11918
11919 VkPipelineLayout pipeline_layout;
11920 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11921
11922 VkPipelineObj pipe(m_device);
11923 pipe.AddColorAttachment();
11924 pipe.AddShader(&vs);
11925 pipe.AddShader(&fs);
11926
11927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
11928 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11929 m_errorMonitor->VerifyFound();
11930
11931 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11932 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11933 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11934}
11935
11936TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
11937 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
11938 "accessible from the current shader stage.");
11939
11940 ASSERT_NO_FATAL_FAILURE(InitState());
11941 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11942
11943 const char *push_constant_not_accessible_message =
11944 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
11945
11946 char const *vsSource =
11947 "#version 450\n"
11948 "\n"
11949 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
11950 "out gl_PerVertex {\n"
11951 " vec4 gl_Position;\n"
11952 "};\n"
11953 "void main(){\n"
11954 " gl_Position = vec4(consts.x);\n"
11955 "}\n";
11956
11957 char const *fsSource =
11958 "#version 450\n"
11959 "\n"
11960 "layout(location = 0) out vec4 uFragColor;\n"
11961 "void main(){\n"
11962 " uFragColor = vec4(0,1,0,1);\n"
11963 "}\n";
11964
11965 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11966 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11967
11968 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11969 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11970
11971 // Set up a push constant range
11972 VkPushConstantRange push_constant_ranges = {};
11973 // Set to the wrong stage to challenge core_validation
11974 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11975 push_constant_ranges.size = 4;
11976
11977 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
11978 pipeline_layout_create_info.pushConstantRangeCount = 1;
11979
11980 VkPipelineLayout pipeline_layout;
11981 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11982
11983 VkPipelineObj pipe(m_device);
11984 pipe.AddColorAttachment();
11985 pipe.AddShader(&vs);
11986 pipe.AddShader(&fs);
11987
11988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
11989 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11990 m_errorMonitor->VerifyFound();
11991
11992 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11993}
11994
11995TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
11996 TEST_DESCRIPTION(
11997 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
11998
11999 ASSERT_NO_FATAL_FAILURE(InitState());
12000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12001
12002 const char *feature_not_enabled_message =
12003 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12004
12005 // Some awkward steps are required to test with custom device features.
12006 std::vector<const char *> device_extension_names;
12007 auto features = m_device->phy().features();
12008 // Disable support for 64 bit floats
12009 features.shaderFloat64 = false;
12010 // The sacrificial device object
12011 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12012
12013 char const *vsSource = "#version 450\n"
12014 "\n"
12015 "out gl_PerVertex {\n"
12016 " vec4 gl_Position;\n"
12017 "};\n"
12018 "void main(){\n"
12019 " gl_Position = vec4(1);\n"
12020 "}\n";
12021 char const *fsSource = "#version 450\n"
12022 "\n"
12023 "layout(location=0) out vec4 color;\n"
12024 "void main(){\n"
12025 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12026 " color = vec4(green);\n"
12027 "}\n";
12028
12029 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12030 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12031
12032 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012033
12034 VkPipelineObj pipe(&test_device);
12035 pipe.AddColorAttachment();
12036 pipe.AddShader(&vs);
12037 pipe.AddShader(&fs);
12038
12039 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12040 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12041 VkPipelineLayout pipeline_layout;
12042 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12043
12044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12045 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12046 m_errorMonitor->VerifyFound();
12047
12048 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12049}
12050
12051TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12052 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12053
12054 ASSERT_NO_FATAL_FAILURE(InitState());
12055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12056
12057 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12058
12059 char const *vsSource = "#version 450\n"
12060 "\n"
12061 "out gl_PerVertex {\n"
12062 " vec4 gl_Position;\n"
12063 "};\n"
12064 "layout(xfb_buffer = 1) out;"
12065 "void main(){\n"
12066 " gl_Position = vec4(1);\n"
12067 "}\n";
12068 char const *fsSource = "#version 450\n"
12069 "\n"
12070 "layout(location=0) out vec4 color;\n"
12071 "void main(){\n"
12072 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12073 " color = vec4(green);\n"
12074 "}\n";
12075
12076 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12077 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12078
12079 VkPipelineObj pipe(m_device);
12080 pipe.AddColorAttachment();
12081 pipe.AddShader(&vs);
12082 pipe.AddShader(&fs);
12083
12084 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12085 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12086 VkPipelineLayout pipeline_layout;
12087 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12088
12089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12090 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12091 m_errorMonitor->VerifyFound();
12092
12093 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12094}
12095
Karl Schultz6addd812016-02-02 17:17:23 -070012096TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012097 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12098 "which is not present in the outputs of the previous stage");
12099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012101
Chris Forbes59cb88d2015-05-25 11:13:13 +120012102 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012105 char const *vsSource = "#version 450\n"
12106 "\n"
12107 "out gl_PerVertex {\n"
12108 " vec4 gl_Position;\n"
12109 "};\n"
12110 "void main(){\n"
12111 " gl_Position = vec4(1);\n"
12112 "}\n";
12113 char const *fsSource = "#version 450\n"
12114 "\n"
12115 "layout(location=0) in float x;\n"
12116 "layout(location=0) out vec4 color;\n"
12117 "void main(){\n"
12118 " color = vec4(x);\n"
12119 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012120
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012121 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12122 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012123
12124 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012125 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012126 pipe.AddShader(&vs);
12127 pipe.AddShader(&fs);
12128
Chris Forbes59cb88d2015-05-25 11:13:13 +120012129 VkDescriptorSetObj descriptorSet(m_device);
12130 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012131 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012132
Tony Barbour5781e8f2015-08-04 16:23:11 -060012133 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012134
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012135 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012136}
12137
Karl Schultz6addd812016-02-02 17:17:23 -070012138TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012139 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12140 "within an interace block, which is not present in the outputs "
12141 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012143
12144 ASSERT_NO_FATAL_FAILURE(InitState());
12145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012147 char const *vsSource = "#version 450\n"
12148 "\n"
12149 "out gl_PerVertex {\n"
12150 " vec4 gl_Position;\n"
12151 "};\n"
12152 "void main(){\n"
12153 " gl_Position = vec4(1);\n"
12154 "}\n";
12155 char const *fsSource = "#version 450\n"
12156 "\n"
12157 "in block { layout(location=0) float x; } ins;\n"
12158 "layout(location=0) out vec4 color;\n"
12159 "void main(){\n"
12160 " color = vec4(ins.x);\n"
12161 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012162
12163 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12164 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12165
12166 VkPipelineObj pipe(m_device);
12167 pipe.AddColorAttachment();
12168 pipe.AddShader(&vs);
12169 pipe.AddShader(&fs);
12170
12171 VkDescriptorSetObj descriptorSet(m_device);
12172 descriptorSet.AppendDummy();
12173 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12174
12175 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12176
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012177 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012178}
12179
Karl Schultz6addd812016-02-02 17:17:23 -070012180TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012181 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012182 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12184 "output arr[2] of float32' vs 'ptr to "
12185 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012186
12187 ASSERT_NO_FATAL_FAILURE(InitState());
12188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012190 char const *vsSource = "#version 450\n"
12191 "\n"
12192 "layout(location=0) out float x[2];\n"
12193 "out gl_PerVertex {\n"
12194 " vec4 gl_Position;\n"
12195 "};\n"
12196 "void main(){\n"
12197 " x[0] = 0; x[1] = 0;\n"
12198 " gl_Position = vec4(1);\n"
12199 "}\n";
12200 char const *fsSource = "#version 450\n"
12201 "\n"
12202 "layout(location=0) in float x[3];\n"
12203 "layout(location=0) out vec4 color;\n"
12204 "void main(){\n"
12205 " color = vec4(x[0] + x[1] + x[2]);\n"
12206 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012207
12208 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12209 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12210
12211 VkPipelineObj pipe(m_device);
12212 pipe.AddColorAttachment();
12213 pipe.AddShader(&vs);
12214 pipe.AddShader(&fs);
12215
12216 VkDescriptorSetObj descriptorSet(m_device);
12217 descriptorSet.AppendDummy();
12218 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12219
12220 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12221
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012222 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012223}
12224
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012225
Karl Schultz6addd812016-02-02 17:17:23 -070012226TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012227 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012228 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012230
Chris Forbesb56af562015-05-25 11:13:17 +120012231 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012234 char const *vsSource = "#version 450\n"
12235 "\n"
12236 "layout(location=0) out int x;\n"
12237 "out gl_PerVertex {\n"
12238 " vec4 gl_Position;\n"
12239 "};\n"
12240 "void main(){\n"
12241 " x = 0;\n"
12242 " gl_Position = vec4(1);\n"
12243 "}\n";
12244 char const *fsSource = "#version 450\n"
12245 "\n"
12246 "layout(location=0) in float x;\n" /* VS writes int */
12247 "layout(location=0) out vec4 color;\n"
12248 "void main(){\n"
12249 " color = vec4(x);\n"
12250 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012251
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012252 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12253 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012254
12255 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012256 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012257 pipe.AddShader(&vs);
12258 pipe.AddShader(&fs);
12259
Chris Forbesb56af562015-05-25 11:13:17 +120012260 VkDescriptorSetObj descriptorSet(m_device);
12261 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012262 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012263
Tony Barbour5781e8f2015-08-04 16:23:11 -060012264 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012265
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012266 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012267}
12268
Karl Schultz6addd812016-02-02 17:17:23 -070012269TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012270 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012271 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012272 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012274
12275 ASSERT_NO_FATAL_FAILURE(InitState());
12276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012278 char const *vsSource = "#version 450\n"
12279 "\n"
12280 "out block { layout(location=0) int x; } outs;\n"
12281 "out gl_PerVertex {\n"
12282 " vec4 gl_Position;\n"
12283 "};\n"
12284 "void main(){\n"
12285 " outs.x = 0;\n"
12286 " gl_Position = vec4(1);\n"
12287 "}\n";
12288 char const *fsSource = "#version 450\n"
12289 "\n"
12290 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12291 "layout(location=0) out vec4 color;\n"
12292 "void main(){\n"
12293 " color = vec4(ins.x);\n"
12294 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012295
12296 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12297 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12298
12299 VkPipelineObj pipe(m_device);
12300 pipe.AddColorAttachment();
12301 pipe.AddShader(&vs);
12302 pipe.AddShader(&fs);
12303
12304 VkDescriptorSetObj descriptorSet(m_device);
12305 descriptorSet.AppendDummy();
12306 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12307
12308 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12309
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012310 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012311}
12312
12313TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012314 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012315 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012316 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012317 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 +130012318
12319 ASSERT_NO_FATAL_FAILURE(InitState());
12320 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012322 char const *vsSource = "#version 450\n"
12323 "\n"
12324 "out block { layout(location=1) float x; } outs;\n"
12325 "out gl_PerVertex {\n"
12326 " vec4 gl_Position;\n"
12327 "};\n"
12328 "void main(){\n"
12329 " outs.x = 0;\n"
12330 " gl_Position = vec4(1);\n"
12331 "}\n";
12332 char const *fsSource = "#version 450\n"
12333 "\n"
12334 "in block { layout(location=0) float x; } ins;\n"
12335 "layout(location=0) out vec4 color;\n"
12336 "void main(){\n"
12337 " color = vec4(ins.x);\n"
12338 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012339
12340 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12341 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12342
12343 VkPipelineObj pipe(m_device);
12344 pipe.AddColorAttachment();
12345 pipe.AddShader(&vs);
12346 pipe.AddShader(&fs);
12347
12348 VkDescriptorSetObj descriptorSet(m_device);
12349 descriptorSet.AppendDummy();
12350 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12351
12352 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12353
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012354 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012355}
12356
12357TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012358 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012359 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012360 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012361 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 +130012362
12363 ASSERT_NO_FATAL_FAILURE(InitState());
12364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012366 char const *vsSource = "#version 450\n"
12367 "\n"
12368 "out block { layout(location=0, component=0) float x; } outs;\n"
12369 "out gl_PerVertex {\n"
12370 " vec4 gl_Position;\n"
12371 "};\n"
12372 "void main(){\n"
12373 " outs.x = 0;\n"
12374 " gl_Position = vec4(1);\n"
12375 "}\n";
12376 char const *fsSource = "#version 450\n"
12377 "\n"
12378 "in block { layout(location=0, component=1) float x; } ins;\n"
12379 "layout(location=0) out vec4 color;\n"
12380 "void main(){\n"
12381 " color = vec4(ins.x);\n"
12382 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012383
12384 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12385 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12386
12387 VkPipelineObj pipe(m_device);
12388 pipe.AddColorAttachment();
12389 pipe.AddShader(&vs);
12390 pipe.AddShader(&fs);
12391
12392 VkDescriptorSetObj descriptorSet(m_device);
12393 descriptorSet.AppendDummy();
12394 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12395
12396 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12397
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012398 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012399}
12400
Karl Schultz6addd812016-02-02 17:17:23 -070012401TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012402 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12403 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012405
Chris Forbesde136e02015-05-25 11:13:28 +120012406 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012408
12409 VkVertexInputBindingDescription input_binding;
12410 memset(&input_binding, 0, sizeof(input_binding));
12411
12412 VkVertexInputAttributeDescription input_attrib;
12413 memset(&input_attrib, 0, sizeof(input_attrib));
12414 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12415
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012416 char const *vsSource = "#version 450\n"
12417 "\n"
12418 "out gl_PerVertex {\n"
12419 " vec4 gl_Position;\n"
12420 "};\n"
12421 "void main(){\n"
12422 " gl_Position = vec4(1);\n"
12423 "}\n";
12424 char const *fsSource = "#version 450\n"
12425 "\n"
12426 "layout(location=0) out vec4 color;\n"
12427 "void main(){\n"
12428 " color = vec4(1);\n"
12429 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012430
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012431 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12432 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012433
12434 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012435 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012436 pipe.AddShader(&vs);
12437 pipe.AddShader(&fs);
12438
12439 pipe.AddVertexInputBindings(&input_binding, 1);
12440 pipe.AddVertexInputAttribs(&input_attrib, 1);
12441
Chris Forbesde136e02015-05-25 11:13:28 +120012442 VkDescriptorSetObj descriptorSet(m_device);
12443 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012444 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012445
Tony Barbour5781e8f2015-08-04 16:23:11 -060012446 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012447
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012448 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012449}
12450
Karl Schultz6addd812016-02-02 17:17:23 -070012451TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012452 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12453 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012455
12456 ASSERT_NO_FATAL_FAILURE(InitState());
12457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12458
12459 VkVertexInputBindingDescription input_binding;
12460 memset(&input_binding, 0, sizeof(input_binding));
12461
12462 VkVertexInputAttributeDescription input_attrib;
12463 memset(&input_attrib, 0, sizeof(input_attrib));
12464 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012466 char const *vsSource = "#version 450\n"
12467 "\n"
12468 "layout(location=1) in float x;\n"
12469 "out gl_PerVertex {\n"
12470 " vec4 gl_Position;\n"
12471 "};\n"
12472 "void main(){\n"
12473 " gl_Position = vec4(x);\n"
12474 "}\n";
12475 char const *fsSource = "#version 450\n"
12476 "\n"
12477 "layout(location=0) out vec4 color;\n"
12478 "void main(){\n"
12479 " color = vec4(1);\n"
12480 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012481
12482 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12483 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12484
12485 VkPipelineObj pipe(m_device);
12486 pipe.AddColorAttachment();
12487 pipe.AddShader(&vs);
12488 pipe.AddShader(&fs);
12489
12490 pipe.AddVertexInputBindings(&input_binding, 1);
12491 pipe.AddVertexInputAttribs(&input_attrib, 1);
12492
12493 VkDescriptorSetObj descriptorSet(m_device);
12494 descriptorSet.AppendDummy();
12495 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12496
12497 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12498
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012499 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012500}
12501
Karl Schultz6addd812016-02-02 17:17:23 -070012502TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012503 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012504 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012505 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 -060012506
Chris Forbes62e8e502015-05-25 11:13:29 +120012507 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012510 char const *vsSource = "#version 450\n"
12511 "\n"
12512 "layout(location=0) in vec4 x;\n" /* not provided */
12513 "out gl_PerVertex {\n"
12514 " vec4 gl_Position;\n"
12515 "};\n"
12516 "void main(){\n"
12517 " gl_Position = x;\n"
12518 "}\n";
12519 char const *fsSource = "#version 450\n"
12520 "\n"
12521 "layout(location=0) out vec4 color;\n"
12522 "void main(){\n"
12523 " color = vec4(1);\n"
12524 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012525
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012526 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12527 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012528
12529 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012530 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012531 pipe.AddShader(&vs);
12532 pipe.AddShader(&fs);
12533
Chris Forbes62e8e502015-05-25 11:13:29 +120012534 VkDescriptorSetObj descriptorSet(m_device);
12535 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012536 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012537
Tony Barbour5781e8f2015-08-04 16:23:11 -060012538 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012539
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012540 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012541}
12542
Karl Schultz6addd812016-02-02 17:17:23 -070012543TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012544 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12545 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012546 "vertex shader input that consumes it");
12547 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 -060012548
Chris Forbesc97d98e2015-05-25 11:13:31 +120012549 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012551
12552 VkVertexInputBindingDescription input_binding;
12553 memset(&input_binding, 0, sizeof(input_binding));
12554
12555 VkVertexInputAttributeDescription input_attrib;
12556 memset(&input_attrib, 0, sizeof(input_attrib));
12557 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012559 char const *vsSource = "#version 450\n"
12560 "\n"
12561 "layout(location=0) in int x;\n" /* attrib provided float */
12562 "out gl_PerVertex {\n"
12563 " vec4 gl_Position;\n"
12564 "};\n"
12565 "void main(){\n"
12566 " gl_Position = vec4(x);\n"
12567 "}\n";
12568 char const *fsSource = "#version 450\n"
12569 "\n"
12570 "layout(location=0) out vec4 color;\n"
12571 "void main(){\n"
12572 " color = vec4(1);\n"
12573 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012574
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012575 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12576 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012577
12578 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012579 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012580 pipe.AddShader(&vs);
12581 pipe.AddShader(&fs);
12582
12583 pipe.AddVertexInputBindings(&input_binding, 1);
12584 pipe.AddVertexInputAttribs(&input_attrib, 1);
12585
Chris Forbesc97d98e2015-05-25 11:13:31 +120012586 VkDescriptorSetObj descriptorSet(m_device);
12587 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012588 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012589
Tony Barbour5781e8f2015-08-04 16:23:11 -060012590 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012591
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012592 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012593}
12594
Chris Forbesc68b43c2016-04-06 11:18:47 +120012595TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012596 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12597 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12599 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012600
12601 ASSERT_NO_FATAL_FAILURE(InitState());
12602 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012604 char const *vsSource = "#version 450\n"
12605 "\n"
12606 "out gl_PerVertex {\n"
12607 " vec4 gl_Position;\n"
12608 "};\n"
12609 "void main(){\n"
12610 " gl_Position = vec4(1);\n"
12611 "}\n";
12612 char const *fsSource = "#version 450\n"
12613 "\n"
12614 "layout(location=0) out vec4 color;\n"
12615 "void main(){\n"
12616 " color = vec4(1);\n"
12617 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012618
12619 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12620 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12621
12622 VkPipelineObj pipe(m_device);
12623 pipe.AddColorAttachment();
12624 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012625 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012626 pipe.AddShader(&fs);
12627
12628 VkDescriptorSetObj descriptorSet(m_device);
12629 descriptorSet.AppendDummy();
12630 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12631
12632 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12633
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012634 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012635}
12636
Chris Forbes82ff92a2016-09-09 10:50:24 +120012637TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12639 "No entrypoint found named `foo`");
12640
12641 ASSERT_NO_FATAL_FAILURE(InitState());
12642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12643
12644 char const *vsSource = "#version 450\n"
12645 "out gl_PerVertex {\n"
12646 " vec4 gl_Position;\n"
12647 "};\n"
12648 "void main(){\n"
12649 " gl_Position = vec4(0);\n"
12650 "}\n";
12651 char const *fsSource = "#version 450\n"
12652 "\n"
12653 "layout(location=0) out vec4 color;\n"
12654 "void main(){\n"
12655 " color = vec4(1);\n"
12656 "}\n";
12657
12658 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12659 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12660
12661 VkPipelineObj pipe(m_device);
12662 pipe.AddColorAttachment();
12663 pipe.AddShader(&vs);
12664 pipe.AddShader(&fs);
12665
12666 VkDescriptorSetObj descriptorSet(m_device);
12667 descriptorSet.AppendDummy();
12668 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12669
12670 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12671
12672 m_errorMonitor->VerifyFound();
12673}
12674
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012675TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12676 m_errorMonitor->SetDesiredFailureMsg(
12677 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12678 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12679 "uses a depth/stencil attachment");
12680
12681 ASSERT_NO_FATAL_FAILURE(InitState());
12682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12683
12684 char const *vsSource = "#version 450\n"
12685 "void main(){ gl_Position = vec4(0); }\n";
12686 char const *fsSource = "#version 450\n"
12687 "\n"
12688 "layout(location=0) out vec4 color;\n"
12689 "void main(){\n"
12690 " color = vec4(1);\n"
12691 "}\n";
12692
12693 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12694 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12695
12696 VkPipelineObj pipe(m_device);
12697 pipe.AddColorAttachment();
12698 pipe.AddShader(&vs);
12699 pipe.AddShader(&fs);
12700
12701 VkDescriptorSetObj descriptorSet(m_device);
12702 descriptorSet.AppendDummy();
12703 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12704
12705 VkAttachmentDescription attachments[] = {
12706 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12707 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12708 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12709 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12710 },
12711 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12712 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12713 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12714 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12715 },
12716 };
12717 VkAttachmentReference refs[] = {
12718 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12719 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12720 };
12721 VkSubpassDescription subpass = {
12722 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12723 1, &refs[0], nullptr, &refs[1],
12724 0, nullptr
12725 };
12726 VkRenderPassCreateInfo rpci = {
12727 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12728 0, 2, attachments, 1, &subpass, 0, nullptr
12729 };
12730 VkRenderPass rp;
12731 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12732 ASSERT_VK_SUCCESS(err);
12733
12734 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12735
12736 m_errorMonitor->VerifyFound();
12737
12738 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12739}
12740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012741TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012742 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12743 "the TCS without the patch decoration, but consumed in the TES "
12744 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12746 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012747
12748 ASSERT_NO_FATAL_FAILURE(InitState());
12749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12750
Chris Forbesc1e852d2016-04-04 19:26:42 +120012751 if (!m_device->phy().features().tessellationShader) {
12752 printf("Device does not support tessellation shaders; skipped.\n");
12753 return;
12754 }
12755
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012756 char const *vsSource = "#version 450\n"
12757 "void main(){}\n";
12758 char const *tcsSource = "#version 450\n"
12759 "layout(location=0) out int x[];\n"
12760 "layout(vertices=3) out;\n"
12761 "void main(){\n"
12762 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12763 " gl_TessLevelInner[0] = 1;\n"
12764 " x[gl_InvocationID] = gl_InvocationID;\n"
12765 "}\n";
12766 char const *tesSource = "#version 450\n"
12767 "layout(triangles, equal_spacing, cw) in;\n"
12768 "layout(location=0) patch in int x;\n"
12769 "out gl_PerVertex { vec4 gl_Position; };\n"
12770 "void main(){\n"
12771 " gl_Position.xyz = gl_TessCoord;\n"
12772 " gl_Position.w = x;\n"
12773 "}\n";
12774 char const *fsSource = "#version 450\n"
12775 "layout(location=0) out vec4 color;\n"
12776 "void main(){\n"
12777 " color = vec4(1);\n"
12778 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012779
12780 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12781 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12782 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12783 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012785 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12786 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012788 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012789
12790 VkPipelineObj pipe(m_device);
12791 pipe.SetInputAssembly(&iasci);
12792 pipe.SetTessellation(&tsci);
12793 pipe.AddColorAttachment();
12794 pipe.AddShader(&vs);
12795 pipe.AddShader(&tcs);
12796 pipe.AddShader(&tes);
12797 pipe.AddShader(&fs);
12798
12799 VkDescriptorSetObj descriptorSet(m_device);
12800 descriptorSet.AppendDummy();
12801 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12802
12803 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12804
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012805 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012806}
12807
Karl Schultz6addd812016-02-02 17:17:23 -070012808TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012809 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12810 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12812 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012813
Chris Forbes280ba2c2015-06-12 11:16:41 +120012814 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012816
12817 /* Two binding descriptions for binding 0 */
12818 VkVertexInputBindingDescription input_bindings[2];
12819 memset(input_bindings, 0, sizeof(input_bindings));
12820
12821 VkVertexInputAttributeDescription input_attrib;
12822 memset(&input_attrib, 0, sizeof(input_attrib));
12823 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012825 char const *vsSource = "#version 450\n"
12826 "\n"
12827 "layout(location=0) in float x;\n" /* attrib provided float */
12828 "out gl_PerVertex {\n"
12829 " vec4 gl_Position;\n"
12830 "};\n"
12831 "void main(){\n"
12832 " gl_Position = vec4(x);\n"
12833 "}\n";
12834 char const *fsSource = "#version 450\n"
12835 "\n"
12836 "layout(location=0) out vec4 color;\n"
12837 "void main(){\n"
12838 " color = vec4(1);\n"
12839 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012840
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012841 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12842 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012843
12844 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012845 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012846 pipe.AddShader(&vs);
12847 pipe.AddShader(&fs);
12848
12849 pipe.AddVertexInputBindings(input_bindings, 2);
12850 pipe.AddVertexInputAttribs(&input_attrib, 1);
12851
Chris Forbes280ba2c2015-06-12 11:16:41 +120012852 VkDescriptorSetObj descriptorSet(m_device);
12853 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012854 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012855
Tony Barbour5781e8f2015-08-04 16:23:11 -060012856 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012857
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012858 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012859}
Chris Forbes8f68b562015-05-25 11:13:32 +120012860
Karl Schultz6addd812016-02-02 17:17:23 -070012861TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012862 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012863 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012865
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012866 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012868 char const *vsSource = "#version 450\n"
12869 "\n"
12870 "out gl_PerVertex {\n"
12871 " vec4 gl_Position;\n"
12872 "};\n"
12873 "void main(){\n"
12874 " gl_Position = vec4(1);\n"
12875 "}\n";
12876 char const *fsSource = "#version 450\n"
12877 "\n"
12878 "void main(){\n"
12879 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012880
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012881 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12882 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012883
12884 VkPipelineObj pipe(m_device);
12885 pipe.AddShader(&vs);
12886 pipe.AddShader(&fs);
12887
Chia-I Wu08accc62015-07-07 11:50:03 +080012888 /* set up CB 0, not written */
12889 pipe.AddColorAttachment();
12890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012891
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012892 VkDescriptorSetObj descriptorSet(m_device);
12893 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012894 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012895
Tony Barbour5781e8f2015-08-04 16:23:11 -060012896 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012897
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012898 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012899}
12900
Karl Schultz6addd812016-02-02 17:17:23 -070012901TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012902 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120012903 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012905 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012906
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012907 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012909 char const *vsSource = "#version 450\n"
12910 "\n"
12911 "out gl_PerVertex {\n"
12912 " vec4 gl_Position;\n"
12913 "};\n"
12914 "void main(){\n"
12915 " gl_Position = vec4(1);\n"
12916 "}\n";
12917 char const *fsSource = "#version 450\n"
12918 "\n"
12919 "layout(location=0) out vec4 x;\n"
12920 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
12921 "void main(){\n"
12922 " x = vec4(1);\n"
12923 " y = vec4(1);\n"
12924 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012925
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012926 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12927 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012928
12929 VkPipelineObj pipe(m_device);
12930 pipe.AddShader(&vs);
12931 pipe.AddShader(&fs);
12932
Chia-I Wu08accc62015-07-07 11:50:03 +080012933 /* set up CB 0, not written */
12934 pipe.AddColorAttachment();
12935 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012936 /* FS writes CB 1, but we don't configure it */
12937
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012938 VkDescriptorSetObj descriptorSet(m_device);
12939 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012940 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012941
Tony Barbour5781e8f2015-08-04 16:23:11 -060012942 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012943
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012944 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012945}
12946
Karl Schultz6addd812016-02-02 17:17:23 -070012947TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012948 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012949 "type of an fragment shader output variable, and the format of the corresponding attachment");
12950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012951
Chris Forbesa36d69e2015-05-25 11:13:44 +120012952 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012953
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012954 char const *vsSource = "#version 450\n"
12955 "\n"
12956 "out gl_PerVertex {\n"
12957 " vec4 gl_Position;\n"
12958 "};\n"
12959 "void main(){\n"
12960 " gl_Position = vec4(1);\n"
12961 "}\n";
12962 char const *fsSource = "#version 450\n"
12963 "\n"
12964 "layout(location=0) out ivec4 x;\n" /* not UNORM */
12965 "void main(){\n"
12966 " x = ivec4(1);\n"
12967 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120012968
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012969 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12970 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012971
12972 VkPipelineObj pipe(m_device);
12973 pipe.AddShader(&vs);
12974 pipe.AddShader(&fs);
12975
Chia-I Wu08accc62015-07-07 11:50:03 +080012976 /* set up CB 0; type is UNORM by default */
12977 pipe.AddColorAttachment();
12978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012979
Chris Forbesa36d69e2015-05-25 11:13:44 +120012980 VkDescriptorSetObj descriptorSet(m_device);
12981 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012982 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012983
Tony Barbour5781e8f2015-08-04 16:23:11 -060012984 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012985
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012986 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120012987}
Chris Forbes7b1b8932015-06-05 14:43:36 +120012988
Karl Schultz6addd812016-02-02 17:17:23 -070012989TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012990 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
12991 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012993
Chris Forbes556c76c2015-08-14 12:04:59 +120012994 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120012995
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012996 char const *vsSource = "#version 450\n"
12997 "\n"
12998 "out gl_PerVertex {\n"
12999 " vec4 gl_Position;\n"
13000 "};\n"
13001 "void main(){\n"
13002 " gl_Position = vec4(1);\n"
13003 "}\n";
13004 char const *fsSource = "#version 450\n"
13005 "\n"
13006 "layout(location=0) out vec4 x;\n"
13007 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13008 "void main(){\n"
13009 " x = vec4(bar.y);\n"
13010 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013011
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013012 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13013 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013014
Chris Forbes556c76c2015-08-14 12:04:59 +120013015 VkPipelineObj pipe(m_device);
13016 pipe.AddShader(&vs);
13017 pipe.AddShader(&fs);
13018
13019 /* set up CB 0; type is UNORM by default */
13020 pipe.AddColorAttachment();
13021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13022
13023 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013024 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013025
13026 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13027
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013028 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013029}
13030
Chris Forbes5c59e902016-02-26 16:56:09 +130013031TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013032 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13033 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013035
13036 ASSERT_NO_FATAL_FAILURE(InitState());
13037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013038 char const *vsSource = "#version 450\n"
13039 "\n"
13040 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13041 "out gl_PerVertex {\n"
13042 " vec4 gl_Position;\n"
13043 "};\n"
13044 "void main(){\n"
13045 " gl_Position = vec4(consts.x);\n"
13046 "}\n";
13047 char const *fsSource = "#version 450\n"
13048 "\n"
13049 "layout(location=0) out vec4 x;\n"
13050 "void main(){\n"
13051 " x = vec4(1);\n"
13052 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013053
13054 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13055 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13056
13057 VkPipelineObj pipe(m_device);
13058 pipe.AddShader(&vs);
13059 pipe.AddShader(&fs);
13060
13061 /* set up CB 0; type is UNORM by default */
13062 pipe.AddColorAttachment();
13063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13064
13065 VkDescriptorSetObj descriptorSet(m_device);
13066 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13067
13068 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13069
13070 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013071 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013072}
13073
Chris Forbes3fb17902016-08-22 14:57:55 +120013074TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13075 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13076 "which is not included in the subpass description");
13077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13078 "consumes input attachment index 0 but not provided in subpass");
13079
13080 ASSERT_NO_FATAL_FAILURE(InitState());
13081
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013082 char const *vsSource = "#version 450\n"
13083 "\n"
13084 "out gl_PerVertex {\n"
13085 " vec4 gl_Position;\n"
13086 "};\n"
13087 "void main(){\n"
13088 " gl_Position = vec4(1);\n"
13089 "}\n";
13090 char const *fsSource = "#version 450\n"
13091 "\n"
13092 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13093 "layout(location=0) out vec4 color;\n"
13094 "void main() {\n"
13095 " color = subpassLoad(x);\n"
13096 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013097
13098 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13099 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13100
13101 VkPipelineObj pipe(m_device);
13102 pipe.AddShader(&vs);
13103 pipe.AddShader(&fs);
13104 pipe.AddColorAttachment();
13105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13106
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013107 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13108 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013109 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013110 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013111 ASSERT_VK_SUCCESS(err);
13112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013113 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013114 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013115 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013116 ASSERT_VK_SUCCESS(err);
13117
13118 // error here.
13119 pipe.CreateVKPipeline(pl, renderPass());
13120
13121 m_errorMonitor->VerifyFound();
13122
13123 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13124 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13125}
13126
Chris Forbes5a9a0472016-08-22 16:02:09 +120013127TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13128 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13129 "with a format having a different fundamental type");
13130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13131 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13132
13133 ASSERT_NO_FATAL_FAILURE(InitState());
13134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013135 char const *vsSource = "#version 450\n"
13136 "\n"
13137 "out gl_PerVertex {\n"
13138 " vec4 gl_Position;\n"
13139 "};\n"
13140 "void main(){\n"
13141 " gl_Position = vec4(1);\n"
13142 "}\n";
13143 char const *fsSource = "#version 450\n"
13144 "\n"
13145 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13146 "layout(location=0) out vec4 color;\n"
13147 "void main() {\n"
13148 " color = subpassLoad(x);\n"
13149 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013150
13151 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13152 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13153
13154 VkPipelineObj pipe(m_device);
13155 pipe.AddShader(&vs);
13156 pipe.AddShader(&fs);
13157 pipe.AddColorAttachment();
13158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13159
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013160 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13161 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013162 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013163 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013164 ASSERT_VK_SUCCESS(err);
13165
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013166 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013167 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013168 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013169 ASSERT_VK_SUCCESS(err);
13170
13171 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013172 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13173 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13174 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13175 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13176 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 +120013177 };
13178 VkAttachmentReference color = {
13179 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13180 };
13181 VkAttachmentReference input = {
13182 1, VK_IMAGE_LAYOUT_GENERAL,
13183 };
13184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013185 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013187 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013188 VkRenderPass rp;
13189 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13190 ASSERT_VK_SUCCESS(err);
13191
13192 // error here.
13193 pipe.CreateVKPipeline(pl, rp);
13194
13195 m_errorMonitor->VerifyFound();
13196
13197 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13198 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13199 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13200}
13201
Chris Forbes541f7b02016-08-22 15:30:27 +120013202TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13203 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13204 "which is not included in the subpass description -- array case");
13205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13206 "consumes input attachment index 1 but not provided in subpass");
13207
13208 ASSERT_NO_FATAL_FAILURE(InitState());
13209
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013210 char const *vsSource = "#version 450\n"
13211 "\n"
13212 "out gl_PerVertex {\n"
13213 " vec4 gl_Position;\n"
13214 "};\n"
13215 "void main(){\n"
13216 " gl_Position = vec4(1);\n"
13217 "}\n";
13218 char const *fsSource = "#version 450\n"
13219 "\n"
13220 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13221 "layout(location=0) out vec4 color;\n"
13222 "void main() {\n"
13223 " color = subpassLoad(xs[1]);\n"
13224 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013225
13226 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13227 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13228
13229 VkPipelineObj pipe(m_device);
13230 pipe.AddShader(&vs);
13231 pipe.AddShader(&fs);
13232 pipe.AddColorAttachment();
13233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013235 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13236 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013237 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013238 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013239 ASSERT_VK_SUCCESS(err);
13240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013241 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013242 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013243 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013244 ASSERT_VK_SUCCESS(err);
13245
13246 // error here.
13247 pipe.CreateVKPipeline(pl, renderPass());
13248
13249 m_errorMonitor->VerifyFound();
13250
13251 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13252 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13253}
13254
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013255TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013256 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13257 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013259
13260 ASSERT_NO_FATAL_FAILURE(InitState());
13261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013262 char const *csSource = "#version 450\n"
13263 "\n"
13264 "layout(local_size_x=1) in;\n"
13265 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13266 "void main(){\n"
13267 " x = vec4(1);\n"
13268 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013269
13270 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13271
13272 VkDescriptorSetObj descriptorSet(m_device);
13273 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013275 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13276 nullptr,
13277 0,
13278 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13279 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13280 descriptorSet.GetPipelineLayout(),
13281 VK_NULL_HANDLE,
13282 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013283
13284 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013285 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013286
13287 m_errorMonitor->VerifyFound();
13288
13289 if (err == VK_SUCCESS) {
13290 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13291 }
13292}
13293
Chris Forbes22a9b092016-07-19 14:34:05 +120013294TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013295 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13296 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13298 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013299
13300 ASSERT_NO_FATAL_FAILURE(InitState());
13301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013302 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13303 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013304 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013305 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013306 ASSERT_VK_SUCCESS(err);
13307
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013308 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013309 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013310 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013311 ASSERT_VK_SUCCESS(err);
13312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013313 char const *csSource = "#version 450\n"
13314 "\n"
13315 "layout(local_size_x=1) in;\n"
13316 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13317 "void main() {\n"
13318 " x.x = 1.0f;\n"
13319 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013320 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013322 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13323 nullptr,
13324 0,
13325 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13326 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13327 pl,
13328 VK_NULL_HANDLE,
13329 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013330
13331 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013332 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013333
13334 m_errorMonitor->VerifyFound();
13335
13336 if (err == VK_SUCCESS) {
13337 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13338 }
13339
13340 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13341 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13342}
13343
Chris Forbes50020592016-07-27 13:52:41 +120013344TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13345 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13346 "does not match the dimensionality declared in the shader");
13347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013348 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 +120013349
13350 ASSERT_NO_FATAL_FAILURE(InitState());
13351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013353 char const *vsSource = "#version 450\n"
13354 "\n"
13355 "out gl_PerVertex { vec4 gl_Position; };\n"
13356 "void main() { gl_Position = vec4(0); }\n";
13357 char const *fsSource = "#version 450\n"
13358 "\n"
13359 "layout(set=0, binding=0) uniform sampler3D s;\n"
13360 "layout(location=0) out vec4 color;\n"
13361 "void main() {\n"
13362 " color = texture(s, vec3(0));\n"
13363 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013364 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13365 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13366
13367 VkPipelineObj pipe(m_device);
13368 pipe.AddShader(&vs);
13369 pipe.AddShader(&fs);
13370 pipe.AddColorAttachment();
13371
13372 VkTextureObj texture(m_device, nullptr);
13373 VkSamplerObj sampler(m_device);
13374
13375 VkDescriptorSetObj descriptorSet(m_device);
13376 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13377 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13378
13379 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13380 ASSERT_VK_SUCCESS(err);
13381
13382 BeginCommandBuffer();
13383
13384 m_commandBuffer->BindPipeline(pipe);
13385 m_commandBuffer->BindDescriptorSet(descriptorSet);
13386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013387 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013388 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013389 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013390 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13391
13392 // error produced here.
13393 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13394
13395 m_errorMonitor->VerifyFound();
13396
13397 EndCommandBuffer();
13398}
13399
Chris Forbes5533bfc2016-07-27 14:12:34 +120013400TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13401 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13402 "are consumed via singlesample images types in the shader, or vice versa.");
13403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013405
13406 ASSERT_NO_FATAL_FAILURE(InitState());
13407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013409 char const *vsSource = "#version 450\n"
13410 "\n"
13411 "out gl_PerVertex { vec4 gl_Position; };\n"
13412 "void main() { gl_Position = vec4(0); }\n";
13413 char const *fsSource = "#version 450\n"
13414 "\n"
13415 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13416 "layout(location=0) out vec4 color;\n"
13417 "void main() {\n"
13418 " color = texelFetch(s, ivec2(0), 0);\n"
13419 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013420 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13421 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13422
13423 VkPipelineObj pipe(m_device);
13424 pipe.AddShader(&vs);
13425 pipe.AddShader(&fs);
13426 pipe.AddColorAttachment();
13427
13428 VkTextureObj texture(m_device, nullptr);
13429 VkSamplerObj sampler(m_device);
13430
13431 VkDescriptorSetObj descriptorSet(m_device);
13432 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13434
13435 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13436 ASSERT_VK_SUCCESS(err);
13437
13438 BeginCommandBuffer();
13439
13440 m_commandBuffer->BindPipeline(pipe);
13441 m_commandBuffer->BindDescriptorSet(descriptorSet);
13442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013443 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013444 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013445 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013446 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13447
13448 // error produced here.
13449 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13450
13451 m_errorMonitor->VerifyFound();
13452
13453 EndCommandBuffer();
13454}
13455
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013456#endif // SHADER_CHECKER_TESTS
13457
13458#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013459TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013461
13462 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013463
13464 // Create an image
13465 VkImage image;
13466
Karl Schultz6addd812016-02-02 17:17:23 -070013467 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13468 const int32_t tex_width = 32;
13469 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013470
13471 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013472 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13473 image_create_info.pNext = NULL;
13474 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13475 image_create_info.format = tex_format;
13476 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013477 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013478 image_create_info.extent.depth = 1;
13479 image_create_info.mipLevels = 1;
13480 image_create_info.arrayLayers = 1;
13481 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13482 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13483 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13484 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013485
13486 // Introduce error by sending down a bogus width extent
13487 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013488 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013489
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013490 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013491}
13492
Mark Youngc48c4c12016-04-11 14:26:49 -060013493TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13495 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013496
13497 ASSERT_NO_FATAL_FAILURE(InitState());
13498
13499 // Create an image
13500 VkImage image;
13501
13502 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13503 const int32_t tex_width = 32;
13504 const int32_t tex_height = 32;
13505
13506 VkImageCreateInfo image_create_info = {};
13507 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13508 image_create_info.pNext = NULL;
13509 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13510 image_create_info.format = tex_format;
13511 image_create_info.extent.width = tex_width;
13512 image_create_info.extent.height = tex_height;
13513 image_create_info.extent.depth = 1;
13514 image_create_info.mipLevels = 1;
13515 image_create_info.arrayLayers = 1;
13516 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13517 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13518 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13519 image_create_info.flags = 0;
13520
13521 // Introduce error by sending down a bogus width extent
13522 image_create_info.extent.width = 0;
13523 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13524
13525 m_errorMonitor->VerifyFound();
13526}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013527#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013528
Tobin Ehliscde08892015-09-22 10:11:37 -060013529#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013530TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13531 TEST_DESCRIPTION("Create a render pass with an attachment description "
13532 "format set to VK_FORMAT_UNDEFINED");
13533
13534 ASSERT_NO_FATAL_FAILURE(InitState());
13535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13536
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013538
13539 VkAttachmentReference color_attach = {};
13540 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13541 color_attach.attachment = 0;
13542 VkSubpassDescription subpass = {};
13543 subpass.colorAttachmentCount = 1;
13544 subpass.pColorAttachments = &color_attach;
13545
13546 VkRenderPassCreateInfo rpci = {};
13547 rpci.subpassCount = 1;
13548 rpci.pSubpasses = &subpass;
13549 rpci.attachmentCount = 1;
13550 VkAttachmentDescription attach_desc = {};
13551 attach_desc.format = VK_FORMAT_UNDEFINED;
13552 rpci.pAttachments = &attach_desc;
13553 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13554 VkRenderPass rp;
13555 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13556
13557 m_errorMonitor->VerifyFound();
13558
13559 if (result == VK_SUCCESS) {
13560 vkDestroyRenderPass(m_device->device(), rp, NULL);
13561 }
13562}
13563
Karl Schultz6addd812016-02-02 17:17:23 -070013564TEST_F(VkLayerTest, InvalidImageView) {
13565 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013566
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013568
Tobin Ehliscde08892015-09-22 10:11:37 -060013569 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013570
Mike Stroyana3082432015-09-25 13:39:21 -060013571 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013572 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013573
Karl Schultz6addd812016-02-02 17:17:23 -070013574 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13575 const int32_t tex_width = 32;
13576 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013577
13578 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013579 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13580 image_create_info.pNext = NULL;
13581 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13582 image_create_info.format = tex_format;
13583 image_create_info.extent.width = tex_width;
13584 image_create_info.extent.height = tex_height;
13585 image_create_info.extent.depth = 1;
13586 image_create_info.mipLevels = 1;
13587 image_create_info.arrayLayers = 1;
13588 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13589 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13590 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13591 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013592
Chia-I Wuf7458c52015-10-26 21:10:41 +080013593 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013594 ASSERT_VK_SUCCESS(err);
13595
13596 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013597 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13598 image_view_create_info.image = image;
13599 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13600 image_view_create_info.format = tex_format;
13601 image_view_create_info.subresourceRange.layerCount = 1;
13602 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13603 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013604 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013605
13606 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013607 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013608
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013609 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013610 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013611}
Mike Stroyana3082432015-09-25 13:39:21 -060013612
Mark Youngd339ba32016-05-30 13:28:35 -060013613TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13614 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013616 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013617
13618 ASSERT_NO_FATAL_FAILURE(InitState());
13619
13620 // Create an image and try to create a view with no memory backing the image
13621 VkImage image;
13622
13623 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13624 const int32_t tex_width = 32;
13625 const int32_t tex_height = 32;
13626
13627 VkImageCreateInfo image_create_info = {};
13628 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13629 image_create_info.pNext = NULL;
13630 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13631 image_create_info.format = tex_format;
13632 image_create_info.extent.width = tex_width;
13633 image_create_info.extent.height = tex_height;
13634 image_create_info.extent.depth = 1;
13635 image_create_info.mipLevels = 1;
13636 image_create_info.arrayLayers = 1;
13637 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13638 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13639 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13640 image_create_info.flags = 0;
13641
13642 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13643 ASSERT_VK_SUCCESS(err);
13644
13645 VkImageViewCreateInfo image_view_create_info = {};
13646 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13647 image_view_create_info.image = image;
13648 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13649 image_view_create_info.format = tex_format;
13650 image_view_create_info.subresourceRange.layerCount = 1;
13651 image_view_create_info.subresourceRange.baseMipLevel = 0;
13652 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013653 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013654
13655 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013656 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013657
13658 m_errorMonitor->VerifyFound();
13659 vkDestroyImage(m_device->device(), image, NULL);
13660 // If last error is success, it still created the view, so delete it.
13661 if (err == VK_SUCCESS) {
13662 vkDestroyImageView(m_device->device(), view, NULL);
13663 }
Mark Youngd339ba32016-05-30 13:28:35 -060013664}
13665
Karl Schultz6addd812016-02-02 17:17:23 -070013666TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013667 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013669 "formats must have ONLY the "
13670 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13672 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013673
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013674 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013675
Karl Schultz6addd812016-02-02 17:17:23 -070013676 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013677 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013678 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013679 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013680
13681 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013682 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013683 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013684 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13685 image_view_create_info.format = tex_format;
13686 image_view_create_info.subresourceRange.baseMipLevel = 0;
13687 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013688 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013689 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013690 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013691
13692 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013693 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013694
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013695 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013696}
13697
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013698TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013699 VkResult err;
13700 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013701
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13703 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013704
Mike Stroyana3082432015-09-25 13:39:21 -060013705 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013706
13707 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013708 VkImage srcImage;
13709 VkImage dstImage;
13710 VkDeviceMemory srcMem;
13711 VkDeviceMemory destMem;
13712 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013713
13714 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013715 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13716 image_create_info.pNext = NULL;
13717 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13718 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13719 image_create_info.extent.width = 32;
13720 image_create_info.extent.height = 32;
13721 image_create_info.extent.depth = 1;
13722 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013723 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013724 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13725 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13726 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13727 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013728
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013729 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013730 ASSERT_VK_SUCCESS(err);
13731
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013732 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013733 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013734 ASSERT_VK_SUCCESS(err);
13735
13736 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013737 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013738 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13739 memAlloc.pNext = NULL;
13740 memAlloc.allocationSize = 0;
13741 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013742
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013743 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013744 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013745 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013746 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013747 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013748 ASSERT_VK_SUCCESS(err);
13749
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013750 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013751 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013752 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013753 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013754 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013755 ASSERT_VK_SUCCESS(err);
13756
13757 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13758 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013759 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013760 ASSERT_VK_SUCCESS(err);
13761
13762 BeginCommandBuffer();
13763 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013764 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013765 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013766 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013767 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013768 copyRegion.srcOffset.x = 0;
13769 copyRegion.srcOffset.y = 0;
13770 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013771 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013772 copyRegion.dstSubresource.mipLevel = 0;
13773 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013774 // Introduce failure by forcing the dst layerCount to differ from src
13775 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013776 copyRegion.dstOffset.x = 0;
13777 copyRegion.dstOffset.y = 0;
13778 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013779 copyRegion.extent.width = 1;
13780 copyRegion.extent.height = 1;
13781 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013782 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013783 EndCommandBuffer();
13784
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013785 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013786
Chia-I Wuf7458c52015-10-26 21:10:41 +080013787 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013788 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013789 vkFreeMemory(m_device->device(), srcMem, NULL);
13790 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013791}
13792
Tony Barbourd6673642016-05-05 14:46:39 -060013793TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13794
13795 TEST_DESCRIPTION("Creating images with unsuported formats ");
13796
13797 ASSERT_NO_FATAL_FAILURE(InitState());
13798 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13799 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013800 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 -060013801 VK_IMAGE_TILING_OPTIMAL, 0);
13802 ASSERT_TRUE(image.initialized());
13803
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013804 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13805 VkImageCreateInfo image_create_info;
13806 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13807 image_create_info.pNext = NULL;
13808 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13809 image_create_info.format = VK_FORMAT_UNDEFINED;
13810 image_create_info.extent.width = 32;
13811 image_create_info.extent.height = 32;
13812 image_create_info.extent.depth = 1;
13813 image_create_info.mipLevels = 1;
13814 image_create_info.arrayLayers = 1;
13815 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13816 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13817 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13818 image_create_info.flags = 0;
13819
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13821 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013822
13823 VkImage localImage;
13824 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13825 m_errorMonitor->VerifyFound();
13826
Tony Barbourd6673642016-05-05 14:46:39 -060013827 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013828 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013829 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13830 VkFormat format = static_cast<VkFormat>(f);
13831 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013832 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013833 unsupported = format;
13834 break;
13835 }
13836 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013837
Tony Barbourd6673642016-05-05 14:46:39 -060013838 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013839 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013841
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013842 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013843 m_errorMonitor->VerifyFound();
13844 }
13845}
13846
13847TEST_F(VkLayerTest, ImageLayerViewTests) {
13848 VkResult ret;
13849 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13850
13851 ASSERT_NO_FATAL_FAILURE(InitState());
13852
13853 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013854 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 -060013855 VK_IMAGE_TILING_OPTIMAL, 0);
13856 ASSERT_TRUE(image.initialized());
13857
13858 VkImageView imgView;
13859 VkImageViewCreateInfo imgViewInfo = {};
13860 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13861 imgViewInfo.image = image.handle();
13862 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13863 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13864 imgViewInfo.subresourceRange.layerCount = 1;
13865 imgViewInfo.subresourceRange.baseMipLevel = 0;
13866 imgViewInfo.subresourceRange.levelCount = 1;
13867 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013870 // View can't have baseMipLevel >= image's mipLevels - Expect
13871 // VIEW_CREATE_ERROR
13872 imgViewInfo.subresourceRange.baseMipLevel = 1;
13873 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13874 m_errorMonitor->VerifyFound();
13875 imgViewInfo.subresourceRange.baseMipLevel = 0;
13876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013878 // View can't have baseArrayLayer >= image's arraySize - Expect
13879 // VIEW_CREATE_ERROR
13880 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13881 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13882 m_errorMonitor->VerifyFound();
13883 imgViewInfo.subresourceRange.baseArrayLayer = 0;
13884
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13886 "pCreateInfo->subresourceRange."
13887 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013888 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
13889 imgViewInfo.subresourceRange.levelCount = 0;
13890 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13891 m_errorMonitor->VerifyFound();
13892 imgViewInfo.subresourceRange.levelCount = 1;
13893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13895 "pCreateInfo->subresourceRange."
13896 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013897 m_errorMonitor->SetDesiredFailureMsg(
13898 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13899 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060013900 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
13901 imgViewInfo.subresourceRange.layerCount = 0;
13902 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13903 m_errorMonitor->VerifyFound();
13904 imgViewInfo.subresourceRange.layerCount = 1;
13905
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13908 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13909 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013910 // Can't use depth format for view into color image - Expect INVALID_FORMAT
13911 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
13912 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13913 m_errorMonitor->VerifyFound();
13914 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13917 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13918 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013919 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
13920 // VIEW_CREATE_ERROR
13921 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
13922 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13923 m_errorMonitor->VerifyFound();
13924 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13925
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
13927 "differing formats but they must be "
13928 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013929 // TODO: Update framework to easily passing mutable flag into ImageObj init
13930 // For now just allowing image for this one test to not have memory bound
13931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13932 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060013933 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
13934 // VIEW_CREATE_ERROR
13935 VkImageCreateInfo mutImgInfo = image.create_info();
13936 VkImage mutImage;
13937 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013938 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060013939 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
13940 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
13941 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
13942 ASSERT_VK_SUCCESS(ret);
13943 imgViewInfo.image = mutImage;
13944 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13945 m_errorMonitor->VerifyFound();
13946 imgViewInfo.image = image.handle();
13947 vkDestroyImage(m_device->handle(), mutImage, NULL);
13948}
13949
13950TEST_F(VkLayerTest, MiscImageLayerTests) {
13951
13952 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
13953
13954 ASSERT_NO_FATAL_FAILURE(InitState());
13955
13956 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013957 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 -060013958 VK_IMAGE_TILING_OPTIMAL, 0);
13959 ASSERT_TRUE(image.initialized());
13960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060013962 vk_testing::Buffer buffer;
13963 VkMemoryPropertyFlags reqs = 0;
13964 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
13965 VkBufferImageCopy region = {};
13966 region.bufferRowLength = 128;
13967 region.bufferImageHeight = 128;
13968 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13969 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
13970 region.imageSubresource.layerCount = 0;
13971 region.imageExtent.height = 4;
13972 region.imageExtent.width = 4;
13973 region.imageExtent.depth = 1;
13974 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013975 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13976 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060013977 m_errorMonitor->VerifyFound();
13978 region.imageSubresource.layerCount = 1;
13979
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013980 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
13981 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
13982 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
13984 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13985 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013986 m_errorMonitor->VerifyFound();
13987
13988 // BufferOffset must be a multiple of 4
13989 // Introduce failure by setting bufferOffset to a value not divisible by 4
13990 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
13992 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13993 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013994 m_errorMonitor->VerifyFound();
13995
13996 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
13997 region.bufferOffset = 0;
13998 region.imageExtent.height = 128;
13999 region.imageExtent.width = 128;
14000 // Introduce failure by setting bufferRowLength > 0 but less than width
14001 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14003 "must be zero or greater-than-or-equal-to imageExtent.width");
14004 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14005 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014006 m_errorMonitor->VerifyFound();
14007
14008 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14009 region.bufferRowLength = 128;
14010 // Introduce failure by setting bufferRowHeight > 0 but less than height
14011 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14013 "must be zero or greater-than-or-equal-to imageExtent.height");
14014 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14015 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014016 m_errorMonitor->VerifyFound();
14017
14018 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14020 "specify only COLOR or DEPTH or "
14021 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014022 // Expect MISMATCHED_IMAGE_ASPECT
14023 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014024 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14025 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014026 m_errorMonitor->VerifyFound();
14027 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14028
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14030 "If the format of srcImage is a depth, stencil, depth stencil or "
14031 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014032 // Expect INVALID_FILTER
14033 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014034 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 -060014035 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014036 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 -060014037 VkImageBlit blitRegion = {};
14038 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14039 blitRegion.srcSubresource.baseArrayLayer = 0;
14040 blitRegion.srcSubresource.layerCount = 1;
14041 blitRegion.srcSubresource.mipLevel = 0;
14042 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14043 blitRegion.dstSubresource.baseArrayLayer = 0;
14044 blitRegion.dstSubresource.layerCount = 1;
14045 blitRegion.dstSubresource.mipLevel = 0;
14046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014047 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14048 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014049 m_errorMonitor->VerifyFound();
14050
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014051 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14053 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14054 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014055 m_errorMonitor->VerifyFound();
14056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014058 VkImageMemoryBarrier img_barrier;
14059 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14060 img_barrier.pNext = NULL;
14061 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14062 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14063 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14064 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14065 img_barrier.image = image.handle();
14066 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14067 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14068 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14069 img_barrier.subresourceRange.baseArrayLayer = 0;
14070 img_barrier.subresourceRange.baseMipLevel = 0;
14071 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14072 img_barrier.subresourceRange.layerCount = 0;
14073 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014074 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14075 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014076 m_errorMonitor->VerifyFound();
14077 img_barrier.subresourceRange.layerCount = 1;
14078}
14079
14080TEST_F(VkLayerTest, ImageFormatLimits) {
14081
14082 TEST_DESCRIPTION("Exceed the limits of image format ");
14083
Cody Northropc31a84f2016-08-22 10:41:47 -060014084 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014086 VkImageCreateInfo image_create_info = {};
14087 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14088 image_create_info.pNext = NULL;
14089 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14090 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14091 image_create_info.extent.width = 32;
14092 image_create_info.extent.height = 32;
14093 image_create_info.extent.depth = 1;
14094 image_create_info.mipLevels = 1;
14095 image_create_info.arrayLayers = 1;
14096 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14097 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14098 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14099 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14100 image_create_info.flags = 0;
14101
14102 VkImage nullImg;
14103 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014104 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14105 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014106 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14107 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14108 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14109 m_errorMonitor->VerifyFound();
14110 image_create_info.extent.depth = 1;
14111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014113 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14114 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14115 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14116 m_errorMonitor->VerifyFound();
14117 image_create_info.mipLevels = 1;
14118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014120 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14121 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14122 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14123 m_errorMonitor->VerifyFound();
14124 image_create_info.arrayLayers = 1;
14125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014127 int samples = imgFmtProps.sampleCounts >> 1;
14128 image_create_info.samples = (VkSampleCountFlagBits)samples;
14129 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14130 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14131 m_errorMonitor->VerifyFound();
14132 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14135 "VK_IMAGE_LAYOUT_UNDEFINED or "
14136 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014137 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14138 // Expect INVALID_LAYOUT
14139 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14140 m_errorMonitor->VerifyFound();
14141 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14142}
14143
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014144TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14145
14146 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014148
14149 ASSERT_NO_FATAL_FAILURE(InitState());
14150
14151 VkImageObj src_image(m_device);
14152 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14153 VkImageObj dst_image(m_device);
14154 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14155
14156 BeginCommandBuffer();
14157 VkImageCopy copy_region;
14158 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14159 copy_region.srcSubresource.mipLevel = 0;
14160 copy_region.srcSubresource.baseArrayLayer = 0;
14161 copy_region.srcSubresource.layerCount = 0;
14162 copy_region.srcOffset.x = 0;
14163 copy_region.srcOffset.y = 0;
14164 copy_region.srcOffset.z = 0;
14165 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14166 copy_region.dstSubresource.mipLevel = 0;
14167 copy_region.dstSubresource.baseArrayLayer = 0;
14168 copy_region.dstSubresource.layerCount = 0;
14169 copy_region.dstOffset.x = 0;
14170 copy_region.dstOffset.y = 0;
14171 copy_region.dstOffset.z = 0;
14172 copy_region.extent.width = 64;
14173 copy_region.extent.height = 64;
14174 copy_region.extent.depth = 1;
14175 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14176 &copy_region);
14177 EndCommandBuffer();
14178
14179 m_errorMonitor->VerifyFound();
14180}
14181
14182TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14183
14184 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014186
14187 ASSERT_NO_FATAL_FAILURE(InitState());
14188
14189 VkImageObj src_image(m_device);
14190 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14191 VkImageObj dst_image(m_device);
14192 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14193
14194 BeginCommandBuffer();
14195 VkImageCopy copy_region;
14196 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14197 copy_region.srcSubresource.mipLevel = 0;
14198 copy_region.srcSubresource.baseArrayLayer = 0;
14199 copy_region.srcSubresource.layerCount = 0;
14200 copy_region.srcOffset.x = 0;
14201 copy_region.srcOffset.y = 0;
14202 copy_region.srcOffset.z = 0;
14203 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14204 copy_region.dstSubresource.mipLevel = 0;
14205 copy_region.dstSubresource.baseArrayLayer = 0;
14206 copy_region.dstSubresource.layerCount = 0;
14207 copy_region.dstOffset.x = 0;
14208 copy_region.dstOffset.y = 0;
14209 copy_region.dstOffset.z = 0;
14210 copy_region.extent.width = 64;
14211 copy_region.extent.height = 64;
14212 copy_region.extent.depth = 1;
14213 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14214 &copy_region);
14215 EndCommandBuffer();
14216
14217 m_errorMonitor->VerifyFound();
14218}
14219
Karl Schultz6addd812016-02-02 17:17:23 -070014220TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014221 VkResult err;
14222 bool pass;
14223
14224 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14226 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014227
14228 ASSERT_NO_FATAL_FAILURE(InitState());
14229
14230 // Create two images of different types and try to copy between them
14231 VkImage srcImage;
14232 VkImage dstImage;
14233 VkDeviceMemory srcMem;
14234 VkDeviceMemory destMem;
14235 VkMemoryRequirements memReqs;
14236
14237 VkImageCreateInfo image_create_info = {};
14238 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14239 image_create_info.pNext = NULL;
14240 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14241 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14242 image_create_info.extent.width = 32;
14243 image_create_info.extent.height = 32;
14244 image_create_info.extent.depth = 1;
14245 image_create_info.mipLevels = 1;
14246 image_create_info.arrayLayers = 1;
14247 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14248 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14249 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14250 image_create_info.flags = 0;
14251
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014252 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014253 ASSERT_VK_SUCCESS(err);
14254
14255 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14256 // Introduce failure by creating second image with a different-sized format.
14257 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14258
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014259 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014260 ASSERT_VK_SUCCESS(err);
14261
14262 // Allocate memory
14263 VkMemoryAllocateInfo memAlloc = {};
14264 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14265 memAlloc.pNext = NULL;
14266 memAlloc.allocationSize = 0;
14267 memAlloc.memoryTypeIndex = 0;
14268
14269 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14270 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014271 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014272 ASSERT_TRUE(pass);
14273 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14274 ASSERT_VK_SUCCESS(err);
14275
14276 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14277 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014278 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014279 ASSERT_TRUE(pass);
14280 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14281 ASSERT_VK_SUCCESS(err);
14282
14283 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14284 ASSERT_VK_SUCCESS(err);
14285 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14286 ASSERT_VK_SUCCESS(err);
14287
14288 BeginCommandBuffer();
14289 VkImageCopy copyRegion;
14290 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14291 copyRegion.srcSubresource.mipLevel = 0;
14292 copyRegion.srcSubresource.baseArrayLayer = 0;
14293 copyRegion.srcSubresource.layerCount = 0;
14294 copyRegion.srcOffset.x = 0;
14295 copyRegion.srcOffset.y = 0;
14296 copyRegion.srcOffset.z = 0;
14297 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14298 copyRegion.dstSubresource.mipLevel = 0;
14299 copyRegion.dstSubresource.baseArrayLayer = 0;
14300 copyRegion.dstSubresource.layerCount = 0;
14301 copyRegion.dstOffset.x = 0;
14302 copyRegion.dstOffset.y = 0;
14303 copyRegion.dstOffset.z = 0;
14304 copyRegion.extent.width = 1;
14305 copyRegion.extent.height = 1;
14306 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014307 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014308 EndCommandBuffer();
14309
14310 m_errorMonitor->VerifyFound();
14311
14312 vkDestroyImage(m_device->device(), srcImage, NULL);
14313 vkDestroyImage(m_device->device(), dstImage, NULL);
14314 vkFreeMemory(m_device->device(), srcMem, NULL);
14315 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014316}
14317
Karl Schultz6addd812016-02-02 17:17:23 -070014318TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14319 VkResult err;
14320 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014321
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014322 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14324 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014325
Mike Stroyana3082432015-09-25 13:39:21 -060014326 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014327
14328 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014329 VkImage srcImage;
14330 VkImage dstImage;
14331 VkDeviceMemory srcMem;
14332 VkDeviceMemory destMem;
14333 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014334
14335 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014336 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14337 image_create_info.pNext = NULL;
14338 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14339 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14340 image_create_info.extent.width = 32;
14341 image_create_info.extent.height = 32;
14342 image_create_info.extent.depth = 1;
14343 image_create_info.mipLevels = 1;
14344 image_create_info.arrayLayers = 1;
14345 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14346 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14347 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14348 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014350 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014351 ASSERT_VK_SUCCESS(err);
14352
Karl Schultzbdb75952016-04-19 11:36:49 -060014353 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14354
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014355 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014356 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014357 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014358 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014360 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014361 ASSERT_VK_SUCCESS(err);
14362
14363 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014364 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014365 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14366 memAlloc.pNext = NULL;
14367 memAlloc.allocationSize = 0;
14368 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014369
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014370 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014371 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014372 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014373 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014374 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014375 ASSERT_VK_SUCCESS(err);
14376
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014377 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014378 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014379 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014380 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014381 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014382 ASSERT_VK_SUCCESS(err);
14383
14384 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14385 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014386 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014387 ASSERT_VK_SUCCESS(err);
14388
14389 BeginCommandBuffer();
14390 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014391 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014392 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014393 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014394 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014395 copyRegion.srcOffset.x = 0;
14396 copyRegion.srcOffset.y = 0;
14397 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014398 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014399 copyRegion.dstSubresource.mipLevel = 0;
14400 copyRegion.dstSubresource.baseArrayLayer = 0;
14401 copyRegion.dstSubresource.layerCount = 0;
14402 copyRegion.dstOffset.x = 0;
14403 copyRegion.dstOffset.y = 0;
14404 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014405 copyRegion.extent.width = 1;
14406 copyRegion.extent.height = 1;
14407 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014408 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014409 EndCommandBuffer();
14410
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014411 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014412
Chia-I Wuf7458c52015-10-26 21:10:41 +080014413 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014414 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014415 vkFreeMemory(m_device->device(), srcMem, NULL);
14416 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014417}
14418
Karl Schultz6addd812016-02-02 17:17:23 -070014419TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14420 VkResult err;
14421 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14424 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014425
Mike Stroyana3082432015-09-25 13:39:21 -060014426 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014427
14428 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014429 VkImage srcImage;
14430 VkImage dstImage;
14431 VkDeviceMemory srcMem;
14432 VkDeviceMemory destMem;
14433 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014434
14435 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014436 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14437 image_create_info.pNext = NULL;
14438 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14439 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14440 image_create_info.extent.width = 32;
14441 image_create_info.extent.height = 1;
14442 image_create_info.extent.depth = 1;
14443 image_create_info.mipLevels = 1;
14444 image_create_info.arrayLayers = 1;
14445 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14446 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14447 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14448 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014450 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014451 ASSERT_VK_SUCCESS(err);
14452
Karl Schultz6addd812016-02-02 17:17:23 -070014453 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014454
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014455 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014456 ASSERT_VK_SUCCESS(err);
14457
14458 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014459 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014460 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14461 memAlloc.pNext = NULL;
14462 memAlloc.allocationSize = 0;
14463 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014464
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014465 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014466 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014467 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014468 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014469 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014470 ASSERT_VK_SUCCESS(err);
14471
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014472 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014473 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014474 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014475 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014476 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014477 ASSERT_VK_SUCCESS(err);
14478
14479 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14480 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014481 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014482 ASSERT_VK_SUCCESS(err);
14483
14484 BeginCommandBuffer();
14485 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014486 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14487 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014488 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014489 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014490 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014491 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014492 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014493 resolveRegion.srcOffset.x = 0;
14494 resolveRegion.srcOffset.y = 0;
14495 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014496 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014497 resolveRegion.dstSubresource.mipLevel = 0;
14498 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014499 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014500 resolveRegion.dstOffset.x = 0;
14501 resolveRegion.dstOffset.y = 0;
14502 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014503 resolveRegion.extent.width = 1;
14504 resolveRegion.extent.height = 1;
14505 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014506 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014507 EndCommandBuffer();
14508
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014509 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014510
Chia-I Wuf7458c52015-10-26 21:10:41 +080014511 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014512 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014513 vkFreeMemory(m_device->device(), srcMem, NULL);
14514 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014515}
14516
Karl Schultz6addd812016-02-02 17:17:23 -070014517TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14518 VkResult err;
14519 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14522 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014523
Mike Stroyana3082432015-09-25 13:39:21 -060014524 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014525
Chris Forbesa7530692016-05-08 12:35:39 +120014526 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014527 VkImage srcImage;
14528 VkImage dstImage;
14529 VkDeviceMemory srcMem;
14530 VkDeviceMemory destMem;
14531 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014532
14533 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014534 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14535 image_create_info.pNext = NULL;
14536 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14537 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14538 image_create_info.extent.width = 32;
14539 image_create_info.extent.height = 1;
14540 image_create_info.extent.depth = 1;
14541 image_create_info.mipLevels = 1;
14542 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014543 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014544 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14545 // Note: Some implementations expect color attachment usage for any
14546 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014547 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014548 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014550 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014551 ASSERT_VK_SUCCESS(err);
14552
Karl Schultz6addd812016-02-02 17:17:23 -070014553 // Note: Some implementations expect color attachment usage for any
14554 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014555 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014556
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014557 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014558 ASSERT_VK_SUCCESS(err);
14559
14560 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014561 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014562 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14563 memAlloc.pNext = NULL;
14564 memAlloc.allocationSize = 0;
14565 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014566
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014567 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014568 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014569 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014570 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014571 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014572 ASSERT_VK_SUCCESS(err);
14573
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014574 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014575 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014576 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014577 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014578 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014579 ASSERT_VK_SUCCESS(err);
14580
14581 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14582 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014583 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014584 ASSERT_VK_SUCCESS(err);
14585
14586 BeginCommandBuffer();
14587 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014588 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14589 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014590 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014591 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014592 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014593 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014594 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014595 resolveRegion.srcOffset.x = 0;
14596 resolveRegion.srcOffset.y = 0;
14597 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014598 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014599 resolveRegion.dstSubresource.mipLevel = 0;
14600 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014601 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014602 resolveRegion.dstOffset.x = 0;
14603 resolveRegion.dstOffset.y = 0;
14604 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014605 resolveRegion.extent.width = 1;
14606 resolveRegion.extent.height = 1;
14607 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014608 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014609 EndCommandBuffer();
14610
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014611 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014612
Chia-I Wuf7458c52015-10-26 21:10:41 +080014613 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014614 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014615 vkFreeMemory(m_device->device(), srcMem, NULL);
14616 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014617}
14618
Karl Schultz6addd812016-02-02 17:17:23 -070014619TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14620 VkResult err;
14621 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14624 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014625
Mike Stroyana3082432015-09-25 13:39:21 -060014626 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014627
14628 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014629 VkImage srcImage;
14630 VkImage dstImage;
14631 VkDeviceMemory srcMem;
14632 VkDeviceMemory destMem;
14633 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014634
14635 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014636 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14637 image_create_info.pNext = NULL;
14638 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14639 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14640 image_create_info.extent.width = 32;
14641 image_create_info.extent.height = 1;
14642 image_create_info.extent.depth = 1;
14643 image_create_info.mipLevels = 1;
14644 image_create_info.arrayLayers = 1;
14645 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14646 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14647 // Note: Some implementations expect color attachment usage for any
14648 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014649 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014650 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014651
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014652 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014653 ASSERT_VK_SUCCESS(err);
14654
Karl Schultz6addd812016-02-02 17:17:23 -070014655 // Set format to something other than source image
14656 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14657 // Note: Some implementations expect color attachment usage for any
14658 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014659 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014660 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014662 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014663 ASSERT_VK_SUCCESS(err);
14664
14665 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014666 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014667 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14668 memAlloc.pNext = NULL;
14669 memAlloc.allocationSize = 0;
14670 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014671
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014672 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014673 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014674 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014675 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014676 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014677 ASSERT_VK_SUCCESS(err);
14678
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014679 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014680 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014681 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014682 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014683 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014684 ASSERT_VK_SUCCESS(err);
14685
14686 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14687 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014688 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014689 ASSERT_VK_SUCCESS(err);
14690
14691 BeginCommandBuffer();
14692 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014693 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14694 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014695 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014696 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014697 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014698 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014699 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014700 resolveRegion.srcOffset.x = 0;
14701 resolveRegion.srcOffset.y = 0;
14702 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014703 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014704 resolveRegion.dstSubresource.mipLevel = 0;
14705 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014706 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014707 resolveRegion.dstOffset.x = 0;
14708 resolveRegion.dstOffset.y = 0;
14709 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014710 resolveRegion.extent.width = 1;
14711 resolveRegion.extent.height = 1;
14712 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014713 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014714 EndCommandBuffer();
14715
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014716 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014717
Chia-I Wuf7458c52015-10-26 21:10:41 +080014718 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014719 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014720 vkFreeMemory(m_device->device(), srcMem, NULL);
14721 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014722}
14723
Karl Schultz6addd812016-02-02 17:17:23 -070014724TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14725 VkResult err;
14726 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014727
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14729 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014730
Mike Stroyana3082432015-09-25 13:39:21 -060014731 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014732
14733 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014734 VkImage srcImage;
14735 VkImage dstImage;
14736 VkDeviceMemory srcMem;
14737 VkDeviceMemory destMem;
14738 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014739
14740 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014741 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14742 image_create_info.pNext = NULL;
14743 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14744 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14745 image_create_info.extent.width = 32;
14746 image_create_info.extent.height = 1;
14747 image_create_info.extent.depth = 1;
14748 image_create_info.mipLevels = 1;
14749 image_create_info.arrayLayers = 1;
14750 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14751 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14752 // Note: Some implementations expect color attachment usage for any
14753 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014754 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014755 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014756
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014757 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014758 ASSERT_VK_SUCCESS(err);
14759
Karl Schultz6addd812016-02-02 17:17:23 -070014760 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14761 // Note: Some implementations expect color attachment usage for any
14762 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014763 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014764 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014765
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014766 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014767 ASSERT_VK_SUCCESS(err);
14768
14769 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014770 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014771 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14772 memAlloc.pNext = NULL;
14773 memAlloc.allocationSize = 0;
14774 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014775
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014776 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014777 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014778 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014779 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014780 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014781 ASSERT_VK_SUCCESS(err);
14782
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014783 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014784 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014785 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014786 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014787 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014788 ASSERT_VK_SUCCESS(err);
14789
14790 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14791 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014792 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014793 ASSERT_VK_SUCCESS(err);
14794
14795 BeginCommandBuffer();
14796 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014797 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14798 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014799 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014800 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014801 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014802 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014803 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014804 resolveRegion.srcOffset.x = 0;
14805 resolveRegion.srcOffset.y = 0;
14806 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014807 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014808 resolveRegion.dstSubresource.mipLevel = 0;
14809 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014810 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014811 resolveRegion.dstOffset.x = 0;
14812 resolveRegion.dstOffset.y = 0;
14813 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014814 resolveRegion.extent.width = 1;
14815 resolveRegion.extent.height = 1;
14816 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014817 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014818 EndCommandBuffer();
14819
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014820 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014821
Chia-I Wuf7458c52015-10-26 21:10:41 +080014822 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014823 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014824 vkFreeMemory(m_device->device(), srcMem, NULL);
14825 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014826}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014827
Karl Schultz6addd812016-02-02 17:17:23 -070014828TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014829 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014830 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14831 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014832 // The image format check comes 2nd in validation so we trigger it first,
14833 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014834 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14837 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014838
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014839 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014840
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014841 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014842 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14843 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014844
14845 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014846 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14847 ds_pool_ci.pNext = NULL;
14848 ds_pool_ci.maxSets = 1;
14849 ds_pool_ci.poolSizeCount = 1;
14850 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014851
14852 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014853 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014854 ASSERT_VK_SUCCESS(err);
14855
14856 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014857 dsl_binding.binding = 0;
14858 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14859 dsl_binding.descriptorCount = 1;
14860 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14861 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014862
14863 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014864 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14865 ds_layout_ci.pNext = NULL;
14866 ds_layout_ci.bindingCount = 1;
14867 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014868 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014869 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014870 ASSERT_VK_SUCCESS(err);
14871
14872 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014873 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014874 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014875 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014876 alloc_info.descriptorPool = ds_pool;
14877 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014878 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014879 ASSERT_VK_SUCCESS(err);
14880
Karl Schultz6addd812016-02-02 17:17:23 -070014881 VkImage image_bad;
14882 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014883 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060014884 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014885 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070014886 const int32_t tex_width = 32;
14887 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014888
14889 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014890 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14891 image_create_info.pNext = NULL;
14892 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14893 image_create_info.format = tex_format_bad;
14894 image_create_info.extent.width = tex_width;
14895 image_create_info.extent.height = tex_height;
14896 image_create_info.extent.depth = 1;
14897 image_create_info.mipLevels = 1;
14898 image_create_info.arrayLayers = 1;
14899 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14900 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014901 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014902 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014903
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014904 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014905 ASSERT_VK_SUCCESS(err);
14906 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014907 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14908 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014909 ASSERT_VK_SUCCESS(err);
14910
14911 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014912 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14913 image_view_create_info.image = image_bad;
14914 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14915 image_view_create_info.format = tex_format_bad;
14916 image_view_create_info.subresourceRange.baseArrayLayer = 0;
14917 image_view_create_info.subresourceRange.baseMipLevel = 0;
14918 image_view_create_info.subresourceRange.layerCount = 1;
14919 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014920 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014921
14922 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014923 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014924
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014925 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014926
Chia-I Wuf7458c52015-10-26 21:10:41 +080014927 vkDestroyImage(m_device->device(), image_bad, NULL);
14928 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014929 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
14930 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014931}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014932
14933TEST_F(VkLayerTest, ClearImageErrors) {
14934 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
14935 "ClearDepthStencilImage with a color image.");
14936
14937 ASSERT_NO_FATAL_FAILURE(InitState());
14938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14939
14940 // Renderpass is started here so end it as Clear cmds can't be in renderpass
14941 BeginCommandBuffer();
14942 m_commandBuffer->EndRenderPass();
14943
14944 // Color image
14945 VkClearColorValue clear_color;
14946 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
14947 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
14948 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
14949 const int32_t img_width = 32;
14950 const int32_t img_height = 32;
14951 VkImageCreateInfo image_create_info = {};
14952 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14953 image_create_info.pNext = NULL;
14954 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14955 image_create_info.format = color_format;
14956 image_create_info.extent.width = img_width;
14957 image_create_info.extent.height = img_height;
14958 image_create_info.extent.depth = 1;
14959 image_create_info.mipLevels = 1;
14960 image_create_info.arrayLayers = 1;
14961 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14962 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14963 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14964
14965 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014966 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014968 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014969
14970 // Depth/Stencil image
14971 VkClearDepthStencilValue clear_value = {0};
14972 reqs = 0; // don't need HOST_VISIBLE DS image
14973 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
14974 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
14975 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
14976 ds_image_create_info.extent.width = 64;
14977 ds_image_create_info.extent.height = 64;
14978 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14979 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
14980
14981 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014982 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014984 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 -060014985
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014988 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014989 &color_range);
14990
14991 m_errorMonitor->VerifyFound();
14992
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
14994 "image created without "
14995 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060014996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014997 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060014998 &color_range);
14999
15000 m_errorMonitor->VerifyFound();
15001
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015002 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15004 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015006 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15007 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015008
15009 m_errorMonitor->VerifyFound();
15010}
Tobin Ehliscde08892015-09-22 10:11:37 -060015011#endif // IMAGE_TESTS
15012
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015013
15014// WSI Enabled Tests
15015//
15016TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15017
15018#if defined(VK_USE_PLATFORM_XCB_KHR)
15019 VkSurfaceKHR surface = VK_NULL_HANDLE;
15020
15021 VkResult err;
15022 bool pass;
15023 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15024 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15025 // uint32_t swapchain_image_count = 0;
15026 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15027 // uint32_t image_index = 0;
15028 // VkPresentInfoKHR present_info = {};
15029
15030 ASSERT_NO_FATAL_FAILURE(InitState());
15031
15032 // Use the create function from one of the VK_KHR_*_surface extension in
15033 // order to create a surface, testing all known errors in the process,
15034 // before successfully creating a surface:
15035 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15037 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15038 pass = (err != VK_SUCCESS);
15039 ASSERT_TRUE(pass);
15040 m_errorMonitor->VerifyFound();
15041
15042 // Next, try to create a surface with the wrong
15043 // VkXcbSurfaceCreateInfoKHR::sType:
15044 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15045 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15047 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15048 pass = (err != VK_SUCCESS);
15049 ASSERT_TRUE(pass);
15050 m_errorMonitor->VerifyFound();
15051
15052 // Create a native window, and then correctly create a surface:
15053 xcb_connection_t *connection;
15054 xcb_screen_t *screen;
15055 xcb_window_t xcb_window;
15056 xcb_intern_atom_reply_t *atom_wm_delete_window;
15057
15058 const xcb_setup_t *setup;
15059 xcb_screen_iterator_t iter;
15060 int scr;
15061 uint32_t value_mask, value_list[32];
15062 int width = 1;
15063 int height = 1;
15064
15065 connection = xcb_connect(NULL, &scr);
15066 ASSERT_TRUE(connection != NULL);
15067 setup = xcb_get_setup(connection);
15068 iter = xcb_setup_roots_iterator(setup);
15069 while (scr-- > 0)
15070 xcb_screen_next(&iter);
15071 screen = iter.data;
15072
15073 xcb_window = xcb_generate_id(connection);
15074
15075 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15076 value_list[0] = screen->black_pixel;
15077 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15078
15079 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15080 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15081
15082 /* Magic code that will send notification when window is destroyed */
15083 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15084 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15085
15086 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15087 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15088 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15089 free(reply);
15090
15091 xcb_map_window(connection, xcb_window);
15092
15093 // Force the x/y coordinates to 100,100 results are identical in consecutive
15094 // runs
15095 const uint32_t coords[] = { 100, 100 };
15096 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15097
15098 // Finally, try to correctly create a surface:
15099 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15100 xcb_create_info.pNext = NULL;
15101 xcb_create_info.flags = 0;
15102 xcb_create_info.connection = connection;
15103 xcb_create_info.window = xcb_window;
15104 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15105 pass = (err == VK_SUCCESS);
15106 ASSERT_TRUE(pass);
15107
15108 // Check if surface supports presentation:
15109
15110 // 1st, do so without having queried the queue families:
15111 VkBool32 supported = false;
15112 // TODO: Get the following error to come out:
15113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15114 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15115 "function");
15116 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15117 pass = (err != VK_SUCCESS);
15118 // ASSERT_TRUE(pass);
15119 // m_errorMonitor->VerifyFound();
15120
15121 // Next, query a queue family index that's too large:
15122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15123 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15124 pass = (err != VK_SUCCESS);
15125 ASSERT_TRUE(pass);
15126 m_errorMonitor->VerifyFound();
15127
15128 // Finally, do so correctly:
15129 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15130 // SUPPORTED
15131 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15132 pass = (err == VK_SUCCESS);
15133 ASSERT_TRUE(pass);
15134
15135 // Before proceeding, try to create a swapchain without having called
15136 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15137 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15138 swapchain_create_info.pNext = NULL;
15139 swapchain_create_info.flags = 0;
15140 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15141 swapchain_create_info.surface = surface;
15142 swapchain_create_info.imageArrayLayers = 1;
15143 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15144 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15146 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15147 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15148 pass = (err != VK_SUCCESS);
15149 ASSERT_TRUE(pass);
15150 m_errorMonitor->VerifyFound();
15151
15152 // Get the surface capabilities:
15153 VkSurfaceCapabilitiesKHR surface_capabilities;
15154
15155 // Do so correctly (only error logged by this entrypoint is if the
15156 // extension isn't enabled):
15157 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15158 pass = (err == VK_SUCCESS);
15159 ASSERT_TRUE(pass);
15160
15161 // Get the surface formats:
15162 uint32_t surface_format_count;
15163
15164 // First, try without a pointer to surface_format_count:
15165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15166 "specified as NULL");
15167 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15168 pass = (err == VK_SUCCESS);
15169 ASSERT_TRUE(pass);
15170 m_errorMonitor->VerifyFound();
15171
15172 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15173 // correctly done a 1st try (to get the count):
15174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15175 surface_format_count = 0;
15176 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15177 pass = (err == VK_SUCCESS);
15178 ASSERT_TRUE(pass);
15179 m_errorMonitor->VerifyFound();
15180
15181 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15182 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15183 pass = (err == VK_SUCCESS);
15184 ASSERT_TRUE(pass);
15185
15186 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15187 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15188
15189 // Next, do a 2nd try with surface_format_count being set too high:
15190 surface_format_count += 5;
15191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15192 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15193 pass = (err == VK_SUCCESS);
15194 ASSERT_TRUE(pass);
15195 m_errorMonitor->VerifyFound();
15196
15197 // Finally, do a correct 1st and 2nd try:
15198 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15199 pass = (err == VK_SUCCESS);
15200 ASSERT_TRUE(pass);
15201 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15202 pass = (err == VK_SUCCESS);
15203 ASSERT_TRUE(pass);
15204
15205 // Get the surface present modes:
15206 uint32_t surface_present_mode_count;
15207
15208 // First, try without a pointer to surface_format_count:
15209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15210 "specified as NULL");
15211
15212 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15213 pass = (err == VK_SUCCESS);
15214 ASSERT_TRUE(pass);
15215 m_errorMonitor->VerifyFound();
15216
15217 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15218 // correctly done a 1st try (to get the count):
15219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15220 surface_present_mode_count = 0;
15221 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15222 (VkPresentModeKHR *)&surface_present_mode_count);
15223 pass = (err == VK_SUCCESS);
15224 ASSERT_TRUE(pass);
15225 m_errorMonitor->VerifyFound();
15226
15227 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15228 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15229 pass = (err == VK_SUCCESS);
15230 ASSERT_TRUE(pass);
15231
15232 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15233 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15234
15235 // Next, do a 2nd try with surface_format_count being set too high:
15236 surface_present_mode_count += 5;
15237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15238 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15239 pass = (err == VK_SUCCESS);
15240 ASSERT_TRUE(pass);
15241 m_errorMonitor->VerifyFound();
15242
15243 // Finally, do a correct 1st and 2nd try:
15244 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15245 pass = (err == VK_SUCCESS);
15246 ASSERT_TRUE(pass);
15247 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15248 pass = (err == VK_SUCCESS);
15249 ASSERT_TRUE(pass);
15250
15251 // Create a swapchain:
15252
15253 // First, try without a pointer to swapchain_create_info:
15254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15255 "specified as NULL");
15256
15257 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15258 pass = (err != VK_SUCCESS);
15259 ASSERT_TRUE(pass);
15260 m_errorMonitor->VerifyFound();
15261
15262 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15263 // sType:
15264 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15266
15267 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15268 pass = (err != VK_SUCCESS);
15269 ASSERT_TRUE(pass);
15270 m_errorMonitor->VerifyFound();
15271
15272 // Next, call with a NULL swapchain pointer:
15273 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15274 swapchain_create_info.pNext = NULL;
15275 swapchain_create_info.flags = 0;
15276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15277 "specified as NULL");
15278
15279 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15280 pass = (err != VK_SUCCESS);
15281 ASSERT_TRUE(pass);
15282 m_errorMonitor->VerifyFound();
15283
15284 // TODO: Enhance swapchain layer so that
15285 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15286
15287 // Next, call with a queue family index that's too large:
15288 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15289 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15290 swapchain_create_info.queueFamilyIndexCount = 2;
15291 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15293 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15294 pass = (err != VK_SUCCESS);
15295 ASSERT_TRUE(pass);
15296 m_errorMonitor->VerifyFound();
15297
15298 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15299 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15300 swapchain_create_info.queueFamilyIndexCount = 1;
15301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15302 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15303 "pCreateInfo->pQueueFamilyIndices).");
15304 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15305 pass = (err != VK_SUCCESS);
15306 ASSERT_TRUE(pass);
15307 m_errorMonitor->VerifyFound();
15308
15309 // Next, call with an invalid imageSharingMode:
15310 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15311 swapchain_create_info.queueFamilyIndexCount = 1;
15312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15313 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15314 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15315 pass = (err != VK_SUCCESS);
15316 ASSERT_TRUE(pass);
15317 m_errorMonitor->VerifyFound();
15318 // Fix for the future:
15319 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15320 // SUPPORTED
15321 swapchain_create_info.queueFamilyIndexCount = 0;
15322 queueFamilyIndex[0] = 0;
15323 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15324
15325 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15326 // Get the images from a swapchain:
15327 // Acquire an image from a swapchain:
15328 // Present an image to a swapchain:
15329 // Destroy the swapchain:
15330
15331 // TODOs:
15332 //
15333 // - Try destroying the device without first destroying the swapchain
15334 //
15335 // - Try destroying the device without first destroying the surface
15336 //
15337 // - Try destroying the surface without first destroying the swapchain
15338
15339 // Destroy the surface:
15340 vkDestroySurfaceKHR(instance(), surface, NULL);
15341
15342 // Tear down the window:
15343 xcb_destroy_window(connection, xcb_window);
15344 xcb_disconnect(connection);
15345
15346#else // VK_USE_PLATFORM_XCB_KHR
15347 return;
15348#endif // VK_USE_PLATFORM_XCB_KHR
15349}
15350
15351//
15352// POSITIVE VALIDATION TESTS
15353//
15354// These tests do not expect to encounter ANY validation errors pass only if this is true
15355
Tobin Ehlise0006882016-11-03 10:14:28 -060015356TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15357 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15358 "by a transition in the primary.");
15359 VkResult err;
15360 m_errorMonitor->ExpectSuccess();
15361 ASSERT_NO_FATAL_FAILURE(InitState());
15362 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15363 // Allocate a secondary and primary cmd buffer
15364 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15365 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15366 command_buffer_allocate_info.commandPool = m_commandPool;
15367 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15368 command_buffer_allocate_info.commandBufferCount = 1;
15369
15370 VkCommandBuffer secondary_command_buffer;
15371 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15372 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15373 VkCommandBuffer primary_command_buffer;
15374 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15375 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15376 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15377 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15378 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15379 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15380 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15381
15382 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15383 ASSERT_VK_SUCCESS(err);
15384 VkImageObj image(m_device);
15385 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15386 ASSERT_TRUE(image.initialized());
15387 VkImageMemoryBarrier img_barrier = {};
15388 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15389 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15390 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15391 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15392 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15393 img_barrier.image = image.handle();
15394 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15395 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15396 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15397 img_barrier.subresourceRange.baseArrayLayer = 0;
15398 img_barrier.subresourceRange.baseMipLevel = 0;
15399 img_barrier.subresourceRange.layerCount = 1;
15400 img_barrier.subresourceRange.levelCount = 1;
15401 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15402 0, nullptr, 1, &img_barrier);
15403 err = vkEndCommandBuffer(secondary_command_buffer);
15404 ASSERT_VK_SUCCESS(err);
15405
15406 // Now update primary cmd buffer to execute secondary and transitions image
15407 command_buffer_begin_info.pInheritanceInfo = nullptr;
15408 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15409 ASSERT_VK_SUCCESS(err);
15410 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15411 VkImageMemoryBarrier img_barrier2 = {};
15412 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15413 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15414 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15415 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15416 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15417 img_barrier2.image = image.handle();
15418 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15419 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15420 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15421 img_barrier2.subresourceRange.baseArrayLayer = 0;
15422 img_barrier2.subresourceRange.baseMipLevel = 0;
15423 img_barrier2.subresourceRange.layerCount = 1;
15424 img_barrier2.subresourceRange.levelCount = 1;
15425 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15426 nullptr, 1, &img_barrier2);
15427 err = vkEndCommandBuffer(primary_command_buffer);
15428 ASSERT_VK_SUCCESS(err);
15429 VkSubmitInfo submit_info = {};
15430 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15431 submit_info.commandBufferCount = 1;
15432 submit_info.pCommandBuffers = &primary_command_buffer;
15433 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15434 ASSERT_VK_SUCCESS(err);
15435 m_errorMonitor->VerifyNotFound();
15436 err = vkDeviceWaitIdle(m_device->device());
15437 ASSERT_VK_SUCCESS(err);
15438 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15439 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15440}
15441
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015442// This is a positive test. No failures are expected.
15443TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15444 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15445 "is ignoring VkWriteDescriptorSet members that are not "
15446 "related to the descriptor type specified by "
15447 "VkWriteDescriptorSet::descriptorType. Correct "
15448 "validation behavior will result in the test running to "
15449 "completion without validation errors.");
15450
15451 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15452
15453 ASSERT_NO_FATAL_FAILURE(InitState());
15454
15455 // Image Case
15456 {
15457 m_errorMonitor->ExpectSuccess();
15458
15459 VkImage image;
15460 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15461 const int32_t tex_width = 32;
15462 const int32_t tex_height = 32;
15463 VkImageCreateInfo image_create_info = {};
15464 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15465 image_create_info.pNext = NULL;
15466 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15467 image_create_info.format = tex_format;
15468 image_create_info.extent.width = tex_width;
15469 image_create_info.extent.height = tex_height;
15470 image_create_info.extent.depth = 1;
15471 image_create_info.mipLevels = 1;
15472 image_create_info.arrayLayers = 1;
15473 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15474 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15475 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15476 image_create_info.flags = 0;
15477 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15478 ASSERT_VK_SUCCESS(err);
15479
15480 VkMemoryRequirements memory_reqs;
15481 VkDeviceMemory image_memory;
15482 bool pass;
15483 VkMemoryAllocateInfo memory_info = {};
15484 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15485 memory_info.pNext = NULL;
15486 memory_info.allocationSize = 0;
15487 memory_info.memoryTypeIndex = 0;
15488 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15489 memory_info.allocationSize = memory_reqs.size;
15490 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15491 ASSERT_TRUE(pass);
15492 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15493 ASSERT_VK_SUCCESS(err);
15494 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15495 ASSERT_VK_SUCCESS(err);
15496
15497 VkImageViewCreateInfo image_view_create_info = {};
15498 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15499 image_view_create_info.image = image;
15500 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15501 image_view_create_info.format = tex_format;
15502 image_view_create_info.subresourceRange.layerCount = 1;
15503 image_view_create_info.subresourceRange.baseMipLevel = 0;
15504 image_view_create_info.subresourceRange.levelCount = 1;
15505 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15506
15507 VkImageView view;
15508 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15509 ASSERT_VK_SUCCESS(err);
15510
15511 VkDescriptorPoolSize ds_type_count = {};
15512 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15513 ds_type_count.descriptorCount = 1;
15514
15515 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15516 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15517 ds_pool_ci.pNext = NULL;
15518 ds_pool_ci.maxSets = 1;
15519 ds_pool_ci.poolSizeCount = 1;
15520 ds_pool_ci.pPoolSizes = &ds_type_count;
15521
15522 VkDescriptorPool ds_pool;
15523 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15524 ASSERT_VK_SUCCESS(err);
15525
15526 VkDescriptorSetLayoutBinding dsl_binding = {};
15527 dsl_binding.binding = 0;
15528 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15529 dsl_binding.descriptorCount = 1;
15530 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15531 dsl_binding.pImmutableSamplers = NULL;
15532
15533 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15534 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15535 ds_layout_ci.pNext = NULL;
15536 ds_layout_ci.bindingCount = 1;
15537 ds_layout_ci.pBindings = &dsl_binding;
15538 VkDescriptorSetLayout ds_layout;
15539 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15540 ASSERT_VK_SUCCESS(err);
15541
15542 VkDescriptorSet descriptor_set;
15543 VkDescriptorSetAllocateInfo alloc_info = {};
15544 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15545 alloc_info.descriptorSetCount = 1;
15546 alloc_info.descriptorPool = ds_pool;
15547 alloc_info.pSetLayouts = &ds_layout;
15548 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15549 ASSERT_VK_SUCCESS(err);
15550
15551 VkDescriptorImageInfo image_info = {};
15552 image_info.imageView = view;
15553 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15554
15555 VkWriteDescriptorSet descriptor_write;
15556 memset(&descriptor_write, 0, sizeof(descriptor_write));
15557 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15558 descriptor_write.dstSet = descriptor_set;
15559 descriptor_write.dstBinding = 0;
15560 descriptor_write.descriptorCount = 1;
15561 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15562 descriptor_write.pImageInfo = &image_info;
15563
15564 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15565 // be
15566 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15567 // This will most likely produce a crash if the parameter_validation
15568 // layer
15569 // does not correctly ignore pBufferInfo.
15570 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15571 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15572
15573 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15574
15575 m_errorMonitor->VerifyNotFound();
15576
15577 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15578 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15579 vkDestroyImageView(m_device->device(), view, NULL);
15580 vkDestroyImage(m_device->device(), image, NULL);
15581 vkFreeMemory(m_device->device(), image_memory, NULL);
15582 }
15583
15584 // Buffer Case
15585 {
15586 m_errorMonitor->ExpectSuccess();
15587
15588 VkBuffer buffer;
15589 uint32_t queue_family_index = 0;
15590 VkBufferCreateInfo buffer_create_info = {};
15591 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15592 buffer_create_info.size = 1024;
15593 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15594 buffer_create_info.queueFamilyIndexCount = 1;
15595 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15596
15597 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15598 ASSERT_VK_SUCCESS(err);
15599
15600 VkMemoryRequirements memory_reqs;
15601 VkDeviceMemory buffer_memory;
15602 bool pass;
15603 VkMemoryAllocateInfo memory_info = {};
15604 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15605 memory_info.pNext = NULL;
15606 memory_info.allocationSize = 0;
15607 memory_info.memoryTypeIndex = 0;
15608
15609 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15610 memory_info.allocationSize = memory_reqs.size;
15611 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15612 ASSERT_TRUE(pass);
15613
15614 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15615 ASSERT_VK_SUCCESS(err);
15616 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15617 ASSERT_VK_SUCCESS(err);
15618
15619 VkDescriptorPoolSize ds_type_count = {};
15620 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15621 ds_type_count.descriptorCount = 1;
15622
15623 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15624 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15625 ds_pool_ci.pNext = NULL;
15626 ds_pool_ci.maxSets = 1;
15627 ds_pool_ci.poolSizeCount = 1;
15628 ds_pool_ci.pPoolSizes = &ds_type_count;
15629
15630 VkDescriptorPool ds_pool;
15631 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15632 ASSERT_VK_SUCCESS(err);
15633
15634 VkDescriptorSetLayoutBinding dsl_binding = {};
15635 dsl_binding.binding = 0;
15636 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15637 dsl_binding.descriptorCount = 1;
15638 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15639 dsl_binding.pImmutableSamplers = NULL;
15640
15641 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15642 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15643 ds_layout_ci.pNext = NULL;
15644 ds_layout_ci.bindingCount = 1;
15645 ds_layout_ci.pBindings = &dsl_binding;
15646 VkDescriptorSetLayout ds_layout;
15647 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15648 ASSERT_VK_SUCCESS(err);
15649
15650 VkDescriptorSet descriptor_set;
15651 VkDescriptorSetAllocateInfo alloc_info = {};
15652 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15653 alloc_info.descriptorSetCount = 1;
15654 alloc_info.descriptorPool = ds_pool;
15655 alloc_info.pSetLayouts = &ds_layout;
15656 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15657 ASSERT_VK_SUCCESS(err);
15658
15659 VkDescriptorBufferInfo buffer_info = {};
15660 buffer_info.buffer = buffer;
15661 buffer_info.offset = 0;
15662 buffer_info.range = 1024;
15663
15664 VkWriteDescriptorSet descriptor_write;
15665 memset(&descriptor_write, 0, sizeof(descriptor_write));
15666 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15667 descriptor_write.dstSet = descriptor_set;
15668 descriptor_write.dstBinding = 0;
15669 descriptor_write.descriptorCount = 1;
15670 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15671 descriptor_write.pBufferInfo = &buffer_info;
15672
15673 // Set pImageInfo and pTexelBufferView to invalid values, which should
15674 // be
15675 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15676 // This will most likely produce a crash if the parameter_validation
15677 // layer
15678 // does not correctly ignore pImageInfo.
15679 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15680 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15681
15682 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15683
15684 m_errorMonitor->VerifyNotFound();
15685
15686 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15687 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15688 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15689 vkDestroyBuffer(m_device->device(), buffer, NULL);
15690 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15691 }
15692
15693 // Texel Buffer Case
15694 {
15695 m_errorMonitor->ExpectSuccess();
15696
15697 VkBuffer buffer;
15698 uint32_t queue_family_index = 0;
15699 VkBufferCreateInfo buffer_create_info = {};
15700 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15701 buffer_create_info.size = 1024;
15702 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15703 buffer_create_info.queueFamilyIndexCount = 1;
15704 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15705
15706 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15707 ASSERT_VK_SUCCESS(err);
15708
15709 VkMemoryRequirements memory_reqs;
15710 VkDeviceMemory buffer_memory;
15711 bool pass;
15712 VkMemoryAllocateInfo memory_info = {};
15713 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15714 memory_info.pNext = NULL;
15715 memory_info.allocationSize = 0;
15716 memory_info.memoryTypeIndex = 0;
15717
15718 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15719 memory_info.allocationSize = memory_reqs.size;
15720 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15721 ASSERT_TRUE(pass);
15722
15723 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15724 ASSERT_VK_SUCCESS(err);
15725 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15726 ASSERT_VK_SUCCESS(err);
15727
15728 VkBufferViewCreateInfo buff_view_ci = {};
15729 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15730 buff_view_ci.buffer = buffer;
15731 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15732 buff_view_ci.range = VK_WHOLE_SIZE;
15733 VkBufferView buffer_view;
15734 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15735
15736 VkDescriptorPoolSize ds_type_count = {};
15737 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15738 ds_type_count.descriptorCount = 1;
15739
15740 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15741 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15742 ds_pool_ci.pNext = NULL;
15743 ds_pool_ci.maxSets = 1;
15744 ds_pool_ci.poolSizeCount = 1;
15745 ds_pool_ci.pPoolSizes = &ds_type_count;
15746
15747 VkDescriptorPool ds_pool;
15748 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15749 ASSERT_VK_SUCCESS(err);
15750
15751 VkDescriptorSetLayoutBinding dsl_binding = {};
15752 dsl_binding.binding = 0;
15753 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15754 dsl_binding.descriptorCount = 1;
15755 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15756 dsl_binding.pImmutableSamplers = NULL;
15757
15758 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15759 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15760 ds_layout_ci.pNext = NULL;
15761 ds_layout_ci.bindingCount = 1;
15762 ds_layout_ci.pBindings = &dsl_binding;
15763 VkDescriptorSetLayout ds_layout;
15764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15765 ASSERT_VK_SUCCESS(err);
15766
15767 VkDescriptorSet descriptor_set;
15768 VkDescriptorSetAllocateInfo alloc_info = {};
15769 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15770 alloc_info.descriptorSetCount = 1;
15771 alloc_info.descriptorPool = ds_pool;
15772 alloc_info.pSetLayouts = &ds_layout;
15773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15774 ASSERT_VK_SUCCESS(err);
15775
15776 VkWriteDescriptorSet descriptor_write;
15777 memset(&descriptor_write, 0, sizeof(descriptor_write));
15778 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15779 descriptor_write.dstSet = descriptor_set;
15780 descriptor_write.dstBinding = 0;
15781 descriptor_write.descriptorCount = 1;
15782 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15783 descriptor_write.pTexelBufferView = &buffer_view;
15784
15785 // Set pImageInfo and pBufferInfo to invalid values, which should be
15786 // ignored for descriptorType ==
15787 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15788 // This will most likely produce a crash if the parameter_validation
15789 // layer
15790 // does not correctly ignore pImageInfo and pBufferInfo.
15791 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15792 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15793
15794 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15795
15796 m_errorMonitor->VerifyNotFound();
15797
15798 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15799 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15800 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15801 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15802 vkDestroyBuffer(m_device->device(), buffer, NULL);
15803 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15804 }
15805}
15806
Tobin Ehlisf7428442016-10-25 07:58:24 -060015807TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15808 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15809
15810 ASSERT_NO_FATAL_FAILURE(InitState());
15811 // Create layout where two binding #s are "1"
15812 static const uint32_t NUM_BINDINGS = 3;
15813 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15814 dsl_binding[0].binding = 1;
15815 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15816 dsl_binding[0].descriptorCount = 1;
15817 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15818 dsl_binding[0].pImmutableSamplers = NULL;
15819 dsl_binding[1].binding = 0;
15820 dsl_binding[1].descriptorCount = 1;
15821 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15822 dsl_binding[1].descriptorCount = 1;
15823 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15824 dsl_binding[1].pImmutableSamplers = NULL;
15825 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15826 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15827 dsl_binding[2].descriptorCount = 1;
15828 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15829 dsl_binding[2].pImmutableSamplers = NULL;
15830
15831 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15832 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15833 ds_layout_ci.pNext = NULL;
15834 ds_layout_ci.bindingCount = NUM_BINDINGS;
15835 ds_layout_ci.pBindings = dsl_binding;
15836 VkDescriptorSetLayout ds_layout;
15837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15838 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15839 m_errorMonitor->VerifyFound();
15840}
15841
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015842TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015843 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
15844
15845 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015846
15847 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015848
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015849 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
15850
15851 {
15852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
15853 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
15854 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15855 m_errorMonitor->VerifyFound();
15856 }
15857
15858 {
15859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
15860 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
15861 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15862 m_errorMonitor->VerifyFound();
15863 }
15864
15865 {
15866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15867 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
15868 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15869 m_errorMonitor->VerifyFound();
15870 }
15871
15872 {
15873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15874 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
15875 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15876 m_errorMonitor->VerifyFound();
15877 }
15878
15879 {
15880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
15881 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
15882 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15883 m_errorMonitor->VerifyFound();
15884 }
15885
15886 {
15887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
15888 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
15889 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15890 m_errorMonitor->VerifyFound();
15891 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015892
15893 {
15894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15895 VkRect2D scissor = {{-1, 0}, {16, 16}};
15896 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15897 m_errorMonitor->VerifyFound();
15898 }
15899
15900 {
15901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15902 VkRect2D scissor = {{0, -2}, {16, 16}};
15903 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15904 m_errorMonitor->VerifyFound();
15905 }
15906
15907 {
15908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
15909 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
15910 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15911 m_errorMonitor->VerifyFound();
15912 }
15913
15914 {
15915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
15916 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
15917 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15918 m_errorMonitor->VerifyFound();
15919 }
15920
15921 EndCommandBuffer();
15922}
15923
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015924// This is a positive test. No failures are expected.
15925TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
15926 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
15927 VkResult err;
15928
15929 ASSERT_NO_FATAL_FAILURE(InitState());
15930 m_errorMonitor->ExpectSuccess();
15931 VkDescriptorPoolSize ds_type_count = {};
15932 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15933 ds_type_count.descriptorCount = 2;
15934
15935 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15936 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15937 ds_pool_ci.pNext = NULL;
15938 ds_pool_ci.maxSets = 1;
15939 ds_pool_ci.poolSizeCount = 1;
15940 ds_pool_ci.pPoolSizes = &ds_type_count;
15941
15942 VkDescriptorPool ds_pool;
15943 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15944 ASSERT_VK_SUCCESS(err);
15945
15946 // Create layout with two uniform buffer descriptors w/ empty binding between them
15947 static const uint32_t NUM_BINDINGS = 3;
15948 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15949 dsl_binding[0].binding = 0;
15950 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15951 dsl_binding[0].descriptorCount = 1;
15952 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
15953 dsl_binding[0].pImmutableSamplers = NULL;
15954 dsl_binding[1].binding = 1;
15955 dsl_binding[1].descriptorCount = 0; // empty binding
15956 dsl_binding[2].binding = 2;
15957 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15958 dsl_binding[2].descriptorCount = 1;
15959 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
15960 dsl_binding[2].pImmutableSamplers = NULL;
15961
15962 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15963 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15964 ds_layout_ci.pNext = NULL;
15965 ds_layout_ci.bindingCount = NUM_BINDINGS;
15966 ds_layout_ci.pBindings = dsl_binding;
15967 VkDescriptorSetLayout ds_layout;
15968 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15969 ASSERT_VK_SUCCESS(err);
15970
15971 VkDescriptorSet descriptor_set = {};
15972 VkDescriptorSetAllocateInfo alloc_info = {};
15973 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15974 alloc_info.descriptorSetCount = 1;
15975 alloc_info.descriptorPool = ds_pool;
15976 alloc_info.pSetLayouts = &ds_layout;
15977 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15978 ASSERT_VK_SUCCESS(err);
15979
15980 // Create a buffer to be used for update
15981 VkBufferCreateInfo buff_ci = {};
15982 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15983 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15984 buff_ci.size = 256;
15985 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15986 VkBuffer buffer;
15987 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
15988 ASSERT_VK_SUCCESS(err);
15989 // Have to bind memory to buffer before descriptor update
15990 VkMemoryAllocateInfo mem_alloc = {};
15991 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15992 mem_alloc.pNext = NULL;
15993 mem_alloc.allocationSize = 512; // one allocation for both buffers
15994 mem_alloc.memoryTypeIndex = 0;
15995
15996 VkMemoryRequirements mem_reqs;
15997 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15998 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
15999 if (!pass) {
16000 vkDestroyBuffer(m_device->device(), buffer, NULL);
16001 return;
16002 }
16003
16004 VkDeviceMemory mem;
16005 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16006 ASSERT_VK_SUCCESS(err);
16007 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16008 ASSERT_VK_SUCCESS(err);
16009
16010 // Only update the descriptor at binding 2
16011 VkDescriptorBufferInfo buff_info = {};
16012 buff_info.buffer = buffer;
16013 buff_info.offset = 0;
16014 buff_info.range = VK_WHOLE_SIZE;
16015 VkWriteDescriptorSet descriptor_write = {};
16016 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16017 descriptor_write.dstBinding = 2;
16018 descriptor_write.descriptorCount = 1;
16019 descriptor_write.pTexelBufferView = nullptr;
16020 descriptor_write.pBufferInfo = &buff_info;
16021 descriptor_write.pImageInfo = nullptr;
16022 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16023 descriptor_write.dstSet = descriptor_set;
16024
16025 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16026
16027 m_errorMonitor->VerifyNotFound();
16028 // Cleanup
16029 vkFreeMemory(m_device->device(), mem, NULL);
16030 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16031 vkDestroyBuffer(m_device->device(), buffer, NULL);
16032 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16033}
16034
16035// This is a positive test. No failures are expected.
16036TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16037 VkResult err;
16038 bool pass;
16039
16040 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16041 "the buffer, create an image, and bind the same memory to "
16042 "it");
16043
16044 m_errorMonitor->ExpectSuccess();
16045
16046 ASSERT_NO_FATAL_FAILURE(InitState());
16047
16048 VkBuffer buffer;
16049 VkImage image;
16050 VkDeviceMemory mem;
16051 VkMemoryRequirements mem_reqs;
16052
16053 VkBufferCreateInfo buf_info = {};
16054 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16055 buf_info.pNext = NULL;
16056 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16057 buf_info.size = 256;
16058 buf_info.queueFamilyIndexCount = 0;
16059 buf_info.pQueueFamilyIndices = NULL;
16060 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16061 buf_info.flags = 0;
16062 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16063 ASSERT_VK_SUCCESS(err);
16064
16065 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16066
16067 VkMemoryAllocateInfo alloc_info = {};
16068 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16069 alloc_info.pNext = NULL;
16070 alloc_info.memoryTypeIndex = 0;
16071
16072 // Ensure memory is big enough for both bindings
16073 alloc_info.allocationSize = 0x10000;
16074
16075 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16076 if (!pass) {
16077 vkDestroyBuffer(m_device->device(), buffer, NULL);
16078 return;
16079 }
16080
16081 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16082 ASSERT_VK_SUCCESS(err);
16083
16084 uint8_t *pData;
16085 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16086 ASSERT_VK_SUCCESS(err);
16087
16088 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16089
16090 vkUnmapMemory(m_device->device(), mem);
16091
16092 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16093 ASSERT_VK_SUCCESS(err);
16094
16095 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16096 // memory. In fact, it was never used by the GPU.
16097 // Just be be sure, wait for idle.
16098 vkDestroyBuffer(m_device->device(), buffer, NULL);
16099 vkDeviceWaitIdle(m_device->device());
16100
16101 VkImageCreateInfo image_create_info = {};
16102 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16103 image_create_info.pNext = NULL;
16104 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16105 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16106 image_create_info.extent.width = 64;
16107 image_create_info.extent.height = 64;
16108 image_create_info.extent.depth = 1;
16109 image_create_info.mipLevels = 1;
16110 image_create_info.arrayLayers = 1;
16111 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16112 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16113 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16114 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16115 image_create_info.queueFamilyIndexCount = 0;
16116 image_create_info.pQueueFamilyIndices = NULL;
16117 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16118 image_create_info.flags = 0;
16119
16120 VkMemoryAllocateInfo mem_alloc = {};
16121 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16122 mem_alloc.pNext = NULL;
16123 mem_alloc.allocationSize = 0;
16124 mem_alloc.memoryTypeIndex = 0;
16125
16126 /* Create a mappable image. It will be the texture if linear images are ok
16127 * to be textures or it will be the staging image if they are not.
16128 */
16129 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16130 ASSERT_VK_SUCCESS(err);
16131
16132 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16133
16134 mem_alloc.allocationSize = mem_reqs.size;
16135
16136 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16137 if (!pass) {
16138 vkDestroyImage(m_device->device(), image, NULL);
16139 return;
16140 }
16141
16142 // VALIDATION FAILURE:
16143 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16144 ASSERT_VK_SUCCESS(err);
16145
16146 m_errorMonitor->VerifyNotFound();
16147
16148 vkFreeMemory(m_device->device(), mem, NULL);
16149 vkDestroyBuffer(m_device->device(), buffer, NULL);
16150 vkDestroyImage(m_device->device(), image, NULL);
16151}
16152
16153TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16154
16155 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16156 "mapping while using VK_WHOLE_SIZE does not cause access "
16157 "violations");
16158 VkResult err;
16159 uint8_t *pData;
16160 ASSERT_NO_FATAL_FAILURE(InitState());
16161
16162 VkDeviceMemory mem;
16163 VkMemoryRequirements mem_reqs;
16164 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16165 VkMemoryAllocateInfo alloc_info = {};
16166 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16167 alloc_info.pNext = NULL;
16168 alloc_info.memoryTypeIndex = 0;
16169
16170 static const VkDeviceSize allocation_size = 0x1000;
16171 alloc_info.allocationSize = allocation_size;
16172
16173 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16174 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16175 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16176 if (!pass) {
16177 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16178 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16179 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16180 if (!pass) {
16181 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16182 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16183 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16184 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16185 if (!pass) {
16186 return;
16187 }
16188 }
16189 }
16190
16191 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16192 ASSERT_VK_SUCCESS(err);
16193
16194 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16195 // mapped range
16196 m_errorMonitor->ExpectSuccess();
16197 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16198 ASSERT_VK_SUCCESS(err);
16199 VkMappedMemoryRange mmr = {};
16200 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16201 mmr.memory = mem;
16202 mmr.offset = 0;
16203 mmr.size = VK_WHOLE_SIZE;
16204 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16205 ASSERT_VK_SUCCESS(err);
16206 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16207 ASSERT_VK_SUCCESS(err);
16208 m_errorMonitor->VerifyNotFound();
16209 vkUnmapMemory(m_device->device(), mem);
16210
16211 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16212 // mapped range
16213 m_errorMonitor->ExpectSuccess();
16214 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16215 ASSERT_VK_SUCCESS(err);
16216 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16217 mmr.memory = mem;
16218 mmr.offset = 13;
16219 mmr.size = VK_WHOLE_SIZE;
16220 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16221 ASSERT_VK_SUCCESS(err);
16222 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16223 ASSERT_VK_SUCCESS(err);
16224 m_errorMonitor->VerifyNotFound();
16225 vkUnmapMemory(m_device->device(), mem);
16226
16227 // Map with prime offset and size
16228 // Flush/Invalidate subrange of mapped area with prime offset and size
16229 m_errorMonitor->ExpectSuccess();
16230 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16231 ASSERT_VK_SUCCESS(err);
16232 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16233 mmr.memory = mem;
16234 mmr.offset = allocation_size - 107;
16235 mmr.size = 61;
16236 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16237 ASSERT_VK_SUCCESS(err);
16238 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16239 ASSERT_VK_SUCCESS(err);
16240 m_errorMonitor->VerifyNotFound();
16241 vkUnmapMemory(m_device->device(), mem);
16242
16243 // Map without offset and flush WHOLE_SIZE with two separate offsets
16244 m_errorMonitor->ExpectSuccess();
16245 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16246 ASSERT_VK_SUCCESS(err);
16247 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16248 mmr.memory = mem;
16249 mmr.offset = allocation_size - 100;
16250 mmr.size = VK_WHOLE_SIZE;
16251 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16252 ASSERT_VK_SUCCESS(err);
16253 mmr.offset = allocation_size - 200;
16254 mmr.size = VK_WHOLE_SIZE;
16255 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16256 ASSERT_VK_SUCCESS(err);
16257 m_errorMonitor->VerifyNotFound();
16258 vkUnmapMemory(m_device->device(), mem);
16259
16260 vkFreeMemory(m_device->device(), mem, NULL);
16261}
16262
16263// This is a positive test. We used to expect error in this case but spec now allows it
16264TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16265 m_errorMonitor->ExpectSuccess();
16266 vk_testing::Fence testFence;
16267 VkFenceCreateInfo fenceInfo = {};
16268 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16269 fenceInfo.pNext = NULL;
16270
16271 ASSERT_NO_FATAL_FAILURE(InitState());
16272 testFence.init(*m_device, fenceInfo);
16273 VkFence fences[1] = { testFence.handle() };
16274 VkResult result = vkResetFences(m_device->device(), 1, fences);
16275 ASSERT_VK_SUCCESS(result);
16276
16277 m_errorMonitor->VerifyNotFound();
16278}
16279
16280TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16281 m_errorMonitor->ExpectSuccess();
16282
16283 ASSERT_NO_FATAL_FAILURE(InitState());
16284 VkResult err;
16285
16286 // Record (empty!) command buffer that can be submitted multiple times
16287 // simultaneously.
16288 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16289 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16290 m_commandBuffer->BeginCommandBuffer(&cbbi);
16291 m_commandBuffer->EndCommandBuffer();
16292
16293 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16294 VkFence fence;
16295 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16296 ASSERT_VK_SUCCESS(err);
16297
16298 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16299 VkSemaphore s1, s2;
16300 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16301 ASSERT_VK_SUCCESS(err);
16302 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16303 ASSERT_VK_SUCCESS(err);
16304
16305 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16306 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16307 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16308 ASSERT_VK_SUCCESS(err);
16309
16310 // Submit CB again, signaling s2.
16311 si.pSignalSemaphores = &s2;
16312 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16313 ASSERT_VK_SUCCESS(err);
16314
16315 // Wait for fence.
16316 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16317 ASSERT_VK_SUCCESS(err);
16318
16319 // CB is still in flight from second submission, but semaphore s1 is no
16320 // longer in flight. delete it.
16321 vkDestroySemaphore(m_device->device(), s1, nullptr);
16322
16323 m_errorMonitor->VerifyNotFound();
16324
16325 // Force device idle and clean up remaining objects
16326 vkDeviceWaitIdle(m_device->device());
16327 vkDestroySemaphore(m_device->device(), s2, nullptr);
16328 vkDestroyFence(m_device->device(), fence, nullptr);
16329}
16330
16331TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16332 m_errorMonitor->ExpectSuccess();
16333
16334 ASSERT_NO_FATAL_FAILURE(InitState());
16335 VkResult err;
16336
16337 // A fence created signaled
16338 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16339 VkFence f1;
16340 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16341 ASSERT_VK_SUCCESS(err);
16342
16343 // A fence created not
16344 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16345 VkFence f2;
16346 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16347 ASSERT_VK_SUCCESS(err);
16348
16349 // Submit the unsignaled fence
16350 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16351 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16352
16353 // Wait on both fences, with signaled first.
16354 VkFence fences[] = { f1, f2 };
16355 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16356
16357 // Should have both retired!
16358 vkDestroyFence(m_device->device(), f1, nullptr);
16359 vkDestroyFence(m_device->device(), f2, nullptr);
16360
16361 m_errorMonitor->VerifyNotFound();
16362}
16363
16364TEST_F(VkPositiveLayerTest, ValidUsage) {
16365 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16366 "doesn't generate validation errors");
16367
16368 ASSERT_NO_FATAL_FAILURE(InitState());
16369
16370 m_errorMonitor->ExpectSuccess();
16371 // Verify that we can create a view with usage INPUT_ATTACHMENT
16372 VkImageObj image(m_device);
16373 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16374 ASSERT_TRUE(image.initialized());
16375 VkImageView imageView;
16376 VkImageViewCreateInfo ivci = {};
16377 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16378 ivci.image = image.handle();
16379 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16380 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16381 ivci.subresourceRange.layerCount = 1;
16382 ivci.subresourceRange.baseMipLevel = 0;
16383 ivci.subresourceRange.levelCount = 1;
16384 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16385
16386 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16387 m_errorMonitor->VerifyNotFound();
16388 vkDestroyImageView(m_device->device(), imageView, NULL);
16389}
16390
16391// This is a positive test. No failures are expected.
16392TEST_F(VkPositiveLayerTest, BindSparse) {
16393 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16394 "and then free the memory");
16395
16396 ASSERT_NO_FATAL_FAILURE(InitState());
16397
16398 auto index = m_device->graphics_queue_node_index_;
16399 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16400 return;
16401
16402 m_errorMonitor->ExpectSuccess();
16403
16404 VkImage image;
16405 VkImageCreateInfo image_create_info = {};
16406 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16407 image_create_info.pNext = NULL;
16408 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16409 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16410 image_create_info.extent.width = 64;
16411 image_create_info.extent.height = 64;
16412 image_create_info.extent.depth = 1;
16413 image_create_info.mipLevels = 1;
16414 image_create_info.arrayLayers = 1;
16415 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16416 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16417 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16418 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16419 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16420 ASSERT_VK_SUCCESS(err);
16421
16422 VkMemoryRequirements memory_reqs;
16423 VkDeviceMemory memory_one, memory_two;
16424 bool pass;
16425 VkMemoryAllocateInfo memory_info = {};
16426 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16427 memory_info.pNext = NULL;
16428 memory_info.allocationSize = 0;
16429 memory_info.memoryTypeIndex = 0;
16430 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16431 // Find an image big enough to allow sparse mapping of 2 memory regions
16432 // Increase the image size until it is at least twice the
16433 // size of the required alignment, to ensure we can bind both
16434 // allocated memory blocks to the image on aligned offsets.
16435 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16436 vkDestroyImage(m_device->device(), image, nullptr);
16437 image_create_info.extent.width *= 2;
16438 image_create_info.extent.height *= 2;
16439 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16440 ASSERT_VK_SUCCESS(err);
16441 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16442 }
16443 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16444 // at the end of the first
16445 memory_info.allocationSize = memory_reqs.alignment;
16446 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16447 ASSERT_TRUE(pass);
16448 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16449 ASSERT_VK_SUCCESS(err);
16450 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16451 ASSERT_VK_SUCCESS(err);
16452 VkSparseMemoryBind binds[2];
16453 binds[0].flags = 0;
16454 binds[0].memory = memory_one;
16455 binds[0].memoryOffset = 0;
16456 binds[0].resourceOffset = 0;
16457 binds[0].size = memory_info.allocationSize;
16458 binds[1].flags = 0;
16459 binds[1].memory = memory_two;
16460 binds[1].memoryOffset = 0;
16461 binds[1].resourceOffset = memory_info.allocationSize;
16462 binds[1].size = memory_info.allocationSize;
16463
16464 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16465 opaqueBindInfo.image = image;
16466 opaqueBindInfo.bindCount = 2;
16467 opaqueBindInfo.pBinds = binds;
16468
16469 VkFence fence = VK_NULL_HANDLE;
16470 VkBindSparseInfo bindSparseInfo = {};
16471 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16472 bindSparseInfo.imageOpaqueBindCount = 1;
16473 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16474
16475 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16476 vkQueueWaitIdle(m_device->m_queue);
16477 vkDestroyImage(m_device->device(), image, NULL);
16478 vkFreeMemory(m_device->device(), memory_one, NULL);
16479 vkFreeMemory(m_device->device(), memory_two, NULL);
16480 m_errorMonitor->VerifyNotFound();
16481}
16482
16483TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16484 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16485 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16486 "the command buffer has prior knowledge of that "
16487 "attachment's layout.");
16488
16489 m_errorMonitor->ExpectSuccess();
16490
16491 ASSERT_NO_FATAL_FAILURE(InitState());
16492
16493 // A renderpass with one color attachment.
16494 VkAttachmentDescription attachment = { 0,
16495 VK_FORMAT_R8G8B8A8_UNORM,
16496 VK_SAMPLE_COUNT_1_BIT,
16497 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16498 VK_ATTACHMENT_STORE_OP_STORE,
16499 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16500 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16501 VK_IMAGE_LAYOUT_UNDEFINED,
16502 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16503
16504 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16505
16506 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16507
16508 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16509
16510 VkRenderPass rp;
16511 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16512 ASSERT_VK_SUCCESS(err);
16513
16514 // A compatible framebuffer.
16515 VkImageObj image(m_device);
16516 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16517 ASSERT_TRUE(image.initialized());
16518
16519 VkImageViewCreateInfo ivci = {
16520 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16521 nullptr,
16522 0,
16523 image.handle(),
16524 VK_IMAGE_VIEW_TYPE_2D,
16525 VK_FORMAT_R8G8B8A8_UNORM,
16526 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16527 VK_COMPONENT_SWIZZLE_IDENTITY },
16528 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16529 };
16530 VkImageView view;
16531 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16532 ASSERT_VK_SUCCESS(err);
16533
16534 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16535 VkFramebuffer fb;
16536 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16537 ASSERT_VK_SUCCESS(err);
16538
16539 // Record a single command buffer which uses this renderpass twice. The
16540 // bug is triggered at the beginning of the second renderpass, when the
16541 // command buffer already has a layout recorded for the attachment.
16542 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16543 BeginCommandBuffer();
16544 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16545 vkCmdEndRenderPass(m_commandBuffer->handle());
16546 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16547
16548 m_errorMonitor->VerifyNotFound();
16549
16550 vkCmdEndRenderPass(m_commandBuffer->handle());
16551 EndCommandBuffer();
16552
16553 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16554 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16555 vkDestroyImageView(m_device->device(), view, nullptr);
16556}
16557
16558TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16559 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16560 "command buffer, bind them together, then destroy "
16561 "command pool and framebuffer and verify there are no "
16562 "errors.");
16563
16564 m_errorMonitor->ExpectSuccess();
16565
16566 ASSERT_NO_FATAL_FAILURE(InitState());
16567
16568 // A renderpass with one color attachment.
16569 VkAttachmentDescription attachment = { 0,
16570 VK_FORMAT_R8G8B8A8_UNORM,
16571 VK_SAMPLE_COUNT_1_BIT,
16572 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16573 VK_ATTACHMENT_STORE_OP_STORE,
16574 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16575 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16576 VK_IMAGE_LAYOUT_UNDEFINED,
16577 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16578
16579 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16580
16581 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16582
16583 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16584
16585 VkRenderPass rp;
16586 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16587 ASSERT_VK_SUCCESS(err);
16588
16589 // A compatible framebuffer.
16590 VkImageObj image(m_device);
16591 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16592 ASSERT_TRUE(image.initialized());
16593
16594 VkImageViewCreateInfo ivci = {
16595 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16596 nullptr,
16597 0,
16598 image.handle(),
16599 VK_IMAGE_VIEW_TYPE_2D,
16600 VK_FORMAT_R8G8B8A8_UNORM,
16601 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16602 VK_COMPONENT_SWIZZLE_IDENTITY },
16603 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16604 };
16605 VkImageView view;
16606 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16607 ASSERT_VK_SUCCESS(err);
16608
16609 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16610 VkFramebuffer fb;
16611 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16612 ASSERT_VK_SUCCESS(err);
16613
16614 // Explicitly create a command buffer to bind the FB to so that we can then
16615 // destroy the command pool in order to implicitly free command buffer
16616 VkCommandPool command_pool;
16617 VkCommandPoolCreateInfo pool_create_info{};
16618 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16619 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16620 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16621 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16622
16623 VkCommandBuffer command_buffer;
16624 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16625 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16626 command_buffer_allocate_info.commandPool = command_pool;
16627 command_buffer_allocate_info.commandBufferCount = 1;
16628 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16629 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16630
16631 // Begin our cmd buffer with renderpass using our framebuffer
16632 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16633 VkCommandBufferBeginInfo begin_info{};
16634 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16635 vkBeginCommandBuffer(command_buffer, &begin_info);
16636
16637 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16638 vkCmdEndRenderPass(command_buffer);
16639 vkEndCommandBuffer(command_buffer);
16640 vkDestroyImageView(m_device->device(), view, nullptr);
16641 // Destroy command pool to implicitly free command buffer
16642 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16643 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16644 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16645 m_errorMonitor->VerifyNotFound();
16646}
16647
16648TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16649 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16650 "transitions for the first subpass");
16651
16652 m_errorMonitor->ExpectSuccess();
16653
16654 ASSERT_NO_FATAL_FAILURE(InitState());
16655
16656 // A renderpass with one color attachment.
16657 VkAttachmentDescription attachment = { 0,
16658 VK_FORMAT_R8G8B8A8_UNORM,
16659 VK_SAMPLE_COUNT_1_BIT,
16660 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16661 VK_ATTACHMENT_STORE_OP_STORE,
16662 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16663 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16664 VK_IMAGE_LAYOUT_UNDEFINED,
16665 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16666
16667 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16668
16669 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16670
16671 VkSubpassDependency dep = { 0,
16672 0,
16673 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16674 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16675 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16676 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16677 VK_DEPENDENCY_BY_REGION_BIT };
16678
16679 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16680
16681 VkResult err;
16682 VkRenderPass rp;
16683 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16684 ASSERT_VK_SUCCESS(err);
16685
16686 // A compatible framebuffer.
16687 VkImageObj image(m_device);
16688 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16689 ASSERT_TRUE(image.initialized());
16690
16691 VkImageViewCreateInfo ivci = {
16692 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16693 nullptr,
16694 0,
16695 image.handle(),
16696 VK_IMAGE_VIEW_TYPE_2D,
16697 VK_FORMAT_R8G8B8A8_UNORM,
16698 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16699 VK_COMPONENT_SWIZZLE_IDENTITY },
16700 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16701 };
16702 VkImageView view;
16703 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16704 ASSERT_VK_SUCCESS(err);
16705
16706 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16707 VkFramebuffer fb;
16708 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16709 ASSERT_VK_SUCCESS(err);
16710
16711 // Record a single command buffer which issues a pipeline barrier w/
16712 // image memory barrier for the attachment. This detects the previously
16713 // missing tracking of the subpass layout by throwing a validation error
16714 // if it doesn't occur.
16715 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16716 BeginCommandBuffer();
16717 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16718
16719 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
16720 nullptr,
16721 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16722 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16723 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16724 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16725 VK_QUEUE_FAMILY_IGNORED,
16726 VK_QUEUE_FAMILY_IGNORED,
16727 image.handle(),
16728 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
16729 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16730 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16731 &imb);
16732
16733 vkCmdEndRenderPass(m_commandBuffer->handle());
16734 m_errorMonitor->VerifyNotFound();
16735 EndCommandBuffer();
16736
16737 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16738 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16739 vkDestroyImageView(m_device->device(), view, nullptr);
16740}
16741
16742TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
16743 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
16744 "is used as a depth/stencil framebuffer attachment, the "
16745 "aspectMask is ignored and both depth and stencil image "
16746 "subresources are used.");
16747
16748 VkFormatProperties format_properties;
16749 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
16750 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
16751 return;
16752 }
16753
16754 m_errorMonitor->ExpectSuccess();
16755
16756 ASSERT_NO_FATAL_FAILURE(InitState());
16757
16758 VkAttachmentDescription attachment = { 0,
16759 VK_FORMAT_D32_SFLOAT_S8_UINT,
16760 VK_SAMPLE_COUNT_1_BIT,
16761 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16762 VK_ATTACHMENT_STORE_OP_STORE,
16763 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16764 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16765 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
16766 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16767
16768 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16769
16770 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
16771
16772 VkSubpassDependency dep = { 0,
16773 0,
16774 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16775 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16776 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16777 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16778 VK_DEPENDENCY_BY_REGION_BIT};
16779
16780 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16781
16782 VkResult err;
16783 VkRenderPass rp;
16784 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16785 ASSERT_VK_SUCCESS(err);
16786
16787 VkImageObj image(m_device);
16788 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
16789 0x26, // usage
16790 VK_IMAGE_TILING_OPTIMAL, 0);
16791 ASSERT_TRUE(image.initialized());
16792 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
16793
16794 VkImageViewCreateInfo ivci = {
16795 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16796 nullptr,
16797 0,
16798 image.handle(),
16799 VK_IMAGE_VIEW_TYPE_2D,
16800 VK_FORMAT_D32_SFLOAT_S8_UINT,
16801 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
16802 { 0x2, 0, 1, 0, 1 },
16803 };
16804 VkImageView view;
16805 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16806 ASSERT_VK_SUCCESS(err);
16807
16808 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16809 VkFramebuffer fb;
16810 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16811 ASSERT_VK_SUCCESS(err);
16812
16813 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16814 BeginCommandBuffer();
16815 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16816
16817 VkImageMemoryBarrier imb = {};
16818 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16819 imb.pNext = nullptr;
16820 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16821 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16822 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16823 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16824 imb.srcQueueFamilyIndex = 0;
16825 imb.dstQueueFamilyIndex = 0;
16826 imb.image = image.handle();
16827 imb.subresourceRange.aspectMask = 0x6;
16828 imb.subresourceRange.baseMipLevel = 0;
16829 imb.subresourceRange.levelCount = 0x1;
16830 imb.subresourceRange.baseArrayLayer = 0;
16831 imb.subresourceRange.layerCount = 0x1;
16832
16833 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16834 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16835 &imb);
16836
16837 vkCmdEndRenderPass(m_commandBuffer->handle());
16838 EndCommandBuffer();
16839 QueueCommandBuffer(false);
16840 m_errorMonitor->VerifyNotFound();
16841
16842 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16843 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16844 vkDestroyImageView(m_device->device(), view, nullptr);
16845}
16846
16847TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
16848 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
16849 "errors, when an attachment reference is "
16850 "VK_ATTACHMENT_UNUSED");
16851
16852 m_errorMonitor->ExpectSuccess();
16853
16854 ASSERT_NO_FATAL_FAILURE(InitState());
16855
16856 // A renderpass with no attachments
16857 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16858
16859 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16860
16861 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
16862
16863 VkRenderPass rp;
16864 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16865 ASSERT_VK_SUCCESS(err);
16866
16867 // A compatible framebuffer.
16868 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
16869 VkFramebuffer fb;
16870 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16871 ASSERT_VK_SUCCESS(err);
16872
16873 // Record a command buffer which just begins and ends the renderpass. The
16874 // bug manifests in BeginRenderPass.
16875 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16876 BeginCommandBuffer();
16877 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16878 vkCmdEndRenderPass(m_commandBuffer->handle());
16879 m_errorMonitor->VerifyNotFound();
16880 EndCommandBuffer();
16881
16882 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16883 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16884}
16885
16886// This is a positive test. No errors are expected.
16887TEST_F(VkPositiveLayerTest, StencilLoadOp) {
16888 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
16889 "CLEAR. stencil[Load|Store]Op used to be ignored.");
16890 VkResult result = VK_SUCCESS;
16891 VkImageFormatProperties formatProps;
16892 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
16893 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
16894 &formatProps);
16895 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
16896 return;
16897 }
16898
16899 ASSERT_NO_FATAL_FAILURE(InitState());
16900 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
16901 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
16902 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
16903 VkAttachmentDescription att = {};
16904 VkAttachmentReference ref = {};
16905 att.format = depth_stencil_fmt;
16906 att.samples = VK_SAMPLE_COUNT_1_BIT;
16907 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
16908 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
16909 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
16910 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
16911 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16912 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16913
16914 VkClearValue clear;
16915 clear.depthStencil.depth = 1.0;
16916 clear.depthStencil.stencil = 0;
16917 ref.attachment = 0;
16918 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16919
16920 VkSubpassDescription subpass = {};
16921 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
16922 subpass.flags = 0;
16923 subpass.inputAttachmentCount = 0;
16924 subpass.pInputAttachments = NULL;
16925 subpass.colorAttachmentCount = 0;
16926 subpass.pColorAttachments = NULL;
16927 subpass.pResolveAttachments = NULL;
16928 subpass.pDepthStencilAttachment = &ref;
16929 subpass.preserveAttachmentCount = 0;
16930 subpass.pPreserveAttachments = NULL;
16931
16932 VkRenderPass rp;
16933 VkRenderPassCreateInfo rp_info = {};
16934 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16935 rp_info.attachmentCount = 1;
16936 rp_info.pAttachments = &att;
16937 rp_info.subpassCount = 1;
16938 rp_info.pSubpasses = &subpass;
16939 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
16940 ASSERT_VK_SUCCESS(result);
16941
16942 VkImageView *depthView = m_depthStencil->BindInfo();
16943 VkFramebufferCreateInfo fb_info = {};
16944 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
16945 fb_info.pNext = NULL;
16946 fb_info.renderPass = rp;
16947 fb_info.attachmentCount = 1;
16948 fb_info.pAttachments = depthView;
16949 fb_info.width = 100;
16950 fb_info.height = 100;
16951 fb_info.layers = 1;
16952 VkFramebuffer fb;
16953 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
16954 ASSERT_VK_SUCCESS(result);
16955
16956 VkRenderPassBeginInfo rpbinfo = {};
16957 rpbinfo.clearValueCount = 1;
16958 rpbinfo.pClearValues = &clear;
16959 rpbinfo.pNext = NULL;
16960 rpbinfo.renderPass = rp;
16961 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
16962 rpbinfo.renderArea.extent.width = 100;
16963 rpbinfo.renderArea.extent.height = 100;
16964 rpbinfo.renderArea.offset.x = 0;
16965 rpbinfo.renderArea.offset.y = 0;
16966 rpbinfo.framebuffer = fb;
16967
16968 VkFence fence = {};
16969 VkFenceCreateInfo fence_ci = {};
16970 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16971 fence_ci.pNext = nullptr;
16972 fence_ci.flags = 0;
16973 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
16974 ASSERT_VK_SUCCESS(result);
16975
16976 m_commandBuffer->BeginCommandBuffer();
16977 m_commandBuffer->BeginRenderPass(rpbinfo);
16978 m_commandBuffer->EndRenderPass();
16979 m_commandBuffer->EndCommandBuffer();
16980 m_commandBuffer->QueueCommandBuffer(fence);
16981
16982 VkImageObj destImage(m_device);
16983 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16984 VK_IMAGE_TILING_OPTIMAL, 0);
16985 VkImageMemoryBarrier barrier = {};
16986 VkImageSubresourceRange range;
16987 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16988 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16989 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
16990 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16991 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
16992 barrier.image = m_depthStencil->handle();
16993 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16994 range.baseMipLevel = 0;
16995 range.levelCount = 1;
16996 range.baseArrayLayer = 0;
16997 range.layerCount = 1;
16998 barrier.subresourceRange = range;
16999 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17000 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17001 cmdbuf.BeginCommandBuffer();
17002 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17003 &barrier);
17004 barrier.srcAccessMask = 0;
17005 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17006 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17007 barrier.image = destImage.handle();
17008 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17009 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17010 &barrier);
17011 VkImageCopy cregion;
17012 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17013 cregion.srcSubresource.mipLevel = 0;
17014 cregion.srcSubresource.baseArrayLayer = 0;
17015 cregion.srcSubresource.layerCount = 1;
17016 cregion.srcOffset.x = 0;
17017 cregion.srcOffset.y = 0;
17018 cregion.srcOffset.z = 0;
17019 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17020 cregion.dstSubresource.mipLevel = 0;
17021 cregion.dstSubresource.baseArrayLayer = 0;
17022 cregion.dstSubresource.layerCount = 1;
17023 cregion.dstOffset.x = 0;
17024 cregion.dstOffset.y = 0;
17025 cregion.dstOffset.z = 0;
17026 cregion.extent.width = 100;
17027 cregion.extent.height = 100;
17028 cregion.extent.depth = 1;
17029 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17030 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17031 cmdbuf.EndCommandBuffer();
17032
17033 VkSubmitInfo submit_info;
17034 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17035 submit_info.pNext = NULL;
17036 submit_info.waitSemaphoreCount = 0;
17037 submit_info.pWaitSemaphores = NULL;
17038 submit_info.pWaitDstStageMask = NULL;
17039 submit_info.commandBufferCount = 1;
17040 submit_info.pCommandBuffers = &cmdbuf.handle();
17041 submit_info.signalSemaphoreCount = 0;
17042 submit_info.pSignalSemaphores = NULL;
17043
17044 m_errorMonitor->ExpectSuccess();
17045 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17046 m_errorMonitor->VerifyNotFound();
17047
17048 vkQueueWaitIdle(m_device->m_queue);
17049 vkDestroyFence(m_device->device(), fence, nullptr);
17050 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17051 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17052}
17053
17054// This is a positive test. No errors should be generated.
17055TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17056 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17057
17058 m_errorMonitor->ExpectSuccess();
17059 ASSERT_NO_FATAL_FAILURE(InitState());
17060
17061 VkEvent event;
17062 VkEventCreateInfo event_create_info{};
17063 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17064 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17065
17066 VkCommandPool command_pool;
17067 VkCommandPoolCreateInfo pool_create_info{};
17068 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17069 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17070 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17071 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17072
17073 VkCommandBuffer command_buffer;
17074 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17075 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17076 command_buffer_allocate_info.commandPool = command_pool;
17077 command_buffer_allocate_info.commandBufferCount = 1;
17078 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17079 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17080
17081 VkQueue queue = VK_NULL_HANDLE;
17082 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17083
17084 {
17085 VkCommandBufferBeginInfo begin_info{};
17086 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17087 vkBeginCommandBuffer(command_buffer, &begin_info);
17088
17089 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17090 nullptr, 0, nullptr);
17091 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17092 vkEndCommandBuffer(command_buffer);
17093 }
17094 {
17095 VkSubmitInfo submit_info{};
17096 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17097 submit_info.commandBufferCount = 1;
17098 submit_info.pCommandBuffers = &command_buffer;
17099 submit_info.signalSemaphoreCount = 0;
17100 submit_info.pSignalSemaphores = nullptr;
17101 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17102 }
17103 { vkSetEvent(m_device->device(), event); }
17104
17105 vkQueueWaitIdle(queue);
17106
17107 vkDestroyEvent(m_device->device(), event, nullptr);
17108 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17109 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17110
17111 m_errorMonitor->VerifyNotFound();
17112}
17113// This is a positive test. No errors should be generated.
17114TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17115 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17116
17117 ASSERT_NO_FATAL_FAILURE(InitState());
17118 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17119 return;
17120
17121 m_errorMonitor->ExpectSuccess();
17122
17123 VkQueryPool query_pool;
17124 VkQueryPoolCreateInfo query_pool_create_info{};
17125 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17126 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17127 query_pool_create_info.queryCount = 1;
17128 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17129
17130 VkCommandPool command_pool;
17131 VkCommandPoolCreateInfo pool_create_info{};
17132 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17133 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17134 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17135 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17136
17137 VkCommandBuffer command_buffer;
17138 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17139 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17140 command_buffer_allocate_info.commandPool = command_pool;
17141 command_buffer_allocate_info.commandBufferCount = 1;
17142 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17143 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17144
17145 VkCommandBuffer secondary_command_buffer;
17146 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17147 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17148
17149 VkQueue queue = VK_NULL_HANDLE;
17150 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17151
17152 uint32_t qfi = 0;
17153 VkBufferCreateInfo buff_create_info = {};
17154 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17155 buff_create_info.size = 1024;
17156 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17157 buff_create_info.queueFamilyIndexCount = 1;
17158 buff_create_info.pQueueFamilyIndices = &qfi;
17159
17160 VkResult err;
17161 VkBuffer buffer;
17162 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17163 ASSERT_VK_SUCCESS(err);
17164 VkMemoryAllocateInfo mem_alloc = {};
17165 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17166 mem_alloc.pNext = NULL;
17167 mem_alloc.allocationSize = 1024;
17168 mem_alloc.memoryTypeIndex = 0;
17169
17170 VkMemoryRequirements memReqs;
17171 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17172 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17173 if (!pass) {
17174 vkDestroyBuffer(m_device->device(), buffer, NULL);
17175 return;
17176 }
17177
17178 VkDeviceMemory mem;
17179 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17180 ASSERT_VK_SUCCESS(err);
17181 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17182 ASSERT_VK_SUCCESS(err);
17183
17184 VkCommandBufferInheritanceInfo hinfo = {};
17185 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17186 hinfo.renderPass = VK_NULL_HANDLE;
17187 hinfo.subpass = 0;
17188 hinfo.framebuffer = VK_NULL_HANDLE;
17189 hinfo.occlusionQueryEnable = VK_FALSE;
17190 hinfo.queryFlags = 0;
17191 hinfo.pipelineStatistics = 0;
17192
17193 {
17194 VkCommandBufferBeginInfo begin_info{};
17195 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17196 begin_info.pInheritanceInfo = &hinfo;
17197 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17198
17199 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17200 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17201
17202 vkEndCommandBuffer(secondary_command_buffer);
17203
17204 begin_info.pInheritanceInfo = nullptr;
17205 vkBeginCommandBuffer(command_buffer, &begin_info);
17206
17207 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17208 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17209
17210 vkEndCommandBuffer(command_buffer);
17211 }
17212 {
17213 VkSubmitInfo submit_info{};
17214 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17215 submit_info.commandBufferCount = 1;
17216 submit_info.pCommandBuffers = &command_buffer;
17217 submit_info.signalSemaphoreCount = 0;
17218 submit_info.pSignalSemaphores = nullptr;
17219 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17220 }
17221
17222 vkQueueWaitIdle(queue);
17223
17224 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17225 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17226 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17227 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17228 vkDestroyBuffer(m_device->device(), buffer, NULL);
17229 vkFreeMemory(m_device->device(), mem, NULL);
17230
17231 m_errorMonitor->VerifyNotFound();
17232}
17233
17234// This is a positive test. No errors should be generated.
17235TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17236 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17237
17238 ASSERT_NO_FATAL_FAILURE(InitState());
17239 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17240 return;
17241
17242 m_errorMonitor->ExpectSuccess();
17243
17244 VkQueryPool query_pool;
17245 VkQueryPoolCreateInfo query_pool_create_info{};
17246 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17247 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17248 query_pool_create_info.queryCount = 1;
17249 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17250
17251 VkCommandPool command_pool;
17252 VkCommandPoolCreateInfo pool_create_info{};
17253 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17254 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17255 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17256 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17257
17258 VkCommandBuffer command_buffer[2];
17259 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17260 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17261 command_buffer_allocate_info.commandPool = command_pool;
17262 command_buffer_allocate_info.commandBufferCount = 2;
17263 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17264 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17265
17266 VkQueue queue = VK_NULL_HANDLE;
17267 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17268
17269 uint32_t qfi = 0;
17270 VkBufferCreateInfo buff_create_info = {};
17271 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17272 buff_create_info.size = 1024;
17273 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17274 buff_create_info.queueFamilyIndexCount = 1;
17275 buff_create_info.pQueueFamilyIndices = &qfi;
17276
17277 VkResult err;
17278 VkBuffer buffer;
17279 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17280 ASSERT_VK_SUCCESS(err);
17281 VkMemoryAllocateInfo mem_alloc = {};
17282 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17283 mem_alloc.pNext = NULL;
17284 mem_alloc.allocationSize = 1024;
17285 mem_alloc.memoryTypeIndex = 0;
17286
17287 VkMemoryRequirements memReqs;
17288 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17289 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17290 if (!pass) {
17291 vkDestroyBuffer(m_device->device(), buffer, NULL);
17292 return;
17293 }
17294
17295 VkDeviceMemory mem;
17296 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17297 ASSERT_VK_SUCCESS(err);
17298 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17299 ASSERT_VK_SUCCESS(err);
17300
17301 {
17302 VkCommandBufferBeginInfo begin_info{};
17303 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17304 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17305
17306 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17307 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17308
17309 vkEndCommandBuffer(command_buffer[0]);
17310
17311 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17312
17313 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17314
17315 vkEndCommandBuffer(command_buffer[1]);
17316 }
17317 {
17318 VkSubmitInfo submit_info{};
17319 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17320 submit_info.commandBufferCount = 2;
17321 submit_info.pCommandBuffers = command_buffer;
17322 submit_info.signalSemaphoreCount = 0;
17323 submit_info.pSignalSemaphores = nullptr;
17324 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17325 }
17326
17327 vkQueueWaitIdle(queue);
17328
17329 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17330 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17331 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17332 vkDestroyBuffer(m_device->device(), buffer, NULL);
17333 vkFreeMemory(m_device->device(), mem, NULL);
17334
17335 m_errorMonitor->VerifyNotFound();
17336}
17337
Tony Barbourc46924f2016-11-04 11:49:52 -060017338TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017339 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17340
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017341 ASSERT_NO_FATAL_FAILURE(InitState());
17342 VkEvent event;
17343 VkEventCreateInfo event_create_info{};
17344 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17345 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17346
17347 VkCommandPool command_pool;
17348 VkCommandPoolCreateInfo pool_create_info{};
17349 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17350 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17351 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17352 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17353
17354 VkCommandBuffer command_buffer;
17355 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17356 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17357 command_buffer_allocate_info.commandPool = command_pool;
17358 command_buffer_allocate_info.commandBufferCount = 1;
17359 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17360 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17361
17362 VkQueue queue = VK_NULL_HANDLE;
17363 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17364
17365 {
17366 VkCommandBufferBeginInfo begin_info{};
17367 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17368 vkBeginCommandBuffer(command_buffer, &begin_info);
17369
17370 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017371 vkEndCommandBuffer(command_buffer);
17372 }
17373 {
17374 VkSubmitInfo submit_info{};
17375 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17376 submit_info.commandBufferCount = 1;
17377 submit_info.pCommandBuffers = &command_buffer;
17378 submit_info.signalSemaphoreCount = 0;
17379 submit_info.pSignalSemaphores = nullptr;
17380 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17381 }
17382 {
17383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17384 "command buffer.");
17385 vkSetEvent(m_device->device(), event);
17386 m_errorMonitor->VerifyFound();
17387 }
17388
17389 vkQueueWaitIdle(queue);
17390
17391 vkDestroyEvent(m_device->device(), event, nullptr);
17392 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17393 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17394}
17395
17396// This is a positive test. No errors should be generated.
17397TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17398 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17399 "run through a Submit & WaitForFences cycle 3 times. This "
17400 "previously revealed a bug so running this positive test "
17401 "to prevent a regression.");
17402 m_errorMonitor->ExpectSuccess();
17403
17404 ASSERT_NO_FATAL_FAILURE(InitState());
17405 VkQueue queue = VK_NULL_HANDLE;
17406 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17407
17408 static const uint32_t NUM_OBJECTS = 2;
17409 static const uint32_t NUM_FRAMES = 3;
17410 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17411 VkFence fences[NUM_OBJECTS] = {};
17412
17413 VkCommandPool cmd_pool;
17414 VkCommandPoolCreateInfo cmd_pool_ci = {};
17415 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17416 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17417 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17418 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17419 ASSERT_VK_SUCCESS(err);
17420
17421 VkCommandBufferAllocateInfo cmd_buf_info = {};
17422 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17423 cmd_buf_info.commandPool = cmd_pool;
17424 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17425 cmd_buf_info.commandBufferCount = 1;
17426
17427 VkFenceCreateInfo fence_ci = {};
17428 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17429 fence_ci.pNext = nullptr;
17430 fence_ci.flags = 0;
17431
17432 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17433 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17434 ASSERT_VK_SUCCESS(err);
17435 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17436 ASSERT_VK_SUCCESS(err);
17437 }
17438
17439 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17440 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17441 // Create empty cmd buffer
17442 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17443 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17444
17445 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17446 ASSERT_VK_SUCCESS(err);
17447 err = vkEndCommandBuffer(cmd_buffers[obj]);
17448 ASSERT_VK_SUCCESS(err);
17449
17450 VkSubmitInfo submit_info = {};
17451 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17452 submit_info.commandBufferCount = 1;
17453 submit_info.pCommandBuffers = &cmd_buffers[obj];
17454 // Submit cmd buffer and wait for fence
17455 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17456 ASSERT_VK_SUCCESS(err);
17457 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17458 ASSERT_VK_SUCCESS(err);
17459 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17460 ASSERT_VK_SUCCESS(err);
17461 }
17462 }
17463 m_errorMonitor->VerifyNotFound();
17464 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17465 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17466 vkDestroyFence(m_device->device(), fences[i], nullptr);
17467 }
17468}
17469// This is a positive test. No errors should be generated.
17470TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17471
17472 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17473 "submitted on separate queues followed by a QueueWaitIdle.");
17474
17475 ASSERT_NO_FATAL_FAILURE(InitState());
17476 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17477 return;
17478
17479 m_errorMonitor->ExpectSuccess();
17480
17481 VkSemaphore semaphore;
17482 VkSemaphoreCreateInfo semaphore_create_info{};
17483 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17484 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17485
17486 VkCommandPool command_pool;
17487 VkCommandPoolCreateInfo pool_create_info{};
17488 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17489 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17490 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17491 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17492
17493 VkCommandBuffer command_buffer[2];
17494 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17495 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17496 command_buffer_allocate_info.commandPool = command_pool;
17497 command_buffer_allocate_info.commandBufferCount = 2;
17498 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17499 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17500
17501 VkQueue queue = VK_NULL_HANDLE;
17502 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17503
17504 {
17505 VkCommandBufferBeginInfo begin_info{};
17506 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17507 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17508
17509 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17510 nullptr, 0, nullptr, 0, nullptr);
17511
17512 VkViewport viewport{};
17513 viewport.maxDepth = 1.0f;
17514 viewport.minDepth = 0.0f;
17515 viewport.width = 512;
17516 viewport.height = 512;
17517 viewport.x = 0;
17518 viewport.y = 0;
17519 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17520 vkEndCommandBuffer(command_buffer[0]);
17521 }
17522 {
17523 VkCommandBufferBeginInfo begin_info{};
17524 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17525 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17526
17527 VkViewport viewport{};
17528 viewport.maxDepth = 1.0f;
17529 viewport.minDepth = 0.0f;
17530 viewport.width = 512;
17531 viewport.height = 512;
17532 viewport.x = 0;
17533 viewport.y = 0;
17534 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17535 vkEndCommandBuffer(command_buffer[1]);
17536 }
17537 {
17538 VkSubmitInfo submit_info{};
17539 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17540 submit_info.commandBufferCount = 1;
17541 submit_info.pCommandBuffers = &command_buffer[0];
17542 submit_info.signalSemaphoreCount = 1;
17543 submit_info.pSignalSemaphores = &semaphore;
17544 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17545 }
17546 {
17547 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17548 VkSubmitInfo submit_info{};
17549 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17550 submit_info.commandBufferCount = 1;
17551 submit_info.pCommandBuffers = &command_buffer[1];
17552 submit_info.waitSemaphoreCount = 1;
17553 submit_info.pWaitSemaphores = &semaphore;
17554 submit_info.pWaitDstStageMask = flags;
17555 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17556 }
17557
17558 vkQueueWaitIdle(m_device->m_queue);
17559
17560 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17561 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17562 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17563
17564 m_errorMonitor->VerifyNotFound();
17565}
17566
17567// This is a positive test. No errors should be generated.
17568TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17569
17570 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17571 "submitted on separate queues, the second having a fence"
17572 "followed by a QueueWaitIdle.");
17573
17574 ASSERT_NO_FATAL_FAILURE(InitState());
17575 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17576 return;
17577
17578 m_errorMonitor->ExpectSuccess();
17579
17580 VkFence fence;
17581 VkFenceCreateInfo fence_create_info{};
17582 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17583 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17584
17585 VkSemaphore semaphore;
17586 VkSemaphoreCreateInfo semaphore_create_info{};
17587 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17588 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17589
17590 VkCommandPool command_pool;
17591 VkCommandPoolCreateInfo pool_create_info{};
17592 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17593 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17594 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17595 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17596
17597 VkCommandBuffer command_buffer[2];
17598 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17599 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17600 command_buffer_allocate_info.commandPool = command_pool;
17601 command_buffer_allocate_info.commandBufferCount = 2;
17602 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17603 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17604
17605 VkQueue queue = VK_NULL_HANDLE;
17606 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17607
17608 {
17609 VkCommandBufferBeginInfo begin_info{};
17610 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17611 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17612
17613 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17614 nullptr, 0, nullptr, 0, nullptr);
17615
17616 VkViewport viewport{};
17617 viewport.maxDepth = 1.0f;
17618 viewport.minDepth = 0.0f;
17619 viewport.width = 512;
17620 viewport.height = 512;
17621 viewport.x = 0;
17622 viewport.y = 0;
17623 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17624 vkEndCommandBuffer(command_buffer[0]);
17625 }
17626 {
17627 VkCommandBufferBeginInfo begin_info{};
17628 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17629 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17630
17631 VkViewport viewport{};
17632 viewport.maxDepth = 1.0f;
17633 viewport.minDepth = 0.0f;
17634 viewport.width = 512;
17635 viewport.height = 512;
17636 viewport.x = 0;
17637 viewport.y = 0;
17638 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17639 vkEndCommandBuffer(command_buffer[1]);
17640 }
17641 {
17642 VkSubmitInfo submit_info{};
17643 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17644 submit_info.commandBufferCount = 1;
17645 submit_info.pCommandBuffers = &command_buffer[0];
17646 submit_info.signalSemaphoreCount = 1;
17647 submit_info.pSignalSemaphores = &semaphore;
17648 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17649 }
17650 {
17651 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17652 VkSubmitInfo submit_info{};
17653 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17654 submit_info.commandBufferCount = 1;
17655 submit_info.pCommandBuffers = &command_buffer[1];
17656 submit_info.waitSemaphoreCount = 1;
17657 submit_info.pWaitSemaphores = &semaphore;
17658 submit_info.pWaitDstStageMask = flags;
17659 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17660 }
17661
17662 vkQueueWaitIdle(m_device->m_queue);
17663
17664 vkDestroyFence(m_device->device(), fence, nullptr);
17665 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17666 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17667 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17668
17669 m_errorMonitor->VerifyNotFound();
17670}
17671
17672// This is a positive test. No errors should be generated.
17673TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17674
17675 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17676 "submitted on separate queues, the second having a fence"
17677 "followed by two consecutive WaitForFences calls on the same fence.");
17678
17679 ASSERT_NO_FATAL_FAILURE(InitState());
17680 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17681 return;
17682
17683 m_errorMonitor->ExpectSuccess();
17684
17685 VkFence fence;
17686 VkFenceCreateInfo fence_create_info{};
17687 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17688 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17689
17690 VkSemaphore semaphore;
17691 VkSemaphoreCreateInfo semaphore_create_info{};
17692 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17693 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17694
17695 VkCommandPool command_pool;
17696 VkCommandPoolCreateInfo pool_create_info{};
17697 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17698 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17699 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17700 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17701
17702 VkCommandBuffer command_buffer[2];
17703 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17704 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17705 command_buffer_allocate_info.commandPool = command_pool;
17706 command_buffer_allocate_info.commandBufferCount = 2;
17707 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17708 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17709
17710 VkQueue queue = VK_NULL_HANDLE;
17711 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17712
17713 {
17714 VkCommandBufferBeginInfo begin_info{};
17715 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17716 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17717
17718 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17719 nullptr, 0, nullptr, 0, nullptr);
17720
17721 VkViewport viewport{};
17722 viewport.maxDepth = 1.0f;
17723 viewport.minDepth = 0.0f;
17724 viewport.width = 512;
17725 viewport.height = 512;
17726 viewport.x = 0;
17727 viewport.y = 0;
17728 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17729 vkEndCommandBuffer(command_buffer[0]);
17730 }
17731 {
17732 VkCommandBufferBeginInfo begin_info{};
17733 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17734 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17735
17736 VkViewport viewport{};
17737 viewport.maxDepth = 1.0f;
17738 viewport.minDepth = 0.0f;
17739 viewport.width = 512;
17740 viewport.height = 512;
17741 viewport.x = 0;
17742 viewport.y = 0;
17743 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17744 vkEndCommandBuffer(command_buffer[1]);
17745 }
17746 {
17747 VkSubmitInfo submit_info{};
17748 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17749 submit_info.commandBufferCount = 1;
17750 submit_info.pCommandBuffers = &command_buffer[0];
17751 submit_info.signalSemaphoreCount = 1;
17752 submit_info.pSignalSemaphores = &semaphore;
17753 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17754 }
17755 {
17756 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17757 VkSubmitInfo submit_info{};
17758 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17759 submit_info.commandBufferCount = 1;
17760 submit_info.pCommandBuffers = &command_buffer[1];
17761 submit_info.waitSemaphoreCount = 1;
17762 submit_info.pWaitSemaphores = &semaphore;
17763 submit_info.pWaitDstStageMask = flags;
17764 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17765 }
17766
17767 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17768 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17769
17770 vkDestroyFence(m_device->device(), fence, nullptr);
17771 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17772 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17773 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17774
17775 m_errorMonitor->VerifyNotFound();
17776}
17777
17778TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
17779
17780 ASSERT_NO_FATAL_FAILURE(InitState());
17781 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
17782 printf("Test requires two queues, skipping\n");
17783 return;
17784 }
17785
17786 VkResult err;
17787
17788 m_errorMonitor->ExpectSuccess();
17789
17790 VkQueue q0 = m_device->m_queue;
17791 VkQueue q1 = nullptr;
17792 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
17793 ASSERT_NE(q1, nullptr);
17794
17795 // An (empty) command buffer. We must have work in the first submission --
17796 // the layer treats unfenced work differently from fenced work.
17797 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
17798 VkCommandPool pool;
17799 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
17800 ASSERT_VK_SUCCESS(err);
17801 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
17802 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
17803 VkCommandBuffer cb;
17804 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
17805 ASSERT_VK_SUCCESS(err);
17806 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
17807 err = vkBeginCommandBuffer(cb, &cbbi);
17808 ASSERT_VK_SUCCESS(err);
17809 err = vkEndCommandBuffer(cb);
17810 ASSERT_VK_SUCCESS(err);
17811
17812 // A semaphore
17813 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17814 VkSemaphore s;
17815 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
17816 ASSERT_VK_SUCCESS(err);
17817
17818 // First submission, to q0
17819 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
17820
17821 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
17822 ASSERT_VK_SUCCESS(err);
17823
17824 // Second submission, to q1, waiting on s
17825 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
17826 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
17827
17828 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
17829 ASSERT_VK_SUCCESS(err);
17830
17831 // Wait for q0 idle
17832 err = vkQueueWaitIdle(q0);
17833 ASSERT_VK_SUCCESS(err);
17834
17835 // Command buffer should have been completed (it was on q0); reset the pool.
17836 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
17837
17838 m_errorMonitor->VerifyNotFound();
17839
17840 // Force device completely idle and clean up resources
17841 vkDeviceWaitIdle(m_device->device());
17842 vkDestroyCommandPool(m_device->device(), pool, nullptr);
17843 vkDestroySemaphore(m_device->device(), s, nullptr);
17844}
17845
17846// This is a positive test. No errors should be generated.
17847TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
17848
17849 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17850 "submitted on separate queues, the second having a fence, "
17851 "followed by a WaitForFences call.");
17852
17853 ASSERT_NO_FATAL_FAILURE(InitState());
17854 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17855 return;
17856
17857 m_errorMonitor->ExpectSuccess();
17858
17859 ASSERT_NO_FATAL_FAILURE(InitState());
17860 VkFence fence;
17861 VkFenceCreateInfo fence_create_info{};
17862 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17863 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17864
17865 VkSemaphore semaphore;
17866 VkSemaphoreCreateInfo semaphore_create_info{};
17867 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17868 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17869
17870 VkCommandPool command_pool;
17871 VkCommandPoolCreateInfo pool_create_info{};
17872 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17873 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17874 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17875 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17876
17877 VkCommandBuffer command_buffer[2];
17878 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17879 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17880 command_buffer_allocate_info.commandPool = command_pool;
17881 command_buffer_allocate_info.commandBufferCount = 2;
17882 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17883 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17884
17885 VkQueue queue = VK_NULL_HANDLE;
17886 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17887
17888 {
17889 VkCommandBufferBeginInfo begin_info{};
17890 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17891 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17892
17893 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17894 nullptr, 0, nullptr, 0, nullptr);
17895
17896 VkViewport viewport{};
17897 viewport.maxDepth = 1.0f;
17898 viewport.minDepth = 0.0f;
17899 viewport.width = 512;
17900 viewport.height = 512;
17901 viewport.x = 0;
17902 viewport.y = 0;
17903 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17904 vkEndCommandBuffer(command_buffer[0]);
17905 }
17906 {
17907 VkCommandBufferBeginInfo begin_info{};
17908 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17909 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17910
17911 VkViewport viewport{};
17912 viewport.maxDepth = 1.0f;
17913 viewport.minDepth = 0.0f;
17914 viewport.width = 512;
17915 viewport.height = 512;
17916 viewport.x = 0;
17917 viewport.y = 0;
17918 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17919 vkEndCommandBuffer(command_buffer[1]);
17920 }
17921 {
17922 VkSubmitInfo submit_info{};
17923 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17924 submit_info.commandBufferCount = 1;
17925 submit_info.pCommandBuffers = &command_buffer[0];
17926 submit_info.signalSemaphoreCount = 1;
17927 submit_info.pSignalSemaphores = &semaphore;
17928 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17929 }
17930 {
17931 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17932 VkSubmitInfo submit_info{};
17933 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17934 submit_info.commandBufferCount = 1;
17935 submit_info.pCommandBuffers = &command_buffer[1];
17936 submit_info.waitSemaphoreCount = 1;
17937 submit_info.pWaitSemaphores = &semaphore;
17938 submit_info.pWaitDstStageMask = flags;
17939 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17940 }
17941
17942 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17943
17944 vkDestroyFence(m_device->device(), fence, nullptr);
17945 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17946 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17947 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17948
17949 m_errorMonitor->VerifyNotFound();
17950}
17951
17952// This is a positive test. No errors should be generated.
17953TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
17954
17955 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17956 "on the same queue, sharing a signal/wait semaphore, the "
17957 "second having a fence, "
17958 "followed by a WaitForFences call.");
17959
17960 m_errorMonitor->ExpectSuccess();
17961
17962 ASSERT_NO_FATAL_FAILURE(InitState());
17963 VkFence fence;
17964 VkFenceCreateInfo fence_create_info{};
17965 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17966 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17967
17968 VkSemaphore semaphore;
17969 VkSemaphoreCreateInfo semaphore_create_info{};
17970 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17971 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17972
17973 VkCommandPool command_pool;
17974 VkCommandPoolCreateInfo pool_create_info{};
17975 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17976 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17977 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17978 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17979
17980 VkCommandBuffer command_buffer[2];
17981 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17982 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17983 command_buffer_allocate_info.commandPool = command_pool;
17984 command_buffer_allocate_info.commandBufferCount = 2;
17985 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17986 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17987
17988 {
17989 VkCommandBufferBeginInfo begin_info{};
17990 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17991 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17992
17993 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17994 nullptr, 0, nullptr, 0, nullptr);
17995
17996 VkViewport viewport{};
17997 viewport.maxDepth = 1.0f;
17998 viewport.minDepth = 0.0f;
17999 viewport.width = 512;
18000 viewport.height = 512;
18001 viewport.x = 0;
18002 viewport.y = 0;
18003 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18004 vkEndCommandBuffer(command_buffer[0]);
18005 }
18006 {
18007 VkCommandBufferBeginInfo begin_info{};
18008 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18009 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18010
18011 VkViewport viewport{};
18012 viewport.maxDepth = 1.0f;
18013 viewport.minDepth = 0.0f;
18014 viewport.width = 512;
18015 viewport.height = 512;
18016 viewport.x = 0;
18017 viewport.y = 0;
18018 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18019 vkEndCommandBuffer(command_buffer[1]);
18020 }
18021 {
18022 VkSubmitInfo submit_info{};
18023 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18024 submit_info.commandBufferCount = 1;
18025 submit_info.pCommandBuffers = &command_buffer[0];
18026 submit_info.signalSemaphoreCount = 1;
18027 submit_info.pSignalSemaphores = &semaphore;
18028 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18029 }
18030 {
18031 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18032 VkSubmitInfo submit_info{};
18033 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18034 submit_info.commandBufferCount = 1;
18035 submit_info.pCommandBuffers = &command_buffer[1];
18036 submit_info.waitSemaphoreCount = 1;
18037 submit_info.pWaitSemaphores = &semaphore;
18038 submit_info.pWaitDstStageMask = flags;
18039 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18040 }
18041
18042 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18043
18044 vkDestroyFence(m_device->device(), fence, nullptr);
18045 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18046 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18047 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18048
18049 m_errorMonitor->VerifyNotFound();
18050}
18051
18052// This is a positive test. No errors should be generated.
18053TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18054
18055 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18056 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18057 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18058
18059 m_errorMonitor->ExpectSuccess();
18060
18061 ASSERT_NO_FATAL_FAILURE(InitState());
18062 VkFence fence;
18063 VkFenceCreateInfo fence_create_info{};
18064 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18065 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18066
18067 VkCommandPool command_pool;
18068 VkCommandPoolCreateInfo pool_create_info{};
18069 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18070 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18071 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18072 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18073
18074 VkCommandBuffer command_buffer[2];
18075 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18076 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18077 command_buffer_allocate_info.commandPool = command_pool;
18078 command_buffer_allocate_info.commandBufferCount = 2;
18079 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18080 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18081
18082 {
18083 VkCommandBufferBeginInfo begin_info{};
18084 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18085 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18086
18087 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18088 nullptr, 0, nullptr, 0, nullptr);
18089
18090 VkViewport viewport{};
18091 viewport.maxDepth = 1.0f;
18092 viewport.minDepth = 0.0f;
18093 viewport.width = 512;
18094 viewport.height = 512;
18095 viewport.x = 0;
18096 viewport.y = 0;
18097 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18098 vkEndCommandBuffer(command_buffer[0]);
18099 }
18100 {
18101 VkCommandBufferBeginInfo begin_info{};
18102 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18103 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18104
18105 VkViewport viewport{};
18106 viewport.maxDepth = 1.0f;
18107 viewport.minDepth = 0.0f;
18108 viewport.width = 512;
18109 viewport.height = 512;
18110 viewport.x = 0;
18111 viewport.y = 0;
18112 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18113 vkEndCommandBuffer(command_buffer[1]);
18114 }
18115 {
18116 VkSubmitInfo submit_info{};
18117 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18118 submit_info.commandBufferCount = 1;
18119 submit_info.pCommandBuffers = &command_buffer[0];
18120 submit_info.signalSemaphoreCount = 0;
18121 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18122 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18123 }
18124 {
18125 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18126 VkSubmitInfo submit_info{};
18127 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18128 submit_info.commandBufferCount = 1;
18129 submit_info.pCommandBuffers = &command_buffer[1];
18130 submit_info.waitSemaphoreCount = 0;
18131 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18132 submit_info.pWaitDstStageMask = flags;
18133 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18134 }
18135
18136 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18137
18138 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18139 ASSERT_VK_SUCCESS(err);
18140
18141 vkDestroyFence(m_device->device(), fence, nullptr);
18142 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18143 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18144
18145 m_errorMonitor->VerifyNotFound();
18146}
18147
18148// This is a positive test. No errors should be generated.
18149TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18150
18151 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18152 "on the same queue, the second having a fence, followed "
18153 "by a WaitForFences call.");
18154
18155 m_errorMonitor->ExpectSuccess();
18156
18157 ASSERT_NO_FATAL_FAILURE(InitState());
18158 VkFence fence;
18159 VkFenceCreateInfo fence_create_info{};
18160 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18161 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18162
18163 VkCommandPool command_pool;
18164 VkCommandPoolCreateInfo pool_create_info{};
18165 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18166 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18167 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18168 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18169
18170 VkCommandBuffer command_buffer[2];
18171 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18172 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18173 command_buffer_allocate_info.commandPool = command_pool;
18174 command_buffer_allocate_info.commandBufferCount = 2;
18175 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18176 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18177
18178 {
18179 VkCommandBufferBeginInfo begin_info{};
18180 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18181 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18182
18183 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18184 nullptr, 0, nullptr, 0, nullptr);
18185
18186 VkViewport viewport{};
18187 viewport.maxDepth = 1.0f;
18188 viewport.minDepth = 0.0f;
18189 viewport.width = 512;
18190 viewport.height = 512;
18191 viewport.x = 0;
18192 viewport.y = 0;
18193 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18194 vkEndCommandBuffer(command_buffer[0]);
18195 }
18196 {
18197 VkCommandBufferBeginInfo begin_info{};
18198 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18199 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18200
18201 VkViewport viewport{};
18202 viewport.maxDepth = 1.0f;
18203 viewport.minDepth = 0.0f;
18204 viewport.width = 512;
18205 viewport.height = 512;
18206 viewport.x = 0;
18207 viewport.y = 0;
18208 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18209 vkEndCommandBuffer(command_buffer[1]);
18210 }
18211 {
18212 VkSubmitInfo submit_info{};
18213 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18214 submit_info.commandBufferCount = 1;
18215 submit_info.pCommandBuffers = &command_buffer[0];
18216 submit_info.signalSemaphoreCount = 0;
18217 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18218 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18219 }
18220 {
18221 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18222 VkSubmitInfo submit_info{};
18223 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18224 submit_info.commandBufferCount = 1;
18225 submit_info.pCommandBuffers = &command_buffer[1];
18226 submit_info.waitSemaphoreCount = 0;
18227 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18228 submit_info.pWaitDstStageMask = flags;
18229 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18230 }
18231
18232 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18233
18234 vkDestroyFence(m_device->device(), fence, nullptr);
18235 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18236 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18237
18238 m_errorMonitor->VerifyNotFound();
18239}
18240
18241// This is a positive test. No errors should be generated.
18242TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18243
18244 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18245 "QueueSubmit call followed by a WaitForFences call.");
18246 ASSERT_NO_FATAL_FAILURE(InitState());
18247
18248 m_errorMonitor->ExpectSuccess();
18249
18250 VkFence fence;
18251 VkFenceCreateInfo fence_create_info{};
18252 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18253 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18254
18255 VkSemaphore semaphore;
18256 VkSemaphoreCreateInfo semaphore_create_info{};
18257 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18258 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18259
18260 VkCommandPool command_pool;
18261 VkCommandPoolCreateInfo pool_create_info{};
18262 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18263 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18264 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18265 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18266
18267 VkCommandBuffer command_buffer[2];
18268 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18269 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18270 command_buffer_allocate_info.commandPool = command_pool;
18271 command_buffer_allocate_info.commandBufferCount = 2;
18272 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18273 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18274
18275 {
18276 VkCommandBufferBeginInfo begin_info{};
18277 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18278 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18279
18280 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18281 nullptr, 0, nullptr, 0, nullptr);
18282
18283 VkViewport viewport{};
18284 viewport.maxDepth = 1.0f;
18285 viewport.minDepth = 0.0f;
18286 viewport.width = 512;
18287 viewport.height = 512;
18288 viewport.x = 0;
18289 viewport.y = 0;
18290 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18291 vkEndCommandBuffer(command_buffer[0]);
18292 }
18293 {
18294 VkCommandBufferBeginInfo begin_info{};
18295 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18296 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18297
18298 VkViewport viewport{};
18299 viewport.maxDepth = 1.0f;
18300 viewport.minDepth = 0.0f;
18301 viewport.width = 512;
18302 viewport.height = 512;
18303 viewport.x = 0;
18304 viewport.y = 0;
18305 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18306 vkEndCommandBuffer(command_buffer[1]);
18307 }
18308 {
18309 VkSubmitInfo submit_info[2];
18310 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18311
18312 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18313 submit_info[0].pNext = NULL;
18314 submit_info[0].commandBufferCount = 1;
18315 submit_info[0].pCommandBuffers = &command_buffer[0];
18316 submit_info[0].signalSemaphoreCount = 1;
18317 submit_info[0].pSignalSemaphores = &semaphore;
18318 submit_info[0].waitSemaphoreCount = 0;
18319 submit_info[0].pWaitSemaphores = NULL;
18320 submit_info[0].pWaitDstStageMask = 0;
18321
18322 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18323 submit_info[1].pNext = NULL;
18324 submit_info[1].commandBufferCount = 1;
18325 submit_info[1].pCommandBuffers = &command_buffer[1];
18326 submit_info[1].waitSemaphoreCount = 1;
18327 submit_info[1].pWaitSemaphores = &semaphore;
18328 submit_info[1].pWaitDstStageMask = flags;
18329 submit_info[1].signalSemaphoreCount = 0;
18330 submit_info[1].pSignalSemaphores = NULL;
18331 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18332 }
18333
18334 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18335
18336 vkDestroyFence(m_device->device(), fence, nullptr);
18337 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18338 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18339 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18340
18341 m_errorMonitor->VerifyNotFound();
18342}
18343
18344TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18345 m_errorMonitor->ExpectSuccess();
18346
18347 ASSERT_NO_FATAL_FAILURE(InitState());
18348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18349
18350 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18351 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18352
18353 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18354 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18355 m_errorMonitor->VerifyNotFound();
18356 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18357 m_errorMonitor->VerifyNotFound();
18358 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18359 m_errorMonitor->VerifyNotFound();
18360
18361 m_commandBuffer->EndCommandBuffer();
18362 m_errorMonitor->VerifyNotFound();
18363}
18364
18365TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18366 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18367 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18368 "has a valid layout, and a second subpass then uses a "
18369 "valid *READ_ONLY* layout.");
18370 m_errorMonitor->ExpectSuccess();
18371 ASSERT_NO_FATAL_FAILURE(InitState());
18372
18373 VkAttachmentReference attach[2] = {};
18374 attach[0].attachment = 0;
18375 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18376 attach[1].attachment = 0;
18377 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18378 VkSubpassDescription subpasses[2] = {};
18379 // First subpass clears DS attach on load
18380 subpasses[0].pDepthStencilAttachment = &attach[0];
18381 // 2nd subpass reads in DS as input attachment
18382 subpasses[1].inputAttachmentCount = 1;
18383 subpasses[1].pInputAttachments = &attach[1];
18384 VkAttachmentDescription attach_desc = {};
18385 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18386 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18387 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18388 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18389 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18390 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18391 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18392 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18393 VkRenderPassCreateInfo rpci = {};
18394 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18395 rpci.attachmentCount = 1;
18396 rpci.pAttachments = &attach_desc;
18397 rpci.subpassCount = 2;
18398 rpci.pSubpasses = subpasses;
18399
18400 // Now create RenderPass and verify no errors
18401 VkRenderPass rp;
18402 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18403 m_errorMonitor->VerifyNotFound();
18404
18405 vkDestroyRenderPass(m_device->device(), rp, NULL);
18406}
18407
18408TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18409 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18410 "as vertex attributes");
18411 m_errorMonitor->ExpectSuccess();
18412
18413 ASSERT_NO_FATAL_FAILURE(InitState());
18414 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18415
18416 VkVertexInputBindingDescription input_binding;
18417 memset(&input_binding, 0, sizeof(input_binding));
18418
18419 VkVertexInputAttributeDescription input_attribs[2];
18420 memset(input_attribs, 0, sizeof(input_attribs));
18421
18422 for (int i = 0; i < 2; i++) {
18423 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18424 input_attribs[i].location = i;
18425 }
18426
18427 char const *vsSource = "#version 450\n"
18428 "\n"
18429 "layout(location=0) in mat2x4 x;\n"
18430 "out gl_PerVertex {\n"
18431 " vec4 gl_Position;\n"
18432 "};\n"
18433 "void main(){\n"
18434 " gl_Position = x[0] + x[1];\n"
18435 "}\n";
18436 char const *fsSource = "#version 450\n"
18437 "\n"
18438 "layout(location=0) out vec4 color;\n"
18439 "void main(){\n"
18440 " color = vec4(1);\n"
18441 "}\n";
18442
18443 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18444 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18445
18446 VkPipelineObj pipe(m_device);
18447 pipe.AddColorAttachment();
18448 pipe.AddShader(&vs);
18449 pipe.AddShader(&fs);
18450
18451 pipe.AddVertexInputBindings(&input_binding, 1);
18452 pipe.AddVertexInputAttribs(input_attribs, 2);
18453
18454 VkDescriptorSetObj descriptorSet(m_device);
18455 descriptorSet.AppendDummy();
18456 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18457
18458 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18459
18460 /* expect success */
18461 m_errorMonitor->VerifyNotFound();
18462}
18463
18464TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18465 m_errorMonitor->ExpectSuccess();
18466
18467 ASSERT_NO_FATAL_FAILURE(InitState());
18468 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18469
18470 VkVertexInputBindingDescription input_binding;
18471 memset(&input_binding, 0, sizeof(input_binding));
18472
18473 VkVertexInputAttributeDescription input_attribs[2];
18474 memset(input_attribs, 0, sizeof(input_attribs));
18475
18476 for (int i = 0; i < 2; i++) {
18477 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18478 input_attribs[i].location = i;
18479 }
18480
18481 char const *vsSource = "#version 450\n"
18482 "\n"
18483 "layout(location=0) in vec4 x[2];\n"
18484 "out gl_PerVertex {\n"
18485 " vec4 gl_Position;\n"
18486 "};\n"
18487 "void main(){\n"
18488 " gl_Position = x[0] + x[1];\n"
18489 "}\n";
18490 char const *fsSource = "#version 450\n"
18491 "\n"
18492 "layout(location=0) out vec4 color;\n"
18493 "void main(){\n"
18494 " color = vec4(1);\n"
18495 "}\n";
18496
18497 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18498 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18499
18500 VkPipelineObj pipe(m_device);
18501 pipe.AddColorAttachment();
18502 pipe.AddShader(&vs);
18503 pipe.AddShader(&fs);
18504
18505 pipe.AddVertexInputBindings(&input_binding, 1);
18506 pipe.AddVertexInputAttribs(input_attribs, 2);
18507
18508 VkDescriptorSetObj descriptorSet(m_device);
18509 descriptorSet.AppendDummy();
18510 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18511
18512 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18513
18514 m_errorMonitor->VerifyNotFound();
18515}
18516
18517TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18518 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18519 "through multiple vertex shader inputs, each consuming a different "
18520 "subset of the components.");
18521 m_errorMonitor->ExpectSuccess();
18522
18523 ASSERT_NO_FATAL_FAILURE(InitState());
18524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18525
18526 VkVertexInputBindingDescription input_binding;
18527 memset(&input_binding, 0, sizeof(input_binding));
18528
18529 VkVertexInputAttributeDescription input_attribs[3];
18530 memset(input_attribs, 0, sizeof(input_attribs));
18531
18532 for (int i = 0; i < 3; i++) {
18533 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18534 input_attribs[i].location = i;
18535 }
18536
18537 char const *vsSource = "#version 450\n"
18538 "\n"
18539 "layout(location=0) in vec4 x;\n"
18540 "layout(location=1) in vec3 y1;\n"
18541 "layout(location=1, component=3) in float y2;\n"
18542 "layout(location=2) in vec4 z;\n"
18543 "out gl_PerVertex {\n"
18544 " vec4 gl_Position;\n"
18545 "};\n"
18546 "void main(){\n"
18547 " gl_Position = x + vec4(y1, y2) + z;\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, 3);
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, CreatePipelineSimplePositive) {
18577 m_errorMonitor->ExpectSuccess();
18578
18579 ASSERT_NO_FATAL_FAILURE(InitState());
18580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18581
18582 char const *vsSource = "#version 450\n"
18583 "out gl_PerVertex {\n"
18584 " vec4 gl_Position;\n"
18585 "};\n"
18586 "void main(){\n"
18587 " gl_Position = vec4(0);\n"
18588 "}\n";
18589 char const *fsSource = "#version 450\n"
18590 "\n"
18591 "layout(location=0) out vec4 color;\n"
18592 "void main(){\n"
18593 " color = vec4(1);\n"
18594 "}\n";
18595
18596 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18597 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18598
18599 VkPipelineObj pipe(m_device);
18600 pipe.AddColorAttachment();
18601 pipe.AddShader(&vs);
18602 pipe.AddShader(&fs);
18603
18604 VkDescriptorSetObj descriptorSet(m_device);
18605 descriptorSet.AppendDummy();
18606 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18607
18608 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18609
18610 m_errorMonitor->VerifyNotFound();
18611}
18612
18613TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18614 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18615 "set out in 14.1.3: fundamental type must match, and producer side must "
18616 "have at least as many components");
18617 m_errorMonitor->ExpectSuccess();
18618
18619 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18620
18621 ASSERT_NO_FATAL_FAILURE(InitState());
18622 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18623
18624 char const *vsSource = "#version 450\n"
18625 "out gl_PerVertex {\n"
18626 " vec4 gl_Position;\n"
18627 "};\n"
18628 "layout(location=0) out vec3 x;\n"
18629 "layout(location=1) out ivec3 y;\n"
18630 "layout(location=2) out vec3 z;\n"
18631 "void main(){\n"
18632 " gl_Position = vec4(0);\n"
18633 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18634 "}\n";
18635 char const *fsSource = "#version 450\n"
18636 "\n"
18637 "layout(location=0) out vec4 color;\n"
18638 "layout(location=0) in float x;\n"
18639 "layout(location=1) flat in int y;\n"
18640 "layout(location=2) in vec2 z;\n"
18641 "void main(){\n"
18642 " color = vec4(1 + x + y + z.x);\n"
18643 "}\n";
18644
18645 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18646 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18647
18648 VkPipelineObj pipe(m_device);
18649 pipe.AddColorAttachment();
18650 pipe.AddShader(&vs);
18651 pipe.AddShader(&fs);
18652
18653 VkDescriptorSetObj descriptorSet(m_device);
18654 descriptorSet.AppendDummy();
18655 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18656
18657 VkResult err = VK_SUCCESS;
18658 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18659 ASSERT_VK_SUCCESS(err);
18660
18661 m_errorMonitor->VerifyNotFound();
18662}
18663
18664TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18665 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18666 "passed between the TCS and TES stages");
18667 m_errorMonitor->ExpectSuccess();
18668
18669 ASSERT_NO_FATAL_FAILURE(InitState());
18670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18671
18672 if (!m_device->phy().features().tessellationShader) {
18673 printf("Device does not support tessellation shaders; skipped.\n");
18674 return;
18675 }
18676
18677 char const *vsSource = "#version 450\n"
18678 "void main(){}\n";
18679 char const *tcsSource = "#version 450\n"
18680 "layout(location=0) out int x[];\n"
18681 "layout(vertices=3) out;\n"
18682 "void main(){\n"
18683 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18684 " gl_TessLevelInner[0] = 1;\n"
18685 " x[gl_InvocationID] = gl_InvocationID;\n"
18686 "}\n";
18687 char const *tesSource = "#version 450\n"
18688 "layout(triangles, equal_spacing, cw) in;\n"
18689 "layout(location=0) in int x[];\n"
18690 "out gl_PerVertex { vec4 gl_Position; };\n"
18691 "void main(){\n"
18692 " gl_Position.xyz = gl_TessCoord;\n"
18693 " gl_Position.w = x[0] + x[1] + x[2];\n"
18694 "}\n";
18695 char const *fsSource = "#version 450\n"
18696 "layout(location=0) out vec4 color;\n"
18697 "void main(){\n"
18698 " color = vec4(1);\n"
18699 "}\n";
18700
18701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18702 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
18703 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
18704 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18705
18706 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
18707 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
18708
18709 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
18710
18711 VkPipelineObj pipe(m_device);
18712 pipe.SetInputAssembly(&iasci);
18713 pipe.SetTessellation(&tsci);
18714 pipe.AddColorAttachment();
18715 pipe.AddShader(&vs);
18716 pipe.AddShader(&tcs);
18717 pipe.AddShader(&tes);
18718 pipe.AddShader(&fs);
18719
18720 VkDescriptorSetObj descriptorSet(m_device);
18721 descriptorSet.AppendDummy();
18722 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18723
18724 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18725
18726 m_errorMonitor->VerifyNotFound();
18727}
18728
18729TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
18730 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
18731 "interface block passed into the geometry shader. This "
18732 "is interesting because the 'extra' array level is not "
18733 "present on the member type, but on the block instance.");
18734 m_errorMonitor->ExpectSuccess();
18735
18736 ASSERT_NO_FATAL_FAILURE(InitState());
18737 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18738
18739 if (!m_device->phy().features().geometryShader) {
18740 printf("Device does not support geometry shaders; skipped.\n");
18741 return;
18742 }
18743
18744 char const *vsSource = "#version 450\n"
18745 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
18746 "void main(){\n"
18747 " vs_out.x = vec4(1);\n"
18748 "}\n";
18749 char const *gsSource = "#version 450\n"
18750 "layout(triangles) in;\n"
18751 "layout(triangle_strip, max_vertices=3) out;\n"
18752 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
18753 "out gl_PerVertex { vec4 gl_Position; };\n"
18754 "void main() {\n"
18755 " gl_Position = gs_in[0].x;\n"
18756 " EmitVertex();\n"
18757 "}\n";
18758 char const *fsSource = "#version 450\n"
18759 "layout(location=0) out vec4 color;\n"
18760 "void main(){\n"
18761 " color = vec4(1);\n"
18762 "}\n";
18763
18764 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18765 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
18766 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18767
18768 VkPipelineObj pipe(m_device);
18769 pipe.AddColorAttachment();
18770 pipe.AddShader(&vs);
18771 pipe.AddShader(&gs);
18772 pipe.AddShader(&fs);
18773
18774 VkDescriptorSetObj descriptorSet(m_device);
18775 descriptorSet.AppendDummy();
18776 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18777
18778 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18779
18780 m_errorMonitor->VerifyNotFound();
18781}
18782
18783TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
18784 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
18785 "attributes. This is interesting because they consume multiple "
18786 "locations.");
18787 m_errorMonitor->ExpectSuccess();
18788
18789 ASSERT_NO_FATAL_FAILURE(InitState());
18790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18791
18792 if (!m_device->phy().features().shaderFloat64) {
18793 printf("Device does not support 64bit vertex attributes; skipped.\n");
18794 return;
18795 }
18796
18797 VkVertexInputBindingDescription input_bindings[1];
18798 memset(input_bindings, 0, sizeof(input_bindings));
18799
18800 VkVertexInputAttributeDescription input_attribs[4];
18801 memset(input_attribs, 0, sizeof(input_attribs));
18802 input_attribs[0].location = 0;
18803 input_attribs[0].offset = 0;
18804 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18805 input_attribs[1].location = 2;
18806 input_attribs[1].offset = 32;
18807 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18808 input_attribs[2].location = 4;
18809 input_attribs[2].offset = 64;
18810 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18811 input_attribs[3].location = 6;
18812 input_attribs[3].offset = 96;
18813 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18814
18815 char const *vsSource = "#version 450\n"
18816 "\n"
18817 "layout(location=0) in dmat4 x;\n"
18818 "out gl_PerVertex {\n"
18819 " vec4 gl_Position;\n"
18820 "};\n"
18821 "void main(){\n"
18822 " gl_Position = vec4(x[0][0]);\n"
18823 "}\n";
18824 char const *fsSource = "#version 450\n"
18825 "\n"
18826 "layout(location=0) out vec4 color;\n"
18827 "void main(){\n"
18828 " color = vec4(1);\n"
18829 "}\n";
18830
18831 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18832 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18833
18834 VkPipelineObj pipe(m_device);
18835 pipe.AddColorAttachment();
18836 pipe.AddShader(&vs);
18837 pipe.AddShader(&fs);
18838
18839 pipe.AddVertexInputBindings(input_bindings, 1);
18840 pipe.AddVertexInputAttribs(input_attribs, 4);
18841
18842 VkDescriptorSetObj descriptorSet(m_device);
18843 descriptorSet.AppendDummy();
18844 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18845
18846 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18847
18848 m_errorMonitor->VerifyNotFound();
18849}
18850
18851TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
18852 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
18853 m_errorMonitor->ExpectSuccess();
18854
18855 ASSERT_NO_FATAL_FAILURE(InitState());
18856
18857 char const *vsSource = "#version 450\n"
18858 "\n"
18859 "out gl_PerVertex {\n"
18860 " vec4 gl_Position;\n"
18861 "};\n"
18862 "void main(){\n"
18863 " gl_Position = vec4(1);\n"
18864 "}\n";
18865 char const *fsSource = "#version 450\n"
18866 "\n"
18867 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
18868 "layout(location=0) out vec4 color;\n"
18869 "void main() {\n"
18870 " color = subpassLoad(x);\n"
18871 "}\n";
18872
18873 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18874 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18875
18876 VkPipelineObj pipe(m_device);
18877 pipe.AddShader(&vs);
18878 pipe.AddShader(&fs);
18879 pipe.AddColorAttachment();
18880 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18881
18882 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
18883 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
18884 VkDescriptorSetLayout dsl;
18885 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18886 ASSERT_VK_SUCCESS(err);
18887
18888 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18889 VkPipelineLayout pl;
18890 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18891 ASSERT_VK_SUCCESS(err);
18892
18893 VkAttachmentDescription descs[2] = {
18894 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18895 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18896 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
18897 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18898 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
18899 };
18900 VkAttachmentReference color = {
18901 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18902 };
18903 VkAttachmentReference input = {
18904 1, VK_IMAGE_LAYOUT_GENERAL,
18905 };
18906
18907 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
18908
18909 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
18910 VkRenderPass rp;
18911 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18912 ASSERT_VK_SUCCESS(err);
18913
18914 // should be OK. would go wrong here if it's going to...
18915 pipe.CreateVKPipeline(pl, rp);
18916
18917 m_errorMonitor->VerifyNotFound();
18918
18919 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18920 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18921 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18922}
18923
18924TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
18925 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
18926 "descriptor-backed resource which is not provided, but the shader does not "
18927 "statically use it. This is interesting because it requires compute pipelines "
18928 "to have a proper descriptor use walk, which they didn't for some time.");
18929 m_errorMonitor->ExpectSuccess();
18930
18931 ASSERT_NO_FATAL_FAILURE(InitState());
18932
18933 char const *csSource = "#version 450\n"
18934 "\n"
18935 "layout(local_size_x=1) in;\n"
18936 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
18937 "void main(){\n"
18938 " // x is not used.\n"
18939 "}\n";
18940
18941 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18942
18943 VkDescriptorSetObj descriptorSet(m_device);
18944 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18945
18946 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18947 nullptr,
18948 0,
18949 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18950 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18951 descriptorSet.GetPipelineLayout(),
18952 VK_NULL_HANDLE,
18953 -1 };
18954
18955 VkPipeline pipe;
18956 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18957
18958 m_errorMonitor->VerifyNotFound();
18959
18960 if (err == VK_SUCCESS) {
18961 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18962 }
18963}
18964
18965TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
18966 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18967 "sampler portion of a combined image + sampler");
18968 m_errorMonitor->ExpectSuccess();
18969
18970 ASSERT_NO_FATAL_FAILURE(InitState());
18971
18972 VkDescriptorSetLayoutBinding bindings[] = {
18973 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18974 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18975 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18976 };
18977 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18978 VkDescriptorSetLayout dsl;
18979 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18980 ASSERT_VK_SUCCESS(err);
18981
18982 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18983 VkPipelineLayout pl;
18984 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18985 ASSERT_VK_SUCCESS(err);
18986
18987 char const *csSource = "#version 450\n"
18988 "\n"
18989 "layout(local_size_x=1) in;\n"
18990 "layout(set=0, binding=0) uniform sampler s;\n"
18991 "layout(set=0, binding=1) uniform texture2D t;\n"
18992 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18993 "void main() {\n"
18994 " x = texture(sampler2D(t, s), vec2(0));\n"
18995 "}\n";
18996 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18997
18998 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18999 nullptr,
19000 0,
19001 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19002 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19003 pl,
19004 VK_NULL_HANDLE,
19005 -1 };
19006
19007 VkPipeline pipe;
19008 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19009
19010 m_errorMonitor->VerifyNotFound();
19011
19012 if (err == VK_SUCCESS) {
19013 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19014 }
19015
19016 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19017 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19018}
19019
19020TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19021 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19022 "image portion of a combined image + sampler");
19023 m_errorMonitor->ExpectSuccess();
19024
19025 ASSERT_NO_FATAL_FAILURE(InitState());
19026
19027 VkDescriptorSetLayoutBinding bindings[] = {
19028 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19029 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19030 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19031 };
19032 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19033 VkDescriptorSetLayout dsl;
19034 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19035 ASSERT_VK_SUCCESS(err);
19036
19037 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19038 VkPipelineLayout pl;
19039 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19040 ASSERT_VK_SUCCESS(err);
19041
19042 char const *csSource = "#version 450\n"
19043 "\n"
19044 "layout(local_size_x=1) in;\n"
19045 "layout(set=0, binding=0) uniform texture2D t;\n"
19046 "layout(set=0, binding=1) uniform sampler s;\n"
19047 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19048 "void main() {\n"
19049 " x = texture(sampler2D(t, s), vec2(0));\n"
19050 "}\n";
19051 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19052
19053 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19054 nullptr,
19055 0,
19056 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19057 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19058 pl,
19059 VK_NULL_HANDLE,
19060 -1 };
19061
19062 VkPipeline pipe;
19063 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19064
19065 m_errorMonitor->VerifyNotFound();
19066
19067 if (err == VK_SUCCESS) {
19068 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19069 }
19070
19071 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19072 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19073}
19074
19075TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19076 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19077 "both the sampler and the image of a combined image+sampler "
19078 "but via separate variables");
19079 m_errorMonitor->ExpectSuccess();
19080
19081 ASSERT_NO_FATAL_FAILURE(InitState());
19082
19083 VkDescriptorSetLayoutBinding bindings[] = {
19084 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19085 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19086 };
19087 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19088 VkDescriptorSetLayout dsl;
19089 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19090 ASSERT_VK_SUCCESS(err);
19091
19092 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19093 VkPipelineLayout pl;
19094 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19095 ASSERT_VK_SUCCESS(err);
19096
19097 char const *csSource = "#version 450\n"
19098 "\n"
19099 "layout(local_size_x=1) in;\n"
19100 "layout(set=0, binding=0) uniform texture2D t;\n"
19101 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19102 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19103 "void main() {\n"
19104 " x = texture(sampler2D(t, s), vec2(0));\n"
19105 "}\n";
19106 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19107
19108 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19109 nullptr,
19110 0,
19111 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19112 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19113 pl,
19114 VK_NULL_HANDLE,
19115 -1 };
19116
19117 VkPipeline pipe;
19118 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19119
19120 m_errorMonitor->VerifyNotFound();
19121
19122 if (err == VK_SUCCESS) {
19123 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19124 }
19125
19126 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19127 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19128}
19129
19130TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19131 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19132
19133 ASSERT_NO_FATAL_FAILURE(InitState());
19134
19135 // Positive test to check parameter_validation and unique_objects support
19136 // for NV_dedicated_allocation
19137 uint32_t extension_count = 0;
19138 bool supports_nv_dedicated_allocation = false;
19139 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19140 ASSERT_VK_SUCCESS(err);
19141
19142 if (extension_count > 0) {
19143 std::vector<VkExtensionProperties> available_extensions(extension_count);
19144
19145 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19146 ASSERT_VK_SUCCESS(err);
19147
19148 for (const auto &extension_props : available_extensions) {
19149 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19150 supports_nv_dedicated_allocation = true;
19151 }
19152 }
19153 }
19154
19155 if (supports_nv_dedicated_allocation) {
19156 m_errorMonitor->ExpectSuccess();
19157
19158 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19159 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19160 dedicated_buffer_create_info.pNext = nullptr;
19161 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19162
19163 uint32_t queue_family_index = 0;
19164 VkBufferCreateInfo buffer_create_info = {};
19165 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19166 buffer_create_info.pNext = &dedicated_buffer_create_info;
19167 buffer_create_info.size = 1024;
19168 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19169 buffer_create_info.queueFamilyIndexCount = 1;
19170 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19171
19172 VkBuffer buffer;
19173 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19174 ASSERT_VK_SUCCESS(err);
19175
19176 VkMemoryRequirements memory_reqs;
19177 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19178
19179 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19180 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19181 dedicated_memory_info.pNext = nullptr;
19182 dedicated_memory_info.buffer = buffer;
19183 dedicated_memory_info.image = VK_NULL_HANDLE;
19184
19185 VkMemoryAllocateInfo memory_info = {};
19186 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19187 memory_info.pNext = &dedicated_memory_info;
19188 memory_info.allocationSize = memory_reqs.size;
19189
19190 bool pass;
19191 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19192 ASSERT_TRUE(pass);
19193
19194 VkDeviceMemory buffer_memory;
19195 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19196 ASSERT_VK_SUCCESS(err);
19197
19198 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19199 ASSERT_VK_SUCCESS(err);
19200
19201 vkDestroyBuffer(m_device->device(), buffer, NULL);
19202 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19203
19204 m_errorMonitor->VerifyNotFound();
19205 }
19206}
19207
19208TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19209 VkResult err;
19210
19211 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19212
19213 ASSERT_NO_FATAL_FAILURE(InitState());
19214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19215
19216 std::vector<const char *> device_extension_names;
19217 auto features = m_device->phy().features();
19218 // Artificially disable support for non-solid fill modes
19219 features.fillModeNonSolid = false;
19220 // The sacrificial device object
19221 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19222
19223 VkRenderpassObj render_pass(&test_device);
19224
19225 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19226 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19227 pipeline_layout_ci.setLayoutCount = 0;
19228 pipeline_layout_ci.pSetLayouts = NULL;
19229
19230 VkPipelineLayout pipeline_layout;
19231 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19232 ASSERT_VK_SUCCESS(err);
19233
19234 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19235 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19236 rs_ci.pNext = nullptr;
19237 rs_ci.lineWidth = 1.0f;
19238 rs_ci.rasterizerDiscardEnable = true;
19239
19240 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19241 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19242
19243 // Set polygonMode=FILL. No error is expected
19244 m_errorMonitor->ExpectSuccess();
19245 {
19246 VkPipelineObj pipe(&test_device);
19247 pipe.AddShader(&vs);
19248 pipe.AddShader(&fs);
19249 pipe.AddColorAttachment();
19250 // Set polygonMode to a good value
19251 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19252 pipe.SetRasterization(&rs_ci);
19253 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19254 }
19255 m_errorMonitor->VerifyNotFound();
19256
19257 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19258}
19259
19260TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19261 VkResult err;
19262 ASSERT_NO_FATAL_FAILURE(InitState());
19263 ASSERT_NO_FATAL_FAILURE(InitViewport());
19264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19265
19266 VkPipelineLayout pipeline_layout;
19267 VkPushConstantRange pc_range = {};
19268 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19269 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19270 pipeline_layout_ci.pushConstantRangeCount = 1;
19271 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19272
19273 //
19274 // Check for invalid push constant ranges in pipeline layouts.
19275 //
19276 struct PipelineLayoutTestCase {
19277 VkPushConstantRange const range;
19278 char const *msg;
19279 };
19280
19281 // Check for overlapping ranges
19282 const uint32_t ranges_per_test = 5;
19283 struct OverlappingRangeTestCase {
19284 VkPushConstantRange const ranges[ranges_per_test];
19285 char const *msg;
19286 };
19287
19288 // Run some positive tests to make sure overlap checking in the layer is OK
19289 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19290 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19291 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19292 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19293 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19294 "" },
19295 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19296 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19297 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19298 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19299 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19300 "" } } };
19301 for (const auto &iter : overlapping_range_tests_pos) {
19302 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19303 m_errorMonitor->ExpectSuccess();
19304 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19305 m_errorMonitor->VerifyNotFound();
19306 if (VK_SUCCESS == err) {
19307 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19308 }
19309 }
19310
19311 //
19312 // CmdPushConstants tests
19313 //
19314 const uint8_t dummy_values[100] = {};
19315
19316 BeginCommandBuffer();
19317
19318 // positive overlapping range tests with cmd
19319 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19320 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19321 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19322 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19323 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19324 } };
19325
19326 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19327 const VkPushConstantRange pc_range4[] = {
19328 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19329 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19330 };
19331
19332 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19333 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19334 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19335 ASSERT_VK_SUCCESS(err);
19336 for (const auto &iter : cmd_overlap_tests_pos) {
19337 m_errorMonitor->ExpectSuccess();
19338 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19339 iter.range.size, dummy_values);
19340 m_errorMonitor->VerifyNotFound();
19341 }
19342 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19343
19344 EndCommandBuffer();
19345}
19346
19347
19348
19349
19350
19351
19352
19353#if 0 // A few devices have issues with this test so disabling for now
19354TEST_F(VkPositiveLayerTest, LongFenceChain)
19355{
19356 m_errorMonitor->ExpectSuccess();
19357
19358 ASSERT_NO_FATAL_FAILURE(InitState());
19359 VkResult err;
19360
19361 std::vector<VkFence> fences;
19362
19363 const int chainLength = 32768;
19364
19365 for (int i = 0; i < chainLength; i++) {
19366 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19367 VkFence fence;
19368 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19369 ASSERT_VK_SUCCESS(err);
19370
19371 fences.push_back(fence);
19372
19373 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19374 0, nullptr, 0, nullptr };
19375 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19376 ASSERT_VK_SUCCESS(err);
19377
19378 }
19379
19380 // BOOM, stack overflow.
19381 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19382
19383 for (auto fence : fences)
19384 vkDestroyFence(m_device->device(), fence, nullptr);
19385
19386 m_errorMonitor->VerifyNotFound();
19387}
19388#endif
19389
19390
Cody Northrop1242dfd2016-07-13 17:24:59 -060019391#if defined(ANDROID) && defined(VALIDATION_APK)
19392static bool initialized = false;
19393static bool active = false;
19394
19395// Convert Intents to argv
19396// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019397std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019398 std::vector<std::string> args;
19399 JavaVM &vm = *app.activity->vm;
19400 JNIEnv *p_env;
19401 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19402 return args;
19403
19404 JNIEnv &env = *p_env;
19405 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019406 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019407 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019408 jmethodID get_string_extra_method =
19409 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019410 jvalue get_string_extra_args;
19411 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019412 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019413
19414 std::string args_str;
19415 if (extra_str) {
19416 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19417 args_str = extra_utf;
19418 env.ReleaseStringUTFChars(extra_str, extra_utf);
19419 env.DeleteLocalRef(extra_str);
19420 }
19421
19422 env.DeleteLocalRef(get_string_extra_args.l);
19423 env.DeleteLocalRef(intent);
19424 vm.DetachCurrentThread();
19425
19426 // split args_str
19427 std::stringstream ss(args_str);
19428 std::string arg;
19429 while (std::getline(ss, arg, ' ')) {
19430 if (!arg.empty())
19431 args.push_back(arg);
19432 }
19433
19434 return args;
19435}
19436
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019437static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019439static void processCommand(struct android_app *app, int32_t cmd) {
19440 switch (cmd) {
19441 case APP_CMD_INIT_WINDOW: {
19442 if (app->window) {
19443 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019444 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019445 break;
19446 }
19447 case APP_CMD_GAINED_FOCUS: {
19448 active = true;
19449 break;
19450 }
19451 case APP_CMD_LOST_FOCUS: {
19452 active = false;
19453 break;
19454 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019455 }
19456}
19457
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019458void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019459 app_dummy();
19460
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019461 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019462
19463 int vulkanSupport = InitVulkan();
19464 if (vulkanSupport == 0) {
19465 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19466 return;
19467 }
19468
19469 app->onAppCmd = processCommand;
19470 app->onInputEvent = processInput;
19471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019472 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019473 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019474 struct android_poll_source *source;
19475 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019476 if (source) {
19477 source->process(app, source);
19478 }
19479
19480 if (app->destroyRequested != 0) {
19481 VkTestFramework::Finish();
19482 return;
19483 }
19484 }
19485
19486 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019487 // Use the following key to send arguments to gtest, i.e.
19488 // --es args "--gtest_filter=-VkLayerTest.foo"
19489 const char key[] = "args";
19490 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019492 std::string filter = "";
19493 if (args.size() > 0) {
19494 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19495 filter += args[0];
19496 } else {
19497 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19498 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019500 int argc = 2;
19501 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19502 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019503
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019504 // Route output to files until we can override the gtest output
19505 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19506 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019508 ::testing::InitGoogleTest(&argc, argv);
19509 VkTestFramework::InitArgs(&argc, argv);
19510 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019511
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019512 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019514 if (result != 0) {
19515 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19516 } else {
19517 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19518 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019519
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019520 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019522 fclose(stdout);
19523 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019525 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019527 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019528 }
19529 }
19530}
19531#endif
19532
Tony Barbour300a6082015-04-07 13:44:53 -060019533int main(int argc, char **argv) {
19534 int result;
19535
Cody Northrop8e54a402016-03-08 22:25:52 -070019536#ifdef ANDROID
19537 int vulkanSupport = InitVulkan();
19538 if (vulkanSupport == 0)
19539 return 1;
19540#endif
19541
Tony Barbour300a6082015-04-07 13:44:53 -060019542 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019543 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019544
19545 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19546
19547 result = RUN_ALL_TESTS();
19548
Tony Barbour6918cd52015-04-09 12:58:51 -060019549 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019550 return result;
19551}