blob: da74816438efe02fa028482c2387bd88e279730b [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
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001396 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1397
Tobin Ehlis35372522016-05-12 08:32:31 -06001398 VkBufferCreateInfo buf_info = {};
1399 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1400 buf_info.pNext = NULL;
1401 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1402 buf_info.size = 256;
1403 buf_info.queueFamilyIndexCount = 0;
1404 buf_info.pQueueFamilyIndices = NULL;
1405 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1406 buf_info.flags = 0;
1407 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1408 ASSERT_VK_SUCCESS(err);
1409
1410 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1411 VkMemoryAllocateInfo alloc_info = {};
1412 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1413 alloc_info.pNext = NULL;
1414 alloc_info.memoryTypeIndex = 0;
1415
1416 // Ensure memory is big enough for both bindings
1417 static const VkDeviceSize allocation_size = 0x10000;
1418 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001419 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 -06001420 if (!pass) {
1421 vkDestroyBuffer(m_device->device(), buffer, NULL);
1422 return;
1423 }
1424 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1425 ASSERT_VK_SUCCESS(err);
1426
1427 uint8_t *pData;
1428 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001429 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 -06001430 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1431 m_errorMonitor->VerifyFound();
1432 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001434 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1436 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1437 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001438 m_errorMonitor->VerifyFound();
1439
1440 // Unmap the memory to avoid re-map error
1441 vkUnmapMemory(m_device->device(), mem);
1442 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1444 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1445 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001446 m_errorMonitor->VerifyFound();
1447 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1449 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001450 m_errorMonitor->VerifyFound();
1451 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001453 vkUnmapMemory(m_device->device(), mem);
1454 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001455
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001457 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 ASSERT_VK_SUCCESS(err);
1459 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001460 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001462 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1465 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001466
Tobin Ehlis35372522016-05-12 08:32:31 -06001467 // Now flush range that oversteps mapped range
1468 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001469 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001471 mmr.offset = atom_size;
1472 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1474 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1475 m_errorMonitor->VerifyFound();
1476
1477 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1478 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001479 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001481 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001482 mmr.size = VK_WHOLE_SIZE;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1485 m_errorMonitor->VerifyFound();
1486
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001487 // Some platforms have an atomsize of 1 which makes the test meaningless
1488 if (atom_size > 3) {
1489 // Now with an offset NOT a multiple of the device limit
1490 vkUnmapMemory(m_device->device(), mem);
1491 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1492 ASSERT_VK_SUCCESS(err);
1493 mmr.offset = 3; // Not a multiple of atom_size
1494 mmr.size = VK_WHOLE_SIZE;
1495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1496 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1497 m_errorMonitor->VerifyFound();
1498
1499 // Now with a size NOT a multiple of the device limit
1500 vkUnmapMemory(m_device->device(), mem);
1501 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1502 ASSERT_VK_SUCCESS(err);
1503 mmr.offset = atom_size;
1504 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1506 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1507 m_errorMonitor->VerifyFound();
1508 }
1509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001510 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1511 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001512 if (!pass) {
1513 vkFreeMemory(m_device->device(), mem, NULL);
1514 vkDestroyBuffer(m_device->device(), buffer, NULL);
1515 return;
1516 }
1517 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1518 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1519
1520 vkDestroyBuffer(m_device->device(), buffer, NULL);
1521 vkFreeMemory(m_device->device(), mem, NULL);
1522}
1523
Chris Forbes09368e42016-10-13 11:59:22 +13001524#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001525TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1526 VkResult err;
1527 bool pass;
1528
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001529 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1530 // following declaration (which is temporarily being moved below):
1531 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001532 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001533 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001534 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001535 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001536 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001537 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001538
1539 ASSERT_NO_FATAL_FAILURE(InitState());
1540
Ian Elliott3f06ce52016-04-29 14:46:21 -06001541#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1542#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1543 // Use the functions from the VK_KHR_android_surface extension without
1544 // enabling that extension:
1545
1546 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001547 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1549 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001550 pass = (err != VK_SUCCESS);
1551 ASSERT_TRUE(pass);
1552 m_errorMonitor->VerifyFound();
1553#endif // VK_USE_PLATFORM_ANDROID_KHR
1554
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555#if defined(VK_USE_PLATFORM_MIR_KHR)
1556 // Use the functions from the VK_KHR_mir_surface extension without enabling
1557 // that extension:
1558
1559 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001560 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001562 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1563 pass = (err != VK_SUCCESS);
1564 ASSERT_TRUE(pass);
1565 m_errorMonitor->VerifyFound();
1566
1567 // Tell whether an mir_connection supports presentation:
1568 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1570 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001571 m_errorMonitor->VerifyFound();
1572#endif // VK_USE_PLATFORM_MIR_KHR
1573
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1575 // Use the functions from the VK_KHR_wayland_surface extension without
1576 // enabling that extension:
1577
1578 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001579 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1581 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001582 pass = (err != VK_SUCCESS);
1583 ASSERT_TRUE(pass);
1584 m_errorMonitor->VerifyFound();
1585
1586 // Tell whether an wayland_display supports presentation:
1587 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1589 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001590 m_errorMonitor->VerifyFound();
1591#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001592#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593
Ian Elliott3f06ce52016-04-29 14:46:21 -06001594#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001595 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1596 // TO NON-LINUX PLATFORMS:
1597 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001598 // Use the functions from the VK_KHR_win32_surface extension without
1599 // enabling that extension:
1600
1601 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001602 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1604 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001605 pass = (err != VK_SUCCESS);
1606 ASSERT_TRUE(pass);
1607 m_errorMonitor->VerifyFound();
1608
1609 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001611 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001612 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001613// Set this (for now, until all platforms are supported and tested):
1614#define NEED_TO_TEST_THIS_ON_PLATFORM
1615#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001616#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001617 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1618 // TO NON-LINUX PLATFORMS:
1619 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001620#endif
1621#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001622 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1623 // that extension:
1624
1625 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001626 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001628 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1629 pass = (err != VK_SUCCESS);
1630 ASSERT_TRUE(pass);
1631 m_errorMonitor->VerifyFound();
1632
1633 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001634 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001635 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1637 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001638 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001639// Set this (for now, until all platforms are supported and tested):
1640#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001641#endif // VK_USE_PLATFORM_XCB_KHR
1642
Ian Elliott12630812016-04-29 14:35:43 -06001643#if defined(VK_USE_PLATFORM_XLIB_KHR)
1644 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1645 // that extension:
1646
1647 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001648 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001650 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1651 pass = (err != VK_SUCCESS);
1652 ASSERT_TRUE(pass);
1653 m_errorMonitor->VerifyFound();
1654
1655 // Tell whether an Xlib VisualID supports presentation:
1656 Display *dpy = NULL;
1657 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001659 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1660 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001661// Set this (for now, until all platforms are supported and tested):
1662#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001663#endif // VK_USE_PLATFORM_XLIB_KHR
1664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001665// Use the functions from the VK_KHR_surface extension without enabling
1666// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001667
Ian Elliott489eec02016-05-05 14:12:44 -06001668#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001669 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001671 vkDestroySurfaceKHR(instance(), surface, NULL);
1672 m_errorMonitor->VerifyFound();
1673
1674 // Check if surface supports presentation:
1675 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001677 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1678 pass = (err != VK_SUCCESS);
1679 ASSERT_TRUE(pass);
1680 m_errorMonitor->VerifyFound();
1681
1682 // Check surface capabilities:
1683 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1685 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001686 pass = (err != VK_SUCCESS);
1687 ASSERT_TRUE(pass);
1688 m_errorMonitor->VerifyFound();
1689
1690 // Check surface formats:
1691 uint32_t format_count = 0;
1692 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1694 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001695 pass = (err != VK_SUCCESS);
1696 ASSERT_TRUE(pass);
1697 m_errorMonitor->VerifyFound();
1698
1699 // Check surface present modes:
1700 uint32_t present_mode_count = 0;
1701 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1703 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001704 pass = (err != VK_SUCCESS);
1705 ASSERT_TRUE(pass);
1706 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001707#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001708
Ian Elliott1c32c772016-04-28 14:47:13 -06001709 // Use the functions from the VK_KHR_swapchain extension without enabling
1710 // that extension:
1711
1712 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001714 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1715 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001716 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001717 pass = (err != VK_SUCCESS);
1718 ASSERT_TRUE(pass);
1719 m_errorMonitor->VerifyFound();
1720
1721 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1723 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001724 pass = (err != VK_SUCCESS);
1725 ASSERT_TRUE(pass);
1726 m_errorMonitor->VerifyFound();
1727
Chris Forbeseb7d5502016-09-13 18:19:21 +12001728 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1729 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1730 VkFence fence;
1731 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1732
Ian Elliott1c32c772016-04-28 14:47:13 -06001733 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001735 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001736 pass = (err != VK_SUCCESS);
1737 ASSERT_TRUE(pass);
1738 m_errorMonitor->VerifyFound();
1739
Chris Forbeseb7d5502016-09-13 18:19:21 +12001740 vkDestroyFence(m_device->device(), fence, nullptr);
1741
Ian Elliott1c32c772016-04-28 14:47:13 -06001742 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001743 //
1744 // NOTE: Currently can't test this because a real swapchain is needed (as
1745 // opposed to the fake one we created) in order for the layer to lookup the
1746 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001747
1748 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001750 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1751 m_errorMonitor->VerifyFound();
1752}
Chris Forbes09368e42016-10-13 11:59:22 +13001753#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001754
Karl Schultz6addd812016-02-02 17:17:23 -07001755TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1756 VkResult err;
1757 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1760 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001761
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001762 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001763
1764 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001765 VkImage image;
1766 VkDeviceMemory mem;
1767 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001768
Karl Schultz6addd812016-02-02 17:17:23 -07001769 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1770 const int32_t tex_width = 32;
1771 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001772
Tony Barboureb254902015-07-15 12:50:33 -06001773 VkImageCreateInfo image_create_info = {};
1774 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001775 image_create_info.pNext = NULL;
1776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1777 image_create_info.format = tex_format;
1778 image_create_info.extent.width = tex_width;
1779 image_create_info.extent.height = tex_height;
1780 image_create_info.extent.depth = 1;
1781 image_create_info.mipLevels = 1;
1782 image_create_info.arrayLayers = 1;
1783 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1784 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1785 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1786 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001787 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001788
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001789 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001790 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001791 mem_alloc.pNext = NULL;
1792 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001793
Chia-I Wuf7458c52015-10-26 21:10:41 +08001794 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001795 ASSERT_VK_SUCCESS(err);
1796
Karl Schultz6addd812016-02-02 17:17:23 -07001797 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001798
Mark Lobodzinski23065352015-05-29 09:32:35 -05001799 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001800
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001801 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 -07001802 if (!pass) { // If we can't find any unmappable memory this test doesn't
1803 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001804 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001805 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001806 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001807
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001808 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001809 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001810 ASSERT_VK_SUCCESS(err);
1811
1812 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001813 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001814 ASSERT_VK_SUCCESS(err);
1815
1816 // Map memory as if to initialize the image
1817 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001818 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001820 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001821
Chia-I Wuf7458c52015-10-26 21:10:41 +08001822 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001823 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001824}
1825
Karl Schultz6addd812016-02-02 17:17:23 -07001826TEST_F(VkLayerTest, RebindMemory) {
1827 VkResult err;
1828 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001829
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001831
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001832 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001833
1834 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001835 VkImage image;
1836 VkDeviceMemory mem1;
1837 VkDeviceMemory mem2;
1838 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001839
Karl Schultz6addd812016-02-02 17:17:23 -07001840 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1841 const int32_t tex_width = 32;
1842 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001843
Tony Barboureb254902015-07-15 12:50:33 -06001844 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001845 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1846 image_create_info.pNext = NULL;
1847 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1848 image_create_info.format = tex_format;
1849 image_create_info.extent.width = tex_width;
1850 image_create_info.extent.height = tex_height;
1851 image_create_info.extent.depth = 1;
1852 image_create_info.mipLevels = 1;
1853 image_create_info.arrayLayers = 1;
1854 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1855 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1856 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1857 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001858
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001859 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001860 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1861 mem_alloc.pNext = NULL;
1862 mem_alloc.allocationSize = 0;
1863 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001864
Karl Schultz6addd812016-02-02 17:17:23 -07001865 // Introduce failure, do NOT set memProps to
1866 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001867 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001868 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001869 ASSERT_VK_SUCCESS(err);
1870
Karl Schultz6addd812016-02-02 17:17:23 -07001871 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001872
1873 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001875 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001876
1877 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001878 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001880 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001881 ASSERT_VK_SUCCESS(err);
1882
1883 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001884 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001885 ASSERT_VK_SUCCESS(err);
1886
Karl Schultz6addd812016-02-02 17:17:23 -07001887 // Introduce validation failure, try to bind a different memory object to
1888 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001889 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001890
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001891 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001892
Chia-I Wuf7458c52015-10-26 21:10:41 +08001893 vkDestroyImage(m_device->device(), image, NULL);
1894 vkFreeMemory(m_device->device(), mem1, NULL);
1895 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001896}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001897
Karl Schultz6addd812016-02-02 17:17:23 -07001898TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001899 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1902 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001903
1904 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001905 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1906 fenceInfo.pNext = NULL;
1907 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001908
Tony Barbour300a6082015-04-07 13:44:53 -06001909 ASSERT_NO_FATAL_FAILURE(InitState());
1910 ASSERT_NO_FATAL_FAILURE(InitViewport());
1911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1912
Tony Barbourfe3351b2015-07-28 10:17:20 -06001913 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001914 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001915 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001916
1917 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001918
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001919 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001920 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1921 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001922 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001923 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001924 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001925 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001926 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001927 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001928 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001929
1930 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001931 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001932
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001933 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001934}
Chris Forbes4e44c912016-06-16 10:20:00 +12001935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936TEST_F(VkLayerTest, InvalidUsageBits) {
1937 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1938 "Initialize buffer with wrong usage then perform copy expecting errors "
1939 "from both the image and the buffer (2 calls)");
1940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001941
1942 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001943 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001944 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001945 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 -06001946 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001947
Tony Barbourf92621a2016-05-02 14:28:12 -06001948 VkImageView dsv;
1949 VkImageViewCreateInfo dsvci = {};
1950 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1951 dsvci.image = image.handle();
1952 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1953 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1954 dsvci.subresourceRange.layerCount = 1;
1955 dsvci.subresourceRange.baseMipLevel = 0;
1956 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001957 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001958
Tony Barbourf92621a2016-05-02 14:28:12 -06001959 // Create a view with depth / stencil aspect for image with different usage
1960 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001961
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001962 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001963
1964 // Initialize buffer with TRANSFER_DST usage
1965 vk_testing::Buffer buffer;
1966 VkMemoryPropertyFlags reqs = 0;
1967 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1968 VkBufferImageCopy region = {};
1969 region.bufferRowLength = 128;
1970 region.bufferImageHeight = 128;
1971 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1972 region.imageSubresource.layerCount = 1;
1973 region.imageExtent.height = 16;
1974 region.imageExtent.width = 16;
1975 region.imageExtent.depth = 1;
1976
Tony Barbourf92621a2016-05-02 14:28:12 -06001977 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1978 // TRANSFER_DST
1979 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001980
Chris Forbesda581202016-10-06 18:25:26 +13001981 // two separate errors from this call:
1982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1984
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001985 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1986 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001987 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001988}
Tony Barbour75d79f02016-08-30 09:39:07 -06001989
Tony Barbour75d79f02016-08-30 09:39:07 -06001990
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001991#endif // MEM_TRACKER_TESTS
1992
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001993#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001994
1995TEST_F(VkLayerTest, LeakAnObject) {
1996 VkResult err;
1997
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001998 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001999
2000 // Note that we have to create a new device since destroying the
2001 // framework's device causes Teardown() to fail and just calling Teardown
2002 // will destroy the errorMonitor.
2003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002005
2006 ASSERT_NO_FATAL_FAILURE(InitState());
2007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002008 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002009 std::vector<VkDeviceQueueCreateInfo> queue_info;
2010 queue_info.reserve(queue_props.size());
2011 std::vector<std::vector<float>> queue_priorities;
2012 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2013 VkDeviceQueueCreateInfo qi = {};
2014 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2015 qi.pNext = NULL;
2016 qi.queueFamilyIndex = i;
2017 qi.queueCount = queue_props[i].queueCount;
2018 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2019 qi.pQueuePriorities = queue_priorities[i].data();
2020 queue_info.push_back(qi);
2021 }
2022
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002023 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002024
2025 // The sacrificial device object
2026 VkDevice testDevice;
2027 VkDeviceCreateInfo device_create_info = {};
2028 auto features = m_device->phy().features();
2029 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2030 device_create_info.pNext = NULL;
2031 device_create_info.queueCreateInfoCount = queue_info.size();
2032 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002033 device_create_info.enabledLayerCount = 0;
2034 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002035 device_create_info.pEnabledFeatures = &features;
2036 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2037 ASSERT_VK_SUCCESS(err);
2038
2039 VkFence fence;
2040 VkFenceCreateInfo fence_create_info = {};
2041 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2042 fence_create_info.pNext = NULL;
2043 fence_create_info.flags = 0;
2044 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2045 ASSERT_VK_SUCCESS(err);
2046
2047 // Induce failure by not calling vkDestroyFence
2048 vkDestroyDevice(testDevice, NULL);
2049 m_errorMonitor->VerifyFound();
2050}
2051
2052TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2053
2054 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2055 "attempt to delete them from another.");
2056
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002058
Cody Northropc31a84f2016-08-22 10:41:47 -06002059 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002060 VkCommandPool command_pool_one;
2061 VkCommandPool command_pool_two;
2062
2063 VkCommandPoolCreateInfo pool_create_info{};
2064 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2065 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2066 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002068 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002070 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002071
2072 VkCommandBuffer command_buffer[9];
2073 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002074 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002075 command_buffer_allocate_info.commandPool = command_pool_one;
2076 command_buffer_allocate_info.commandBufferCount = 9;
2077 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002080 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002081
2082 m_errorMonitor->VerifyFound();
2083
2084 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2085 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2086}
2087
2088TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2089 VkResult err;
2090
2091 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002093
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002095
2096 ASSERT_NO_FATAL_FAILURE(InitState());
2097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2098
2099 VkDescriptorPoolSize ds_type_count = {};
2100 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2101 ds_type_count.descriptorCount = 1;
2102
2103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2105 ds_pool_ci.pNext = NULL;
2106 ds_pool_ci.flags = 0;
2107 ds_pool_ci.maxSets = 1;
2108 ds_pool_ci.poolSizeCount = 1;
2109 ds_pool_ci.pPoolSizes = &ds_type_count;
2110
2111 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002112 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002113 ASSERT_VK_SUCCESS(err);
2114
2115 // Create a second descriptor pool
2116 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002117 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002118 ASSERT_VK_SUCCESS(err);
2119
2120 VkDescriptorSetLayoutBinding dsl_binding = {};
2121 dsl_binding.binding = 0;
2122 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2123 dsl_binding.descriptorCount = 1;
2124 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2125 dsl_binding.pImmutableSamplers = NULL;
2126
2127 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2128 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2129 ds_layout_ci.pNext = NULL;
2130 ds_layout_ci.bindingCount = 1;
2131 ds_layout_ci.pBindings = &dsl_binding;
2132
2133 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002134 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135 ASSERT_VK_SUCCESS(err);
2136
2137 VkDescriptorSet descriptorSet;
2138 VkDescriptorSetAllocateInfo alloc_info = {};
2139 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2140 alloc_info.descriptorSetCount = 1;
2141 alloc_info.descriptorPool = ds_pool_one;
2142 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002143 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002144 ASSERT_VK_SUCCESS(err);
2145
2146 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2147
2148 m_errorMonitor->VerifyFound();
2149
2150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2151 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2152 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2153}
2154
2155TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002158 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002159
2160 ASSERT_NO_FATAL_FAILURE(InitState());
2161
2162 // Pass bogus handle into GetImageMemoryRequirements
2163 VkMemoryRequirements mem_reqs;
2164 uint64_t fakeImageHandle = 0xCADECADE;
2165 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2166
2167 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2168
2169 m_errorMonitor->VerifyFound();
2170}
2171
Karl Schultz6addd812016-02-02 17:17:23 -07002172TEST_F(VkLayerTest, PipelineNotBound) {
2173 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002175 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002176
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002178
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002179 ASSERT_NO_FATAL_FAILURE(InitState());
2180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002181
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002182 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002183 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2184 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002185
2186 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002187 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2188 ds_pool_ci.pNext = NULL;
2189 ds_pool_ci.maxSets = 1;
2190 ds_pool_ci.poolSizeCount = 1;
2191 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002192
2193 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002194 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002195 ASSERT_VK_SUCCESS(err);
2196
2197 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002198 dsl_binding.binding = 0;
2199 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2200 dsl_binding.descriptorCount = 1;
2201 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2202 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002203
2204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2206 ds_layout_ci.pNext = NULL;
2207 ds_layout_ci.bindingCount = 1;
2208 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002209
2210 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002211 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002212 ASSERT_VK_SUCCESS(err);
2213
2214 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002215 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002216 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002217 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002218 alloc_info.descriptorPool = ds_pool;
2219 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002220 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002221 ASSERT_VK_SUCCESS(err);
2222
2223 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002224 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2225 pipeline_layout_ci.pNext = NULL;
2226 pipeline_layout_ci.setLayoutCount = 1;
2227 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002228
2229 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002230 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002231 ASSERT_VK_SUCCESS(err);
2232
Mark Youngad779052016-01-06 14:26:04 -07002233 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234
2235 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002236 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002237
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002238 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002239
Chia-I Wuf7458c52015-10-26 21:10:41 +08002240 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2241 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2242 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002243}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002244
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002245TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2246 VkResult err;
2247
2248 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2249 "during bind[Buffer|Image]Memory time");
2250
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002251 ASSERT_NO_FATAL_FAILURE(InitState());
2252
2253 // Create an image, allocate memory, set a bad typeIndex and then try to
2254 // bind it
2255 VkImage image;
2256 VkDeviceMemory mem;
2257 VkMemoryRequirements mem_reqs;
2258 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2259 const int32_t tex_width = 32;
2260 const int32_t tex_height = 32;
2261
2262 VkImageCreateInfo image_create_info = {};
2263 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2264 image_create_info.pNext = NULL;
2265 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2266 image_create_info.format = tex_format;
2267 image_create_info.extent.width = tex_width;
2268 image_create_info.extent.height = tex_height;
2269 image_create_info.extent.depth = 1;
2270 image_create_info.mipLevels = 1;
2271 image_create_info.arrayLayers = 1;
2272 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2273 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2274 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2275 image_create_info.flags = 0;
2276
2277 VkMemoryAllocateInfo mem_alloc = {};
2278 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2279 mem_alloc.pNext = NULL;
2280 mem_alloc.allocationSize = 0;
2281 mem_alloc.memoryTypeIndex = 0;
2282
2283 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2284 ASSERT_VK_SUCCESS(err);
2285
2286 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2287 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002288
2289 // Introduce Failure, select invalid TypeIndex
2290 VkPhysicalDeviceMemoryProperties memory_info;
2291
2292 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2293 unsigned int i;
2294 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2295 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2296 mem_alloc.memoryTypeIndex = i;
2297 break;
2298 }
2299 }
2300 if (i >= memory_info.memoryTypeCount) {
2301 printf("No invalid memory type index could be found; skipped.\n");
2302 vkDestroyImage(m_device->device(), image, NULL);
2303 return;
2304 }
2305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002306 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 -06002307
2308 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2309 ASSERT_VK_SUCCESS(err);
2310
2311 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2312 (void)err;
2313
2314 m_errorMonitor->VerifyFound();
2315
2316 vkDestroyImage(m_device->device(), image, NULL);
2317 vkFreeMemory(m_device->device(), mem, NULL);
2318}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002319
Karl Schultz6addd812016-02-02 17:17:23 -07002320TEST_F(VkLayerTest, BindInvalidMemory) {
2321 VkResult err;
2322 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002323
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002325
Tobin Ehlisec598302015-09-15 15:02:17 -06002326 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002327
2328 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002329 VkImage image;
2330 VkDeviceMemory mem;
2331 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002332
Karl Schultz6addd812016-02-02 17:17:23 -07002333 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2334 const int32_t tex_width = 32;
2335 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002336
2337 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002338 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2339 image_create_info.pNext = NULL;
2340 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2341 image_create_info.format = tex_format;
2342 image_create_info.extent.width = tex_width;
2343 image_create_info.extent.height = tex_height;
2344 image_create_info.extent.depth = 1;
2345 image_create_info.mipLevels = 1;
2346 image_create_info.arrayLayers = 1;
2347 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2348 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2349 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2350 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002351
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002352 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002353 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2354 mem_alloc.pNext = NULL;
2355 mem_alloc.allocationSize = 0;
2356 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002357
Chia-I Wuf7458c52015-10-26 21:10:41 +08002358 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002359 ASSERT_VK_SUCCESS(err);
2360
Karl Schultz6addd812016-02-02 17:17:23 -07002361 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002362
2363 mem_alloc.allocationSize = mem_reqs.size;
2364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002365 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002366 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002367
2368 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002369 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002370 ASSERT_VK_SUCCESS(err);
2371
2372 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002373 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002374
2375 // Try to bind free memory that has been freed
2376 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2377 // This may very well return an error.
2378 (void)err;
2379
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002380 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002381
Chia-I Wuf7458c52015-10-26 21:10:41 +08002382 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002383}
2384
Karl Schultz6addd812016-02-02 17:17:23 -07002385TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2386 VkResult err;
2387 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002388
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002390
Tobin Ehlisec598302015-09-15 15:02:17 -06002391 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002392
Karl Schultz6addd812016-02-02 17:17:23 -07002393 // Create an image object, allocate memory, destroy the object and then try
2394 // to bind it
2395 VkImage image;
2396 VkDeviceMemory mem;
2397 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002398
Karl Schultz6addd812016-02-02 17:17:23 -07002399 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2400 const int32_t tex_width = 32;
2401 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002402
2403 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002404 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2405 image_create_info.pNext = NULL;
2406 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2407 image_create_info.format = tex_format;
2408 image_create_info.extent.width = tex_width;
2409 image_create_info.extent.height = tex_height;
2410 image_create_info.extent.depth = 1;
2411 image_create_info.mipLevels = 1;
2412 image_create_info.arrayLayers = 1;
2413 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2414 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2415 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2416 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002417
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002418 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002419 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2420 mem_alloc.pNext = NULL;
2421 mem_alloc.allocationSize = 0;
2422 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002423
Chia-I Wuf7458c52015-10-26 21:10:41 +08002424 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002425 ASSERT_VK_SUCCESS(err);
2426
Karl Schultz6addd812016-02-02 17:17:23 -07002427 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002428
2429 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002430 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002431 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002432
2433 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002434 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002435 ASSERT_VK_SUCCESS(err);
2436
2437 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002438 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002439 ASSERT_VK_SUCCESS(err);
2440
2441 // Now Try to bind memory to this destroyed object
2442 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2443 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002444 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002445
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002446 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002447
Chia-I Wuf7458c52015-10-26 21:10:41 +08002448 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002449}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002450
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002451#endif // OBJ_TRACKER_TESTS
2452
Tobin Ehlis0788f522015-05-26 16:11:58 -06002453#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002454
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002455TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2456 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2457
2458 ASSERT_NO_FATAL_FAILURE(InitState());
2459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2460
2461 VkVertexInputBindingDescription input_binding;
2462 memset(&input_binding, 0, sizeof(input_binding));
2463
2464 VkVertexInputAttributeDescription input_attribs;
2465 memset(&input_attribs, 0, sizeof(input_attribs));
2466
2467 // Pick a really bad format for this purpose and make sure it should fail
2468 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2469 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2470 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2471 printf("Format unsuitable for test; skipped.\n");
2472 return;
2473 }
2474
2475 input_attribs.location = 0;
2476 char const *vsSource = "#version 450\n"
2477 "\n"
2478 "out gl_PerVertex {\n"
2479 " vec4 gl_Position;\n"
2480 "};\n"
2481 "void main(){\n"
2482 " gl_Position = vec4(1);\n"
2483 "}\n";
2484 char const *fsSource = "#version 450\n"
2485 "\n"
2486 "layout(location=0) out vec4 color;\n"
2487 "void main(){\n"
2488 " color = vec4(1);\n"
2489 "}\n";
2490
2491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2492 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2493 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2494
2495 VkPipelineObj pipe(m_device);
2496 pipe.AddColorAttachment();
2497 pipe.AddShader(&vs);
2498 pipe.AddShader(&fs);
2499
2500 pipe.AddVertexInputBindings(&input_binding, 1);
2501 pipe.AddVertexInputAttribs(&input_attribs, 1);
2502
2503 VkDescriptorSetObj descriptorSet(m_device);
2504 descriptorSet.AppendDummy();
2505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2506
2507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2508
2509 m_errorMonitor->VerifyFound();
2510}
2511
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002512TEST_F(VkLayerTest, ImageSampleCounts) {
2513
2514 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2515 "validation errors.");
2516 ASSERT_NO_FATAL_FAILURE(InitState());
2517
2518 VkMemoryPropertyFlags reqs = 0;
2519 VkImageCreateInfo image_create_info = {};
2520 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2521 image_create_info.pNext = NULL;
2522 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2523 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2524 image_create_info.extent.width = 256;
2525 image_create_info.extent.height = 256;
2526 image_create_info.extent.depth = 1;
2527 image_create_info.mipLevels = 1;
2528 image_create_info.arrayLayers = 1;
2529 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2530 image_create_info.flags = 0;
2531
2532 VkImageBlit blit_region = {};
2533 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2534 blit_region.srcSubresource.baseArrayLayer = 0;
2535 blit_region.srcSubresource.layerCount = 1;
2536 blit_region.srcSubresource.mipLevel = 0;
2537 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2538 blit_region.dstSubresource.baseArrayLayer = 0;
2539 blit_region.dstSubresource.layerCount = 1;
2540 blit_region.dstSubresource.mipLevel = 0;
2541
2542 // Create two images, the source with sampleCount = 2, and attempt to blit
2543 // between them
2544 {
2545 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002546 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002547 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002549 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002550 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002551 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002553 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2555 "of VK_SAMPLE_COUNT_2_BIT but "
2556 "must be VK_SAMPLE_COUNT_1_BIT");
2557 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2558 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002559 m_errorMonitor->VerifyFound();
2560 m_commandBuffer->EndCommandBuffer();
2561 }
2562
2563 // Create two images, the dest with sampleCount = 4, and attempt to blit
2564 // between them
2565 {
2566 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002567 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002568 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002569 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002570 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002571 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002572 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002574 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2576 "of VK_SAMPLE_COUNT_4_BIT but "
2577 "must be VK_SAMPLE_COUNT_1_BIT");
2578 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2579 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002580 m_errorMonitor->VerifyFound();
2581 m_commandBuffer->EndCommandBuffer();
2582 }
2583
2584 VkBufferImageCopy copy_region = {};
2585 copy_region.bufferRowLength = 128;
2586 copy_region.bufferImageHeight = 128;
2587 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2588 copy_region.imageSubresource.layerCount = 1;
2589 copy_region.imageExtent.height = 64;
2590 copy_region.imageExtent.width = 64;
2591 copy_region.imageExtent.depth = 1;
2592
2593 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2594 // buffer to image
2595 {
2596 vk_testing::Buffer src_buffer;
2597 VkMemoryPropertyFlags reqs = 0;
2598 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2599 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002603 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2605 "of VK_SAMPLE_COUNT_8_BIT but "
2606 "must be VK_SAMPLE_COUNT_1_BIT");
2607 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2608 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002609 m_errorMonitor->VerifyFound();
2610 m_commandBuffer->EndCommandBuffer();
2611 }
2612
2613 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2614 // image to buffer
2615 {
2616 vk_testing::Buffer dst_buffer;
2617 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2618 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002622 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2624 "of VK_SAMPLE_COUNT_2_BIT but "
2625 "must be VK_SAMPLE_COUNT_1_BIT");
2626 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002627 dst_buffer.handle(), 1, &copy_region);
2628 m_errorMonitor->VerifyFound();
2629 m_commandBuffer->EndCommandBuffer();
2630 }
2631}
2632
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002633TEST_F(VkLayerTest, BlitImageFormats) {
2634
2635 // Image blit with mismatched formats
2636 const char * expected_message =
2637 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2638 " the other one must also have signed/unsigned integer format";
2639
2640 ASSERT_NO_FATAL_FAILURE(InitState());
2641
2642 VkImageObj src_image(m_device);
2643 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2644 VkImageObj dst_image(m_device);
2645 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2646 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002647 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 -06002648
2649 VkImageBlit blitRegion = {};
2650 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2651 blitRegion.srcSubresource.baseArrayLayer = 0;
2652 blitRegion.srcSubresource.layerCount = 1;
2653 blitRegion.srcSubresource.mipLevel = 0;
2654 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2655 blitRegion.dstSubresource.baseArrayLayer = 0;
2656 blitRegion.dstSubresource.layerCount = 1;
2657 blitRegion.dstSubresource.mipLevel = 0;
2658
2659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2660
2661 // Unsigned int vs not an int
2662 BeginCommandBuffer();
2663 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2664 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2665
2666 m_errorMonitor->VerifyFound();
2667
2668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2669
2670 // Unsigned int vs signed int
2671 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2672 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2673
2674 m_errorMonitor->VerifyFound();
2675
2676 EndCommandBuffer();
2677}
2678
2679
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002680TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2681 VkResult err;
2682 bool pass;
2683
2684 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2685 ASSERT_NO_FATAL_FAILURE(InitState());
2686
2687 // If w/d/h granularity is 1, test is not meaningful
2688 // TODO: When virtual device limits are available, create a set of limits for this test that
2689 // will always have a granularity of > 1 for w, h, and d
2690 auto index = m_device->graphics_queue_node_index_;
2691 auto queue_family_properties = m_device->phy().queue_properties();
2692
2693 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2694 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2695 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2696 return;
2697 }
2698
2699 // Create two images of different types and try to copy between them
2700 VkImage srcImage;
2701 VkImage dstImage;
2702 VkDeviceMemory srcMem;
2703 VkDeviceMemory destMem;
2704 VkMemoryRequirements memReqs;
2705
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002706 VkImageCreateInfo image_create_info = {};
2707 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2708 image_create_info.pNext = NULL;
2709 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2710 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2711 image_create_info.extent.width = 32;
2712 image_create_info.extent.height = 32;
2713 image_create_info.extent.depth = 1;
2714 image_create_info.mipLevels = 1;
2715 image_create_info.arrayLayers = 4;
2716 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2717 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2718 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2719 image_create_info.flags = 0;
2720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002722 ASSERT_VK_SUCCESS(err);
2723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002724 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002725 ASSERT_VK_SUCCESS(err);
2726
2727 // Allocate memory
2728 VkMemoryAllocateInfo memAlloc = {};
2729 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2730 memAlloc.pNext = NULL;
2731 memAlloc.allocationSize = 0;
2732 memAlloc.memoryTypeIndex = 0;
2733
2734 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2735 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002736 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002737 ASSERT_TRUE(pass);
2738 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2739 ASSERT_VK_SUCCESS(err);
2740
2741 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2742 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002743 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002744 ASSERT_VK_SUCCESS(err);
2745 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2746 ASSERT_VK_SUCCESS(err);
2747
2748 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2749 ASSERT_VK_SUCCESS(err);
2750 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2751 ASSERT_VK_SUCCESS(err);
2752
2753 BeginCommandBuffer();
2754 VkImageCopy copyRegion;
2755 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2756 copyRegion.srcSubresource.mipLevel = 0;
2757 copyRegion.srcSubresource.baseArrayLayer = 0;
2758 copyRegion.srcSubresource.layerCount = 1;
2759 copyRegion.srcOffset.x = 0;
2760 copyRegion.srcOffset.y = 0;
2761 copyRegion.srcOffset.z = 0;
2762 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2763 copyRegion.dstSubresource.mipLevel = 0;
2764 copyRegion.dstSubresource.baseArrayLayer = 0;
2765 copyRegion.dstSubresource.layerCount = 1;
2766 copyRegion.dstOffset.x = 0;
2767 copyRegion.dstOffset.y = 0;
2768 copyRegion.dstOffset.z = 0;
2769 copyRegion.extent.width = 1;
2770 copyRegion.extent.height = 1;
2771 copyRegion.extent.depth = 1;
2772
2773 // Introduce failure by setting srcOffset to a bad granularity value
2774 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2776 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002777 m_errorMonitor->VerifyFound();
2778
2779 // Introduce failure by setting extent to a bad granularity value
2780 copyRegion.srcOffset.y = 0;
2781 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2783 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002784 m_errorMonitor->VerifyFound();
2785
2786 // Now do some buffer/image copies
2787 vk_testing::Buffer buffer;
2788 VkMemoryPropertyFlags reqs = 0;
2789 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2790 VkBufferImageCopy region = {};
2791 region.bufferOffset = 0;
2792 region.bufferRowLength = 3;
2793 region.bufferImageHeight = 128;
2794 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2795 region.imageSubresource.layerCount = 1;
2796 region.imageExtent.height = 16;
2797 region.imageExtent.width = 16;
2798 region.imageExtent.depth = 1;
2799 region.imageOffset.x = 0;
2800 region.imageOffset.y = 0;
2801 region.imageOffset.z = 0;
2802
2803 // Introduce failure by setting bufferRowLength to a bad granularity value
2804 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2806 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2807 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002808 m_errorMonitor->VerifyFound();
2809 region.bufferRowLength = 128;
2810
2811 // Introduce failure by setting bufferOffset to a bad granularity value
2812 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2814 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2815 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002816 m_errorMonitor->VerifyFound();
2817 region.bufferOffset = 0;
2818
2819 // Introduce failure by setting bufferImageHeight to a bad granularity value
2820 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2822 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2823 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002824 m_errorMonitor->VerifyFound();
2825 region.bufferImageHeight = 128;
2826
2827 // Introduce failure by setting imageExtent to a bad granularity value
2828 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2830 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2831 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002832 m_errorMonitor->VerifyFound();
2833 region.imageExtent.width = 16;
2834
2835 // Introduce failure by setting imageOffset to a bad granularity value
2836 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2838 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2839 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002840 m_errorMonitor->VerifyFound();
2841
2842 EndCommandBuffer();
2843
2844 vkDestroyImage(m_device->device(), srcImage, NULL);
2845 vkDestroyImage(m_device->device(), dstImage, NULL);
2846 vkFreeMemory(m_device->device(), srcMem, NULL);
2847 vkFreeMemory(m_device->device(), destMem, NULL);
2848}
2849
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002850TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002851 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2852 "attempt to submit them on a queue created in a different "
2853 "queue family.");
2854
Cody Northropc31a84f2016-08-22 10:41:47 -06002855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002856 // This test is meaningless unless we have multiple queue families
2857 auto queue_family_properties = m_device->phy().queue_properties();
2858 if (queue_family_properties.size() < 2) {
2859 return;
2860 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002862 // Get safe index of another queue family
2863 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2864 ASSERT_NO_FATAL_FAILURE(InitState());
2865 // Create a second queue using a different queue family
2866 VkQueue other_queue;
2867 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2868
2869 // Record an empty cmd buffer
2870 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2871 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2872 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2873 vkEndCommandBuffer(m_commandBuffer->handle());
2874
2875 // And submit on the wrong queue
2876 VkSubmitInfo submit_info = {};
2877 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2878 submit_info.commandBufferCount = 1;
2879 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002880 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002881
2882 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002883}
2884
Chris Forbes4c24a922016-11-16 08:59:10 +13002885TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2886 ASSERT_NO_FATAL_FAILURE(InitState());
2887
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002888 // There are no attachments, but refer to attachment 0.
2889 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002890 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002891 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2892 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002893 };
2894
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002895 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2896 nullptr,
2897 0,
2898 0,
2899 nullptr,
2900 1,
2901 subpasses,
2902 0,
2903 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002904 VkRenderPass rp;
2905
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002906 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002908 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002909 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2910 m_errorMonitor->VerifyFound();
2911}
2912
Chris Forbesa58c4522016-09-28 15:19:39 +13002913TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2914 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2915 ASSERT_NO_FATAL_FAILURE(InitState());
2916
2917 // A renderpass with two subpasses, both writing the same attachment.
2918 VkAttachmentDescription attach[] = {
2919 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2920 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2921 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2922 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2923 },
2924 };
2925 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2926 VkSubpassDescription subpasses[] = {
2927 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2928 1, &ref, nullptr, nullptr, 0, nullptr },
2929 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2930 1, &ref, nullptr, nullptr, 0, nullptr },
2931 };
2932 VkSubpassDependency dep = {
2933 0, 1,
2934 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2935 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2936 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2937 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2938 VK_DEPENDENCY_BY_REGION_BIT
2939 };
2940 VkRenderPassCreateInfo rpci = {
2941 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2942 0, 1, attach, 2, subpasses, 1, &dep
2943 };
2944 VkRenderPass rp;
2945 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2946 ASSERT_VK_SUCCESS(err);
2947
2948 VkImageObj image(m_device);
2949 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2950 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2951 VK_IMAGE_TILING_OPTIMAL, 0);
2952 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2953
2954 VkFramebufferCreateInfo fbci = {
2955 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2956 0, rp, 1, &imageView, 32, 32, 1
2957 };
2958 VkFramebuffer fb;
2959 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2960 ASSERT_VK_SUCCESS(err);
2961
2962 char const *vsSource =
2963 "#version 450\n"
2964 "void main() { gl_Position = vec4(1); }\n";
2965 char const *fsSource =
2966 "#version 450\n"
2967 "layout(location=0) out vec4 color;\n"
2968 "void main() { color = vec4(1); }\n";
2969
2970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2972 VkPipelineObj pipe(m_device);
2973 pipe.AddColorAttachment();
2974 pipe.AddShader(&vs);
2975 pipe.AddShader(&fs);
2976 VkViewport view_port = {};
2977 m_viewports.push_back(view_port);
2978 pipe.SetViewport(m_viewports);
2979 VkRect2D rect = {};
2980 m_scissors.push_back(rect);
2981 pipe.SetScissor(m_scissors);
2982
2983 VkPipelineLayoutCreateInfo plci = {
2984 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2985 0, 0, nullptr, 0, nullptr
2986 };
2987 VkPipelineLayout pl;
2988 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2989 ASSERT_VK_SUCCESS(err);
2990 pipe.CreateVKPipeline(pl, rp);
2991
2992 BeginCommandBuffer();
2993
2994 VkRenderPassBeginInfo rpbi = {
2995 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2996 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2997 };
2998
2999 // subtest 1: bind in the wrong subpass
3000 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3001 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3003 "built for subpass 0 but used in subpass 1");
3004 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3005 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3006 m_errorMonitor->VerifyFound();
3007
3008 vkCmdEndRenderPass(m_commandBuffer->handle());
3009
3010 // subtest 2: bind in correct subpass, then transition to next subpass
3011 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3012 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3013 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3015 "built for subpass 0 but used in subpass 1");
3016 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3017 m_errorMonitor->VerifyFound();
3018
3019 vkCmdEndRenderPass(m_commandBuffer->handle());
3020
3021 EndCommandBuffer();
3022
3023 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3024 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3025 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3026}
3027
Tony Barbour4e919972016-08-09 13:27:40 -06003028TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3029 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3030 "with extent outside of framebuffer");
3031 ASSERT_NO_FATAL_FAILURE(InitState());
3032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3035 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003036
3037 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3038 m_renderPassBeginInfo.renderArea.extent.width = 257;
3039 m_renderPassBeginInfo.renderArea.extent.height = 257;
3040 BeginCommandBuffer();
3041 m_errorMonitor->VerifyFound();
3042}
3043
3044TEST_F(VkLayerTest, DisabledIndependentBlend) {
3045 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3046 "blend and then specifying different blend states for two "
3047 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003048 VkPhysicalDeviceFeatures features = {};
3049 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003050 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3053 "Invalid Pipeline CreateInfo: If independent blend feature not "
3054 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003055
Cody Northropc31a84f2016-08-22 10:41:47 -06003056 VkDescriptorSetObj descriptorSet(m_device);
3057 descriptorSet.AppendDummy();
3058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003059
Cody Northropc31a84f2016-08-22 10:41:47 -06003060 VkPipelineObj pipeline(m_device);
3061 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003062 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003063 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003064
Cody Northropc31a84f2016-08-22 10:41:47 -06003065 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3066 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3067 att_state1.blendEnable = VK_TRUE;
3068 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3069 att_state2.blendEnable = VK_FALSE;
3070 pipeline.AddColorAttachment(0, &att_state1);
3071 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003072 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003073 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003074}
3075
3076TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3077 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3078 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003079 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3082 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003083
3084 // Create a renderPass with a single color attachment
3085 VkAttachmentReference attach = {};
3086 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3087 VkSubpassDescription subpass = {};
3088 VkRenderPassCreateInfo rpci = {};
3089 rpci.subpassCount = 1;
3090 rpci.pSubpasses = &subpass;
3091 rpci.attachmentCount = 1;
3092 VkAttachmentDescription attach_desc = {};
3093 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3094 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3095 rpci.pAttachments = &attach_desc;
3096 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3097 VkRenderPass rp;
3098 subpass.pDepthStencilAttachment = &attach;
3099 subpass.pColorAttachments = NULL;
3100 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3101 m_errorMonitor->VerifyFound();
3102}
3103
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003104TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3105 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3106 "attachment reference of VK_ATTACHMENT_UNUSED");
3107
3108 ASSERT_NO_FATAL_FAILURE(InitState());
3109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003112
3113 VkAttachmentReference color_attach = {};
3114 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3115 color_attach.attachment = 0;
3116 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3117 VkSubpassDescription subpass = {};
3118 subpass.colorAttachmentCount = 1;
3119 subpass.pColorAttachments = &color_attach;
3120 subpass.preserveAttachmentCount = 1;
3121 subpass.pPreserveAttachments = &preserve_attachment;
3122
3123 VkRenderPassCreateInfo rpci = {};
3124 rpci.subpassCount = 1;
3125 rpci.pSubpasses = &subpass;
3126 rpci.attachmentCount = 1;
3127 VkAttachmentDescription attach_desc = {};
3128 attach_desc.format = VK_FORMAT_UNDEFINED;
3129 rpci.pAttachments = &attach_desc;
3130 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3131 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003132 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003133
3134 m_errorMonitor->VerifyFound();
3135
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003136 if (result == VK_SUCCESS) {
3137 vkDestroyRenderPass(m_device->device(), rp, NULL);
3138 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003139}
3140
Chris Forbesc5389742016-06-29 11:49:23 +12003141TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003142 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3143 "when the source of a subpass multisample resolve "
3144 "does not have multiple samples.");
3145
Chris Forbesc5389742016-06-29 11:49:23 +12003146 ASSERT_NO_FATAL_FAILURE(InitState());
3147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3149 "Subpass 0 requests multisample resolve from attachment 0 which has "
3150 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003151
3152 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003153 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3154 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3155 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3156 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3157 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3158 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003159 };
3160
3161 VkAttachmentReference color = {
3162 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3163 };
3164
3165 VkAttachmentReference resolve = {
3166 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3167 };
3168
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003170
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003172
3173 VkRenderPass rp;
3174 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3175
3176 m_errorMonitor->VerifyFound();
3177
3178 if (err == VK_SUCCESS)
3179 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3180}
3181
3182TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003183 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3184 "when a subpass multisample resolve operation is "
3185 "requested, and the destination of that resolve has "
3186 "multiple samples.");
3187
Chris Forbesc5389742016-06-29 11:49:23 +12003188 ASSERT_NO_FATAL_FAILURE(InitState());
3189
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3191 "Subpass 0 requests multisample resolve into attachment 1, which "
3192 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003193
3194 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003195 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3196 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3197 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3198 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3199 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3200 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003201 };
3202
3203 VkAttachmentReference color = {
3204 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3205 };
3206
3207 VkAttachmentReference resolve = {
3208 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3209 };
3210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003212
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003213 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003214
3215 VkRenderPass rp;
3216 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3217
3218 m_errorMonitor->VerifyFound();
3219
3220 if (err == VK_SUCCESS)
3221 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3222}
3223
Chris Forbes3f128ef2016-06-29 14:58:53 +12003224TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003225 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3226 "when the color and depth attachments used by a subpass "
3227 "have inconsistent sample counts");
3228
Chris Forbes3f128ef2016-06-29 14:58:53 +12003229 ASSERT_NO_FATAL_FAILURE(InitState());
3230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3232 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003233
3234 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003235 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3236 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3237 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3238 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3239 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3240 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003241 };
3242
3243 VkAttachmentReference color[] = {
3244 {
3245 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3246 },
3247 {
3248 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3249 },
3250 };
3251
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003252 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003253
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003254 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003255
3256 VkRenderPass rp;
3257 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3258
3259 m_errorMonitor->VerifyFound();
3260
3261 if (err == VK_SUCCESS)
3262 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3263}
3264
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003265TEST_F(VkLayerTest, FramebufferCreateErrors) {
3266 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003267 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003268 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003269 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3270 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3271 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3272 " 6. Framebuffer attachment where dimensions don't match\n"
3273 " 7. Framebuffer attachment w/o identity swizzle\n"
3274 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003275
3276 ASSERT_NO_FATAL_FAILURE(InitState());
3277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3280 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3281 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003282
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003283 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003284 VkAttachmentReference attach = {};
3285 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3286 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003287 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003288 VkRenderPassCreateInfo rpci = {};
3289 rpci.subpassCount = 1;
3290 rpci.pSubpasses = &subpass;
3291 rpci.attachmentCount = 1;
3292 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003293 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003294 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003295 rpci.pAttachments = &attach_desc;
3296 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3297 VkRenderPass rp;
3298 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3299 ASSERT_VK_SUCCESS(err);
3300
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003301 VkImageView ivs[2];
3302 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3303 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003304 VkFramebufferCreateInfo fb_info = {};
3305 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3306 fb_info.pNext = NULL;
3307 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003308 // Set mis-matching attachmentCount
3309 fb_info.attachmentCount = 2;
3310 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003311 fb_info.width = 100;
3312 fb_info.height = 100;
3313 fb_info.layers = 1;
3314
3315 VkFramebuffer fb;
3316 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3317
3318 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003319 if (err == VK_SUCCESS) {
3320 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3321 }
3322 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003323
3324 // Create a renderPass with a depth-stencil attachment created with
3325 // IMAGE_USAGE_COLOR_ATTACHMENT
3326 // Add our color attachment to pDepthStencilAttachment
3327 subpass.pDepthStencilAttachment = &attach;
3328 subpass.pColorAttachments = NULL;
3329 VkRenderPass rp_ds;
3330 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3331 ASSERT_VK_SUCCESS(err);
3332 // Set correct attachment count, but attachment has COLOR usage bit set
3333 fb_info.attachmentCount = 1;
3334 fb_info.renderPass = rp_ds;
3335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003337 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3338
3339 m_errorMonitor->VerifyFound();
3340 if (err == VK_SUCCESS) {
3341 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3342 }
3343 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003344
3345 // Create new renderpass with alternate attachment format from fb
3346 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3347 subpass.pDepthStencilAttachment = NULL;
3348 subpass.pColorAttachments = &attach;
3349 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3350 ASSERT_VK_SUCCESS(err);
3351
3352 // Cause error due to mis-matched formats between rp & fb
3353 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3354 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3356 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003357 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3358
3359 m_errorMonitor->VerifyFound();
3360 if (err == VK_SUCCESS) {
3361 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3362 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003363 vkDestroyRenderPass(m_device->device(), rp, NULL);
3364
3365 // Create new renderpass with alternate sample count from fb
3366 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3367 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3368 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3369 ASSERT_VK_SUCCESS(err);
3370
3371 // Cause error due to mis-matched sample count between rp & fb
3372 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3374 "that do not match the "
3375 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003376 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3377
3378 m_errorMonitor->VerifyFound();
3379 if (err == VK_SUCCESS) {
3380 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3381 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003382
3383 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003384
3385 // Create a custom imageView with non-1 mip levels
3386 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 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 -06003388 ASSERT_TRUE(image.initialized());
3389
3390 VkImageView view;
3391 VkImageViewCreateInfo ivci = {};
3392 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3393 ivci.image = image.handle();
3394 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3395 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3396 ivci.subresourceRange.layerCount = 1;
3397 ivci.subresourceRange.baseMipLevel = 0;
3398 // Set level count 2 (only 1 is allowed for FB attachment)
3399 ivci.subresourceRange.levelCount = 2;
3400 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3401 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3402 ASSERT_VK_SUCCESS(err);
3403 // Re-create renderpass to have matching sample count
3404 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3405 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3406 ASSERT_VK_SUCCESS(err);
3407
3408 fb_info.renderPass = rp;
3409 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003411 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3412
3413 m_errorMonitor->VerifyFound();
3414 if (err == VK_SUCCESS) {
3415 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3416 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003417 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003418 // Update view to original color buffer and grow FB dimensions too big
3419 fb_info.pAttachments = ivs;
3420 fb_info.height = 1024;
3421 fb_info.width = 1024;
3422 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3424 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003425 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3426
3427 m_errorMonitor->VerifyFound();
3428 if (err == VK_SUCCESS) {
3429 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3430 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003431 // Create view attachment with non-identity swizzle
3432 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3433 ivci.image = image.handle();
3434 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3435 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3436 ivci.subresourceRange.layerCount = 1;
3437 ivci.subresourceRange.baseMipLevel = 0;
3438 ivci.subresourceRange.levelCount = 1;
3439 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3440 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3441 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3442 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3443 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3444 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3445 ASSERT_VK_SUCCESS(err);
3446
3447 fb_info.pAttachments = &view;
3448 fb_info.height = 100;
3449 fb_info.width = 100;
3450 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3452 "framebuffer attachments must have "
3453 "been created with the identity "
3454 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003455 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3456
3457 m_errorMonitor->VerifyFound();
3458 if (err == VK_SUCCESS) {
3459 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3460 }
3461 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003462 // Request fb that exceeds max dimensions
3463 // reset attachment to color attachment
3464 fb_info.pAttachments = ivs;
3465 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3466 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3467 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3469 "dimensions exceed physical device "
3470 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003471 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3472
3473 m_errorMonitor->VerifyFound();
3474 if (err == VK_SUCCESS) {
3475 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3476 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003477
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003478 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003479}
3480
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003481TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003482 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3483 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003484
Cody Northropc31a84f2016-08-22 10:41:47 -06003485 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003486 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3488 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003489 m_errorMonitor->VerifyFound();
3490}
3491
3492TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003493 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3494 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003495
Cody Northropc31a84f2016-08-22 10:41:47 -06003496 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003497 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3499 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003500 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003501}
3502
3503TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003504 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3505 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003506
Cody Northropc31a84f2016-08-22 10:41:47 -06003507 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003508 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003509 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 -06003510 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003511 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003512}
3513
3514TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003515 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3516 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003517
Cody Northropc31a84f2016-08-22 10:41:47 -06003518 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003519 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003520 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 -06003521 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003522 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003523}
3524
Cortd713fe82016-07-27 09:51:27 -07003525TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003526 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3527 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003528
3529 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003530 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3532 "Dynamic blend constants state not set for this command buffer");
3533 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003534 m_errorMonitor->VerifyFound();
3535}
3536
3537TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003538 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3539 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003540
3541 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003542 if (!m_device->phy().features().depthBounds) {
3543 printf("Device does not support depthBounds test; skipped.\n");
3544 return;
3545 }
3546 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3548 "Dynamic depth bounds state not set for this command buffer");
3549 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003550 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003551}
3552
3553TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003554 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3555 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003556
3557 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003558 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3560 "Dynamic stencil read mask state not set for this command buffer");
3561 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003562 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003563}
3564
3565TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003566 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3567 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003568
3569 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003570 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3572 "Dynamic stencil write mask state not set for this command buffer");
3573 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003574 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003575}
3576
3577TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003578 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3579 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003580
3581 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003582 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3584 "Dynamic stencil reference state not set for this command buffer");
3585 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003586 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003587}
3588
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003589TEST_F(VkLayerTest, IndexBufferNotBound) {
3590 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003591
3592 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3594 "Index buffer object not bound to this command buffer when Indexed ");
3595 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003596 m_errorMonitor->VerifyFound();
3597}
3598
Karl Schultz6addd812016-02-02 17:17:23 -07003599TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3601 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3602 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003603
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003604 ASSERT_NO_FATAL_FAILURE(InitState());
3605 ASSERT_NO_FATAL_FAILURE(InitViewport());
3606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3607
Karl Schultz6addd812016-02-02 17:17:23 -07003608 // We luck out b/c by default the framework creates CB w/ the
3609 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003610 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003612 EndCommandBuffer();
3613
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003614 // Bypass framework since it does the waits automatically
3615 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003616 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003617 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3618 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003619 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003620 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003621 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003622 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003623 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003624 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003625 submit_info.pSignalSemaphores = NULL;
3626
Chris Forbes40028e22016-06-13 09:59:34 +12003627 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003628 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003629 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003630
Karl Schultz6addd812016-02-02 17:17:23 -07003631 // Cause validation error by re-submitting cmd buffer that should only be
3632 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003633 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003634 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003635
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003636 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003637}
3638
Karl Schultz6addd812016-02-02 17:17:23 -07003639TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003640 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003641 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3644 "type "
3645 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003646
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003647 ASSERT_NO_FATAL_FAILURE(InitState());
3648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003649
Karl Schultz6addd812016-02-02 17:17:23 -07003650 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3651 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003652 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003653 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3654 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003655
3656 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003657 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3658 ds_pool_ci.pNext = NULL;
3659 ds_pool_ci.flags = 0;
3660 ds_pool_ci.maxSets = 1;
3661 ds_pool_ci.poolSizeCount = 1;
3662 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003663
3664 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003665 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003666 ASSERT_VK_SUCCESS(err);
3667
3668 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003669 dsl_binding.binding = 0;
3670 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3671 dsl_binding.descriptorCount = 1;
3672 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3673 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003674
3675 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003676 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3677 ds_layout_ci.pNext = NULL;
3678 ds_layout_ci.bindingCount = 1;
3679 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003680
3681 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003682 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003683 ASSERT_VK_SUCCESS(err);
3684
3685 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003686 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003687 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003688 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003689 alloc_info.descriptorPool = ds_pool;
3690 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003692
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003693 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003694
Chia-I Wuf7458c52015-10-26 21:10:41 +08003695 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3696 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003697}
3698
Karl Schultz6addd812016-02-02 17:17:23 -07003699TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3700 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3703 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3704 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003705
Tobin Ehlise735c692015-10-08 13:13:50 -06003706 ASSERT_NO_FATAL_FAILURE(InitState());
3707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003708
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003709 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003710 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3711 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003712
3713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3715 ds_pool_ci.pNext = NULL;
3716 ds_pool_ci.maxSets = 1;
3717 ds_pool_ci.poolSizeCount = 1;
3718 ds_pool_ci.flags = 0;
3719 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3720 // app can only call vkResetDescriptorPool on this pool.;
3721 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003722
3723 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003725 ASSERT_VK_SUCCESS(err);
3726
3727 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003728 dsl_binding.binding = 0;
3729 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3730 dsl_binding.descriptorCount = 1;
3731 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3732 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003733
3734 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003735 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3736 ds_layout_ci.pNext = NULL;
3737 ds_layout_ci.bindingCount = 1;
3738 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003739
3740 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003741 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003742 ASSERT_VK_SUCCESS(err);
3743
3744 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003745 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003747 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003748 alloc_info.descriptorPool = ds_pool;
3749 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003750 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003751 ASSERT_VK_SUCCESS(err);
3752
3753 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003754 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003755
Chia-I Wuf7458c52015-10-26 21:10:41 +08003756 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3757 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003758}
3759
Karl Schultz6addd812016-02-02 17:17:23 -07003760TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003761 // Attempt to clear Descriptor Pool with bad object.
3762 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003763
3764 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003766 uint64_t fake_pool_handle = 0xbaad6001;
3767 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3768 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003769 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003770}
3771
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003772TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003773 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3774 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003775 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003776 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003777
3778 uint64_t fake_set_handle = 0xbaad6001;
3779 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003780 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003782
3783 ASSERT_NO_FATAL_FAILURE(InitState());
3784
3785 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3786 layout_bindings[0].binding = 0;
3787 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3788 layout_bindings[0].descriptorCount = 1;
3789 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3790 layout_bindings[0].pImmutableSamplers = NULL;
3791
3792 VkDescriptorSetLayout descriptor_set_layout;
3793 VkDescriptorSetLayoutCreateInfo dslci = {};
3794 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3795 dslci.pNext = NULL;
3796 dslci.bindingCount = 1;
3797 dslci.pBindings = layout_bindings;
3798 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003799 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003800
3801 VkPipelineLayout pipeline_layout;
3802 VkPipelineLayoutCreateInfo plci = {};
3803 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3804 plci.pNext = NULL;
3805 plci.setLayoutCount = 1;
3806 plci.pSetLayouts = &descriptor_set_layout;
3807 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003808 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003809
3810 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003811 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3812 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003813 m_errorMonitor->VerifyFound();
3814 EndCommandBuffer();
3815 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3816 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003817}
3818
Karl Schultz6addd812016-02-02 17:17:23 -07003819TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003820 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3821 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003822 uint64_t fake_layout_handle = 0xbaad6001;
3823 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003825 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003826 VkPipelineLayout pipeline_layout;
3827 VkPipelineLayoutCreateInfo plci = {};
3828 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3829 plci.pNext = NULL;
3830 plci.setLayoutCount = 1;
3831 plci.pSetLayouts = &bad_layout;
3832 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3833
3834 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003835}
3836
Mark Muellerd4914412016-06-13 17:52:06 -06003837TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3838 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3839 "1) A uniform buffer update must have a valid buffer index."
3840 "2) When using an array of descriptors in a single WriteDescriptor,"
3841 " the descriptor types and stageflags must all be the same."
3842 "3) Immutable Sampler state must match across descriptors");
3843
3844 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003845 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3846 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3847 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3848 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3849 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003850
Mark Muellerd4914412016-06-13 17:52:06 -06003851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3852
3853 ASSERT_NO_FATAL_FAILURE(InitState());
3854 VkDescriptorPoolSize ds_type_count[4] = {};
3855 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3856 ds_type_count[0].descriptorCount = 1;
3857 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3858 ds_type_count[1].descriptorCount = 1;
3859 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3860 ds_type_count[2].descriptorCount = 1;
3861 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3862 ds_type_count[3].descriptorCount = 1;
3863
3864 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3865 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3866 ds_pool_ci.maxSets = 1;
3867 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3868 ds_pool_ci.pPoolSizes = ds_type_count;
3869
3870 VkDescriptorPool ds_pool;
3871 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3872 ASSERT_VK_SUCCESS(err);
3873
Mark Muellerb9896722016-06-16 09:54:29 -06003874 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003875 layout_binding[0].binding = 0;
3876 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3877 layout_binding[0].descriptorCount = 1;
3878 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3879 layout_binding[0].pImmutableSamplers = NULL;
3880
3881 layout_binding[1].binding = 1;
3882 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3883 layout_binding[1].descriptorCount = 1;
3884 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3885 layout_binding[1].pImmutableSamplers = NULL;
3886
3887 VkSamplerCreateInfo sampler_ci = {};
3888 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3889 sampler_ci.pNext = NULL;
3890 sampler_ci.magFilter = VK_FILTER_NEAREST;
3891 sampler_ci.minFilter = VK_FILTER_NEAREST;
3892 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3893 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3894 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3895 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3896 sampler_ci.mipLodBias = 1.0;
3897 sampler_ci.anisotropyEnable = VK_FALSE;
3898 sampler_ci.maxAnisotropy = 1;
3899 sampler_ci.compareEnable = VK_FALSE;
3900 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3901 sampler_ci.minLod = 1.0;
3902 sampler_ci.maxLod = 1.0;
3903 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3904 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3905 VkSampler sampler;
3906
3907 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3908 ASSERT_VK_SUCCESS(err);
3909
3910 layout_binding[2].binding = 2;
3911 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3912 layout_binding[2].descriptorCount = 1;
3913 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3914 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3915
Mark Muellerd4914412016-06-13 17:52:06 -06003916 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3917 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3918 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3919 ds_layout_ci.pBindings = layout_binding;
3920 VkDescriptorSetLayout ds_layout;
3921 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3922 ASSERT_VK_SUCCESS(err);
3923
3924 VkDescriptorSetAllocateInfo alloc_info = {};
3925 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3926 alloc_info.descriptorSetCount = 1;
3927 alloc_info.descriptorPool = ds_pool;
3928 alloc_info.pSetLayouts = &ds_layout;
3929 VkDescriptorSet descriptorSet;
3930 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3931 ASSERT_VK_SUCCESS(err);
3932
3933 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3934 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3935 pipeline_layout_ci.pNext = NULL;
3936 pipeline_layout_ci.setLayoutCount = 1;
3937 pipeline_layout_ci.pSetLayouts = &ds_layout;
3938
3939 VkPipelineLayout pipeline_layout;
3940 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3941 ASSERT_VK_SUCCESS(err);
3942
Mark Mueller5c838ce2016-06-16 09:54:29 -06003943 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003944 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3945 descriptor_write.dstSet = descriptorSet;
3946 descriptor_write.dstBinding = 0;
3947 descriptor_write.descriptorCount = 1;
3948 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3949
Mark Mueller5c838ce2016-06-16 09:54:29 -06003950 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003951 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3952 m_errorMonitor->VerifyFound();
3953
3954 // Create a buffer to update the descriptor with
3955 uint32_t qfi = 0;
3956 VkBufferCreateInfo buffCI = {};
3957 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3958 buffCI.size = 1024;
3959 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3960 buffCI.queueFamilyIndexCount = 1;
3961 buffCI.pQueueFamilyIndices = &qfi;
3962
3963 VkBuffer dyub;
3964 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3965 ASSERT_VK_SUCCESS(err);
3966 VkDescriptorBufferInfo buffInfo = {};
3967 buffInfo.buffer = dyub;
3968 buffInfo.offset = 0;
3969 buffInfo.range = 1024;
3970
3971 descriptor_write.pBufferInfo = &buffInfo;
3972 descriptor_write.descriptorCount = 2;
3973
Mark Mueller5c838ce2016-06-16 09:54:29 -06003974 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3976 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3977 m_errorMonitor->VerifyFound();
3978
Mark Mueller5c838ce2016-06-16 09:54:29 -06003979 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3980 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003981 descriptor_write.dstBinding = 1;
3982 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003983
Mark Mueller5c838ce2016-06-16 09:54:29 -06003984 // Make pImageInfo index non-null to avoid complaints of it missing
3985 VkDescriptorImageInfo imageInfo = {};
3986 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3987 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3989 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3990 m_errorMonitor->VerifyFound();
3991
Mark Muellerd4914412016-06-13 17:52:06 -06003992 vkDestroyBuffer(m_device->device(), dyub, NULL);
3993 vkDestroySampler(m_device->device(), sampler, NULL);
3994 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3995 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3996 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3997}
3998
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003999TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4000 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4001 "due to a buffer dependency being destroyed.");
4002 ASSERT_NO_FATAL_FAILURE(InitState());
4003
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004004 VkBuffer buffer;
4005 VkDeviceMemory mem;
4006 VkMemoryRequirements mem_reqs;
4007
4008 VkBufferCreateInfo buf_info = {};
4009 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004010 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004011 buf_info.size = 256;
4012 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4013 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4014 ASSERT_VK_SUCCESS(err);
4015
4016 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4017
4018 VkMemoryAllocateInfo alloc_info = {};
4019 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4020 alloc_info.allocationSize = 256;
4021 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004022 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 -06004023 if (!pass) {
4024 vkDestroyBuffer(m_device->device(), buffer, NULL);
4025 return;
4026 }
4027 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4028 ASSERT_VK_SUCCESS(err);
4029
4030 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4031 ASSERT_VK_SUCCESS(err);
4032
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004033 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004034 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004035 m_commandBuffer->EndCommandBuffer();
4036
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004038 // Destroy buffer dependency prior to submit to cause ERROR
4039 vkDestroyBuffer(m_device->device(), buffer, NULL);
4040
4041 VkSubmitInfo submit_info = {};
4042 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4043 submit_info.commandBufferCount = 1;
4044 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4045 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4046
4047 m_errorMonitor->VerifyFound();
4048 vkFreeMemory(m_device->handle(), mem, NULL);
4049}
4050
Tobin Ehlisea413442016-09-28 10:23:59 -06004051TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4052 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4053
4054 ASSERT_NO_FATAL_FAILURE(InitState());
4055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4056
4057 VkDescriptorPoolSize ds_type_count;
4058 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4059 ds_type_count.descriptorCount = 1;
4060
4061 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4062 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4063 ds_pool_ci.maxSets = 1;
4064 ds_pool_ci.poolSizeCount = 1;
4065 ds_pool_ci.pPoolSizes = &ds_type_count;
4066
4067 VkDescriptorPool ds_pool;
4068 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4069 ASSERT_VK_SUCCESS(err);
4070
4071 VkDescriptorSetLayoutBinding layout_binding;
4072 layout_binding.binding = 0;
4073 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4074 layout_binding.descriptorCount = 1;
4075 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4076 layout_binding.pImmutableSamplers = NULL;
4077
4078 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4079 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4080 ds_layout_ci.bindingCount = 1;
4081 ds_layout_ci.pBindings = &layout_binding;
4082 VkDescriptorSetLayout ds_layout;
4083 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4084 ASSERT_VK_SUCCESS(err);
4085
4086 VkDescriptorSetAllocateInfo alloc_info = {};
4087 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4088 alloc_info.descriptorSetCount = 1;
4089 alloc_info.descriptorPool = ds_pool;
4090 alloc_info.pSetLayouts = &ds_layout;
4091 VkDescriptorSet descriptor_set;
4092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4093 ASSERT_VK_SUCCESS(err);
4094
4095 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4096 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4097 pipeline_layout_ci.pNext = NULL;
4098 pipeline_layout_ci.setLayoutCount = 1;
4099 pipeline_layout_ci.pSetLayouts = &ds_layout;
4100
4101 VkPipelineLayout pipeline_layout;
4102 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4103 ASSERT_VK_SUCCESS(err);
4104
4105 VkBuffer buffer;
4106 uint32_t queue_family_index = 0;
4107 VkBufferCreateInfo buffer_create_info = {};
4108 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4109 buffer_create_info.size = 1024;
4110 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4111 buffer_create_info.queueFamilyIndexCount = 1;
4112 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4113
4114 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4115 ASSERT_VK_SUCCESS(err);
4116
4117 VkMemoryRequirements memory_reqs;
4118 VkDeviceMemory buffer_memory;
4119
4120 VkMemoryAllocateInfo memory_info = {};
4121 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4122 memory_info.allocationSize = 0;
4123 memory_info.memoryTypeIndex = 0;
4124
4125 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4126 memory_info.allocationSize = memory_reqs.size;
4127 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4128 ASSERT_TRUE(pass);
4129
4130 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4131 ASSERT_VK_SUCCESS(err);
4132 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4133 ASSERT_VK_SUCCESS(err);
4134
4135 VkBufferView view;
4136 VkBufferViewCreateInfo bvci = {};
4137 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4138 bvci.buffer = buffer;
4139 bvci.format = VK_FORMAT_R8_UNORM;
4140 bvci.range = VK_WHOLE_SIZE;
4141
4142 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4143 ASSERT_VK_SUCCESS(err);
4144
4145 VkWriteDescriptorSet descriptor_write = {};
4146 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4147 descriptor_write.dstSet = descriptor_set;
4148 descriptor_write.dstBinding = 0;
4149 descriptor_write.descriptorCount = 1;
4150 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4151 descriptor_write.pTexelBufferView = &view;
4152
4153 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4154
4155 char const *vsSource = "#version 450\n"
4156 "\n"
4157 "out gl_PerVertex { \n"
4158 " vec4 gl_Position;\n"
4159 "};\n"
4160 "void main(){\n"
4161 " gl_Position = vec4(1);\n"
4162 "}\n";
4163 char const *fsSource = "#version 450\n"
4164 "\n"
4165 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4166 "layout(location=0) out vec4 x;\n"
4167 "void main(){\n"
4168 " x = imageLoad(s, 0);\n"
4169 "}\n";
4170 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4171 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4172 VkPipelineObj pipe(m_device);
4173 pipe.AddShader(&vs);
4174 pipe.AddShader(&fs);
4175 pipe.AddColorAttachment();
4176 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4177
4178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4180
4181 BeginCommandBuffer();
4182 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4183 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4184 VkRect2D scissor = {{0, 0}, {16, 16}};
4185 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4186 // Bind pipeline to cmd buffer
4187 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4188 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4189 &descriptor_set, 0, nullptr);
4190 Draw(1, 0, 0, 0);
4191 EndCommandBuffer();
4192
4193 // Delete BufferView in order to invalidate cmd buffer
4194 vkDestroyBufferView(m_device->device(), view, NULL);
4195 // Now attempt submit of cmd buffer
4196 VkSubmitInfo submit_info = {};
4197 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4198 submit_info.commandBufferCount = 1;
4199 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4200 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4201 m_errorMonitor->VerifyFound();
4202
4203 // Clean-up
4204 vkDestroyBuffer(m_device->device(), buffer, NULL);
4205 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4206 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4207 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4208 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4209}
4210
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004211TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4212 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4213 "due to an image dependency being destroyed.");
4214 ASSERT_NO_FATAL_FAILURE(InitState());
4215
4216 VkImage image;
4217 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4218 VkImageCreateInfo image_create_info = {};
4219 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4220 image_create_info.pNext = NULL;
4221 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4222 image_create_info.format = tex_format;
4223 image_create_info.extent.width = 32;
4224 image_create_info.extent.height = 32;
4225 image_create_info.extent.depth = 1;
4226 image_create_info.mipLevels = 1;
4227 image_create_info.arrayLayers = 1;
4228 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4229 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004230 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004231 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004232 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004233 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004234 // Have to bind memory to image before recording cmd in cmd buffer using it
4235 VkMemoryRequirements mem_reqs;
4236 VkDeviceMemory image_mem;
4237 bool pass;
4238 VkMemoryAllocateInfo mem_alloc = {};
4239 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4240 mem_alloc.pNext = NULL;
4241 mem_alloc.memoryTypeIndex = 0;
4242 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4243 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004244 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004245 ASSERT_TRUE(pass);
4246 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4247 ASSERT_VK_SUCCESS(err);
4248 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4249 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004250
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004251 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004252 VkClearColorValue ccv;
4253 ccv.float32[0] = 1.0f;
4254 ccv.float32[1] = 1.0f;
4255 ccv.float32[2] = 1.0f;
4256 ccv.float32[3] = 1.0f;
4257 VkImageSubresourceRange isr = {};
4258 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004259 isr.baseArrayLayer = 0;
4260 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004261 isr.layerCount = 1;
4262 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004263 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004264 m_commandBuffer->EndCommandBuffer();
4265
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004267 // Destroy image dependency prior to submit to cause ERROR
4268 vkDestroyImage(m_device->device(), image, NULL);
4269
4270 VkSubmitInfo submit_info = {};
4271 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4272 submit_info.commandBufferCount = 1;
4273 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4274 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4275
4276 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004277 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004278}
4279
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004280TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4281 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4282 "due to a framebuffer image dependency being destroyed.");
4283 VkFormatProperties format_properties;
4284 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4286 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004287 return;
4288 }
4289
4290 ASSERT_NO_FATAL_FAILURE(InitState());
4291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4292
4293 VkImageCreateInfo image_ci = {};
4294 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4295 image_ci.pNext = NULL;
4296 image_ci.imageType = VK_IMAGE_TYPE_2D;
4297 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4298 image_ci.extent.width = 32;
4299 image_ci.extent.height = 32;
4300 image_ci.extent.depth = 1;
4301 image_ci.mipLevels = 1;
4302 image_ci.arrayLayers = 1;
4303 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4304 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004305 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004306 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4307 image_ci.flags = 0;
4308 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004309 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004310
4311 VkMemoryRequirements memory_reqs;
4312 VkDeviceMemory image_memory;
4313 bool pass;
4314 VkMemoryAllocateInfo memory_info = {};
4315 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4316 memory_info.pNext = NULL;
4317 memory_info.allocationSize = 0;
4318 memory_info.memoryTypeIndex = 0;
4319 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4320 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004321 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004322 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004323 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004324 ASSERT_VK_SUCCESS(err);
4325 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4326 ASSERT_VK_SUCCESS(err);
4327
4328 VkImageViewCreateInfo ivci = {
4329 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4330 nullptr,
4331 0,
4332 image,
4333 VK_IMAGE_VIEW_TYPE_2D,
4334 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004335 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004336 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4337 };
4338 VkImageView view;
4339 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4340 ASSERT_VK_SUCCESS(err);
4341
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004342 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004343 VkFramebuffer fb;
4344 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4345 ASSERT_VK_SUCCESS(err);
4346
4347 // Just use default renderpass with our framebuffer
4348 m_renderPassBeginInfo.framebuffer = fb;
4349 // Create Null cmd buffer for submit
4350 BeginCommandBuffer();
4351 EndCommandBuffer();
4352 // Destroy image attached to framebuffer to invalidate cmd buffer
4353 vkDestroyImage(m_device->device(), image, NULL);
4354 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004356 QueueCommandBuffer(false);
4357 m_errorMonitor->VerifyFound();
4358
4359 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4360 vkDestroyImageView(m_device->device(), view, nullptr);
4361 vkFreeMemory(m_device->device(), image_memory, nullptr);
4362}
4363
Tobin Ehlisb329f992016-10-12 13:20:29 -06004364TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4365 TEST_DESCRIPTION("Delete in-use framebuffer.");
4366 VkFormatProperties format_properties;
4367 VkResult err = VK_SUCCESS;
4368 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4369
4370 ASSERT_NO_FATAL_FAILURE(InitState());
4371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4372
4373 VkImageObj image(m_device);
4374 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4375 ASSERT_TRUE(image.initialized());
4376 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4377
4378 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4379 VkFramebuffer fb;
4380 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4381 ASSERT_VK_SUCCESS(err);
4382
4383 // Just use default renderpass with our framebuffer
4384 m_renderPassBeginInfo.framebuffer = fb;
4385 // Create Null cmd buffer for submit
4386 BeginCommandBuffer();
4387 EndCommandBuffer();
4388 // Submit cmd buffer to put it in-flight
4389 VkSubmitInfo submit_info = {};
4390 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4391 submit_info.commandBufferCount = 1;
4392 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4393 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4394 // Destroy framebuffer while in-flight
4395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4396 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4397 m_errorMonitor->VerifyFound();
4398 // Wait for queue to complete so we can safely destroy everything
4399 vkQueueWaitIdle(m_device->m_queue);
4400 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4401}
4402
Tobin Ehlis88becd72016-09-21 14:33:41 -06004403TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4404 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4405 VkFormatProperties format_properties;
4406 VkResult err = VK_SUCCESS;
4407 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004408
4409 ASSERT_NO_FATAL_FAILURE(InitState());
4410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4411
4412 VkImageCreateInfo image_ci = {};
4413 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4414 image_ci.pNext = NULL;
4415 image_ci.imageType = VK_IMAGE_TYPE_2D;
4416 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4417 image_ci.extent.width = 256;
4418 image_ci.extent.height = 256;
4419 image_ci.extent.depth = 1;
4420 image_ci.mipLevels = 1;
4421 image_ci.arrayLayers = 1;
4422 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4423 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004424 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004425 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4426 image_ci.flags = 0;
4427 VkImage image;
4428 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4429
4430 VkMemoryRequirements memory_reqs;
4431 VkDeviceMemory image_memory;
4432 bool pass;
4433 VkMemoryAllocateInfo memory_info = {};
4434 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4435 memory_info.pNext = NULL;
4436 memory_info.allocationSize = 0;
4437 memory_info.memoryTypeIndex = 0;
4438 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4439 memory_info.allocationSize = memory_reqs.size;
4440 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4441 ASSERT_TRUE(pass);
4442 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4443 ASSERT_VK_SUCCESS(err);
4444 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4445 ASSERT_VK_SUCCESS(err);
4446
4447 VkImageViewCreateInfo ivci = {
4448 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4449 nullptr,
4450 0,
4451 image,
4452 VK_IMAGE_VIEW_TYPE_2D,
4453 VK_FORMAT_B8G8R8A8_UNORM,
4454 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4455 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4456 };
4457 VkImageView view;
4458 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4459 ASSERT_VK_SUCCESS(err);
4460
4461 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4462 VkFramebuffer fb;
4463 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4464 ASSERT_VK_SUCCESS(err);
4465
4466 // Just use default renderpass with our framebuffer
4467 m_renderPassBeginInfo.framebuffer = fb;
4468 // Create Null cmd buffer for submit
4469 BeginCommandBuffer();
4470 EndCommandBuffer();
4471 // Submit cmd buffer to put it (and attached imageView) in-flight
4472 VkSubmitInfo submit_info = {};
4473 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4474 submit_info.commandBufferCount = 1;
4475 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4476 // Submit cmd buffer to put framebuffer and children in-flight
4477 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4478 // Destroy image attached to framebuffer while in-flight
4479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4480 vkDestroyImage(m_device->device(), image, NULL);
4481 m_errorMonitor->VerifyFound();
4482 // Wait for queue to complete so we can safely destroy image and other objects
4483 vkQueueWaitIdle(m_device->m_queue);
4484 vkDestroyImage(m_device->device(), image, NULL);
4485 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4486 vkDestroyImageView(m_device->device(), view, nullptr);
4487 vkFreeMemory(m_device->device(), image_memory, nullptr);
4488}
4489
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004490TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4491 TEST_DESCRIPTION("Delete in-use renderPass.");
4492
4493 ASSERT_NO_FATAL_FAILURE(InitState());
4494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4495
4496 // Create simple renderpass
4497 VkAttachmentReference attach = {};
4498 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4499 VkSubpassDescription subpass = {};
4500 subpass.pColorAttachments = &attach;
4501 VkRenderPassCreateInfo rpci = {};
4502 rpci.subpassCount = 1;
4503 rpci.pSubpasses = &subpass;
4504 rpci.attachmentCount = 1;
4505 VkAttachmentDescription attach_desc = {};
4506 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4507 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4508 rpci.pAttachments = &attach_desc;
4509 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4510 VkRenderPass rp;
4511 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4512 ASSERT_VK_SUCCESS(err);
4513
4514 // Create a pipeline that uses the given renderpass
4515 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4516 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4517
4518 VkPipelineLayout pipeline_layout;
4519 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4520 ASSERT_VK_SUCCESS(err);
4521
4522 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4523 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4524 vp_state_ci.viewportCount = 1;
4525 VkViewport vp = {}; // Just need dummy vp to point to
4526 vp_state_ci.pViewports = &vp;
4527 vp_state_ci.scissorCount = 1;
4528 VkRect2D scissors = {}; // Dummy scissors to point to
4529 vp_state_ci.pScissors = &scissors;
4530
4531 VkPipelineShaderStageCreateInfo shaderStages[2];
4532 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4533
4534 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4535 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4536 // but add it to be able to run on more devices
4537 shaderStages[0] = vs.GetStageCreateInfo();
4538 shaderStages[1] = fs.GetStageCreateInfo();
4539
4540 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4541 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4542
4543 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4544 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4545 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4546
4547 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4548 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4549 rs_ci.rasterizerDiscardEnable = true;
4550 rs_ci.lineWidth = 1.0f;
4551
4552 VkPipelineColorBlendAttachmentState att = {};
4553 att.blendEnable = VK_FALSE;
4554 att.colorWriteMask = 0xf;
4555
4556 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4557 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4558 cb_ci.attachmentCount = 1;
4559 cb_ci.pAttachments = &att;
4560
4561 VkGraphicsPipelineCreateInfo gp_ci = {};
4562 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4563 gp_ci.stageCount = 2;
4564 gp_ci.pStages = shaderStages;
4565 gp_ci.pVertexInputState = &vi_ci;
4566 gp_ci.pInputAssemblyState = &ia_ci;
4567 gp_ci.pViewportState = &vp_state_ci;
4568 gp_ci.pRasterizationState = &rs_ci;
4569 gp_ci.pColorBlendState = &cb_ci;
4570 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4571 gp_ci.layout = pipeline_layout;
4572 gp_ci.renderPass = rp;
4573
4574 VkPipelineCacheCreateInfo pc_ci = {};
4575 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4576
4577 VkPipeline pipeline;
4578 VkPipelineCache pipe_cache;
4579 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4580 ASSERT_VK_SUCCESS(err);
4581
4582 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4583 ASSERT_VK_SUCCESS(err);
4584 // Bind pipeline to cmd buffer, will also bind renderpass
4585 m_commandBuffer->BeginCommandBuffer();
4586 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4587 m_commandBuffer->EndCommandBuffer();
4588
4589 VkSubmitInfo submit_info = {};
4590 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4591 submit_info.commandBufferCount = 1;
4592 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4593 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4594
4595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4596 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4597 m_errorMonitor->VerifyFound();
4598
4599 // Wait for queue to complete so we can safely destroy everything
4600 vkQueueWaitIdle(m_device->m_queue);
4601 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4602 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4603 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4604 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4605}
4606
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004607TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004608 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004609 ASSERT_NO_FATAL_FAILURE(InitState());
4610
4611 VkImage image;
4612 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4613 VkImageCreateInfo image_create_info = {};
4614 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4615 image_create_info.pNext = NULL;
4616 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4617 image_create_info.format = tex_format;
4618 image_create_info.extent.width = 32;
4619 image_create_info.extent.height = 32;
4620 image_create_info.extent.depth = 1;
4621 image_create_info.mipLevels = 1;
4622 image_create_info.arrayLayers = 1;
4623 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4624 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004625 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004626 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004627 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004628 ASSERT_VK_SUCCESS(err);
4629 // Have to bind memory to image before recording cmd in cmd buffer using it
4630 VkMemoryRequirements mem_reqs;
4631 VkDeviceMemory image_mem;
4632 bool pass;
4633 VkMemoryAllocateInfo mem_alloc = {};
4634 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4635 mem_alloc.pNext = NULL;
4636 mem_alloc.memoryTypeIndex = 0;
4637 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4638 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004639 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004640 ASSERT_TRUE(pass);
4641 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4642 ASSERT_VK_SUCCESS(err);
4643
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004644 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004646 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004647
4648 m_commandBuffer->BeginCommandBuffer();
4649 VkClearColorValue ccv;
4650 ccv.float32[0] = 1.0f;
4651 ccv.float32[1] = 1.0f;
4652 ccv.float32[2] = 1.0f;
4653 ccv.float32[3] = 1.0f;
4654 VkImageSubresourceRange isr = {};
4655 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4656 isr.baseArrayLayer = 0;
4657 isr.baseMipLevel = 0;
4658 isr.layerCount = 1;
4659 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004660 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004661 m_commandBuffer->EndCommandBuffer();
4662
4663 m_errorMonitor->VerifyFound();
4664 vkDestroyImage(m_device->device(), image, NULL);
4665 vkFreeMemory(m_device->device(), image_mem, nullptr);
4666}
4667
4668TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004669 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004670 ASSERT_NO_FATAL_FAILURE(InitState());
4671
4672 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004673 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 -06004674 VK_IMAGE_TILING_OPTIMAL, 0);
4675 ASSERT_TRUE(image.initialized());
4676
4677 VkBuffer buffer;
4678 VkDeviceMemory mem;
4679 VkMemoryRequirements mem_reqs;
4680
4681 VkBufferCreateInfo buf_info = {};
4682 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004683 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004684 buf_info.size = 256;
4685 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4686 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4687 ASSERT_VK_SUCCESS(err);
4688
4689 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4690
4691 VkMemoryAllocateInfo alloc_info = {};
4692 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4693 alloc_info.allocationSize = 256;
4694 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004695 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 -06004696 if (!pass) {
4697 vkDestroyBuffer(m_device->device(), buffer, NULL);
4698 return;
4699 }
4700 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4701 ASSERT_VK_SUCCESS(err);
4702
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004703 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004705 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004706 VkBufferImageCopy region = {};
4707 region.bufferRowLength = 128;
4708 region.bufferImageHeight = 128;
4709 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4710
4711 region.imageSubresource.layerCount = 1;
4712 region.imageExtent.height = 4;
4713 region.imageExtent.width = 4;
4714 region.imageExtent.depth = 1;
4715 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004716 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4717 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004718 m_commandBuffer->EndCommandBuffer();
4719
4720 m_errorMonitor->VerifyFound();
4721
4722 vkDestroyBuffer(m_device->device(), buffer, NULL);
4723 vkFreeMemory(m_device->handle(), mem, NULL);
4724}
4725
Tobin Ehlis85940f52016-07-07 16:57:21 -06004726TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4727 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4728 "due to an event dependency being destroyed.");
4729 ASSERT_NO_FATAL_FAILURE(InitState());
4730
4731 VkEvent event;
4732 VkEventCreateInfo evci = {};
4733 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4734 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4735 ASSERT_VK_SUCCESS(result);
4736
4737 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004738 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004739 m_commandBuffer->EndCommandBuffer();
4740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004742 // Destroy event dependency prior to submit to cause ERROR
4743 vkDestroyEvent(m_device->device(), event, NULL);
4744
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}
4753
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004754TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4755 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4756 "due to a query pool dependency being destroyed.");
4757 ASSERT_NO_FATAL_FAILURE(InitState());
4758
4759 VkQueryPool query_pool;
4760 VkQueryPoolCreateInfo qpci{};
4761 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4762 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4763 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004764 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004765 ASSERT_VK_SUCCESS(result);
4766
4767 m_commandBuffer->BeginCommandBuffer();
4768 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4769 m_commandBuffer->EndCommandBuffer();
4770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004772 // Destroy query pool dependency prior to submit to cause ERROR
4773 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4774
4775 VkSubmitInfo submit_info = {};
4776 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4777 submit_info.commandBufferCount = 1;
4778 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4779 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4780
4781 m_errorMonitor->VerifyFound();
4782}
4783
Tobin Ehlis24130d92016-07-08 15:50:53 -06004784TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4785 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4786 "due to a pipeline dependency being destroyed.");
4787 ASSERT_NO_FATAL_FAILURE(InitState());
4788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4789
4790 VkResult err;
4791
4792 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4793 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4794
4795 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004796 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004797 ASSERT_VK_SUCCESS(err);
4798
4799 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4800 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4801 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004802 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004803 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004804 vp_state_ci.scissorCount = 1;
4805 VkRect2D scissors = {}; // Dummy scissors to point to
4806 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004807
4808 VkPipelineShaderStageCreateInfo shaderStages[2];
4809 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4810
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004811 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4812 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4813 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004814 shaderStages[0] = vs.GetStageCreateInfo();
4815 shaderStages[1] = fs.GetStageCreateInfo();
4816
4817 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4818 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4819
4820 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4821 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4822 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4823
4824 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4825 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004826 rs_ci.rasterizerDiscardEnable = true;
4827 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004828
4829 VkPipelineColorBlendAttachmentState att = {};
4830 att.blendEnable = VK_FALSE;
4831 att.colorWriteMask = 0xf;
4832
4833 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4834 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4835 cb_ci.attachmentCount = 1;
4836 cb_ci.pAttachments = &att;
4837
4838 VkGraphicsPipelineCreateInfo gp_ci = {};
4839 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4840 gp_ci.stageCount = 2;
4841 gp_ci.pStages = shaderStages;
4842 gp_ci.pVertexInputState = &vi_ci;
4843 gp_ci.pInputAssemblyState = &ia_ci;
4844 gp_ci.pViewportState = &vp_state_ci;
4845 gp_ci.pRasterizationState = &rs_ci;
4846 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004847 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4848 gp_ci.layout = pipeline_layout;
4849 gp_ci.renderPass = renderPass();
4850
4851 VkPipelineCacheCreateInfo pc_ci = {};
4852 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4853
4854 VkPipeline pipeline;
4855 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004856 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004857 ASSERT_VK_SUCCESS(err);
4858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004859 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004860 ASSERT_VK_SUCCESS(err);
4861
4862 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004863 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004864 m_commandBuffer->EndCommandBuffer();
4865 // Now destroy pipeline in order to cause error when submitting
4866 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004869
4870 VkSubmitInfo submit_info = {};
4871 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4872 submit_info.commandBufferCount = 1;
4873 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4874 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4875
4876 m_errorMonitor->VerifyFound();
4877 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4878 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4879}
4880
Tobin Ehlis31289162016-08-17 14:57:58 -06004881TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4882 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4883 "due to a bound descriptor set with a buffer dependency "
4884 "being destroyed.");
4885 ASSERT_NO_FATAL_FAILURE(InitState());
4886 ASSERT_NO_FATAL_FAILURE(InitViewport());
4887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4888
4889 VkDescriptorPoolSize ds_type_count = {};
4890 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4891 ds_type_count.descriptorCount = 1;
4892
4893 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4894 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4895 ds_pool_ci.pNext = NULL;
4896 ds_pool_ci.maxSets = 1;
4897 ds_pool_ci.poolSizeCount = 1;
4898 ds_pool_ci.pPoolSizes = &ds_type_count;
4899
4900 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004901 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004902 ASSERT_VK_SUCCESS(err);
4903
4904 VkDescriptorSetLayoutBinding dsl_binding = {};
4905 dsl_binding.binding = 0;
4906 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4907 dsl_binding.descriptorCount = 1;
4908 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4909 dsl_binding.pImmutableSamplers = NULL;
4910
4911 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4912 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4913 ds_layout_ci.pNext = NULL;
4914 ds_layout_ci.bindingCount = 1;
4915 ds_layout_ci.pBindings = &dsl_binding;
4916 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004917 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004918 ASSERT_VK_SUCCESS(err);
4919
4920 VkDescriptorSet descriptorSet;
4921 VkDescriptorSetAllocateInfo alloc_info = {};
4922 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4923 alloc_info.descriptorSetCount = 1;
4924 alloc_info.descriptorPool = ds_pool;
4925 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004926 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004927 ASSERT_VK_SUCCESS(err);
4928
4929 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4930 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4931 pipeline_layout_ci.pNext = NULL;
4932 pipeline_layout_ci.setLayoutCount = 1;
4933 pipeline_layout_ci.pSetLayouts = &ds_layout;
4934
4935 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004936 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004937 ASSERT_VK_SUCCESS(err);
4938
4939 // Create a buffer to update the descriptor with
4940 uint32_t qfi = 0;
4941 VkBufferCreateInfo buffCI = {};
4942 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4943 buffCI.size = 1024;
4944 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4945 buffCI.queueFamilyIndexCount = 1;
4946 buffCI.pQueueFamilyIndices = &qfi;
4947
4948 VkBuffer buffer;
4949 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4950 ASSERT_VK_SUCCESS(err);
4951 // Allocate memory and bind to buffer so we can make it to the appropriate
4952 // error
4953 VkMemoryAllocateInfo mem_alloc = {};
4954 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4955 mem_alloc.pNext = NULL;
4956 mem_alloc.allocationSize = 1024;
4957 mem_alloc.memoryTypeIndex = 0;
4958
4959 VkMemoryRequirements memReqs;
4960 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004962 if (!pass) {
4963 vkDestroyBuffer(m_device->device(), buffer, NULL);
4964 return;
4965 }
4966
4967 VkDeviceMemory mem;
4968 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4969 ASSERT_VK_SUCCESS(err);
4970 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4971 ASSERT_VK_SUCCESS(err);
4972 // Correctly update descriptor to avoid "NOT_UPDATED" error
4973 VkDescriptorBufferInfo buffInfo = {};
4974 buffInfo.buffer = buffer;
4975 buffInfo.offset = 0;
4976 buffInfo.range = 1024;
4977
4978 VkWriteDescriptorSet descriptor_write;
4979 memset(&descriptor_write, 0, sizeof(descriptor_write));
4980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4981 descriptor_write.dstSet = descriptorSet;
4982 descriptor_write.dstBinding = 0;
4983 descriptor_write.descriptorCount = 1;
4984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4985 descriptor_write.pBufferInfo = &buffInfo;
4986
4987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4988
4989 // Create PSO to be used for draw-time errors below
4990 char const *vsSource = "#version 450\n"
4991 "\n"
4992 "out gl_PerVertex { \n"
4993 " vec4 gl_Position;\n"
4994 "};\n"
4995 "void main(){\n"
4996 " gl_Position = vec4(1);\n"
4997 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004998 char const *fsSource = "#version 450\n"
4999 "\n"
5000 "layout(location=0) out vec4 x;\n"
5001 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5002 "void main(){\n"
5003 " x = vec4(bar.y);\n"
5004 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5007 VkPipelineObj pipe(m_device);
5008 pipe.AddShader(&vs);
5009 pipe.AddShader(&fs);
5010 pipe.AddColorAttachment();
5011 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5012
5013 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005014 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5015 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5016 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06005017 Draw(1, 0, 0, 0);
5018 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005020 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5021 vkDestroyBuffer(m_device->device(), buffer, NULL);
5022 // Attempt to submit cmd buffer
5023 VkSubmitInfo submit_info = {};
5024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5025 submit_info.commandBufferCount = 1;
5026 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5027 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5028 m_errorMonitor->VerifyFound();
5029 // Cleanup
5030 vkFreeMemory(m_device->device(), mem, NULL);
5031
5032 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5033 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5034 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5035}
5036
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005037TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5038 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5039 "due to a bound descriptor sets with a combined image "
5040 "sampler having their image, sampler, and descriptor set "
5041 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005042 "submit associated cmd buffers. Attempt to destroy a "
5043 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005044 ASSERT_NO_FATAL_FAILURE(InitState());
5045 ASSERT_NO_FATAL_FAILURE(InitViewport());
5046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5047
5048 VkDescriptorPoolSize ds_type_count = {};
5049 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5050 ds_type_count.descriptorCount = 1;
5051
5052 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5053 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5054 ds_pool_ci.pNext = NULL;
5055 ds_pool_ci.maxSets = 1;
5056 ds_pool_ci.poolSizeCount = 1;
5057 ds_pool_ci.pPoolSizes = &ds_type_count;
5058
5059 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005060 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005061 ASSERT_VK_SUCCESS(err);
5062
5063 VkDescriptorSetLayoutBinding dsl_binding = {};
5064 dsl_binding.binding = 0;
5065 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5066 dsl_binding.descriptorCount = 1;
5067 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5068 dsl_binding.pImmutableSamplers = NULL;
5069
5070 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5071 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5072 ds_layout_ci.pNext = NULL;
5073 ds_layout_ci.bindingCount = 1;
5074 ds_layout_ci.pBindings = &dsl_binding;
5075 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005076 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005077 ASSERT_VK_SUCCESS(err);
5078
5079 VkDescriptorSet descriptorSet;
5080 VkDescriptorSetAllocateInfo alloc_info = {};
5081 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5082 alloc_info.descriptorSetCount = 1;
5083 alloc_info.descriptorPool = ds_pool;
5084 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005085 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005086 ASSERT_VK_SUCCESS(err);
5087
5088 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5089 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5090 pipeline_layout_ci.pNext = NULL;
5091 pipeline_layout_ci.setLayoutCount = 1;
5092 pipeline_layout_ci.pSetLayouts = &ds_layout;
5093
5094 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005095 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005096 ASSERT_VK_SUCCESS(err);
5097
5098 // Create images to update the descriptor with
5099 VkImage image;
5100 VkImage image2;
5101 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5102 const int32_t tex_width = 32;
5103 const int32_t tex_height = 32;
5104 VkImageCreateInfo image_create_info = {};
5105 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5106 image_create_info.pNext = NULL;
5107 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5108 image_create_info.format = tex_format;
5109 image_create_info.extent.width = tex_width;
5110 image_create_info.extent.height = tex_height;
5111 image_create_info.extent.depth = 1;
5112 image_create_info.mipLevels = 1;
5113 image_create_info.arrayLayers = 1;
5114 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5115 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5116 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5117 image_create_info.flags = 0;
5118 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5119 ASSERT_VK_SUCCESS(err);
5120 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5121 ASSERT_VK_SUCCESS(err);
5122
5123 VkMemoryRequirements memory_reqs;
5124 VkDeviceMemory image_memory;
5125 bool pass;
5126 VkMemoryAllocateInfo memory_info = {};
5127 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5128 memory_info.pNext = NULL;
5129 memory_info.allocationSize = 0;
5130 memory_info.memoryTypeIndex = 0;
5131 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5132 // Allocate enough memory for both images
5133 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005134 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005135 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005136 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005137 ASSERT_VK_SUCCESS(err);
5138 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5139 ASSERT_VK_SUCCESS(err);
5140 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005141 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005142 ASSERT_VK_SUCCESS(err);
5143
5144 VkImageViewCreateInfo image_view_create_info = {};
5145 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5146 image_view_create_info.image = image;
5147 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5148 image_view_create_info.format = tex_format;
5149 image_view_create_info.subresourceRange.layerCount = 1;
5150 image_view_create_info.subresourceRange.baseMipLevel = 0;
5151 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005152 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005153
5154 VkImageView view;
5155 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005156 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005157 ASSERT_VK_SUCCESS(err);
5158 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005159 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005160 ASSERT_VK_SUCCESS(err);
5161 // Create Samplers
5162 VkSamplerCreateInfo sampler_ci = {};
5163 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5164 sampler_ci.pNext = NULL;
5165 sampler_ci.magFilter = VK_FILTER_NEAREST;
5166 sampler_ci.minFilter = VK_FILTER_NEAREST;
5167 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5168 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5169 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5170 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5171 sampler_ci.mipLodBias = 1.0;
5172 sampler_ci.anisotropyEnable = VK_FALSE;
5173 sampler_ci.maxAnisotropy = 1;
5174 sampler_ci.compareEnable = VK_FALSE;
5175 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5176 sampler_ci.minLod = 1.0;
5177 sampler_ci.maxLod = 1.0;
5178 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5179 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5180 VkSampler sampler;
5181 VkSampler sampler2;
5182 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5183 ASSERT_VK_SUCCESS(err);
5184 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5185 ASSERT_VK_SUCCESS(err);
5186 // Update descriptor with image and sampler
5187 VkDescriptorImageInfo img_info = {};
5188 img_info.sampler = sampler;
5189 img_info.imageView = view;
5190 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5191
5192 VkWriteDescriptorSet descriptor_write;
5193 memset(&descriptor_write, 0, sizeof(descriptor_write));
5194 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5195 descriptor_write.dstSet = descriptorSet;
5196 descriptor_write.dstBinding = 0;
5197 descriptor_write.descriptorCount = 1;
5198 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5199 descriptor_write.pImageInfo = &img_info;
5200
5201 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5202
5203 // Create PSO to be used for draw-time errors below
5204 char const *vsSource = "#version 450\n"
5205 "\n"
5206 "out gl_PerVertex { \n"
5207 " vec4 gl_Position;\n"
5208 "};\n"
5209 "void main(){\n"
5210 " gl_Position = vec4(1);\n"
5211 "}\n";
5212 char const *fsSource = "#version 450\n"
5213 "\n"
5214 "layout(set=0, binding=0) uniform sampler2D s;\n"
5215 "layout(location=0) out vec4 x;\n"
5216 "void main(){\n"
5217 " x = texture(s, vec2(1));\n"
5218 "}\n";
5219 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5220 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5221 VkPipelineObj pipe(m_device);
5222 pipe.AddShader(&vs);
5223 pipe.AddShader(&fs);
5224 pipe.AddColorAttachment();
5225 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5226
5227 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005229 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005230 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5231 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5232 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005233 Draw(1, 0, 0, 0);
5234 EndCommandBuffer();
5235 // Destroy sampler invalidates the cmd buffer, causing error on submit
5236 vkDestroySampler(m_device->device(), sampler, NULL);
5237 // Attempt to submit cmd buffer
5238 VkSubmitInfo submit_info = {};
5239 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5240 submit_info.commandBufferCount = 1;
5241 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5242 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5243 m_errorMonitor->VerifyFound();
5244 // Now re-update descriptor with valid sampler and delete image
5245 img_info.sampler = sampler2;
5246 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005248 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005249 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5250 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5251 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005252 Draw(1, 0, 0, 0);
5253 EndCommandBuffer();
5254 // Destroy image invalidates the cmd buffer, causing error on submit
5255 vkDestroyImage(m_device->device(), image, NULL);
5256 // Attempt to submit cmd buffer
5257 submit_info = {};
5258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5259 submit_info.commandBufferCount = 1;
5260 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5261 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5262 m_errorMonitor->VerifyFound();
5263 // Now update descriptor to be valid, but then free descriptor
5264 img_info.imageView = view2;
5265 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005267 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005268 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5270 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005271 Draw(1, 0, 0, 0);
5272 EndCommandBuffer();
5273 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005275 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005276 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005277 // Attempt to submit cmd buffer
5278 submit_info = {};
5279 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5280 submit_info.commandBufferCount = 1;
5281 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5282 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5283 m_errorMonitor->VerifyFound();
5284 // Cleanup
5285 vkFreeMemory(m_device->device(), image_memory, NULL);
5286 vkDestroySampler(m_device->device(), sampler2, NULL);
5287 vkDestroyImage(m_device->device(), image2, NULL);
5288 vkDestroyImageView(m_device->device(), view, NULL);
5289 vkDestroyImageView(m_device->device(), view2, NULL);
5290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5293}
5294
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005295TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5296 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5297 ASSERT_NO_FATAL_FAILURE(InitState());
5298 ASSERT_NO_FATAL_FAILURE(InitViewport());
5299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5300
5301 VkDescriptorPoolSize ds_type_count = {};
5302 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5303 ds_type_count.descriptorCount = 1;
5304
5305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5307 ds_pool_ci.pNext = NULL;
5308 ds_pool_ci.maxSets = 1;
5309 ds_pool_ci.poolSizeCount = 1;
5310 ds_pool_ci.pPoolSizes = &ds_type_count;
5311
5312 VkDescriptorPool ds_pool;
5313 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5314 ASSERT_VK_SUCCESS(err);
5315
5316 VkDescriptorSetLayoutBinding dsl_binding = {};
5317 dsl_binding.binding = 0;
5318 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5319 dsl_binding.descriptorCount = 1;
5320 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5321 dsl_binding.pImmutableSamplers = NULL;
5322
5323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5325 ds_layout_ci.pNext = NULL;
5326 ds_layout_ci.bindingCount = 1;
5327 ds_layout_ci.pBindings = &dsl_binding;
5328 VkDescriptorSetLayout ds_layout;
5329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5330 ASSERT_VK_SUCCESS(err);
5331
5332 VkDescriptorSet descriptor_set;
5333 VkDescriptorSetAllocateInfo alloc_info = {};
5334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5335 alloc_info.descriptorSetCount = 1;
5336 alloc_info.descriptorPool = ds_pool;
5337 alloc_info.pSetLayouts = &ds_layout;
5338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5339 ASSERT_VK_SUCCESS(err);
5340
5341 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5342 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5343 pipeline_layout_ci.pNext = NULL;
5344 pipeline_layout_ci.setLayoutCount = 1;
5345 pipeline_layout_ci.pSetLayouts = &ds_layout;
5346
5347 VkPipelineLayout pipeline_layout;
5348 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5349 ASSERT_VK_SUCCESS(err);
5350
5351 // Create image to update the descriptor with
5352 VkImageObj image(m_device);
5353 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5354 ASSERT_TRUE(image.initialized());
5355
5356 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5357 // Create Sampler
5358 VkSamplerCreateInfo sampler_ci = {};
5359 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5360 sampler_ci.pNext = NULL;
5361 sampler_ci.magFilter = VK_FILTER_NEAREST;
5362 sampler_ci.minFilter = VK_FILTER_NEAREST;
5363 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5364 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5365 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5366 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5367 sampler_ci.mipLodBias = 1.0;
5368 sampler_ci.anisotropyEnable = VK_FALSE;
5369 sampler_ci.maxAnisotropy = 1;
5370 sampler_ci.compareEnable = VK_FALSE;
5371 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5372 sampler_ci.minLod = 1.0;
5373 sampler_ci.maxLod = 1.0;
5374 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5375 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5376 VkSampler sampler;
5377 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5378 ASSERT_VK_SUCCESS(err);
5379 // Update descriptor with image and sampler
5380 VkDescriptorImageInfo img_info = {};
5381 img_info.sampler = sampler;
5382 img_info.imageView = view;
5383 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5384
5385 VkWriteDescriptorSet descriptor_write;
5386 memset(&descriptor_write, 0, sizeof(descriptor_write));
5387 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5388 descriptor_write.dstSet = descriptor_set;
5389 descriptor_write.dstBinding = 0;
5390 descriptor_write.descriptorCount = 1;
5391 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5392 descriptor_write.pImageInfo = &img_info;
5393
5394 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5395
5396 // Create PSO to be used for draw-time errors below
5397 char const *vsSource = "#version 450\n"
5398 "\n"
5399 "out gl_PerVertex { \n"
5400 " vec4 gl_Position;\n"
5401 "};\n"
5402 "void main(){\n"
5403 " gl_Position = vec4(1);\n"
5404 "}\n";
5405 char const *fsSource = "#version 450\n"
5406 "\n"
5407 "layout(set=0, binding=0) uniform sampler2D s;\n"
5408 "layout(location=0) out vec4 x;\n"
5409 "void main(){\n"
5410 " x = texture(s, vec2(1));\n"
5411 "}\n";
5412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5414 VkPipelineObj pipe(m_device);
5415 pipe.AddShader(&vs);
5416 pipe.AddShader(&fs);
5417 pipe.AddColorAttachment();
5418 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5419
5420 BeginCommandBuffer();
5421 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5422 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5423 &descriptor_set, 0, NULL);
5424 Draw(1, 0, 0, 0);
5425 EndCommandBuffer();
5426 // Submit cmd buffer to put pool in-flight
5427 VkSubmitInfo submit_info = {};
5428 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5429 submit_info.commandBufferCount = 1;
5430 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5431 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5432 // Destroy pool while in-flight, causing error
5433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5435 m_errorMonitor->VerifyFound();
5436 vkQueueWaitIdle(m_device->m_queue);
5437 // Cleanup
5438 vkDestroySampler(m_device->device(), sampler, NULL);
5439 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5442}
5443
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005444TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5445 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5446 ASSERT_NO_FATAL_FAILURE(InitState());
5447 ASSERT_NO_FATAL_FAILURE(InitViewport());
5448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5449
5450 VkDescriptorPoolSize ds_type_count = {};
5451 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5452 ds_type_count.descriptorCount = 1;
5453
5454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5456 ds_pool_ci.pNext = NULL;
5457 ds_pool_ci.maxSets = 1;
5458 ds_pool_ci.poolSizeCount = 1;
5459 ds_pool_ci.pPoolSizes = &ds_type_count;
5460
5461 VkDescriptorPool ds_pool;
5462 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5463 ASSERT_VK_SUCCESS(err);
5464
5465 VkDescriptorSetLayoutBinding dsl_binding = {};
5466 dsl_binding.binding = 0;
5467 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5468 dsl_binding.descriptorCount = 1;
5469 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5470 dsl_binding.pImmutableSamplers = NULL;
5471
5472 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5473 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5474 ds_layout_ci.pNext = NULL;
5475 ds_layout_ci.bindingCount = 1;
5476 ds_layout_ci.pBindings = &dsl_binding;
5477 VkDescriptorSetLayout ds_layout;
5478 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5479 ASSERT_VK_SUCCESS(err);
5480
5481 VkDescriptorSet descriptorSet;
5482 VkDescriptorSetAllocateInfo alloc_info = {};
5483 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5484 alloc_info.descriptorSetCount = 1;
5485 alloc_info.descriptorPool = ds_pool;
5486 alloc_info.pSetLayouts = &ds_layout;
5487 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5488 ASSERT_VK_SUCCESS(err);
5489
5490 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5491 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5492 pipeline_layout_ci.pNext = NULL;
5493 pipeline_layout_ci.setLayoutCount = 1;
5494 pipeline_layout_ci.pSetLayouts = &ds_layout;
5495
5496 VkPipelineLayout pipeline_layout;
5497 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5498 ASSERT_VK_SUCCESS(err);
5499
5500 // Create images to update the descriptor with
5501 VkImage image;
5502 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5503 const int32_t tex_width = 32;
5504 const int32_t tex_height = 32;
5505 VkImageCreateInfo image_create_info = {};
5506 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5507 image_create_info.pNext = NULL;
5508 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5509 image_create_info.format = tex_format;
5510 image_create_info.extent.width = tex_width;
5511 image_create_info.extent.height = tex_height;
5512 image_create_info.extent.depth = 1;
5513 image_create_info.mipLevels = 1;
5514 image_create_info.arrayLayers = 1;
5515 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5516 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5517 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5518 image_create_info.flags = 0;
5519 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5520 ASSERT_VK_SUCCESS(err);
5521 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5522 VkMemoryRequirements memory_reqs;
5523 VkDeviceMemory image_memory;
5524 bool pass;
5525 VkMemoryAllocateInfo memory_info = {};
5526 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5527 memory_info.pNext = NULL;
5528 memory_info.allocationSize = 0;
5529 memory_info.memoryTypeIndex = 0;
5530 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5531 // Allocate enough memory for image
5532 memory_info.allocationSize = memory_reqs.size;
5533 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5534 ASSERT_TRUE(pass);
5535 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5536 ASSERT_VK_SUCCESS(err);
5537 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5538 ASSERT_VK_SUCCESS(err);
5539
5540 VkImageViewCreateInfo image_view_create_info = {};
5541 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5542 image_view_create_info.image = image;
5543 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5544 image_view_create_info.format = tex_format;
5545 image_view_create_info.subresourceRange.layerCount = 1;
5546 image_view_create_info.subresourceRange.baseMipLevel = 0;
5547 image_view_create_info.subresourceRange.levelCount = 1;
5548 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5549
5550 VkImageView view;
5551 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5552 ASSERT_VK_SUCCESS(err);
5553 // Create Samplers
5554 VkSamplerCreateInfo sampler_ci = {};
5555 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5556 sampler_ci.pNext = NULL;
5557 sampler_ci.magFilter = VK_FILTER_NEAREST;
5558 sampler_ci.minFilter = VK_FILTER_NEAREST;
5559 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5560 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5561 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5562 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5563 sampler_ci.mipLodBias = 1.0;
5564 sampler_ci.anisotropyEnable = VK_FALSE;
5565 sampler_ci.maxAnisotropy = 1;
5566 sampler_ci.compareEnable = VK_FALSE;
5567 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5568 sampler_ci.minLod = 1.0;
5569 sampler_ci.maxLod = 1.0;
5570 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5571 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5572 VkSampler sampler;
5573 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5574 ASSERT_VK_SUCCESS(err);
5575 // Update descriptor with image and sampler
5576 VkDescriptorImageInfo img_info = {};
5577 img_info.sampler = sampler;
5578 img_info.imageView = view;
5579 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5580
5581 VkWriteDescriptorSet descriptor_write;
5582 memset(&descriptor_write, 0, sizeof(descriptor_write));
5583 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5584 descriptor_write.dstSet = descriptorSet;
5585 descriptor_write.dstBinding = 0;
5586 descriptor_write.descriptorCount = 1;
5587 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5588 descriptor_write.pImageInfo = &img_info;
5589 // Break memory binding and attempt update
5590 vkFreeMemory(m_device->device(), image_memory, nullptr);
5591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005592 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5594 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5595 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5596 m_errorMonitor->VerifyFound();
5597 // Cleanup
5598 vkDestroyImage(m_device->device(), image, NULL);
5599 vkDestroySampler(m_device->device(), sampler, NULL);
5600 vkDestroyImageView(m_device->device(), view, NULL);
5601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5602 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5603 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5604}
5605
Karl Schultz6addd812016-02-02 17:17:23 -07005606TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005607 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5608 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005609 // Create a valid cmd buffer
5610 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005611 uint64_t fake_pipeline_handle = 0xbaad6001;
5612 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005613 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5615
5616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005617 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005618 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005619 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005620
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005621 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005622 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 -06005623 Draw(1, 0, 0, 0);
5624 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005625
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005626 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005627 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 +12005628 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005629 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5630 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005631}
5632
Karl Schultz6addd812016-02-02 17:17:23 -07005633TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005634 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005635 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005636
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005638
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005639 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005640 ASSERT_NO_FATAL_FAILURE(InitViewport());
5641 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005642 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005643 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5644 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005645
5646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5648 ds_pool_ci.pNext = NULL;
5649 ds_pool_ci.maxSets = 1;
5650 ds_pool_ci.poolSizeCount = 1;
5651 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005652
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005653 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005654 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005655 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005656
Tony Barboureb254902015-07-15 12:50:33 -06005657 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005658 dsl_binding.binding = 0;
5659 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5660 dsl_binding.descriptorCount = 1;
5661 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5662 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005663
Tony Barboureb254902015-07-15 12:50:33 -06005664 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005665 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5666 ds_layout_ci.pNext = NULL;
5667 ds_layout_ci.bindingCount = 1;
5668 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005669 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005671 ASSERT_VK_SUCCESS(err);
5672
5673 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005674 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005675 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005676 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005677 alloc_info.descriptorPool = ds_pool;
5678 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005679 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005680 ASSERT_VK_SUCCESS(err);
5681
Tony Barboureb254902015-07-15 12:50:33 -06005682 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005683 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5684 pipeline_layout_ci.pNext = NULL;
5685 pipeline_layout_ci.setLayoutCount = 1;
5686 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005687
5688 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005689 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005690 ASSERT_VK_SUCCESS(err);
5691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005692 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005693 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005694 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005695 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005696
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005697 VkPipelineObj pipe(m_device);
5698 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005699 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005700 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005701 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005702
5703 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005704 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5705 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5706 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005708 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005709
Chia-I Wuf7458c52015-10-26 21:10:41 +08005710 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5711 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5712 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005713}
5714
Karl Schultz6addd812016-02-02 17:17:23 -07005715TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005716 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005717 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5720 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005721
5722 ASSERT_NO_FATAL_FAILURE(InitState());
5723 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005724 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5725 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005726
5727 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005728 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5729 ds_pool_ci.pNext = NULL;
5730 ds_pool_ci.maxSets = 1;
5731 ds_pool_ci.poolSizeCount = 1;
5732 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005733
5734 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005735 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005736 ASSERT_VK_SUCCESS(err);
5737
5738 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005739 dsl_binding.binding = 0;
5740 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5741 dsl_binding.descriptorCount = 1;
5742 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5743 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005744
5745 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005746 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5747 ds_layout_ci.pNext = NULL;
5748 ds_layout_ci.bindingCount = 1;
5749 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005750 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005751 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005752 ASSERT_VK_SUCCESS(err);
5753
5754 VkDescriptorSet descriptorSet;
5755 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005756 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005757 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005758 alloc_info.descriptorPool = ds_pool;
5759 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005760 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005761 ASSERT_VK_SUCCESS(err);
5762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005763 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005764 VkWriteDescriptorSet descriptor_write;
5765 memset(&descriptor_write, 0, sizeof(descriptor_write));
5766 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5767 descriptor_write.dstSet = descriptorSet;
5768 descriptor_write.dstBinding = 0;
5769 descriptor_write.descriptorCount = 1;
5770 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5771 descriptor_write.pTexelBufferView = &view;
5772
5773 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5774
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005775 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005776
5777 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5778 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5779}
5780
Mark Youngd339ba32016-05-30 13:28:35 -06005781TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005782 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 -06005783
5784 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005786 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005787
5788 ASSERT_NO_FATAL_FAILURE(InitState());
5789
5790 // Create a buffer with no bound memory and then attempt to create
5791 // a buffer view.
5792 VkBufferCreateInfo buff_ci = {};
5793 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005794 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005795 buff_ci.size = 256;
5796 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5797 VkBuffer buffer;
5798 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5799 ASSERT_VK_SUCCESS(err);
5800
5801 VkBufferViewCreateInfo buff_view_ci = {};
5802 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5803 buff_view_ci.buffer = buffer;
5804 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5805 buff_view_ci.range = VK_WHOLE_SIZE;
5806 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005807 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005808
5809 m_errorMonitor->VerifyFound();
5810 vkDestroyBuffer(m_device->device(), buffer, NULL);
5811 // If last error is success, it still created the view, so delete it.
5812 if (err == VK_SUCCESS) {
5813 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5814 }
5815}
5816
Karl Schultz6addd812016-02-02 17:17:23 -07005817TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5818 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5819 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005820 // 1. No dynamicOffset supplied
5821 // 2. Too many dynamicOffsets supplied
5822 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005823 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5825 "0 dynamicOffsets are left in "
5826 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005827
5828 ASSERT_NO_FATAL_FAILURE(InitState());
5829 ASSERT_NO_FATAL_FAILURE(InitViewport());
5830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5831
5832 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005833 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5834 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005835
5836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5838 ds_pool_ci.pNext = NULL;
5839 ds_pool_ci.maxSets = 1;
5840 ds_pool_ci.poolSizeCount = 1;
5841 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005842
5843 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005844 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005845 ASSERT_VK_SUCCESS(err);
5846
5847 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005848 dsl_binding.binding = 0;
5849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5850 dsl_binding.descriptorCount = 1;
5851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5852 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005853
5854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5856 ds_layout_ci.pNext = NULL;
5857 ds_layout_ci.bindingCount = 1;
5858 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005859 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005860 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005861 ASSERT_VK_SUCCESS(err);
5862
5863 VkDescriptorSet descriptorSet;
5864 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005865 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005866 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005867 alloc_info.descriptorPool = ds_pool;
5868 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005869 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005870 ASSERT_VK_SUCCESS(err);
5871
5872 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005873 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5874 pipeline_layout_ci.pNext = NULL;
5875 pipeline_layout_ci.setLayoutCount = 1;
5876 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005877
5878 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005879 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005880 ASSERT_VK_SUCCESS(err);
5881
5882 // Create a buffer to update the descriptor with
5883 uint32_t qfi = 0;
5884 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005885 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5886 buffCI.size = 1024;
5887 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5888 buffCI.queueFamilyIndexCount = 1;
5889 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005890
5891 VkBuffer dyub;
5892 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5893 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005894 // Allocate memory and bind to buffer so we can make it to the appropriate
5895 // error
5896 VkMemoryAllocateInfo mem_alloc = {};
5897 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5898 mem_alloc.pNext = NULL;
5899 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005900 mem_alloc.memoryTypeIndex = 0;
5901
5902 VkMemoryRequirements memReqs;
5903 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005904 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005905 if (!pass) {
5906 vkDestroyBuffer(m_device->device(), dyub, NULL);
5907 return;
5908 }
5909
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005910 VkDeviceMemory mem;
5911 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5912 ASSERT_VK_SUCCESS(err);
5913 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5914 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005915 // Correctly update descriptor to avoid "NOT_UPDATED" error
5916 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005917 buffInfo.buffer = dyub;
5918 buffInfo.offset = 0;
5919 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005920
5921 VkWriteDescriptorSet descriptor_write;
5922 memset(&descriptor_write, 0, sizeof(descriptor_write));
5923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5924 descriptor_write.dstSet = descriptorSet;
5925 descriptor_write.dstBinding = 0;
5926 descriptor_write.descriptorCount = 1;
5927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5928 descriptor_write.pBufferInfo = &buffInfo;
5929
5930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5931
5932 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005933 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5934 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005935 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005936 uint32_t pDynOff[2] = {512, 756};
5937 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5939 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5940 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5941 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005942 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005943 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5945 "offset 0 and range 1024 that "
5946 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005947 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005948 char const *vsSource = "#version 450\n"
5949 "\n"
5950 "out gl_PerVertex { \n"
5951 " vec4 gl_Position;\n"
5952 "};\n"
5953 "void main(){\n"
5954 " gl_Position = vec4(1);\n"
5955 "}\n";
5956 char const *fsSource = "#version 450\n"
5957 "\n"
5958 "layout(location=0) out vec4 x;\n"
5959 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5960 "void main(){\n"
5961 " x = vec4(bar.y);\n"
5962 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005963 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5964 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5965 VkPipelineObj pipe(m_device);
5966 pipe.AddShader(&vs);
5967 pipe.AddShader(&fs);
5968 pipe.AddColorAttachment();
5969 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5970
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005971 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005972 // This update should succeed, but offset size of 512 will overstep buffer
5973 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005974 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5975 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005976 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005977 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005978
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005979 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005980 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005981
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005982 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005983 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005984 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5985}
5986
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005987TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5988 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5989 "that doesn't have memory bound");
5990 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005992 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5994 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005995
5996 ASSERT_NO_FATAL_FAILURE(InitState());
5997 ASSERT_NO_FATAL_FAILURE(InitViewport());
5998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5999
6000 VkDescriptorPoolSize ds_type_count = {};
6001 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6002 ds_type_count.descriptorCount = 1;
6003
6004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6006 ds_pool_ci.pNext = NULL;
6007 ds_pool_ci.maxSets = 1;
6008 ds_pool_ci.poolSizeCount = 1;
6009 ds_pool_ci.pPoolSizes = &ds_type_count;
6010
6011 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006013 ASSERT_VK_SUCCESS(err);
6014
6015 VkDescriptorSetLayoutBinding dsl_binding = {};
6016 dsl_binding.binding = 0;
6017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6018 dsl_binding.descriptorCount = 1;
6019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6020 dsl_binding.pImmutableSamplers = NULL;
6021
6022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6024 ds_layout_ci.pNext = NULL;
6025 ds_layout_ci.bindingCount = 1;
6026 ds_layout_ci.pBindings = &dsl_binding;
6027 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006029 ASSERT_VK_SUCCESS(err);
6030
6031 VkDescriptorSet descriptorSet;
6032 VkDescriptorSetAllocateInfo alloc_info = {};
6033 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6034 alloc_info.descriptorSetCount = 1;
6035 alloc_info.descriptorPool = ds_pool;
6036 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006038 ASSERT_VK_SUCCESS(err);
6039
6040 // Create a buffer to update the descriptor with
6041 uint32_t qfi = 0;
6042 VkBufferCreateInfo buffCI = {};
6043 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6044 buffCI.size = 1024;
6045 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6046 buffCI.queueFamilyIndexCount = 1;
6047 buffCI.pQueueFamilyIndices = &qfi;
6048
6049 VkBuffer dyub;
6050 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6051 ASSERT_VK_SUCCESS(err);
6052
6053 // Attempt to update descriptor without binding memory to it
6054 VkDescriptorBufferInfo buffInfo = {};
6055 buffInfo.buffer = dyub;
6056 buffInfo.offset = 0;
6057 buffInfo.range = 1024;
6058
6059 VkWriteDescriptorSet descriptor_write;
6060 memset(&descriptor_write, 0, sizeof(descriptor_write));
6061 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6062 descriptor_write.dstSet = descriptorSet;
6063 descriptor_write.dstBinding = 0;
6064 descriptor_write.descriptorCount = 1;
6065 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6066 descriptor_write.pBufferInfo = &buffInfo;
6067
6068 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6069 m_errorMonitor->VerifyFound();
6070
6071 vkDestroyBuffer(m_device->device(), dyub, NULL);
6072 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6073 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6074}
6075
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006076TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006077 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006078 ASSERT_NO_FATAL_FAILURE(InitState());
6079 ASSERT_NO_FATAL_FAILURE(InitViewport());
6080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6081
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006082 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006083 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006084 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6085 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6086 pipeline_layout_ci.pushConstantRangeCount = 1;
6087 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6088
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006089 //
6090 // Check for invalid push constant ranges in pipeline layouts.
6091 //
6092 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006093 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006094 char const *msg;
6095 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006096
Karl Schultzc81037d2016-05-12 08:11:23 -06006097 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6098 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6099 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6100 "vkCreatePipelineLayout() call has push constants index 0 with "
6101 "size 0."},
6102 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6103 "vkCreatePipelineLayout() call has push constants index 0 with "
6104 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006105 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006106 "vkCreatePipelineLayout() call has push constants index 0 with "
6107 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006108 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006109 "vkCreatePipelineLayout() call has push constants index 0 with "
6110 "size 0."},
6111 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6112 "vkCreatePipelineLayout() call has push constants index 0 with "
6113 "offset 1. Offset must"},
6114 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6115 "vkCreatePipelineLayout() call has push constants index 0 "
6116 "with offset "},
6117 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6118 "vkCreatePipelineLayout() call has push constants "
6119 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006120 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006121 "vkCreatePipelineLayout() call has push constants index 0 "
6122 "with offset "},
6123 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6124 "vkCreatePipelineLayout() call has push "
6125 "constants index 0 with offset "},
6126 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6127 "vkCreatePipelineLayout() call has push "
6128 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006129 }};
6130
6131 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006132 for (const auto &iter : range_tests) {
6133 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6135 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006136 m_errorMonitor->VerifyFound();
6137 if (VK_SUCCESS == err) {
6138 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6139 }
6140 }
6141
6142 // Check for invalid stage flag
6143 pc_range.offset = 0;
6144 pc_range.size = 16;
6145 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006146 m_errorMonitor->SetDesiredFailureMsg(
6147 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6148 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006149 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006150 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006151 if (VK_SUCCESS == err) {
6152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6153 }
6154
6155 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006156 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006157 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006158 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006159 char const *msg;
6160 };
6161
Karl Schultzc81037d2016-05-12 08:11:23 -06006162 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006163 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6164 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6165 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6166 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6167 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006168 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006169 {
6170 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6171 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6172 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6173 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6174 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006175 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006176 },
6177 {
6178 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6179 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6180 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6181 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6182 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006183 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006184 },
6185 {
6186 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6187 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6188 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6189 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6190 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006191 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006192 },
6193 {
6194 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6195 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6196 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6197 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6198 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006199 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006200 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006201
Karl Schultzc81037d2016-05-12 08:11:23 -06006202 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006203 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006204 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6206 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006207 m_errorMonitor->VerifyFound();
6208 if (VK_SUCCESS == err) {
6209 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6210 }
6211 }
6212
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006213 //
6214 // CmdPushConstants tests
6215 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006216 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006217
6218 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006219 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6220 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006221 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6222 "vkCmdPushConstants() call has push constants with size 1. Size "
6223 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006224 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006225 "vkCmdPushConstants() call has push constants with size 1. Size "
6226 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006227 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006228 "vkCmdPushConstants() call has push constants with offset 1. "
6229 "Offset must be a multiple of 4."},
6230 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6231 "vkCmdPushConstants() call has push constants with offset 1. "
6232 "Offset must be a multiple of 4."},
6233 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6234 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6235 "0x1 not within flag-matching ranges in pipeline layout"},
6236 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6237 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6238 "0x1 not within flag-matching ranges in pipeline layout"},
6239 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6240 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6241 "0x1 not within flag-matching ranges in pipeline layout"},
6242 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6243 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6244 "0x1 not within flag-matching ranges in pipeline layout"},
6245 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6246 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6247 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006248 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006249 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6250 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006251 }};
6252
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006253 BeginCommandBuffer();
6254
6255 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006256 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006257 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006258 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006259 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006260 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006261 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006262 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006263 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6265 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006266 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006267 m_errorMonitor->VerifyFound();
6268 }
6269
6270 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006272 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006273 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006274 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006275
Karl Schultzc81037d2016-05-12 08:11:23 -06006276 // overlapping range tests with cmd
6277 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6278 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6279 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6280 "0x1 not within flag-matching ranges in pipeline layout"},
6281 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6282 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6283 "0x1 not within flag-matching ranges in pipeline layout"},
6284 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6285 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6286 "0x1 not within flag-matching ranges in pipeline layout"},
6287 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006288 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006289 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006290 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6291 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006292 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006293 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006294 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006295 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006296 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006297 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6299 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006300 iter.range.size, dummy_values);
6301 m_errorMonitor->VerifyFound();
6302 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6304
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006305 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006306}
6307
Karl Schultz6addd812016-02-02 17:17:23 -07006308TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006309 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006310 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006311
6312 ASSERT_NO_FATAL_FAILURE(InitState());
6313 ASSERT_NO_FATAL_FAILURE(InitViewport());
6314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6315
Mike Stroyanb8a61002016-06-20 16:00:28 -06006316 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6317 VkImageTiling tiling;
6318 VkFormatProperties format_properties;
6319 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006320 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006321 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006322 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006323 tiling = VK_IMAGE_TILING_OPTIMAL;
6324 } else {
6325 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6326 "skipped.\n");
6327 return;
6328 }
6329
Tobin Ehlis559c6382015-11-05 09:52:49 -07006330 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6331 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006332 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6333 ds_type_count[0].descriptorCount = 10;
6334 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6335 ds_type_count[1].descriptorCount = 2;
6336 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6337 ds_type_count[2].descriptorCount = 2;
6338 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6339 ds_type_count[3].descriptorCount = 5;
6340 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6341 // type
6342 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6343 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6344 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006345
6346 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006347 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6348 ds_pool_ci.pNext = NULL;
6349 ds_pool_ci.maxSets = 5;
6350 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6351 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006352
6353 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006354 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006355 ASSERT_VK_SUCCESS(err);
6356
6357 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6358 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006359 dsl_binding[0].binding = 0;
6360 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6361 dsl_binding[0].descriptorCount = 5;
6362 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6363 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006364
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006365 // Create layout identical to set0 layout but w/ different stageFlags
6366 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006367 dsl_fs_stage_only.binding = 0;
6368 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6369 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006370 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6371 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006372 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006373 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006374 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6375 ds_layout_ci.pNext = NULL;
6376 ds_layout_ci.bindingCount = 1;
6377 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006378 static const uint32_t NUM_LAYOUTS = 4;
6379 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006380 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006381 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6382 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006383 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006384 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006385 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006387 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006388 dsl_binding[0].binding = 0;
6389 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006390 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006391 dsl_binding[1].binding = 1;
6392 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6393 dsl_binding[1].descriptorCount = 2;
6394 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6395 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006396 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006397 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006398 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006399 ASSERT_VK_SUCCESS(err);
6400 dsl_binding[0].binding = 0;
6401 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006402 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006403 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006405 ASSERT_VK_SUCCESS(err);
6406 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006407 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006409 ASSERT_VK_SUCCESS(err);
6410
6411 static const uint32_t NUM_SETS = 4;
6412 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6413 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006414 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006415 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006416 alloc_info.descriptorPool = ds_pool;
6417 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006419 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006420 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006421 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006422 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006424 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006425
6426 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006427 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6428 pipeline_layout_ci.pNext = NULL;
6429 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6430 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006431
6432 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006433 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006434 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006435 // Create pipelineLayout with only one setLayout
6436 pipeline_layout_ci.setLayoutCount = 1;
6437 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006439 ASSERT_VK_SUCCESS(err);
6440 // Create pipelineLayout with 2 descriptor setLayout at index 0
6441 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6442 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006444 ASSERT_VK_SUCCESS(err);
6445 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6446 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6447 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006448 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006449 ASSERT_VK_SUCCESS(err);
6450 // Create pipelineLayout with UB type, but stageFlags for FS only
6451 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6452 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006453 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006454 ASSERT_VK_SUCCESS(err);
6455 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6456 VkDescriptorSetLayout pl_bad_s0[2] = {};
6457 pl_bad_s0[0] = ds_layout_fs_only;
6458 pl_bad_s0[1] = ds_layout[1];
6459 pipeline_layout_ci.setLayoutCount = 2;
6460 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6461 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006462 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006463 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006464
6465 // Create a buffer to update the descriptor with
6466 uint32_t qfi = 0;
6467 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006468 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6469 buffCI.size = 1024;
6470 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6471 buffCI.queueFamilyIndexCount = 1;
6472 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006473
6474 VkBuffer dyub;
6475 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6476 ASSERT_VK_SUCCESS(err);
6477 // Correctly update descriptor to avoid "NOT_UPDATED" error
6478 static const uint32_t NUM_BUFFS = 5;
6479 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006480 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006481 buffInfo[i].buffer = dyub;
6482 buffInfo[i].offset = 0;
6483 buffInfo[i].range = 1024;
6484 }
Karl Schultz6addd812016-02-02 17:17:23 -07006485 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006486 const int32_t tex_width = 32;
6487 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006488 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006489 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6490 image_create_info.pNext = NULL;
6491 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6492 image_create_info.format = tex_format;
6493 image_create_info.extent.width = tex_width;
6494 image_create_info.extent.height = tex_height;
6495 image_create_info.extent.depth = 1;
6496 image_create_info.mipLevels = 1;
6497 image_create_info.arrayLayers = 1;
6498 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006499 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006500 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006501 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006502 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6503 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006504
Karl Schultz6addd812016-02-02 17:17:23 -07006505 VkMemoryRequirements memReqs;
6506 VkDeviceMemory imageMem;
6507 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006508 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006509 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6510 memAlloc.pNext = NULL;
6511 memAlloc.allocationSize = 0;
6512 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006513 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6514 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006515 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006516 ASSERT_TRUE(pass);
6517 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6518 ASSERT_VK_SUCCESS(err);
6519 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6520 ASSERT_VK_SUCCESS(err);
6521
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006522 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006523 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6524 image_view_create_info.image = image;
6525 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6526 image_view_create_info.format = tex_format;
6527 image_view_create_info.subresourceRange.layerCount = 1;
6528 image_view_create_info.subresourceRange.baseMipLevel = 0;
6529 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006530 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006531
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006532 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006533 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006534 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006535 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 imageInfo[0].imageView = view;
6537 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6538 imageInfo[1].imageView = view;
6539 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006540 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006541 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006542 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006543 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006544
6545 static const uint32_t NUM_SET_UPDATES = 3;
6546 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6547 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6548 descriptor_write[0].dstSet = descriptorSet[0];
6549 descriptor_write[0].dstBinding = 0;
6550 descriptor_write[0].descriptorCount = 5;
6551 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6552 descriptor_write[0].pBufferInfo = buffInfo;
6553 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6554 descriptor_write[1].dstSet = descriptorSet[1];
6555 descriptor_write[1].dstBinding = 0;
6556 descriptor_write[1].descriptorCount = 2;
6557 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6558 descriptor_write[1].pImageInfo = imageInfo;
6559 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6560 descriptor_write[2].dstSet = descriptorSet[1];
6561 descriptor_write[2].dstBinding = 1;
6562 descriptor_write[2].descriptorCount = 2;
6563 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006564 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006565
6566 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006567
Tobin Ehlis88452832015-12-03 09:40:56 -07006568 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006569 char const *vsSource = "#version 450\n"
6570 "\n"
6571 "out gl_PerVertex {\n"
6572 " vec4 gl_Position;\n"
6573 "};\n"
6574 "void main(){\n"
6575 " gl_Position = vec4(1);\n"
6576 "}\n";
6577 char const *fsSource = "#version 450\n"
6578 "\n"
6579 "layout(location=0) out vec4 x;\n"
6580 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6581 "void main(){\n"
6582 " x = vec4(bar.y);\n"
6583 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006584 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6585 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006586 VkPipelineObj pipe(m_device);
6587 pipe.AddShader(&vs);
6588 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006589 pipe.AddColorAttachment();
6590 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006591
6592 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006593
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006594 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006595 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6596 // of PSO
6597 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6598 // cmd_pipeline.c
6599 // due to the fact that cmd_alloc_dset_data() has not been called in
6600 // cmd_bind_graphics_pipeline()
6601 // TODO : Want to cause various binding incompatibility issues here to test
6602 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006603 // First cause various verify_layout_compatibility() fails
6604 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006605 // verify_set_layout_compatibility fail cases:
6606 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6608 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6609 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006610 m_errorMonitor->VerifyFound();
6611
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006612 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6614 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6615 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006616 m_errorMonitor->VerifyFound();
6617
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006618 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006619 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6620 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6622 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6623 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006624 m_errorMonitor->VerifyFound();
6625
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006626 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6627 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6629 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6630 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006631 m_errorMonitor->VerifyFound();
6632
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006633 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6634 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6636 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6637 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6638 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006639 m_errorMonitor->VerifyFound();
6640
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006641 // Cause INFO messages due to disturbing previously bound Sets
6642 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006643 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6644 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006645 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6647 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6648 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006649 m_errorMonitor->VerifyFound();
6650
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006651 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6652 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006653 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6655 "any subsequent sets were disturbed ");
6656 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6657 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006658 m_errorMonitor->VerifyFound();
6659
Tobin Ehlis10fad692016-07-07 12:00:36 -06006660 // Now that we're done actively using the pipelineLayout that gfx pipeline
6661 // was created with, we should be able to delete it. Do that now to verify
6662 // that validation obeys pipelineLayout lifetime
6663 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6664
Tobin Ehlis88452832015-12-03 09:40:56 -07006665 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006666 // 1. Error due to not binding required set (we actually use same code as
6667 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6669 &descriptorSet[0], 0, NULL);
6670 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6671 &descriptorSet[1], 0, NULL);
6672 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 -07006673 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006674 m_errorMonitor->VerifyFound();
6675
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006676 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006677 // 2. Error due to bound set not being compatible with PSO's
6678 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006679 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6680 &descriptorSet[0], 0, NULL);
6681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006682 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006683 m_errorMonitor->VerifyFound();
6684
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006685 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006686 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006687 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6688 }
6689 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006690 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006691 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6692 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006693 vkFreeMemory(m_device->device(), imageMem, NULL);
6694 vkDestroyImage(m_device->device(), image, NULL);
6695 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006696}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006697
Karl Schultz6addd812016-02-02 17:17:23 -07006698TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006699
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6701 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006702
6703 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006704 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006705 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006706 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006708 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006709}
6710
Karl Schultz6addd812016-02-02 17:17:23 -07006711TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6712 VkResult err;
6713 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006716
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006717 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006718
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006719 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006720 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006721 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006722 cmd.commandPool = m_commandPool;
6723 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006724 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006725
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006726 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006727 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006728
6729 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006730 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006731 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006732 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006733 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006734 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 -07006735 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006736
6737 // The error should be caught by validation of the BeginCommandBuffer call
6738 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6739
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006740 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006741 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006742}
6743
Karl Schultz6addd812016-02-02 17:17:23 -07006744TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006745 // Cause error due to Begin while recording CB
6746 // Then cause 2 errors for attempting to reset CB w/o having
6747 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6748 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006750
6751 ASSERT_NO_FATAL_FAILURE(InitState());
6752
6753 // Calls AllocateCommandBuffers
6754 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6755
Karl Schultz6addd812016-02-02 17:17:23 -07006756 // Force the failure by setting the Renderpass and Framebuffer fields with
6757 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006758 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006759 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006760 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6761 cmd_buf_info.pNext = NULL;
6762 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006763 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006764
6765 // Begin CB to transition to recording state
6766 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6767 // Can't re-begin. This should trigger error
6768 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006769 m_errorMonitor->VerifyFound();
6770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006772 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6773 // Reset attempt will trigger error due to incorrect CommandPool state
6774 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006775 m_errorMonitor->VerifyFound();
6776
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006778 // Transition CB to RECORDED state
6779 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6780 // Now attempting to Begin will implicitly reset, which triggers error
6781 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006782 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006783}
6784
Karl Schultz6addd812016-02-02 17:17:23 -07006785TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006786 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006787 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006788
Mike Weiblencce7ec72016-10-17 19:33:05 -06006789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006790
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006791 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006793
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006794 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006795 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6796 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006797
6798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6800 ds_pool_ci.pNext = NULL;
6801 ds_pool_ci.maxSets = 1;
6802 ds_pool_ci.poolSizeCount = 1;
6803 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006804
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006805 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006806 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006807 ASSERT_VK_SUCCESS(err);
6808
Tony Barboureb254902015-07-15 12:50:33 -06006809 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006810 dsl_binding.binding = 0;
6811 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6812 dsl_binding.descriptorCount = 1;
6813 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6814 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006815
Tony Barboureb254902015-07-15 12:50:33 -06006816 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006817 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6818 ds_layout_ci.pNext = NULL;
6819 ds_layout_ci.bindingCount = 1;
6820 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006821
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006822 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006824 ASSERT_VK_SUCCESS(err);
6825
6826 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006827 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006828 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006829 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006830 alloc_info.descriptorPool = ds_pool;
6831 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006833 ASSERT_VK_SUCCESS(err);
6834
Tony Barboureb254902015-07-15 12:50:33 -06006835 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006836 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6837 pipeline_layout_ci.setLayoutCount = 1;
6838 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006839
6840 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006841 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006842 ASSERT_VK_SUCCESS(err);
6843
Tobin Ehlise68360f2015-10-01 11:15:13 -06006844 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006845 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006846
6847 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006848 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6849 vp_state_ci.scissorCount = 1;
6850 vp_state_ci.pScissors = &sc;
6851 vp_state_ci.viewportCount = 1;
6852 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006853
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006854 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6855 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6856 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6857 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6858 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6859 rs_state_ci.depthClampEnable = VK_FALSE;
6860 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6861 rs_state_ci.depthBiasEnable = VK_FALSE;
6862
Tony Barboureb254902015-07-15 12:50:33 -06006863 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6865 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006866 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006867 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6868 gp_ci.layout = pipeline_layout;
6869 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006870
6871 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006872 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6873 pc_ci.initialDataSize = 0;
6874 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006875
6876 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006877 VkPipelineCache pipelineCache;
6878
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006879 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006880 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006881 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006882
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006883 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006884
Chia-I Wuf7458c52015-10-26 21:10:41 +08006885 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006889}
Tobin Ehlis912df022015-09-17 08:46:18 -06006890/*// TODO : This test should be good, but needs Tess support in compiler to run
6891TEST_F(VkLayerTest, InvalidPatchControlPoints)
6892{
6893 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006894 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006895
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006897 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6898primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006899
Tobin Ehlis912df022015-09-17 08:46:18 -06006900 ASSERT_NO_FATAL_FAILURE(InitState());
6901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006902
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006903 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006904 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006905 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006906
6907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6909 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006910 ds_pool_ci.poolSizeCount = 1;
6911 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006912
6913 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006914 err = vkCreateDescriptorPool(m_device->device(),
6915VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006916 ASSERT_VK_SUCCESS(err);
6917
6918 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006919 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006920 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006921 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006922 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6923 dsl_binding.pImmutableSamplers = NULL;
6924
6925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006926 ds_layout_ci.sType =
6927VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006928 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006929 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006930 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006931
6932 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006933 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6934&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006935 ASSERT_VK_SUCCESS(err);
6936
6937 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006938 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6939VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006940 ASSERT_VK_SUCCESS(err);
6941
6942 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006943 pipeline_layout_ci.sType =
6944VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006945 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006946 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006947 pipeline_layout_ci.pSetLayouts = &ds_layout;
6948
6949 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006950 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6951&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006952 ASSERT_VK_SUCCESS(err);
6953
6954 VkPipelineShaderStageCreateInfo shaderStages[3];
6955 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6956
Karl Schultz6addd812016-02-02 17:17:23 -07006957 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6958this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006959 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006960 VkShaderObj
6961tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6962this);
6963 VkShaderObj
6964te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6965this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006966
Karl Schultz6addd812016-02-02 17:17:23 -07006967 shaderStages[0].sType =
6968VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006969 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006970 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006971 shaderStages[1].sType =
6972VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006973 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006974 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006975 shaderStages[2].sType =
6976VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006977 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006978 shaderStages[2].shader = te.handle();
6979
6980 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006981 iaCI.sType =
6982VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006983 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006984
6985 VkPipelineTessellationStateCreateInfo tsCI = {};
6986 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6987 tsCI.patchControlPoints = 0; // This will cause an error
6988
6989 VkGraphicsPipelineCreateInfo gp_ci = {};
6990 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6991 gp_ci.pNext = NULL;
6992 gp_ci.stageCount = 3;
6993 gp_ci.pStages = shaderStages;
6994 gp_ci.pVertexInputState = NULL;
6995 gp_ci.pInputAssemblyState = &iaCI;
6996 gp_ci.pTessellationState = &tsCI;
6997 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006998 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006999 gp_ci.pMultisampleState = NULL;
7000 gp_ci.pDepthStencilState = NULL;
7001 gp_ci.pColorBlendState = NULL;
7002 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7003 gp_ci.layout = pipeline_layout;
7004 gp_ci.renderPass = renderPass();
7005
7006 VkPipelineCacheCreateInfo pc_ci = {};
7007 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7008 pc_ci.pNext = NULL;
7009 pc_ci.initialSize = 0;
7010 pc_ci.initialData = 0;
7011 pc_ci.maxSize = 0;
7012
7013 VkPipeline pipeline;
7014 VkPipelineCache pipelineCache;
7015
Karl Schultz6addd812016-02-02 17:17:23 -07007016 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7017&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007018 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007019 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7020&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007021
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007022 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007023
Chia-I Wuf7458c52015-10-26 21:10:41 +08007024 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7025 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007028}
7029*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007030// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007031TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007032 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7035 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007036
Tobin Ehlise68360f2015-10-01 11:15:13 -06007037 ASSERT_NO_FATAL_FAILURE(InitState());
7038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007039
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007040 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007041 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7042 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007043
7044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7046 ds_pool_ci.maxSets = 1;
7047 ds_pool_ci.poolSizeCount = 1;
7048 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007049
7050 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007051 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007052 ASSERT_VK_SUCCESS(err);
7053
7054 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007055 dsl_binding.binding = 0;
7056 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7057 dsl_binding.descriptorCount = 1;
7058 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007059
7060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7062 ds_layout_ci.bindingCount = 1;
7063 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007064
7065 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007067 ASSERT_VK_SUCCESS(err);
7068
7069 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007070 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007072 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007073 alloc_info.descriptorPool = ds_pool;
7074 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007076 ASSERT_VK_SUCCESS(err);
7077
7078 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007079 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7080 pipeline_layout_ci.setLayoutCount = 1;
7081 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007082
7083 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007084 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007085 ASSERT_VK_SUCCESS(err);
7086
7087 VkViewport vp = {}; // Just need dummy vp to point to
7088
7089 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007090 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7091 vp_state_ci.scissorCount = 0;
7092 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7093 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007094
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007095 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7096 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7097 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7098 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7099 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7100 rs_state_ci.depthClampEnable = VK_FALSE;
7101 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7102 rs_state_ci.depthBiasEnable = VK_FALSE;
7103
Cody Northropeb3a6c12015-10-05 14:44:45 -06007104 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007105 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007107 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7108 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7109 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007110 shaderStages[0] = vs.GetStageCreateInfo();
7111 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112
7113 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007114 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7115 gp_ci.stageCount = 2;
7116 gp_ci.pStages = shaderStages;
7117 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007118 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007119 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7120 gp_ci.layout = pipeline_layout;
7121 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007122
7123 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007124 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007125
7126 VkPipeline pipeline;
7127 VkPipelineCache pipelineCache;
7128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007129 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007130 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007131 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007132
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007133 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
Chia-I Wuf7458c52015-10-26 21:10:41 +08007135 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7136 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7137 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7138 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007139}
Karl Schultz6addd812016-02-02 17:17:23 -07007140// Don't set viewport state in PSO. This is an error b/c we always need this
7141// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007142// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007143TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007144 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007145 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007146
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007148
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149 ASSERT_NO_FATAL_FAILURE(InitState());
7150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007152 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007153 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7154 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007155
7156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7158 ds_pool_ci.maxSets = 1;
7159 ds_pool_ci.poolSizeCount = 1;
7160 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161
7162 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007163 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007164 ASSERT_VK_SUCCESS(err);
7165
7166 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007167 dsl_binding.binding = 0;
7168 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7169 dsl_binding.descriptorCount = 1;
7170 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171
7172 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007173 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7174 ds_layout_ci.bindingCount = 1;
7175 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007176
7177 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007178 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007179 ASSERT_VK_SUCCESS(err);
7180
7181 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007182 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007183 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007184 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007185 alloc_info.descriptorPool = ds_pool;
7186 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007187 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007188 ASSERT_VK_SUCCESS(err);
7189
7190 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007191 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7192 pipeline_layout_ci.setLayoutCount = 1;
7193 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007194
7195 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007197 ASSERT_VK_SUCCESS(err);
7198
7199 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7200 // Set scissor as dynamic to avoid second error
7201 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007202 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7203 dyn_state_ci.dynamicStateCount = 1;
7204 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007205
Cody Northropeb3a6c12015-10-05 14:44:45 -06007206 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007207 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007209 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7210 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7211 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007212 shaderStages[0] = vs.GetStageCreateInfo();
7213 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007214
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007215 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7216 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7217 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7218 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7219 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7220 rs_state_ci.depthClampEnable = VK_FALSE;
7221 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7222 rs_state_ci.depthBiasEnable = VK_FALSE;
7223
Tobin Ehlise68360f2015-10-01 11:15:13 -06007224 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007225 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7226 gp_ci.stageCount = 2;
7227 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007228 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007229 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7230 // should cause validation error
7231 gp_ci.pDynamicState = &dyn_state_ci;
7232 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7233 gp_ci.layout = pipeline_layout;
7234 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007235
7236 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007237 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007238
7239 VkPipeline pipeline;
7240 VkPipelineCache pipelineCache;
7241
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007242 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007243 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007244 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007245
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007246 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007247
Chia-I Wuf7458c52015-10-26 21:10:41 +08007248 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7249 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7250 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7251 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007252}
7253// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007254// Then run second test where dynamic scissor count doesn't match PSO scissor
7255// count
7256TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7257 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7260 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007261
Tobin Ehlise68360f2015-10-01 11:15:13 -06007262 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007263
7264 if (!m_device->phy().features().multiViewport) {
7265 printf("Device does not support multiple viewports/scissors; skipped.\n");
7266 return;
7267 }
7268
Tobin Ehlise68360f2015-10-01 11:15:13 -06007269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007271 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007272 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7273 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007274
7275 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007276 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7277 ds_pool_ci.maxSets = 1;
7278 ds_pool_ci.poolSizeCount = 1;
7279 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007280
7281 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007282 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007283 ASSERT_VK_SUCCESS(err);
7284
7285 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007286 dsl_binding.binding = 0;
7287 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7288 dsl_binding.descriptorCount = 1;
7289 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007290
7291 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007292 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7293 ds_layout_ci.bindingCount = 1;
7294 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007295
7296 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007297 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007298 ASSERT_VK_SUCCESS(err);
7299
7300 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007301 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007302 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007303 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007304 alloc_info.descriptorPool = ds_pool;
7305 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007306 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007307 ASSERT_VK_SUCCESS(err);
7308
7309 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007310 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7311 pipeline_layout_ci.setLayoutCount = 1;
7312 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007313
7314 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007315 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007316 ASSERT_VK_SUCCESS(err);
7317
7318 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007319 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7320 vp_state_ci.viewportCount = 1;
7321 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7322 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007323 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007324
7325 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7326 // Set scissor as dynamic to avoid that error
7327 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007328 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7329 dyn_state_ci.dynamicStateCount = 1;
7330 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007331
Cody Northropeb3a6c12015-10-05 14:44:45 -06007332 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007333 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007334
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007335 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7336 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7337 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007338 shaderStages[0] = vs.GetStageCreateInfo();
7339 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
Cody Northropf6622dc2015-10-06 10:33:21 -06007341 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7342 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7343 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007344 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007345 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007346 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007347 vi_ci.pVertexAttributeDescriptions = nullptr;
7348
7349 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7350 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7351 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7352
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007353 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007354 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007355 rs_ci.pNext = nullptr;
7356
Mark Youngc89c6312016-03-31 16:03:20 -06007357 VkPipelineColorBlendAttachmentState att = {};
7358 att.blendEnable = VK_FALSE;
7359 att.colorWriteMask = 0xf;
7360
Cody Northropf6622dc2015-10-06 10:33:21 -06007361 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7362 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7363 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007364 cb_ci.attachmentCount = 1;
7365 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007366
Tobin Ehlise68360f2015-10-01 11:15:13 -06007367 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007368 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7369 gp_ci.stageCount = 2;
7370 gp_ci.pStages = shaderStages;
7371 gp_ci.pVertexInputState = &vi_ci;
7372 gp_ci.pInputAssemblyState = &ia_ci;
7373 gp_ci.pViewportState = &vp_state_ci;
7374 gp_ci.pRasterizationState = &rs_ci;
7375 gp_ci.pColorBlendState = &cb_ci;
7376 gp_ci.pDynamicState = &dyn_state_ci;
7377 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7378 gp_ci.layout = pipeline_layout;
7379 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007380
7381 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007382 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007383
7384 VkPipeline pipeline;
7385 VkPipelineCache pipelineCache;
7386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007387 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007389 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007390
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007391 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007392
Tobin Ehlisd332f282015-10-02 11:00:56 -06007393 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007394 // First need to successfully create the PSO from above by setting
7395 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007396 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 -07007397
7398 VkViewport vp = {}; // Just need dummy vp to point to
7399 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007400 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007401 ASSERT_VK_SUCCESS(err);
7402 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007403 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007404 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007405 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007406 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007407 Draw(1, 0, 0, 0);
7408
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007409 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007410
7411 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7412 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007415 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007416}
7417// Create PSO w/o non-zero scissorCount but no scissor data
7418// Then run second test where dynamic viewportCount doesn't match PSO
7419// viewportCount
7420TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7421 VkResult err;
7422
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 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 -07007424
7425 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007426
7427 if (!m_device->phy().features().multiViewport) {
7428 printf("Device does not support multiple viewports/scissors; skipped.\n");
7429 return;
7430 }
7431
Karl Schultz6addd812016-02-02 17:17:23 -07007432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7433
7434 VkDescriptorPoolSize ds_type_count = {};
7435 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7436 ds_type_count.descriptorCount = 1;
7437
7438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7440 ds_pool_ci.maxSets = 1;
7441 ds_pool_ci.poolSizeCount = 1;
7442 ds_pool_ci.pPoolSizes = &ds_type_count;
7443
7444 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007445 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007446 ASSERT_VK_SUCCESS(err);
7447
7448 VkDescriptorSetLayoutBinding dsl_binding = {};
7449 dsl_binding.binding = 0;
7450 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7451 dsl_binding.descriptorCount = 1;
7452 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7453
7454 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7455 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7456 ds_layout_ci.bindingCount = 1;
7457 ds_layout_ci.pBindings = &dsl_binding;
7458
7459 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007460 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007461 ASSERT_VK_SUCCESS(err);
7462
7463 VkDescriptorSet descriptorSet;
7464 VkDescriptorSetAllocateInfo alloc_info = {};
7465 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7466 alloc_info.descriptorSetCount = 1;
7467 alloc_info.descriptorPool = ds_pool;
7468 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007469 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007470 ASSERT_VK_SUCCESS(err);
7471
7472 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7473 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7474 pipeline_layout_ci.setLayoutCount = 1;
7475 pipeline_layout_ci.pSetLayouts = &ds_layout;
7476
7477 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007478 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007479 ASSERT_VK_SUCCESS(err);
7480
7481 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7482 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7483 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007484 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007485 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007486 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007487
7488 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7489 // Set scissor as dynamic to avoid that error
7490 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7491 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7492 dyn_state_ci.dynamicStateCount = 1;
7493 dyn_state_ci.pDynamicStates = &vp_state;
7494
7495 VkPipelineShaderStageCreateInfo shaderStages[2];
7496 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7497
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007498 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7499 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7500 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007501 shaderStages[0] = vs.GetStageCreateInfo();
7502 shaderStages[1] = fs.GetStageCreateInfo();
7503
7504 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7505 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7506 vi_ci.pNext = nullptr;
7507 vi_ci.vertexBindingDescriptionCount = 0;
7508 vi_ci.pVertexBindingDescriptions = nullptr;
7509 vi_ci.vertexAttributeDescriptionCount = 0;
7510 vi_ci.pVertexAttributeDescriptions = nullptr;
7511
7512 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7513 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7514 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7515
7516 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7517 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7518 rs_ci.pNext = nullptr;
7519
Mark Youngc89c6312016-03-31 16:03:20 -06007520 VkPipelineColorBlendAttachmentState att = {};
7521 att.blendEnable = VK_FALSE;
7522 att.colorWriteMask = 0xf;
7523
Karl Schultz6addd812016-02-02 17:17:23 -07007524 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7525 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7526 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007527 cb_ci.attachmentCount = 1;
7528 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007529
7530 VkGraphicsPipelineCreateInfo gp_ci = {};
7531 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7532 gp_ci.stageCount = 2;
7533 gp_ci.pStages = shaderStages;
7534 gp_ci.pVertexInputState = &vi_ci;
7535 gp_ci.pInputAssemblyState = &ia_ci;
7536 gp_ci.pViewportState = &vp_state_ci;
7537 gp_ci.pRasterizationState = &rs_ci;
7538 gp_ci.pColorBlendState = &cb_ci;
7539 gp_ci.pDynamicState = &dyn_state_ci;
7540 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7541 gp_ci.layout = pipeline_layout;
7542 gp_ci.renderPass = renderPass();
7543
7544 VkPipelineCacheCreateInfo pc_ci = {};
7545 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7546
7547 VkPipeline pipeline;
7548 VkPipelineCache pipelineCache;
7549
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007550 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007551 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007552 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007553
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007554 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007555
7556 // Now hit second fail case where we set scissor w/ different count than PSO
7557 // First need to successfully create the PSO from above by setting
7558 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007559 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 -06007560
Tobin Ehlisd332f282015-10-02 11:00:56 -06007561 VkRect2D sc = {}; // Just need dummy vp to point to
7562 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007563 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007564 ASSERT_VK_SUCCESS(err);
7565 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007566 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007567 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007568 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007569 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007570 Draw(1, 0, 0, 0);
7571
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007572 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007573
Chia-I Wuf7458c52015-10-26 21:10:41 +08007574 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7575 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7577 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007578 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007579}
7580
Mark Young7394fdd2016-03-31 14:56:43 -06007581TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7582 VkResult err;
7583
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007585
7586 ASSERT_NO_FATAL_FAILURE(InitState());
7587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7588
7589 VkDescriptorPoolSize ds_type_count = {};
7590 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7591 ds_type_count.descriptorCount = 1;
7592
7593 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7594 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7595 ds_pool_ci.maxSets = 1;
7596 ds_pool_ci.poolSizeCount = 1;
7597 ds_pool_ci.pPoolSizes = &ds_type_count;
7598
7599 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007600 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007601 ASSERT_VK_SUCCESS(err);
7602
7603 VkDescriptorSetLayoutBinding dsl_binding = {};
7604 dsl_binding.binding = 0;
7605 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7606 dsl_binding.descriptorCount = 1;
7607 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7608
7609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7611 ds_layout_ci.bindingCount = 1;
7612 ds_layout_ci.pBindings = &dsl_binding;
7613
7614 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007616 ASSERT_VK_SUCCESS(err);
7617
7618 VkDescriptorSet descriptorSet;
7619 VkDescriptorSetAllocateInfo alloc_info = {};
7620 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7621 alloc_info.descriptorSetCount = 1;
7622 alloc_info.descriptorPool = ds_pool;
7623 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007625 ASSERT_VK_SUCCESS(err);
7626
7627 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7628 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7629 pipeline_layout_ci.setLayoutCount = 1;
7630 pipeline_layout_ci.pSetLayouts = &ds_layout;
7631
7632 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007634 ASSERT_VK_SUCCESS(err);
7635
7636 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7637 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7638 vp_state_ci.scissorCount = 1;
7639 vp_state_ci.pScissors = NULL;
7640 vp_state_ci.viewportCount = 1;
7641 vp_state_ci.pViewports = NULL;
7642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007643 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007644 // Set scissor as dynamic to avoid that error
7645 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7646 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7647 dyn_state_ci.dynamicStateCount = 2;
7648 dyn_state_ci.pDynamicStates = dynamic_states;
7649
7650 VkPipelineShaderStageCreateInfo shaderStages[2];
7651 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7652
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007653 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7654 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007655 this); // TODO - We shouldn't need a fragment shader
7656 // but add it to be able to run on more devices
7657 shaderStages[0] = vs.GetStageCreateInfo();
7658 shaderStages[1] = fs.GetStageCreateInfo();
7659
7660 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7661 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7662 vi_ci.pNext = nullptr;
7663 vi_ci.vertexBindingDescriptionCount = 0;
7664 vi_ci.pVertexBindingDescriptions = nullptr;
7665 vi_ci.vertexAttributeDescriptionCount = 0;
7666 vi_ci.pVertexAttributeDescriptions = nullptr;
7667
7668 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7669 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7670 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7671
7672 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7673 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7674 rs_ci.pNext = nullptr;
7675
Mark Young47107952016-05-02 15:59:55 -06007676 // Check too low (line width of -1.0f).
7677 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007678
7679 VkPipelineColorBlendAttachmentState att = {};
7680 att.blendEnable = VK_FALSE;
7681 att.colorWriteMask = 0xf;
7682
7683 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7684 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7685 cb_ci.pNext = nullptr;
7686 cb_ci.attachmentCount = 1;
7687 cb_ci.pAttachments = &att;
7688
7689 VkGraphicsPipelineCreateInfo gp_ci = {};
7690 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7691 gp_ci.stageCount = 2;
7692 gp_ci.pStages = shaderStages;
7693 gp_ci.pVertexInputState = &vi_ci;
7694 gp_ci.pInputAssemblyState = &ia_ci;
7695 gp_ci.pViewportState = &vp_state_ci;
7696 gp_ci.pRasterizationState = &rs_ci;
7697 gp_ci.pColorBlendState = &cb_ci;
7698 gp_ci.pDynamicState = &dyn_state_ci;
7699 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7700 gp_ci.layout = pipeline_layout;
7701 gp_ci.renderPass = renderPass();
7702
7703 VkPipelineCacheCreateInfo pc_ci = {};
7704 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7705
7706 VkPipeline pipeline;
7707 VkPipelineCache pipelineCache;
7708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007709 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007710 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007711 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007712
7713 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007714 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007715
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007717
7718 // Check too high (line width of 65536.0f).
7719 rs_ci.lineWidth = 65536.0f;
7720
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007721 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007722 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007723 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007724
7725 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007726 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007729
7730 dyn_state_ci.dynamicStateCount = 3;
7731
7732 rs_ci.lineWidth = 1.0f;
7733
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007734 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007735 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007737 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007739
7740 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007741 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007742 m_errorMonitor->VerifyFound();
7743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007745
7746 // Check too high with dynamic setting.
7747 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7748 m_errorMonitor->VerifyFound();
7749 EndCommandBuffer();
7750
7751 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7752 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7753 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7754 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007755 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007756}
7757
Karl Schultz6addd812016-02-02 17:17:23 -07007758TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007759 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7761 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007762
7763 ASSERT_NO_FATAL_FAILURE(InitState());
7764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007765
Tony Barbourfe3351b2015-07-28 10:17:20 -06007766 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007767 // Don't care about RenderPass handle b/c error should be flagged before
7768 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007769 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007770
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007771 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007772}
7773
Karl Schultz6addd812016-02-02 17:17:23 -07007774TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007775 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7777 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007778
7779 ASSERT_NO_FATAL_FAILURE(InitState());
7780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007781
Tony Barbourfe3351b2015-07-28 10:17:20 -06007782 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007783 // Just create a dummy Renderpass that's non-NULL so we can get to the
7784 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007785 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007786
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007787 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007788}
7789
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007790TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7791 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7792 "the number of renderPass attachments that use loadOp"
7793 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7794
7795 ASSERT_NO_FATAL_FAILURE(InitState());
7796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7797
7798 // Create a renderPass with a single attachment that uses loadOp CLEAR
7799 VkAttachmentReference attach = {};
7800 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7801 VkSubpassDescription subpass = {};
7802 subpass.inputAttachmentCount = 1;
7803 subpass.pInputAttachments = &attach;
7804 VkRenderPassCreateInfo rpci = {};
7805 rpci.subpassCount = 1;
7806 rpci.pSubpasses = &subpass;
7807 rpci.attachmentCount = 1;
7808 VkAttachmentDescription attach_desc = {};
7809 attach_desc.format = VK_FORMAT_UNDEFINED;
7810 // Set loadOp to CLEAR
7811 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7812 rpci.pAttachments = &attach_desc;
7813 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7814 VkRenderPass rp;
7815 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7816
7817 VkCommandBufferInheritanceInfo hinfo = {};
7818 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7819 hinfo.renderPass = VK_NULL_HANDLE;
7820 hinfo.subpass = 0;
7821 hinfo.framebuffer = VK_NULL_HANDLE;
7822 hinfo.occlusionQueryEnable = VK_FALSE;
7823 hinfo.queryFlags = 0;
7824 hinfo.pipelineStatistics = 0;
7825 VkCommandBufferBeginInfo info = {};
7826 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7827 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7828 info.pInheritanceInfo = &hinfo;
7829
7830 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7831 VkRenderPassBeginInfo rp_begin = {};
7832 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7833 rp_begin.pNext = NULL;
7834 rp_begin.renderPass = renderPass();
7835 rp_begin.framebuffer = framebuffer();
7836 rp_begin.clearValueCount = 0; // Should be 1
7837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7839 "there must be at least 1 entries in "
7840 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007841
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007843
7844 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007845
7846 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007847}
7848
Cody Northrop3bb4d962016-05-09 16:15:57 -06007849TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7850
7851 TEST_DESCRIPTION("End a command buffer with an active render pass");
7852
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7854 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007855
7856 ASSERT_NO_FATAL_FAILURE(InitState());
7857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7858
7859 // The framework's BeginCommandBuffer calls CreateRenderPass
7860 BeginCommandBuffer();
7861
7862 // Call directly into vkEndCommandBuffer instead of the
7863 // the framework's EndCommandBuffer, which inserts a
7864 // vkEndRenderPass
7865 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7866
7867 m_errorMonitor->VerifyFound();
7868
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007869 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7870 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007871}
7872
Karl Schultz6addd812016-02-02 17:17:23 -07007873TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007874 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7876 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007877
7878 ASSERT_NO_FATAL_FAILURE(InitState());
7879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007880
7881 // Renderpass is started here
7882 BeginCommandBuffer();
7883
7884 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007885 vk_testing::Buffer dstBuffer;
7886 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007887
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007888 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
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
Karl Schultz6addd812016-02-02 17:17:23 -07007893TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007894 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7896 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007897
7898 ASSERT_NO_FATAL_FAILURE(InitState());
7899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007900
7901 // Renderpass is started here
7902 BeginCommandBuffer();
7903
7904 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007905 vk_testing::Buffer dstBuffer;
7906 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007907
Karl Schultz6addd812016-02-02 17:17:23 -07007908 VkDeviceSize dstOffset = 0;
7909 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007910 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007913
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007914 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007915}
7916
Karl Schultz6addd812016-02-02 17:17:23 -07007917TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007918 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7920 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007921
7922 ASSERT_NO_FATAL_FAILURE(InitState());
7923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007924
7925 // Renderpass is started here
7926 BeginCommandBuffer();
7927
Michael Lentine0a369f62016-02-03 16:51:46 -06007928 VkClearColorValue clear_color;
7929 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007930 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7931 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7932 const int32_t tex_width = 32;
7933 const int32_t tex_height = 32;
7934 VkImageCreateInfo image_create_info = {};
7935 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7936 image_create_info.pNext = NULL;
7937 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7938 image_create_info.format = tex_format;
7939 image_create_info.extent.width = tex_width;
7940 image_create_info.extent.height = tex_height;
7941 image_create_info.extent.depth = 1;
7942 image_create_info.mipLevels = 1;
7943 image_create_info.arrayLayers = 1;
7944 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7945 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7946 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007947
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007948 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007949 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007950
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007951 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007953 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007954
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007955 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007956}
7957
Karl Schultz6addd812016-02-02 17:17:23 -07007958TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007959 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7961 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007962
7963 ASSERT_NO_FATAL_FAILURE(InitState());
7964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007965
7966 // Renderpass is started here
7967 BeginCommandBuffer();
7968
7969 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007970 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007971 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7973 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7974 image_create_info.extent.width = 64;
7975 image_create_info.extent.height = 64;
7976 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7977 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007978
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007979 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007980 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007982 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007983
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007984 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7985 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007987 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007988}
7989
Karl Schultz6addd812016-02-02 17:17:23 -07007990TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007991 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007992 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007993
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7995 "must be issued inside an active "
7996 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007997
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007998 ASSERT_NO_FATAL_FAILURE(InitState());
7999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008000
8001 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008002 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008003 ASSERT_VK_SUCCESS(err);
8004
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008005 VkClearAttachment color_attachment;
8006 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8007 color_attachment.clearValue.color.float32[0] = 0;
8008 color_attachment.clearValue.color.float32[1] = 0;
8009 color_attachment.clearValue.color.float32[2] = 0;
8010 color_attachment.clearValue.color.float32[3] = 0;
8011 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008012 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008014
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008015 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008016}
8017
Chris Forbes3b97e932016-09-07 11:29:24 +12008018TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8019 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8020 "called too many times in a renderpass instance");
8021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8023 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008024
8025 ASSERT_NO_FATAL_FAILURE(InitState());
8026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8027
8028 BeginCommandBuffer();
8029
8030 // error here.
8031 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8032 m_errorMonitor->VerifyFound();
8033
8034 EndCommandBuffer();
8035}
8036
Chris Forbes6d624702016-09-07 13:57:05 +12008037TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8038 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8039 "called before the final subpass has been reached");
8040
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8042 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008043
8044 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008045 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8046 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008048 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008049
8050 VkRenderPass rp;
8051 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8052 ASSERT_VK_SUCCESS(err);
8053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008054 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008055
8056 VkFramebuffer fb;
8057 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8058 ASSERT_VK_SUCCESS(err);
8059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008060 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008062 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 +12008063
8064 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8065
8066 // Error here.
8067 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8068 m_errorMonitor->VerifyFound();
8069
8070 // Clean up.
8071 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8072 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8073}
8074
Karl Schultz9e66a292016-04-21 15:57:51 -06008075TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8076 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8078 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008079
8080 ASSERT_NO_FATAL_FAILURE(InitState());
8081 BeginCommandBuffer();
8082
8083 VkBufferMemoryBarrier buf_barrier = {};
8084 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8085 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8086 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8087 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8088 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8089 buf_barrier.buffer = VK_NULL_HANDLE;
8090 buf_barrier.offset = 0;
8091 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008092 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8093 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008094
8095 m_errorMonitor->VerifyFound();
8096}
8097
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008098TEST_F(VkLayerTest, InvalidBarriers) {
8099 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8100
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008102
8103 ASSERT_NO_FATAL_FAILURE(InitState());
8104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8105
8106 VkMemoryBarrier mem_barrier = {};
8107 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8108 mem_barrier.pNext = NULL;
8109 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8110 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8111 BeginCommandBuffer();
8112 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008113 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008114 &mem_barrier, 0, nullptr, 0, nullptr);
8115 m_errorMonitor->VerifyFound();
8116
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008118 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 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 -06008120 ASSERT_TRUE(image.initialized());
8121 VkImageMemoryBarrier img_barrier = {};
8122 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8123 img_barrier.pNext = NULL;
8124 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8125 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8126 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8127 // New layout can't be UNDEFINED
8128 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8129 img_barrier.image = image.handle();
8130 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8131 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8132 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8133 img_barrier.subresourceRange.baseArrayLayer = 0;
8134 img_barrier.subresourceRange.baseMipLevel = 0;
8135 img_barrier.subresourceRange.layerCount = 1;
8136 img_barrier.subresourceRange.levelCount = 1;
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);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008139 m_errorMonitor->VerifyFound();
8140 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8143 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008144 // baseArrayLayer + layerCount must be <= image's arrayLayers
8145 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008146 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8147 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008148 m_errorMonitor->VerifyFound();
8149 img_barrier.subresourceRange.baseArrayLayer = 0;
8150
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008152 // baseMipLevel + levelCount must be <= image's mipLevels
8153 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008154 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8155 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008156 m_errorMonitor->VerifyFound();
8157 img_barrier.subresourceRange.baseMipLevel = 0;
8158
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008159 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 -06008160 vk_testing::Buffer buffer;
8161 buffer.init(*m_device, 256);
8162 VkBufferMemoryBarrier buf_barrier = {};
8163 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8164 buf_barrier.pNext = NULL;
8165 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8166 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8167 buf_barrier.buffer = buffer.handle();
8168 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8169 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8170 buf_barrier.offset = 0;
8171 buf_barrier.size = VK_WHOLE_SIZE;
8172 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8174 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008175 m_errorMonitor->VerifyFound();
8176 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8177
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008179 buf_barrier.offset = 257;
8180 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008181 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8182 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008183 m_errorMonitor->VerifyFound();
8184 buf_barrier.offset = 0;
8185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008187 buf_barrier.size = 257;
8188 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008189 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8190 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008191 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008192
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008193 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008194 m_errorMonitor->SetDesiredFailureMsg(
8195 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8196 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8197 m_errorMonitor->SetDesiredFailureMsg(
8198 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8199 "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 -06008200 VkDepthStencilObj ds_image(m_device);
8201 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8202 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008203 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8204 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008205 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008206 // Use of COLOR aspect on DS image is error
8207 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008208 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8209 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008210 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008211 // Now test depth-only
8212 VkFormatProperties format_props;
8213
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008214 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8215 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8217 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8219 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008220 VkDepthStencilObj d_image(m_device);
8221 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8222 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008223 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008224 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008225 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008226 // Use of COLOR aspect on depth image is error
8227 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008228 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8229 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008230 m_errorMonitor->VerifyFound();
8231 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008232 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8233 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008234 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8236 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008237 VkDepthStencilObj s_image(m_device);
8238 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8239 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008240 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008241 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008242 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008243 // Use of COLOR aspect on depth image is error
8244 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008245 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8246 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008247 m_errorMonitor->VerifyFound();
8248 }
8249 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8251 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8253 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008254 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008255 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 -06008256 ASSERT_TRUE(c_image.initialized());
8257 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8258 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8259 img_barrier.image = c_image.handle();
8260 // Set aspect to depth (non-color)
8261 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008262 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8263 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008264 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008265}
8266
Tony Barbour18ba25c2016-09-29 13:42:40 -06008267TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8268 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8269
8270 m_errorMonitor->SetDesiredFailureMsg(
8271 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8272 "must have required access bit");
8273 ASSERT_NO_FATAL_FAILURE(InitState());
8274 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008275 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 -06008276 ASSERT_TRUE(image.initialized());
8277
8278 VkImageMemoryBarrier barrier = {};
8279 VkImageSubresourceRange range;
8280 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8281 barrier.srcAccessMask = 0;
8282 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8283 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8284 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8285 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8286 barrier.image = image.handle();
8287 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8288 range.baseMipLevel = 0;
8289 range.levelCount = 1;
8290 range.baseArrayLayer = 0;
8291 range.layerCount = 1;
8292 barrier.subresourceRange = range;
8293 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8294 cmdbuf.BeginCommandBuffer();
8295 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8296 &barrier);
8297 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8298 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8299 barrier.srcAccessMask = 0;
8300 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8301 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8302 &barrier);
8303
8304 m_errorMonitor->VerifyFound();
8305}
8306
Karl Schultz6addd812016-02-02 17:17:23 -07008307TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008308 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008309 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008310
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008312
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008313 ASSERT_NO_FATAL_FAILURE(InitState());
8314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008315 uint32_t qfi = 0;
8316 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008317 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8318 buffCI.size = 1024;
8319 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8320 buffCI.queueFamilyIndexCount = 1;
8321 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008322
8323 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008324 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008325 ASSERT_VK_SUCCESS(err);
8326
8327 BeginCommandBuffer();
8328 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008329 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8330 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008331 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008332 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008334 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008335
Chia-I Wuf7458c52015-10-26 21:10:41 +08008336 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008337}
8338
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008339TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8340 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8342 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8343 "of the indices specified when the device was created, via the "
8344 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008345
8346 ASSERT_NO_FATAL_FAILURE(InitState());
8347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8348 VkBufferCreateInfo buffCI = {};
8349 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8350 buffCI.size = 1024;
8351 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8352 buffCI.queueFamilyIndexCount = 1;
8353 // Introduce failure by specifying invalid queue_family_index
8354 uint32_t qfi = 777;
8355 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008356 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008357
8358 VkBuffer ib;
8359 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008361 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008362 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008363}
8364
Karl Schultz6addd812016-02-02 17:17:23 -07008365TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008366TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008367 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008368
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008369 ASSERT_NO_FATAL_FAILURE(InitState());
8370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008371
Chris Forbesf29a84f2016-10-06 18:39:28 +13008372 // An empty primary command buffer
8373 VkCommandBufferObj cb(m_device, m_commandPool);
8374 cb.BeginCommandBuffer();
8375 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008376
Chris Forbesf29a84f2016-10-06 18:39:28 +13008377 m_commandBuffer->BeginCommandBuffer();
8378 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8379 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008380
Chris Forbesf29a84f2016-10-06 18:39:28 +13008381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8382 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008383 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008384}
8385
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008386TEST_F(VkLayerTest, DSUsageBitsErrors) {
8387 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8388 "that do not have correct usage bits sets.");
8389 VkResult err;
8390
8391 ASSERT_NO_FATAL_FAILURE(InitState());
8392 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8393 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8394 ds_type_count[i].type = VkDescriptorType(i);
8395 ds_type_count[i].descriptorCount = 1;
8396 }
8397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8399 ds_pool_ci.pNext = NULL;
8400 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8401 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8402 ds_pool_ci.pPoolSizes = ds_type_count;
8403
8404 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008406 ASSERT_VK_SUCCESS(err);
8407
8408 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008409 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008410 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8411 dsl_binding[i].binding = 0;
8412 dsl_binding[i].descriptorType = VkDescriptorType(i);
8413 dsl_binding[i].descriptorCount = 1;
8414 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8415 dsl_binding[i].pImmutableSamplers = NULL;
8416 }
8417
8418 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8419 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8420 ds_layout_ci.pNext = NULL;
8421 ds_layout_ci.bindingCount = 1;
8422 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8423 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8424 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008426 ASSERT_VK_SUCCESS(err);
8427 }
8428 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8429 VkDescriptorSetAllocateInfo alloc_info = {};
8430 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8431 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8432 alloc_info.descriptorPool = ds_pool;
8433 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008435 ASSERT_VK_SUCCESS(err);
8436
8437 // Create a buffer & bufferView to be used for invalid updates
8438 VkBufferCreateInfo buff_ci = {};
8439 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8440 // This usage is not valid for any descriptor type
8441 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8442 buff_ci.size = 256;
8443 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8444 VkBuffer buffer;
8445 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8446 ASSERT_VK_SUCCESS(err);
8447
8448 VkBufferViewCreateInfo buff_view_ci = {};
8449 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8450 buff_view_ci.buffer = buffer;
8451 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8452 buff_view_ci.range = VK_WHOLE_SIZE;
8453 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008455 ASSERT_VK_SUCCESS(err);
8456
8457 // Create an image to be used for invalid updates
8458 VkImageCreateInfo image_ci = {};
8459 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8460 image_ci.imageType = VK_IMAGE_TYPE_2D;
8461 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8462 image_ci.extent.width = 64;
8463 image_ci.extent.height = 64;
8464 image_ci.extent.depth = 1;
8465 image_ci.mipLevels = 1;
8466 image_ci.arrayLayers = 1;
8467 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8468 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8469 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8470 // This usage is not valid for any descriptor type
8471 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8472 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8473 VkImage image;
8474 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8475 ASSERT_VK_SUCCESS(err);
8476 // Bind memory to image
8477 VkMemoryRequirements mem_reqs;
8478 VkDeviceMemory image_mem;
8479 bool pass;
8480 VkMemoryAllocateInfo mem_alloc = {};
8481 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8482 mem_alloc.pNext = NULL;
8483 mem_alloc.allocationSize = 0;
8484 mem_alloc.memoryTypeIndex = 0;
8485 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8486 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008488 ASSERT_TRUE(pass);
8489 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8490 ASSERT_VK_SUCCESS(err);
8491 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8492 ASSERT_VK_SUCCESS(err);
8493 // Now create view for image
8494 VkImageViewCreateInfo image_view_ci = {};
8495 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8496 image_view_ci.image = image;
8497 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8498 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8499 image_view_ci.subresourceRange.layerCount = 1;
8500 image_view_ci.subresourceRange.baseArrayLayer = 0;
8501 image_view_ci.subresourceRange.levelCount = 1;
8502 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8503 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008504 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008505 ASSERT_VK_SUCCESS(err);
8506
8507 VkDescriptorBufferInfo buff_info = {};
8508 buff_info.buffer = buffer;
8509 VkDescriptorImageInfo img_info = {};
8510 img_info.imageView = image_view;
8511 VkWriteDescriptorSet descriptor_write = {};
8512 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8513 descriptor_write.dstBinding = 0;
8514 descriptor_write.descriptorCount = 1;
8515 descriptor_write.pTexelBufferView = &buff_view;
8516 descriptor_write.pBufferInfo = &buff_info;
8517 descriptor_write.pImageInfo = &img_info;
8518
8519 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008520 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8521 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8522 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8523 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8524 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8525 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8526 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8527 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8528 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8529 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8530 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008531 // Start loop at 1 as SAMPLER desc type has no usage bit error
8532 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8533 descriptor_write.descriptorType = VkDescriptorType(i);
8534 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008536
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008537 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008538
8539 m_errorMonitor->VerifyFound();
8540 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8541 }
8542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8543 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008544 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008545 vkDestroyImageView(m_device->device(), image_view, NULL);
8546 vkDestroyBuffer(m_device->device(), buffer, NULL);
8547 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008548 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008549 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8550}
8551
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008552TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008553 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8554 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8555 "1. offset value greater than buffer size\n"
8556 "2. range value of 0\n"
8557 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008558 VkResult err;
8559
8560 ASSERT_NO_FATAL_FAILURE(InitState());
8561 VkDescriptorPoolSize ds_type_count = {};
8562 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8563 ds_type_count.descriptorCount = 1;
8564
8565 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8566 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8567 ds_pool_ci.pNext = NULL;
8568 ds_pool_ci.maxSets = 1;
8569 ds_pool_ci.poolSizeCount = 1;
8570 ds_pool_ci.pPoolSizes = &ds_type_count;
8571
8572 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008573 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008574 ASSERT_VK_SUCCESS(err);
8575
8576 // Create layout with single uniform buffer descriptor
8577 VkDescriptorSetLayoutBinding dsl_binding = {};
8578 dsl_binding.binding = 0;
8579 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8580 dsl_binding.descriptorCount = 1;
8581 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8582 dsl_binding.pImmutableSamplers = NULL;
8583
8584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8586 ds_layout_ci.pNext = NULL;
8587 ds_layout_ci.bindingCount = 1;
8588 ds_layout_ci.pBindings = &dsl_binding;
8589 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008590 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008591 ASSERT_VK_SUCCESS(err);
8592
8593 VkDescriptorSet descriptor_set = {};
8594 VkDescriptorSetAllocateInfo alloc_info = {};
8595 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8596 alloc_info.descriptorSetCount = 1;
8597 alloc_info.descriptorPool = ds_pool;
8598 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008599 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008600 ASSERT_VK_SUCCESS(err);
8601
8602 // Create a buffer to be used for invalid updates
8603 VkBufferCreateInfo buff_ci = {};
8604 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8605 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8606 buff_ci.size = 256;
8607 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8608 VkBuffer buffer;
8609 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8610 ASSERT_VK_SUCCESS(err);
8611 // Have to bind memory to buffer before descriptor update
8612 VkMemoryAllocateInfo mem_alloc = {};
8613 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8614 mem_alloc.pNext = NULL;
8615 mem_alloc.allocationSize = 256;
8616 mem_alloc.memoryTypeIndex = 0;
8617
8618 VkMemoryRequirements mem_reqs;
8619 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008621 if (!pass) {
8622 vkDestroyBuffer(m_device->device(), buffer, NULL);
8623 return;
8624 }
8625
8626 VkDeviceMemory mem;
8627 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8628 ASSERT_VK_SUCCESS(err);
8629 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8630 ASSERT_VK_SUCCESS(err);
8631
8632 VkDescriptorBufferInfo buff_info = {};
8633 buff_info.buffer = buffer;
8634 // First make offset 1 larger than buffer size
8635 buff_info.offset = 257;
8636 buff_info.range = VK_WHOLE_SIZE;
8637 VkWriteDescriptorSet descriptor_write = {};
8638 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8639 descriptor_write.dstBinding = 0;
8640 descriptor_write.descriptorCount = 1;
8641 descriptor_write.pTexelBufferView = nullptr;
8642 descriptor_write.pBufferInfo = &buff_info;
8643 descriptor_write.pImageInfo = nullptr;
8644
8645 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8646 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008648
8649 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8650
8651 m_errorMonitor->VerifyFound();
8652 // Now cause error due to range of 0
8653 buff_info.offset = 0;
8654 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8656 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008657
8658 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8659
8660 m_errorMonitor->VerifyFound();
8661 // Now cause error due to range exceeding buffer size - offset
8662 buff_info.offset = 128;
8663 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 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 -06008665
8666 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8667
8668 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008669 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008670 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8671 vkDestroyBuffer(m_device->device(), buffer, NULL);
8672 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8673 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8674}
8675
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008676TEST_F(VkLayerTest, DSAspectBitsErrors) {
8677 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8678 // are set, but could expand this test to hit more cases.
8679 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8680 "that do not have correct aspect bits sets.");
8681 VkResult err;
8682
8683 ASSERT_NO_FATAL_FAILURE(InitState());
8684 VkDescriptorPoolSize ds_type_count = {};
8685 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8686 ds_type_count.descriptorCount = 1;
8687
8688 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8689 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8690 ds_pool_ci.pNext = NULL;
8691 ds_pool_ci.maxSets = 5;
8692 ds_pool_ci.poolSizeCount = 1;
8693 ds_pool_ci.pPoolSizes = &ds_type_count;
8694
8695 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008697 ASSERT_VK_SUCCESS(err);
8698
8699 VkDescriptorSetLayoutBinding dsl_binding = {};
8700 dsl_binding.binding = 0;
8701 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8702 dsl_binding.descriptorCount = 1;
8703 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8704 dsl_binding.pImmutableSamplers = NULL;
8705
8706 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8707 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8708 ds_layout_ci.pNext = NULL;
8709 ds_layout_ci.bindingCount = 1;
8710 ds_layout_ci.pBindings = &dsl_binding;
8711 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008712 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008713 ASSERT_VK_SUCCESS(err);
8714
8715 VkDescriptorSet descriptor_set = {};
8716 VkDescriptorSetAllocateInfo alloc_info = {};
8717 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8718 alloc_info.descriptorSetCount = 1;
8719 alloc_info.descriptorPool = ds_pool;
8720 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008721 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008722 ASSERT_VK_SUCCESS(err);
8723
8724 // Create an image to be used for invalid updates
8725 VkImageCreateInfo image_ci = {};
8726 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8727 image_ci.imageType = VK_IMAGE_TYPE_2D;
8728 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8729 image_ci.extent.width = 64;
8730 image_ci.extent.height = 64;
8731 image_ci.extent.depth = 1;
8732 image_ci.mipLevels = 1;
8733 image_ci.arrayLayers = 1;
8734 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8735 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8736 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8737 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8738 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8739 VkImage image;
8740 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8741 ASSERT_VK_SUCCESS(err);
8742 // Bind memory to image
8743 VkMemoryRequirements mem_reqs;
8744 VkDeviceMemory image_mem;
8745 bool pass;
8746 VkMemoryAllocateInfo mem_alloc = {};
8747 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8748 mem_alloc.pNext = NULL;
8749 mem_alloc.allocationSize = 0;
8750 mem_alloc.memoryTypeIndex = 0;
8751 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8752 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008753 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008754 ASSERT_TRUE(pass);
8755 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8756 ASSERT_VK_SUCCESS(err);
8757 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8758 ASSERT_VK_SUCCESS(err);
8759 // Now create view for image
8760 VkImageViewCreateInfo image_view_ci = {};
8761 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8762 image_view_ci.image = image;
8763 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8764 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8765 image_view_ci.subresourceRange.layerCount = 1;
8766 image_view_ci.subresourceRange.baseArrayLayer = 0;
8767 image_view_ci.subresourceRange.levelCount = 1;
8768 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008769 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008770
8771 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008772 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008773 ASSERT_VK_SUCCESS(err);
8774
8775 VkDescriptorImageInfo img_info = {};
8776 img_info.imageView = image_view;
8777 VkWriteDescriptorSet descriptor_write = {};
8778 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8779 descriptor_write.dstBinding = 0;
8780 descriptor_write.descriptorCount = 1;
8781 descriptor_write.pTexelBufferView = NULL;
8782 descriptor_write.pBufferInfo = NULL;
8783 descriptor_write.pImageInfo = &img_info;
8784 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8785 descriptor_write.dstSet = descriptor_set;
8786 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8787 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008789
8790 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8791
8792 m_errorMonitor->VerifyFound();
8793 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8794 vkDestroyImage(m_device->device(), image, NULL);
8795 vkFreeMemory(m_device->device(), image_mem, NULL);
8796 vkDestroyImageView(m_device->device(), image_view, NULL);
8797 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8798 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8799}
8800
Karl Schultz6addd812016-02-02 17:17:23 -07008801TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008802 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008803 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8806 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8807 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008808
Tobin Ehlis3b780662015-05-28 12:11:26 -06008809 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008810 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008811 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008812 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8813 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008814
8815 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008816 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8817 ds_pool_ci.pNext = NULL;
8818 ds_pool_ci.maxSets = 1;
8819 ds_pool_ci.poolSizeCount = 1;
8820 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008821
Tobin Ehlis3b780662015-05-28 12:11:26 -06008822 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008823 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008824 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008825 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008826 dsl_binding.binding = 0;
8827 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8828 dsl_binding.descriptorCount = 1;
8829 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8830 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008831
Tony Barboureb254902015-07-15 12:50:33 -06008832 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008833 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8834 ds_layout_ci.pNext = NULL;
8835 ds_layout_ci.bindingCount = 1;
8836 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008837
Tobin Ehlis3b780662015-05-28 12:11:26 -06008838 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008839 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008840 ASSERT_VK_SUCCESS(err);
8841
8842 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008843 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008844 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008845 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008846 alloc_info.descriptorPool = ds_pool;
8847 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008848 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008849 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008850
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008851 VkSamplerCreateInfo sampler_ci = {};
8852 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8853 sampler_ci.pNext = NULL;
8854 sampler_ci.magFilter = VK_FILTER_NEAREST;
8855 sampler_ci.minFilter = VK_FILTER_NEAREST;
8856 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8857 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8858 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8859 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8860 sampler_ci.mipLodBias = 1.0;
8861 sampler_ci.anisotropyEnable = VK_FALSE;
8862 sampler_ci.maxAnisotropy = 1;
8863 sampler_ci.compareEnable = VK_FALSE;
8864 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8865 sampler_ci.minLod = 1.0;
8866 sampler_ci.maxLod = 1.0;
8867 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8868 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8869 VkSampler sampler;
8870 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8871 ASSERT_VK_SUCCESS(err);
8872
8873 VkDescriptorImageInfo info = {};
8874 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008875
8876 VkWriteDescriptorSet descriptor_write;
8877 memset(&descriptor_write, 0, sizeof(descriptor_write));
8878 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008879 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008880 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008881 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008882 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008883 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008884
8885 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8886
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008887 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008888
Chia-I Wuf7458c52015-10-26 21:10:41 +08008889 vkDestroySampler(m_device->device(), sampler, NULL);
8890 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8891 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008892}
8893
Karl Schultz6addd812016-02-02 17:17:23 -07008894TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008895 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008896 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8899 " binding #0 with 1 total descriptors but update of 1 descriptors "
8900 "starting at binding offset of 0 combined with update array element "
8901 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008902
Tobin Ehlis3b780662015-05-28 12:11:26 -06008903 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008904 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008905 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008906 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8907 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008908
8909 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008910 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8911 ds_pool_ci.pNext = NULL;
8912 ds_pool_ci.maxSets = 1;
8913 ds_pool_ci.poolSizeCount = 1;
8914 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008915
Tobin Ehlis3b780662015-05-28 12:11:26 -06008916 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008917 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008918 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008919
Tony Barboureb254902015-07-15 12:50:33 -06008920 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008921 dsl_binding.binding = 0;
8922 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8923 dsl_binding.descriptorCount = 1;
8924 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8925 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008926
8927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8929 ds_layout_ci.pNext = NULL;
8930 ds_layout_ci.bindingCount = 1;
8931 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008932
Tobin Ehlis3b780662015-05-28 12:11:26 -06008933 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008935 ASSERT_VK_SUCCESS(err);
8936
8937 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008938 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008939 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008940 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008941 alloc_info.descriptorPool = ds_pool;
8942 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008943 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008944 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008945
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008946 // Correctly update descriptor to avoid "NOT_UPDATED" error
8947 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008948 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008949 buff_info.offset = 0;
8950 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008951
8952 VkWriteDescriptorSet descriptor_write;
8953 memset(&descriptor_write, 0, sizeof(descriptor_write));
8954 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008955 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008957 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008958 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8959 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008960
8961 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8962
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008963 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008964
Chia-I Wuf7458c52015-10-26 21:10:41 +08008965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008967}
8968
Karl Schultz6addd812016-02-02 17:17:23 -07008969TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008970 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07008971 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008972
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07008973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008974
Tobin Ehlis3b780662015-05-28 12:11:26 -06008975 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008976 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008977 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008978 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8979 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008980
8981 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008982 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8983 ds_pool_ci.pNext = NULL;
8984 ds_pool_ci.maxSets = 1;
8985 ds_pool_ci.poolSizeCount = 1;
8986 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008987
Tobin Ehlis3b780662015-05-28 12:11:26 -06008988 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008989 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008990 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008991
Tony Barboureb254902015-07-15 12:50:33 -06008992 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008993 dsl_binding.binding = 0;
8994 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8995 dsl_binding.descriptorCount = 1;
8996 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8997 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008998
8999 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009000 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9001 ds_layout_ci.pNext = NULL;
9002 ds_layout_ci.bindingCount = 1;
9003 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009004 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009005 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009006 ASSERT_VK_SUCCESS(err);
9007
9008 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009009 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009010 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009011 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009012 alloc_info.descriptorPool = ds_pool;
9013 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009014 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009015 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009016
Tony Barboureb254902015-07-15 12:50:33 -06009017 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009018 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9019 sampler_ci.pNext = NULL;
9020 sampler_ci.magFilter = VK_FILTER_NEAREST;
9021 sampler_ci.minFilter = VK_FILTER_NEAREST;
9022 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9023 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9024 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9025 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9026 sampler_ci.mipLodBias = 1.0;
9027 sampler_ci.anisotropyEnable = VK_FALSE;
9028 sampler_ci.maxAnisotropy = 1;
9029 sampler_ci.compareEnable = VK_FALSE;
9030 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9031 sampler_ci.minLod = 1.0;
9032 sampler_ci.maxLod = 1.0;
9033 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9034 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009035
Tobin Ehlis3b780662015-05-28 12:11:26 -06009036 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009037 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009038 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009039
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009040 VkDescriptorImageInfo info = {};
9041 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009042
9043 VkWriteDescriptorSet descriptor_write;
9044 memset(&descriptor_write, 0, sizeof(descriptor_write));
9045 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009046 descriptor_write.dstSet = descriptorSet;
9047 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009048 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009049 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009050 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009051 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009052
9053 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9054
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009055 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009056
Chia-I Wuf7458c52015-10-26 21:10:41 +08009057 vkDestroySampler(m_device->device(), sampler, NULL);
9058 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9059 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009060}
9061
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009062TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9063 // Create layout w/ empty binding and attempt to update it
9064 VkResult err;
9065
9066 ASSERT_NO_FATAL_FAILURE(InitState());
9067
9068 VkDescriptorPoolSize ds_type_count = {};
9069 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9070 ds_type_count.descriptorCount = 1;
9071
9072 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9073 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9074 ds_pool_ci.pNext = NULL;
9075 ds_pool_ci.maxSets = 1;
9076 ds_pool_ci.poolSizeCount = 1;
9077 ds_pool_ci.pPoolSizes = &ds_type_count;
9078
9079 VkDescriptorPool ds_pool;
9080 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9081 ASSERT_VK_SUCCESS(err);
9082
9083 VkDescriptorSetLayoutBinding dsl_binding = {};
9084 dsl_binding.binding = 0;
9085 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9086 dsl_binding.descriptorCount = 0;
9087 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9088 dsl_binding.pImmutableSamplers = NULL;
9089
9090 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9091 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9092 ds_layout_ci.pNext = NULL;
9093 ds_layout_ci.bindingCount = 1;
9094 ds_layout_ci.pBindings = &dsl_binding;
9095 VkDescriptorSetLayout ds_layout;
9096 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9097 ASSERT_VK_SUCCESS(err);
9098
9099 VkDescriptorSet descriptor_set;
9100 VkDescriptorSetAllocateInfo alloc_info = {};
9101 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9102 alloc_info.descriptorSetCount = 1;
9103 alloc_info.descriptorPool = ds_pool;
9104 alloc_info.pSetLayouts = &ds_layout;
9105 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9106 ASSERT_VK_SUCCESS(err);
9107
9108 VkSamplerCreateInfo sampler_ci = {};
9109 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9110 sampler_ci.magFilter = VK_FILTER_NEAREST;
9111 sampler_ci.minFilter = VK_FILTER_NEAREST;
9112 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9113 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9114 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9115 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9116 sampler_ci.mipLodBias = 1.0;
9117 sampler_ci.maxAnisotropy = 1;
9118 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9119 sampler_ci.minLod = 1.0;
9120 sampler_ci.maxLod = 1.0;
9121 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9122
9123 VkSampler sampler;
9124 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9125 ASSERT_VK_SUCCESS(err);
9126
9127 VkDescriptorImageInfo info = {};
9128 info.sampler = sampler;
9129
9130 VkWriteDescriptorSet descriptor_write;
9131 memset(&descriptor_write, 0, sizeof(descriptor_write));
9132 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9133 descriptor_write.dstSet = descriptor_set;
9134 descriptor_write.dstBinding = 0;
9135 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9136 // This is the wrong type, but empty binding error will be flagged first
9137 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9138 descriptor_write.pImageInfo = &info;
9139
9140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9141 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9142 m_errorMonitor->VerifyFound();
9143
9144 vkDestroySampler(m_device->device(), sampler, NULL);
9145 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9146 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9147}
9148
Karl Schultz6addd812016-02-02 17:17:23 -07009149TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9150 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9151 // types
9152 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009153
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009154 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 -06009155
Tobin Ehlis3b780662015-05-28 12:11:26 -06009156 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009157
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009158 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009159 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9160 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009161
9162 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009163 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9164 ds_pool_ci.pNext = NULL;
9165 ds_pool_ci.maxSets = 1;
9166 ds_pool_ci.poolSizeCount = 1;
9167 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009168
Tobin Ehlis3b780662015-05-28 12:11:26 -06009169 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009170 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009171 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009172 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009173 dsl_binding.binding = 0;
9174 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9175 dsl_binding.descriptorCount = 1;
9176 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9177 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009178
Tony Barboureb254902015-07-15 12:50:33 -06009179 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009180 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9181 ds_layout_ci.pNext = NULL;
9182 ds_layout_ci.bindingCount = 1;
9183 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009184
Tobin Ehlis3b780662015-05-28 12:11:26 -06009185 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009186 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009187 ASSERT_VK_SUCCESS(err);
9188
9189 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009190 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009191 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009192 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009193 alloc_info.descriptorPool = ds_pool;
9194 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009195 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009196 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009197
Tony Barboureb254902015-07-15 12:50:33 -06009198 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009199 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9200 sampler_ci.pNext = NULL;
9201 sampler_ci.magFilter = VK_FILTER_NEAREST;
9202 sampler_ci.minFilter = VK_FILTER_NEAREST;
9203 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9204 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9205 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9206 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9207 sampler_ci.mipLodBias = 1.0;
9208 sampler_ci.anisotropyEnable = VK_FALSE;
9209 sampler_ci.maxAnisotropy = 1;
9210 sampler_ci.compareEnable = VK_FALSE;
9211 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9212 sampler_ci.minLod = 1.0;
9213 sampler_ci.maxLod = 1.0;
9214 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9215 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009216 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009217 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009218 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009219
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009220 VkDescriptorImageInfo info = {};
9221 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009222
9223 VkWriteDescriptorSet descriptor_write;
9224 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009225 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009226 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009227 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009228 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009229 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009230 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009231
9232 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009234 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009235
Chia-I Wuf7458c52015-10-26 21:10:41 +08009236 vkDestroySampler(m_device->device(), sampler, NULL);
9237 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9238 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009239}
9240
Karl Schultz6addd812016-02-02 17:17:23 -07009241TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009242 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009243 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009244
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9246 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009247
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009248 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009249 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9250 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009251 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009252 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9253 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009254
9255 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009256 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9257 ds_pool_ci.pNext = NULL;
9258 ds_pool_ci.maxSets = 1;
9259 ds_pool_ci.poolSizeCount = 1;
9260 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009261
9262 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009263 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009264 ASSERT_VK_SUCCESS(err);
9265
9266 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009267 dsl_binding.binding = 0;
9268 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9269 dsl_binding.descriptorCount = 1;
9270 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9271 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009272
9273 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009274 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9275 ds_layout_ci.pNext = NULL;
9276 ds_layout_ci.bindingCount = 1;
9277 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009278 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009279 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009280 ASSERT_VK_SUCCESS(err);
9281
9282 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009283 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009284 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009285 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009286 alloc_info.descriptorPool = ds_pool;
9287 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009288 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009289 ASSERT_VK_SUCCESS(err);
9290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009291 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009292
9293 VkDescriptorImageInfo descriptor_info;
9294 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9295 descriptor_info.sampler = sampler;
9296
9297 VkWriteDescriptorSet descriptor_write;
9298 memset(&descriptor_write, 0, sizeof(descriptor_write));
9299 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009300 descriptor_write.dstSet = descriptorSet;
9301 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009302 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009303 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9304 descriptor_write.pImageInfo = &descriptor_info;
9305
9306 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9307
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009308 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009309
Chia-I Wuf7458c52015-10-26 21:10:41 +08009310 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9311 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009312}
9313
Karl Schultz6addd812016-02-02 17:17:23 -07009314TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9315 // Create a single combined Image/Sampler descriptor and send it an invalid
9316 // imageView
9317 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9320 "image sampler descriptor failed due "
9321 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009322
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009323 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009324 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009325 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9326 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009327
9328 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009329 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9330 ds_pool_ci.pNext = NULL;
9331 ds_pool_ci.maxSets = 1;
9332 ds_pool_ci.poolSizeCount = 1;
9333 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009334
9335 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009337 ASSERT_VK_SUCCESS(err);
9338
9339 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009340 dsl_binding.binding = 0;
9341 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9342 dsl_binding.descriptorCount = 1;
9343 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9344 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009345
9346 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009347 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9348 ds_layout_ci.pNext = NULL;
9349 ds_layout_ci.bindingCount = 1;
9350 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009351 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009352 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009353 ASSERT_VK_SUCCESS(err);
9354
9355 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009356 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009357 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009358 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009359 alloc_info.descriptorPool = ds_pool;
9360 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009361 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009362 ASSERT_VK_SUCCESS(err);
9363
9364 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009365 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9366 sampler_ci.pNext = NULL;
9367 sampler_ci.magFilter = VK_FILTER_NEAREST;
9368 sampler_ci.minFilter = VK_FILTER_NEAREST;
9369 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9370 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9371 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9372 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9373 sampler_ci.mipLodBias = 1.0;
9374 sampler_ci.anisotropyEnable = VK_FALSE;
9375 sampler_ci.maxAnisotropy = 1;
9376 sampler_ci.compareEnable = VK_FALSE;
9377 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9378 sampler_ci.minLod = 1.0;
9379 sampler_ci.maxLod = 1.0;
9380 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9381 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009382
9383 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009384 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009385 ASSERT_VK_SUCCESS(err);
9386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009387 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009388
9389 VkDescriptorImageInfo descriptor_info;
9390 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9391 descriptor_info.sampler = sampler;
9392 descriptor_info.imageView = view;
9393
9394 VkWriteDescriptorSet descriptor_write;
9395 memset(&descriptor_write, 0, sizeof(descriptor_write));
9396 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009397 descriptor_write.dstSet = descriptorSet;
9398 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009399 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009400 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9401 descriptor_write.pImageInfo = &descriptor_info;
9402
9403 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9404
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009405 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009406
Chia-I Wuf7458c52015-10-26 21:10:41 +08009407 vkDestroySampler(m_device->device(), sampler, NULL);
9408 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9409 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009410}
9411
Karl Schultz6addd812016-02-02 17:17:23 -07009412TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9413 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9414 // into the other
9415 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9418 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9419 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009420
Tobin Ehlis04356f92015-10-27 16:35:27 -06009421 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009422 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009423 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009424 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9425 ds_type_count[0].descriptorCount = 1;
9426 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9427 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009428
9429 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009430 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9431 ds_pool_ci.pNext = NULL;
9432 ds_pool_ci.maxSets = 1;
9433 ds_pool_ci.poolSizeCount = 2;
9434 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009435
9436 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009437 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009438 ASSERT_VK_SUCCESS(err);
9439 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009440 dsl_binding[0].binding = 0;
9441 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9442 dsl_binding[0].descriptorCount = 1;
9443 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9444 dsl_binding[0].pImmutableSamplers = NULL;
9445 dsl_binding[1].binding = 1;
9446 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9447 dsl_binding[1].descriptorCount = 1;
9448 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9449 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009450
9451 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009452 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9453 ds_layout_ci.pNext = NULL;
9454 ds_layout_ci.bindingCount = 2;
9455 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009456
9457 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009459 ASSERT_VK_SUCCESS(err);
9460
9461 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009462 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009464 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009465 alloc_info.descriptorPool = ds_pool;
9466 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009468 ASSERT_VK_SUCCESS(err);
9469
9470 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009471 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9472 sampler_ci.pNext = NULL;
9473 sampler_ci.magFilter = VK_FILTER_NEAREST;
9474 sampler_ci.minFilter = VK_FILTER_NEAREST;
9475 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9476 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9477 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9478 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9479 sampler_ci.mipLodBias = 1.0;
9480 sampler_ci.anisotropyEnable = VK_FALSE;
9481 sampler_ci.maxAnisotropy = 1;
9482 sampler_ci.compareEnable = VK_FALSE;
9483 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9484 sampler_ci.minLod = 1.0;
9485 sampler_ci.maxLod = 1.0;
9486 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9487 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009488
9489 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009490 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009491 ASSERT_VK_SUCCESS(err);
9492
9493 VkDescriptorImageInfo info = {};
9494 info.sampler = sampler;
9495
9496 VkWriteDescriptorSet descriptor_write;
9497 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9498 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009499 descriptor_write.dstSet = descriptorSet;
9500 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009501 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009502 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9503 descriptor_write.pImageInfo = &info;
9504 // This write update should succeed
9505 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9506 // Now perform a copy update that fails due to type mismatch
9507 VkCopyDescriptorSet copy_ds_update;
9508 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9509 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9510 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009511 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009512 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009513 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009514 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009515 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9516
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009517 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009518 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009519 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 -06009520 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9521 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9522 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009523 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009524 copy_ds_update.dstSet = descriptorSet;
9525 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009526 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009527 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9528
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009529 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009530
Tobin Ehlis04356f92015-10-27 16:35:27 -06009531 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9533 "update array offset of 0 and update of "
9534 "5 descriptors oversteps total number "
9535 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009536
Tobin Ehlis04356f92015-10-27 16:35:27 -06009537 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9538 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9539 copy_ds_update.srcSet = descriptorSet;
9540 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009541 copy_ds_update.dstSet = descriptorSet;
9542 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009543 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009544 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9545
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009546 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009547
Chia-I Wuf7458c52015-10-26 21:10:41 +08009548 vkDestroySampler(m_device->device(), sampler, NULL);
9549 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9550 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009551}
9552
Karl Schultz6addd812016-02-02 17:17:23 -07009553TEST_F(VkLayerTest, NumSamplesMismatch) {
9554 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9555 // sampleCount
9556 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009557
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009559
Tobin Ehlis3b780662015-05-28 12:11:26 -06009560 ASSERT_NO_FATAL_FAILURE(InitState());
9561 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009562 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009563 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009564 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009565
9566 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009567 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9568 ds_pool_ci.pNext = NULL;
9569 ds_pool_ci.maxSets = 1;
9570 ds_pool_ci.poolSizeCount = 1;
9571 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009572
Tobin Ehlis3b780662015-05-28 12:11:26 -06009573 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009574 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009575 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009576
Tony Barboureb254902015-07-15 12:50:33 -06009577 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009578 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009579 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009580 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009581 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9582 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009583
Tony Barboureb254902015-07-15 12:50:33 -06009584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9586 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009587 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009588 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009589
Tobin Ehlis3b780662015-05-28 12:11:26 -06009590 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009591 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009592 ASSERT_VK_SUCCESS(err);
9593
9594 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009595 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009596 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009597 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009598 alloc_info.descriptorPool = ds_pool;
9599 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009600 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009601 ASSERT_VK_SUCCESS(err);
9602
Tony Barboureb254902015-07-15 12:50:33 -06009603 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009604 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009605 pipe_ms_state_ci.pNext = NULL;
9606 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9607 pipe_ms_state_ci.sampleShadingEnable = 0;
9608 pipe_ms_state_ci.minSampleShading = 1.0;
9609 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009610
Tony Barboureb254902015-07-15 12:50:33 -06009611 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009612 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9613 pipeline_layout_ci.pNext = NULL;
9614 pipeline_layout_ci.setLayoutCount = 1;
9615 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009616
9617 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009618 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009619 ASSERT_VK_SUCCESS(err);
9620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009621 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9622 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9623 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009624 VkPipelineObj pipe(m_device);
9625 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009626 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009627 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009628 pipe.SetMSAA(&pipe_ms_state_ci);
9629 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009630
Tony Barbourfe3351b2015-07-28 10:17:20 -06009631 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009632 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009633
Mark Young29927482016-05-04 14:38:51 -06009634 // Render triangle (the error should trigger on the attempt to draw).
9635 Draw(3, 1, 0, 0);
9636
9637 // Finalize recording of the command buffer
9638 EndCommandBuffer();
9639
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009640 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009641
Chia-I Wuf7458c52015-10-26 21:10:41 +08009642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9643 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9644 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009645}
Mark Young29927482016-05-04 14:38:51 -06009646
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009647TEST_F(VkLayerTest, RenderPassIncompatible) {
9648 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9649 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009650 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009651 VkResult err;
9652
9653 ASSERT_NO_FATAL_FAILURE(InitState());
9654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9655
9656 VkDescriptorSetLayoutBinding dsl_binding = {};
9657 dsl_binding.binding = 0;
9658 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9659 dsl_binding.descriptorCount = 1;
9660 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9661 dsl_binding.pImmutableSamplers = NULL;
9662
9663 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9664 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9665 ds_layout_ci.pNext = NULL;
9666 ds_layout_ci.bindingCount = 1;
9667 ds_layout_ci.pBindings = &dsl_binding;
9668
9669 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009670 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009671 ASSERT_VK_SUCCESS(err);
9672
9673 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9674 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9675 pipeline_layout_ci.pNext = NULL;
9676 pipeline_layout_ci.setLayoutCount = 1;
9677 pipeline_layout_ci.pSetLayouts = &ds_layout;
9678
9679 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009680 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009681 ASSERT_VK_SUCCESS(err);
9682
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009683 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9684 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9685 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009686 // Create a renderpass that will be incompatible with default renderpass
9687 VkAttachmentReference attach = {};
9688 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9689 VkAttachmentReference color_att = {};
9690 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9691 VkSubpassDescription subpass = {};
9692 subpass.inputAttachmentCount = 1;
9693 subpass.pInputAttachments = &attach;
9694 subpass.colorAttachmentCount = 1;
9695 subpass.pColorAttachments = &color_att;
9696 VkRenderPassCreateInfo rpci = {};
9697 rpci.subpassCount = 1;
9698 rpci.pSubpasses = &subpass;
9699 rpci.attachmentCount = 1;
9700 VkAttachmentDescription attach_desc = {};
9701 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009702 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9703 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009704 rpci.pAttachments = &attach_desc;
9705 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9706 VkRenderPass rp;
9707 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9708 VkPipelineObj pipe(m_device);
9709 pipe.AddShader(&vs);
9710 pipe.AddShader(&fs);
9711 pipe.AddColorAttachment();
9712 VkViewport view_port = {};
9713 m_viewports.push_back(view_port);
9714 pipe.SetViewport(m_viewports);
9715 VkRect2D rect = {};
9716 m_scissors.push_back(rect);
9717 pipe.SetScissor(m_scissors);
9718 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9719
9720 VkCommandBufferInheritanceInfo cbii = {};
9721 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9722 cbii.renderPass = rp;
9723 cbii.subpass = 0;
9724 VkCommandBufferBeginInfo cbbi = {};
9725 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9726 cbbi.pInheritanceInfo = &cbii;
9727 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9728 VkRenderPassBeginInfo rpbi = {};
9729 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9730 rpbi.framebuffer = m_framebuffer;
9731 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009732 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9733 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009734
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009736 // Render triangle (the error should trigger on the attempt to draw).
9737 Draw(3, 1, 0, 0);
9738
9739 // Finalize recording of the command buffer
9740 EndCommandBuffer();
9741
9742 m_errorMonitor->VerifyFound();
9743
9744 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9746 vkDestroyRenderPass(m_device->device(), rp, NULL);
9747}
9748
Mark Youngc89c6312016-03-31 16:03:20 -06009749TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9750 // Create Pipeline where the number of blend attachments doesn't match the
9751 // number of color attachments. In this case, we don't add any color
9752 // blend attachments even though we have a color attachment.
9753 VkResult err;
9754
9755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009756 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009757
9758 ASSERT_NO_FATAL_FAILURE(InitState());
9759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9760 VkDescriptorPoolSize ds_type_count = {};
9761 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9762 ds_type_count.descriptorCount = 1;
9763
9764 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9765 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9766 ds_pool_ci.pNext = NULL;
9767 ds_pool_ci.maxSets = 1;
9768 ds_pool_ci.poolSizeCount = 1;
9769 ds_pool_ci.pPoolSizes = &ds_type_count;
9770
9771 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009772 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009773 ASSERT_VK_SUCCESS(err);
9774
9775 VkDescriptorSetLayoutBinding dsl_binding = {};
9776 dsl_binding.binding = 0;
9777 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9778 dsl_binding.descriptorCount = 1;
9779 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9780 dsl_binding.pImmutableSamplers = NULL;
9781
9782 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9783 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9784 ds_layout_ci.pNext = NULL;
9785 ds_layout_ci.bindingCount = 1;
9786 ds_layout_ci.pBindings = &dsl_binding;
9787
9788 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009789 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009790 ASSERT_VK_SUCCESS(err);
9791
9792 VkDescriptorSet descriptorSet;
9793 VkDescriptorSetAllocateInfo alloc_info = {};
9794 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9795 alloc_info.descriptorSetCount = 1;
9796 alloc_info.descriptorPool = ds_pool;
9797 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009798 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009799 ASSERT_VK_SUCCESS(err);
9800
9801 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009802 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009803 pipe_ms_state_ci.pNext = NULL;
9804 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9805 pipe_ms_state_ci.sampleShadingEnable = 0;
9806 pipe_ms_state_ci.minSampleShading = 1.0;
9807 pipe_ms_state_ci.pSampleMask = NULL;
9808
9809 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9810 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9811 pipeline_layout_ci.pNext = NULL;
9812 pipeline_layout_ci.setLayoutCount = 1;
9813 pipeline_layout_ci.pSetLayouts = &ds_layout;
9814
9815 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009816 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009817 ASSERT_VK_SUCCESS(err);
9818
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009819 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9820 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9821 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009822 VkPipelineObj pipe(m_device);
9823 pipe.AddShader(&vs);
9824 pipe.AddShader(&fs);
9825 pipe.SetMSAA(&pipe_ms_state_ci);
9826 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9827
9828 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009830
Mark Young29927482016-05-04 14:38:51 -06009831 // Render triangle (the error should trigger on the attempt to draw).
9832 Draw(3, 1, 0, 0);
9833
9834 // Finalize recording of the command buffer
9835 EndCommandBuffer();
9836
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009837 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009838
9839 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9842}
Mark Young29927482016-05-04 14:38:51 -06009843
Mark Muellerd4914412016-06-13 17:52:06 -06009844TEST_F(VkLayerTest, MissingClearAttachment) {
9845 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9846 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009847 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009849 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009850
9851 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9852 m_errorMonitor->VerifyFound();
9853}
9854
Karl Schultz6addd812016-02-02 17:17:23 -07009855TEST_F(VkLayerTest, ClearCmdNoDraw) {
9856 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9857 // to issuing a Draw
9858 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009859
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009861 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009862
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009863 ASSERT_NO_FATAL_FAILURE(InitState());
9864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009865
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009866 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009867 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9868 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009869
9870 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009871 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9872 ds_pool_ci.pNext = NULL;
9873 ds_pool_ci.maxSets = 1;
9874 ds_pool_ci.poolSizeCount = 1;
9875 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009876
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009877 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009878 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009879 ASSERT_VK_SUCCESS(err);
9880
Tony Barboureb254902015-07-15 12:50:33 -06009881 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009882 dsl_binding.binding = 0;
9883 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9884 dsl_binding.descriptorCount = 1;
9885 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9886 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009887
Tony Barboureb254902015-07-15 12:50:33 -06009888 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009889 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9890 ds_layout_ci.pNext = NULL;
9891 ds_layout_ci.bindingCount = 1;
9892 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009893
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009894 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009896 ASSERT_VK_SUCCESS(err);
9897
9898 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009899 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009900 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009901 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009902 alloc_info.descriptorPool = ds_pool;
9903 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009904 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009905 ASSERT_VK_SUCCESS(err);
9906
Tony Barboureb254902015-07-15 12:50:33 -06009907 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009908 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009909 pipe_ms_state_ci.pNext = NULL;
9910 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9911 pipe_ms_state_ci.sampleShadingEnable = 0;
9912 pipe_ms_state_ci.minSampleShading = 1.0;
9913 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009914
Tony Barboureb254902015-07-15 12:50:33 -06009915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9917 pipeline_layout_ci.pNext = NULL;
9918 pipeline_layout_ci.setLayoutCount = 1;
9919 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009920
9921 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009922 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009923 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009924
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009925 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009926 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009927 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009928 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009929
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009930 VkPipelineObj pipe(m_device);
9931 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009932 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009933 pipe.SetMSAA(&pipe_ms_state_ci);
9934 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009935
9936 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009937
Karl Schultz6addd812016-02-02 17:17:23 -07009938 // Main thing we care about for this test is that the VkImage obj we're
9939 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009940 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009941 VkClearAttachment color_attachment;
9942 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9943 color_attachment.clearValue.color.float32[0] = 1.0;
9944 color_attachment.clearValue.color.float32[1] = 1.0;
9945 color_attachment.clearValue.color.float32[2] = 1.0;
9946 color_attachment.clearValue.color.float32[3] = 1.0;
9947 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009948 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009952 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009953
Chia-I Wuf7458c52015-10-26 21:10:41 +08009954 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9955 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9956 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009957}
9958
Karl Schultz6addd812016-02-02 17:17:23 -07009959TEST_F(VkLayerTest, VtxBufferBadIndex) {
9960 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9963 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009964
Tobin Ehlis502480b2015-06-24 15:53:07 -06009965 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009966 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009967 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009968
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009969 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009970 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9971 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009972
9973 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009974 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9975 ds_pool_ci.pNext = NULL;
9976 ds_pool_ci.maxSets = 1;
9977 ds_pool_ci.poolSizeCount = 1;
9978 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009979
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009980 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009981 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009982 ASSERT_VK_SUCCESS(err);
9983
Tony Barboureb254902015-07-15 12:50:33 -06009984 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009985 dsl_binding.binding = 0;
9986 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9987 dsl_binding.descriptorCount = 1;
9988 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9989 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009990
Tony Barboureb254902015-07-15 12:50:33 -06009991 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009992 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9993 ds_layout_ci.pNext = NULL;
9994 ds_layout_ci.bindingCount = 1;
9995 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009996
Tobin Ehlis502480b2015-06-24 15:53:07 -06009997 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009998 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009999 ASSERT_VK_SUCCESS(err);
10000
10001 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010002 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010003 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010004 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010005 alloc_info.descriptorPool = ds_pool;
10006 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010007 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010008 ASSERT_VK_SUCCESS(err);
10009
Tony Barboureb254902015-07-15 12:50:33 -060010010 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010011 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010012 pipe_ms_state_ci.pNext = NULL;
10013 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10014 pipe_ms_state_ci.sampleShadingEnable = 0;
10015 pipe_ms_state_ci.minSampleShading = 1.0;
10016 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010017
Tony Barboureb254902015-07-15 12:50:33 -060010018 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010019 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10020 pipeline_layout_ci.pNext = NULL;
10021 pipeline_layout_ci.setLayoutCount = 1;
10022 pipeline_layout_ci.pSetLayouts = &ds_layout;
10023 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010024
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010025 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010026 ASSERT_VK_SUCCESS(err);
10027
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010028 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10029 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10030 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010031 VkPipelineObj pipe(m_device);
10032 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010033 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010034 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010035 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010036 pipe.SetViewport(m_viewports);
10037 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010038 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010039
10040 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010041 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010042 // Don't care about actual data, just need to get to draw to flag error
10043 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010044 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010045 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010046 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010047
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010048 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010049
Chia-I Wuf7458c52015-10-26 21:10:41 +080010050 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10051 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10052 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010053}
Mark Muellerdfe37552016-07-07 14:47:42 -060010054
Mark Mueller2ee294f2016-08-04 12:59:48 -060010055TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10056 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10057 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010058 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010060 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
10061 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10064 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -060010069 // The following test fails with recent NVidia drivers.
10070 // By the time core_validation is reached, the NVidia
10071 // driver has sanitized the invalid condition and core_validation
10072 // is not introduced to the failure condition. This is not the case
10073 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010074 // uint32_t count = static_cast<uint32_t>(~0);
10075 // VkPhysicalDevice physical_device;
10076 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10077 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010080 float queue_priority = 0.0;
10081
10082 VkDeviceQueueCreateInfo queue_create_info = {};
10083 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10084 queue_create_info.queueCount = 1;
10085 queue_create_info.pQueuePriorities = &queue_priority;
10086 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10087
10088 VkPhysicalDeviceFeatures features = m_device->phy().features();
10089 VkDevice testDevice;
10090 VkDeviceCreateInfo device_create_info = {};
10091 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10092 device_create_info.queueCreateInfoCount = 1;
10093 device_create_info.pQueueCreateInfos = &queue_create_info;
10094 device_create_info.pEnabledFeatures = &features;
10095 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10096 m_errorMonitor->VerifyFound();
10097
10098 queue_create_info.queueFamilyIndex = 1;
10099
10100 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10101 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10102 for (unsigned i = 0; i < feature_count; i++) {
10103 if (VK_FALSE == feature_array[i]) {
10104 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010106 device_create_info.pEnabledFeatures = &features;
10107 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10108 m_errorMonitor->VerifyFound();
10109 break;
10110 }
10111 }
10112}
10113
Tobin Ehlis16edf082016-11-21 12:33:49 -070010114TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10115 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10116
10117 ASSERT_NO_FATAL_FAILURE(InitState());
10118
10119 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10120 std::vector<VkDeviceQueueCreateInfo> queue_info;
10121 queue_info.reserve(queue_props.size());
10122 std::vector<std::vector<float>> queue_priorities;
10123 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10124 VkDeviceQueueCreateInfo qi{};
10125 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10126 qi.queueFamilyIndex = i;
10127 qi.queueCount = queue_props[i].queueCount;
10128 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10129 qi.pQueuePriorities = queue_priorities[i].data();
10130 queue_info.push_back(qi);
10131 }
10132
10133 std::vector<const char *> device_extension_names;
10134
10135 VkDevice local_device;
10136 VkDeviceCreateInfo device_create_info = {};
10137 auto features = m_device->phy().features();
10138 // Intentionally disable pipeline stats
10139 features.pipelineStatisticsQuery = VK_FALSE;
10140 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10141 device_create_info.pNext = NULL;
10142 device_create_info.queueCreateInfoCount = queue_info.size();
10143 device_create_info.pQueueCreateInfos = queue_info.data();
10144 device_create_info.enabledLayerCount = 0;
10145 device_create_info.ppEnabledLayerNames = NULL;
10146 device_create_info.pEnabledFeatures = &features;
10147 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10148 ASSERT_VK_SUCCESS(err);
10149
10150 VkQueryPoolCreateInfo qpci{};
10151 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10152 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10153 qpci.queryCount = 1;
10154 VkQueryPool query_pool;
10155
10156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10157 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10158 m_errorMonitor->VerifyFound();
10159
10160 vkDestroyDevice(local_device, nullptr);
10161}
10162
Mark Mueller2ee294f2016-08-04 12:59:48 -060010163TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10164 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10165 "End a command buffer with a query still in progress.");
10166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010167 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10168 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10169 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010171 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010174
10175 ASSERT_NO_FATAL_FAILURE(InitState());
10176
10177 VkEvent event;
10178 VkEventCreateInfo event_create_info{};
10179 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10180 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10181
Mark Mueller2ee294f2016-08-04 12:59:48 -060010182 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010183 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010184
10185 BeginCommandBuffer();
10186
10187 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010188 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 -060010189 ASSERT_TRUE(image.initialized());
10190 VkImageMemoryBarrier img_barrier = {};
10191 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10192 img_barrier.pNext = NULL;
10193 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10194 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10195 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10196 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10197 img_barrier.image = image.handle();
10198 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010199
10200 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10201 // that layer validation catches the case when it is not.
10202 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010203 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10204 img_barrier.subresourceRange.baseArrayLayer = 0;
10205 img_barrier.subresourceRange.baseMipLevel = 0;
10206 img_barrier.subresourceRange.layerCount = 1;
10207 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10209 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010210 m_errorMonitor->VerifyFound();
10211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010213
10214 VkQueryPool query_pool;
10215 VkQueryPoolCreateInfo query_pool_create_info = {};
10216 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10217 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10218 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010219 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010221 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010222 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10223
10224 vkEndCommandBuffer(m_commandBuffer->handle());
10225 m_errorMonitor->VerifyFound();
10226
10227 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10228 vkDestroyEvent(m_device->device(), event, nullptr);
10229}
10230
Mark Muellerdfe37552016-07-07 14:47:42 -060010231TEST_F(VkLayerTest, VertexBufferInvalid) {
10232 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10233 "delete a buffer twice, use an invalid offset for each "
10234 "buffer type, and attempt to bind a null buffer");
10235
10236 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10237 "using deleted buffer ";
10238 const char *double_destroy_message = "Cannot free buffer 0x";
10239 const char *invalid_offset_message = "vkBindBufferMemory(): "
10240 "memoryOffset is 0x";
10241 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10242 "storage memoryOffset "
10243 "is 0x";
10244 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10245 "texel memoryOffset "
10246 "is 0x";
10247 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10248 "uniform memoryOffset "
10249 "is 0x";
10250 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10251 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010252 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010253
10254 ASSERT_NO_FATAL_FAILURE(InitState());
10255 ASSERT_NO_FATAL_FAILURE(InitViewport());
10256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10257
10258 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010259 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010260 pipe_ms_state_ci.pNext = NULL;
10261 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10262 pipe_ms_state_ci.sampleShadingEnable = 0;
10263 pipe_ms_state_ci.minSampleShading = 1.0;
10264 pipe_ms_state_ci.pSampleMask = nullptr;
10265
10266 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10267 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10268 VkPipelineLayout pipeline_layout;
10269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010270 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010271 ASSERT_VK_SUCCESS(err);
10272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010273 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10274 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010275 VkPipelineObj pipe(m_device);
10276 pipe.AddShader(&vs);
10277 pipe.AddShader(&fs);
10278 pipe.AddColorAttachment();
10279 pipe.SetMSAA(&pipe_ms_state_ci);
10280 pipe.SetViewport(m_viewports);
10281 pipe.SetScissor(m_scissors);
10282 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10283
10284 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010285 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010286
10287 {
10288 // Create and bind a vertex buffer in a reduced scope, which will cause
10289 // it to be deleted upon leaving this scope
10290 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010291 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010292 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10293 draw_verticies.AddVertexInputToPipe(pipe);
10294 }
10295
10296 Draw(1, 0, 0, 0);
10297
10298 EndCommandBuffer();
10299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010301 QueueCommandBuffer(false);
10302 m_errorMonitor->VerifyFound();
10303
10304 {
10305 // Create and bind a vertex buffer in a reduced scope, and delete it
10306 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010307 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010309 buffer_test.TestDoubleDestroy();
10310 }
10311 m_errorMonitor->VerifyFound();
10312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010314 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10316 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10317 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010318 m_errorMonitor->VerifyFound();
10319 }
10320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010321 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10322 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010323 // Create and bind a memory buffer with an invalid offset again,
10324 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10326 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10327 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010328 m_errorMonitor->VerifyFound();
10329 }
10330
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010331 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010332 // Create and bind a memory buffer with an invalid offset again, but
10333 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10335 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10336 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010337 m_errorMonitor->VerifyFound();
10338 }
10339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010340 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010341 // Create and bind a memory buffer with an invalid offset again, but
10342 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10344 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10345 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010346 m_errorMonitor->VerifyFound();
10347 }
10348
10349 {
10350 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10352 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10353 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010354 m_errorMonitor->VerifyFound();
10355 }
10356
10357 {
10358 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10360 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10361 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010362 }
10363 m_errorMonitor->VerifyFound();
10364
10365 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10366}
10367
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010368// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10369TEST_F(VkLayerTest, InvalidImageLayout) {
10370 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010371 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10372 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010373 // 3 in ValidateCmdBufImageLayouts
10374 // * -1 Attempt to submit cmd buf w/ deleted image
10375 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10376 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10378 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010379
10380 ASSERT_NO_FATAL_FAILURE(InitState());
10381 // Create src & dst images to use for copy operations
10382 VkImage src_image;
10383 VkImage dst_image;
10384
10385 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10386 const int32_t tex_width = 32;
10387 const int32_t tex_height = 32;
10388
10389 VkImageCreateInfo image_create_info = {};
10390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10391 image_create_info.pNext = NULL;
10392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10393 image_create_info.format = tex_format;
10394 image_create_info.extent.width = tex_width;
10395 image_create_info.extent.height = tex_height;
10396 image_create_info.extent.depth = 1;
10397 image_create_info.mipLevels = 1;
10398 image_create_info.arrayLayers = 4;
10399 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10400 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10401 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10402 image_create_info.flags = 0;
10403
10404 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10405 ASSERT_VK_SUCCESS(err);
10406 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10407 ASSERT_VK_SUCCESS(err);
10408
10409 BeginCommandBuffer();
10410 VkImageCopy copyRegion;
10411 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10412 copyRegion.srcSubresource.mipLevel = 0;
10413 copyRegion.srcSubresource.baseArrayLayer = 0;
10414 copyRegion.srcSubresource.layerCount = 1;
10415 copyRegion.srcOffset.x = 0;
10416 copyRegion.srcOffset.y = 0;
10417 copyRegion.srcOffset.z = 0;
10418 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10419 copyRegion.dstSubresource.mipLevel = 0;
10420 copyRegion.dstSubresource.baseArrayLayer = 0;
10421 copyRegion.dstSubresource.layerCount = 1;
10422 copyRegion.dstOffset.x = 0;
10423 copyRegion.dstOffset.y = 0;
10424 copyRegion.dstOffset.z = 0;
10425 copyRegion.extent.width = 1;
10426 copyRegion.extent.height = 1;
10427 copyRegion.extent.depth = 1;
10428 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10429 m_errorMonitor->VerifyFound();
10430 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10432 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10433 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010434 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10435 m_errorMonitor->VerifyFound();
10436 // Final src error is due to bad layout type
10437 m_errorMonitor->SetDesiredFailureMsg(
10438 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10439 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10440 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10441 m_errorMonitor->VerifyFound();
10442 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10444 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010445 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10446 m_errorMonitor->VerifyFound();
10447 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10449 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10450 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010451 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10452 m_errorMonitor->VerifyFound();
10453 m_errorMonitor->SetDesiredFailureMsg(
10454 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10455 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10456 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10457 m_errorMonitor->VerifyFound();
10458 // Now cause error due to bad image layout transition in PipelineBarrier
10459 VkImageMemoryBarrier image_barrier[1] = {};
10460 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10461 image_barrier[0].image = src_image;
10462 image_barrier[0].subresourceRange.layerCount = 2;
10463 image_barrier[0].subresourceRange.levelCount = 2;
10464 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10466 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10467 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10468 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10469 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010470 m_errorMonitor->VerifyFound();
10471
10472 // Finally some layout errors at RenderPass create time
10473 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10474 VkAttachmentReference attach = {};
10475 // perf warning for GENERAL layout w/ non-DS input attachment
10476 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10477 VkSubpassDescription subpass = {};
10478 subpass.inputAttachmentCount = 1;
10479 subpass.pInputAttachments = &attach;
10480 VkRenderPassCreateInfo rpci = {};
10481 rpci.subpassCount = 1;
10482 rpci.pSubpasses = &subpass;
10483 rpci.attachmentCount = 1;
10484 VkAttachmentDescription attach_desc = {};
10485 attach_desc.format = VK_FORMAT_UNDEFINED;
10486 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010487 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010488 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10490 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010491 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10492 m_errorMonitor->VerifyFound();
10493 // error w/ non-general layout
10494 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10495
10496 m_errorMonitor->SetDesiredFailureMsg(
10497 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10498 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10499 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10500 m_errorMonitor->VerifyFound();
10501 subpass.inputAttachmentCount = 0;
10502 subpass.colorAttachmentCount = 1;
10503 subpass.pColorAttachments = &attach;
10504 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10505 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10507 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010508 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10509 m_errorMonitor->VerifyFound();
10510 // error w/ non-color opt or GENERAL layout for color attachment
10511 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10512 m_errorMonitor->SetDesiredFailureMsg(
10513 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10514 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10515 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10516 m_errorMonitor->VerifyFound();
10517 subpass.colorAttachmentCount = 0;
10518 subpass.pDepthStencilAttachment = &attach;
10519 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10520 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10522 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010523 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10524 m_errorMonitor->VerifyFound();
10525 // error w/ non-ds opt or GENERAL layout for color attachment
10526 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10528 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10529 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010530 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10531 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010532 // For this error we need a valid renderpass so create default one
10533 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10534 attach.attachment = 0;
10535 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10536 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10537 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10538 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10539 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10540 // Can't do a CLEAR load on READ_ONLY initialLayout
10541 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10542 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10543 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10545 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10546 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010547 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10548 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010549
10550 vkDestroyImage(m_device->device(), src_image, NULL);
10551 vkDestroyImage(m_device->device(), dst_image, NULL);
10552}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010553
Tobin Ehlise0936662016-10-11 08:10:51 -060010554TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10555 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10556 VkResult err;
10557
10558 ASSERT_NO_FATAL_FAILURE(InitState());
10559
10560 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10561 VkImageTiling tiling;
10562 VkFormatProperties format_properties;
10563 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10564 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10565 tiling = VK_IMAGE_TILING_LINEAR;
10566 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10567 tiling = VK_IMAGE_TILING_OPTIMAL;
10568 } else {
10569 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10570 "skipped.\n");
10571 return;
10572 }
10573
10574 VkDescriptorPoolSize ds_type = {};
10575 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10576 ds_type.descriptorCount = 1;
10577
10578 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10579 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10580 ds_pool_ci.maxSets = 1;
10581 ds_pool_ci.poolSizeCount = 1;
10582 ds_pool_ci.pPoolSizes = &ds_type;
10583 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10584
10585 VkDescriptorPool ds_pool;
10586 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10587 ASSERT_VK_SUCCESS(err);
10588
10589 VkDescriptorSetLayoutBinding dsl_binding = {};
10590 dsl_binding.binding = 0;
10591 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10592 dsl_binding.descriptorCount = 1;
10593 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10594 dsl_binding.pImmutableSamplers = NULL;
10595
10596 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10597 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10598 ds_layout_ci.pNext = NULL;
10599 ds_layout_ci.bindingCount = 1;
10600 ds_layout_ci.pBindings = &dsl_binding;
10601
10602 VkDescriptorSetLayout ds_layout;
10603 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10604 ASSERT_VK_SUCCESS(err);
10605
10606 VkDescriptorSetAllocateInfo alloc_info = {};
10607 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10608 alloc_info.descriptorSetCount = 1;
10609 alloc_info.descriptorPool = ds_pool;
10610 alloc_info.pSetLayouts = &ds_layout;
10611 VkDescriptorSet descriptor_set;
10612 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10613 ASSERT_VK_SUCCESS(err);
10614
10615 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10616 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10617 pipeline_layout_ci.pNext = NULL;
10618 pipeline_layout_ci.setLayoutCount = 1;
10619 pipeline_layout_ci.pSetLayouts = &ds_layout;
10620 VkPipelineLayout pipeline_layout;
10621 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10622 ASSERT_VK_SUCCESS(err);
10623
10624 VkImageObj image(m_device);
10625 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10626 ASSERT_TRUE(image.initialized());
10627 VkImageView view = image.targetView(tex_format);
10628
10629 VkDescriptorImageInfo image_info = {};
10630 image_info.imageView = view;
10631 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10632
10633 VkWriteDescriptorSet descriptor_write = {};
10634 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10635 descriptor_write.dstSet = descriptor_set;
10636 descriptor_write.dstBinding = 0;
10637 descriptor_write.descriptorCount = 1;
10638 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10639 descriptor_write.pImageInfo = &image_info;
10640
10641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10642 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10643 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10645 m_errorMonitor->VerifyFound();
10646
10647 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10648 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10649 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10650 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10651}
10652
Mark Mueller93b938f2016-08-18 10:27:40 -060010653TEST_F(VkLayerTest, SimultaneousUse) {
10654 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10655 "in primary and secondary command buffers.");
10656
10657 ASSERT_NO_FATAL_FAILURE(InitState());
10658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10659
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010660 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010661 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10662 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010663
10664 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010665 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010666 command_buffer_allocate_info.commandPool = m_commandPool;
10667 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10668 command_buffer_allocate_info.commandBufferCount = 1;
10669
10670 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010671 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010672 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10673 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010674 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010675 command_buffer_inheritance_info.renderPass = m_renderPass;
10676 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10677 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010678 command_buffer_begin_info.flags =
10679 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010680 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10681
10682 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010683 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10684 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010685 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010686 vkEndCommandBuffer(secondary_command_buffer);
10687
Mark Mueller93b938f2016-08-18 10:27:40 -060010688 VkSubmitInfo submit_info = {};
10689 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10690 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010691 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010692 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010693
Mark Mueller4042b652016-09-05 22:52:21 -060010694 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010695 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10697 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010698 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010699 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10700 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010701
10702 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010703 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10704
Mark Mueller4042b652016-09-05 22:52:21 -060010705 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010706 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010707 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10710 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010711 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010712 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10713 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010714}
10715
Mark Mueller917f6bc2016-08-30 10:57:19 -060010716TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10717 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10718 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010719 "Delete objects that are inuse. Call VkQueueSubmit "
10720 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010721
10722 ASSERT_NO_FATAL_FAILURE(InitState());
10723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10724
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010725 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10726 const char *cannot_delete_event_message = "Cannot delete event 0x";
10727 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10728 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010729
10730 BeginCommandBuffer();
10731
10732 VkEvent event;
10733 VkEventCreateInfo event_create_info = {};
10734 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10735 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010736 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010737
Mark Muellerc8d441e2016-08-23 17:36:00 -060010738 EndCommandBuffer();
10739 vkDestroyEvent(m_device->device(), event, nullptr);
10740
10741 VkSubmitInfo submit_info = {};
10742 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10743 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010744 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010746 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10747 m_errorMonitor->VerifyFound();
10748
10749 m_errorMonitor->SetDesiredFailureMsg(0, "");
10750 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10751
10752 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10753
Mark Mueller917f6bc2016-08-30 10:57:19 -060010754 VkSemaphoreCreateInfo semaphore_create_info = {};
10755 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10756 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010757 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010758 VkFenceCreateInfo fence_create_info = {};
10759 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10760 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010761 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010762
10763 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010764 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010765 descriptor_pool_type_count.descriptorCount = 1;
10766
10767 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10768 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10769 descriptor_pool_create_info.maxSets = 1;
10770 descriptor_pool_create_info.poolSizeCount = 1;
10771 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010772 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010773
10774 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010775 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010776
10777 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010778 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010779 descriptorset_layout_binding.descriptorCount = 1;
10780 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10781
10782 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010783 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010784 descriptorset_layout_create_info.bindingCount = 1;
10785 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10786
10787 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010788 ASSERT_VK_SUCCESS(
10789 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010790
10791 VkDescriptorSet descriptorset;
10792 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010793 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010794 descriptorset_allocate_info.descriptorSetCount = 1;
10795 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10796 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010797 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010798
Mark Mueller4042b652016-09-05 22:52:21 -060010799 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10800
10801 VkDescriptorBufferInfo buffer_info = {};
10802 buffer_info.buffer = buffer_test.GetBuffer();
10803 buffer_info.offset = 0;
10804 buffer_info.range = 1024;
10805
10806 VkWriteDescriptorSet write_descriptor_set = {};
10807 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10808 write_descriptor_set.dstSet = descriptorset;
10809 write_descriptor_set.descriptorCount = 1;
10810 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10811 write_descriptor_set.pBufferInfo = &buffer_info;
10812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010813 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010814
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010815 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10816 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010817
10818 VkPipelineObj pipe(m_device);
10819 pipe.AddColorAttachment();
10820 pipe.AddShader(&vs);
10821 pipe.AddShader(&fs);
10822
10823 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010824 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010825 pipeline_layout_create_info.setLayoutCount = 1;
10826 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10827
10828 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010829 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010830
10831 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10832
Mark Muellerc8d441e2016-08-23 17:36:00 -060010833 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010834 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010836 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10837 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10838 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010839
Mark Muellerc8d441e2016-08-23 17:36:00 -060010840 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010841
Mark Mueller917f6bc2016-08-30 10:57:19 -060010842 submit_info.signalSemaphoreCount = 1;
10843 submit_info.pSignalSemaphores = &semaphore;
10844 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010847 vkDestroyEvent(m_device->device(), event, nullptr);
10848 m_errorMonitor->VerifyFound();
10849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010851 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10852 m_errorMonitor->VerifyFound();
10853
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010855 vkDestroyFence(m_device->device(), fence, nullptr);
10856 m_errorMonitor->VerifyFound();
10857
Tobin Ehlis122207b2016-09-01 08:50:06 -070010858 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010859 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10860 vkDestroyFence(m_device->device(), fence, nullptr);
10861 vkDestroyEvent(m_device->device(), event, nullptr);
10862 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010863 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010864 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10865}
10866
Tobin Ehlis2adda372016-09-01 08:51:06 -070010867TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10868 TEST_DESCRIPTION("Delete in-use query pool.");
10869
10870 ASSERT_NO_FATAL_FAILURE(InitState());
10871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10872
10873 VkQueryPool query_pool;
10874 VkQueryPoolCreateInfo query_pool_ci{};
10875 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10876 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10877 query_pool_ci.queryCount = 1;
10878 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10879 BeginCommandBuffer();
10880 // Reset query pool to create binding with cmd buffer
10881 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10882
10883 EndCommandBuffer();
10884
10885 VkSubmitInfo submit_info = {};
10886 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10887 submit_info.commandBufferCount = 1;
10888 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10889 // Submit cmd buffer and then destroy query pool while in-flight
10890 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10891
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010893 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10894 m_errorMonitor->VerifyFound();
10895
10896 vkQueueWaitIdle(m_device->m_queue);
10897 // Now that cmd buffer done we can safely destroy query_pool
10898 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10899}
10900
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010901TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10902 TEST_DESCRIPTION("Delete in-use pipeline.");
10903
10904 ASSERT_NO_FATAL_FAILURE(InitState());
10905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10906
10907 // Empty pipeline layout used for binding PSO
10908 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10909 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10910 pipeline_layout_ci.setLayoutCount = 0;
10911 pipeline_layout_ci.pSetLayouts = NULL;
10912
10913 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010914 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010915 ASSERT_VK_SUCCESS(err);
10916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010918 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010919 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10920 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010921 // Store pipeline handle so we can actually delete it before test finishes
10922 VkPipeline delete_this_pipeline;
10923 { // Scope pipeline so it will be auto-deleted
10924 VkPipelineObj pipe(m_device);
10925 pipe.AddShader(&vs);
10926 pipe.AddShader(&fs);
10927 pipe.AddColorAttachment();
10928 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10929 delete_this_pipeline = pipe.handle();
10930
10931 BeginCommandBuffer();
10932 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010933 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010934
10935 EndCommandBuffer();
10936
10937 VkSubmitInfo submit_info = {};
10938 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10939 submit_info.commandBufferCount = 1;
10940 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10941 // Submit cmd buffer and then pipeline destroyed while in-flight
10942 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10943 } // Pipeline deletion triggered here
10944 m_errorMonitor->VerifyFound();
10945 // Make sure queue finished and then actually delete pipeline
10946 vkQueueWaitIdle(m_device->m_queue);
10947 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10948 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10949}
10950
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010951TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10952 TEST_DESCRIPTION("Delete in-use imageView.");
10953
10954 ASSERT_NO_FATAL_FAILURE(InitState());
10955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10956
10957 VkDescriptorPoolSize ds_type_count;
10958 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10959 ds_type_count.descriptorCount = 1;
10960
10961 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10962 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10963 ds_pool_ci.maxSets = 1;
10964 ds_pool_ci.poolSizeCount = 1;
10965 ds_pool_ci.pPoolSizes = &ds_type_count;
10966
10967 VkDescriptorPool ds_pool;
10968 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10969 ASSERT_VK_SUCCESS(err);
10970
10971 VkSamplerCreateInfo sampler_ci = {};
10972 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10973 sampler_ci.pNext = NULL;
10974 sampler_ci.magFilter = VK_FILTER_NEAREST;
10975 sampler_ci.minFilter = VK_FILTER_NEAREST;
10976 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10977 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10978 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10979 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10980 sampler_ci.mipLodBias = 1.0;
10981 sampler_ci.anisotropyEnable = VK_FALSE;
10982 sampler_ci.maxAnisotropy = 1;
10983 sampler_ci.compareEnable = VK_FALSE;
10984 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10985 sampler_ci.minLod = 1.0;
10986 sampler_ci.maxLod = 1.0;
10987 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10988 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10989 VkSampler sampler;
10990
10991 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10992 ASSERT_VK_SUCCESS(err);
10993
10994 VkDescriptorSetLayoutBinding layout_binding;
10995 layout_binding.binding = 0;
10996 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10997 layout_binding.descriptorCount = 1;
10998 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10999 layout_binding.pImmutableSamplers = NULL;
11000
11001 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11002 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11003 ds_layout_ci.bindingCount = 1;
11004 ds_layout_ci.pBindings = &layout_binding;
11005 VkDescriptorSetLayout ds_layout;
11006 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11007 ASSERT_VK_SUCCESS(err);
11008
11009 VkDescriptorSetAllocateInfo alloc_info = {};
11010 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11011 alloc_info.descriptorSetCount = 1;
11012 alloc_info.descriptorPool = ds_pool;
11013 alloc_info.pSetLayouts = &ds_layout;
11014 VkDescriptorSet descriptor_set;
11015 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11016 ASSERT_VK_SUCCESS(err);
11017
11018 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11019 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11020 pipeline_layout_ci.pNext = NULL;
11021 pipeline_layout_ci.setLayoutCount = 1;
11022 pipeline_layout_ci.pSetLayouts = &ds_layout;
11023
11024 VkPipelineLayout pipeline_layout;
11025 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11026 ASSERT_VK_SUCCESS(err);
11027
11028 VkImageObj image(m_device);
11029 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11030 ASSERT_TRUE(image.initialized());
11031
11032 VkImageView view;
11033 VkImageViewCreateInfo ivci = {};
11034 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11035 ivci.image = image.handle();
11036 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11037 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11038 ivci.subresourceRange.layerCount = 1;
11039 ivci.subresourceRange.baseMipLevel = 0;
11040 ivci.subresourceRange.levelCount = 1;
11041 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11042
11043 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11044 ASSERT_VK_SUCCESS(err);
11045
11046 VkDescriptorImageInfo image_info{};
11047 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11048 image_info.imageView = view;
11049 image_info.sampler = sampler;
11050
11051 VkWriteDescriptorSet descriptor_write = {};
11052 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11053 descriptor_write.dstSet = descriptor_set;
11054 descriptor_write.dstBinding = 0;
11055 descriptor_write.descriptorCount = 1;
11056 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11057 descriptor_write.pImageInfo = &image_info;
11058
11059 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11060
11061 // Create PSO to use the sampler
11062 char const *vsSource = "#version 450\n"
11063 "\n"
11064 "out gl_PerVertex { \n"
11065 " vec4 gl_Position;\n"
11066 "};\n"
11067 "void main(){\n"
11068 " gl_Position = vec4(1);\n"
11069 "}\n";
11070 char const *fsSource = "#version 450\n"
11071 "\n"
11072 "layout(set=0, binding=0) uniform sampler2D s;\n"
11073 "layout(location=0) out vec4 x;\n"
11074 "void main(){\n"
11075 " x = texture(s, vec2(1));\n"
11076 "}\n";
11077 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11078 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11079 VkPipelineObj pipe(m_device);
11080 pipe.AddShader(&vs);
11081 pipe.AddShader(&fs);
11082 pipe.AddColorAttachment();
11083 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11084
11085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
11086
11087 BeginCommandBuffer();
11088 // Bind pipeline to cmd buffer
11089 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11090 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11091 &descriptor_set, 0, nullptr);
11092 Draw(1, 0, 0, 0);
11093 EndCommandBuffer();
11094 // Submit cmd buffer then destroy sampler
11095 VkSubmitInfo submit_info = {};
11096 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11097 submit_info.commandBufferCount = 1;
11098 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11099 // Submit cmd buffer and then destroy imageView while in-flight
11100 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11101
11102 vkDestroyImageView(m_device->device(), view, nullptr);
11103 m_errorMonitor->VerifyFound();
11104 vkQueueWaitIdle(m_device->m_queue);
11105 // Now we can actually destroy imageView
11106 vkDestroyImageView(m_device->device(), view, NULL);
11107 vkDestroySampler(m_device->device(), sampler, nullptr);
11108 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11109 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11110 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11111}
11112
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011113TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11114 TEST_DESCRIPTION("Delete in-use bufferView.");
11115
11116 ASSERT_NO_FATAL_FAILURE(InitState());
11117 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11118
11119 VkDescriptorPoolSize ds_type_count;
11120 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11121 ds_type_count.descriptorCount = 1;
11122
11123 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11124 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11125 ds_pool_ci.maxSets = 1;
11126 ds_pool_ci.poolSizeCount = 1;
11127 ds_pool_ci.pPoolSizes = &ds_type_count;
11128
11129 VkDescriptorPool ds_pool;
11130 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11131 ASSERT_VK_SUCCESS(err);
11132
11133 VkDescriptorSetLayoutBinding layout_binding;
11134 layout_binding.binding = 0;
11135 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11136 layout_binding.descriptorCount = 1;
11137 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11138 layout_binding.pImmutableSamplers = NULL;
11139
11140 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11141 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11142 ds_layout_ci.bindingCount = 1;
11143 ds_layout_ci.pBindings = &layout_binding;
11144 VkDescriptorSetLayout ds_layout;
11145 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11146 ASSERT_VK_SUCCESS(err);
11147
11148 VkDescriptorSetAllocateInfo alloc_info = {};
11149 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11150 alloc_info.descriptorSetCount = 1;
11151 alloc_info.descriptorPool = ds_pool;
11152 alloc_info.pSetLayouts = &ds_layout;
11153 VkDescriptorSet descriptor_set;
11154 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11155 ASSERT_VK_SUCCESS(err);
11156
11157 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11158 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11159 pipeline_layout_ci.pNext = NULL;
11160 pipeline_layout_ci.setLayoutCount = 1;
11161 pipeline_layout_ci.pSetLayouts = &ds_layout;
11162
11163 VkPipelineLayout pipeline_layout;
11164 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11165 ASSERT_VK_SUCCESS(err);
11166
11167 VkBuffer buffer;
11168 uint32_t queue_family_index = 0;
11169 VkBufferCreateInfo buffer_create_info = {};
11170 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11171 buffer_create_info.size = 1024;
11172 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11173 buffer_create_info.queueFamilyIndexCount = 1;
11174 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11175
11176 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11177 ASSERT_VK_SUCCESS(err);
11178
11179 VkMemoryRequirements memory_reqs;
11180 VkDeviceMemory buffer_memory;
11181
11182 VkMemoryAllocateInfo memory_info = {};
11183 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11184 memory_info.allocationSize = 0;
11185 memory_info.memoryTypeIndex = 0;
11186
11187 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11188 memory_info.allocationSize = memory_reqs.size;
11189 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11190 ASSERT_TRUE(pass);
11191
11192 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11193 ASSERT_VK_SUCCESS(err);
11194 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11195 ASSERT_VK_SUCCESS(err);
11196
11197 VkBufferView view;
11198 VkBufferViewCreateInfo bvci = {};
11199 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11200 bvci.buffer = buffer;
11201 bvci.format = VK_FORMAT_R8_UNORM;
11202 bvci.range = VK_WHOLE_SIZE;
11203
11204 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11205 ASSERT_VK_SUCCESS(err);
11206
11207 VkWriteDescriptorSet descriptor_write = {};
11208 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11209 descriptor_write.dstSet = descriptor_set;
11210 descriptor_write.dstBinding = 0;
11211 descriptor_write.descriptorCount = 1;
11212 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11213 descriptor_write.pTexelBufferView = &view;
11214
11215 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11216
11217 char const *vsSource = "#version 450\n"
11218 "\n"
11219 "out gl_PerVertex { \n"
11220 " vec4 gl_Position;\n"
11221 "};\n"
11222 "void main(){\n"
11223 " gl_Position = vec4(1);\n"
11224 "}\n";
11225 char const *fsSource = "#version 450\n"
11226 "\n"
11227 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11228 "layout(location=0) out vec4 x;\n"
11229 "void main(){\n"
11230 " x = imageLoad(s, 0);\n"
11231 "}\n";
11232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11234 VkPipelineObj pipe(m_device);
11235 pipe.AddShader(&vs);
11236 pipe.AddShader(&fs);
11237 pipe.AddColorAttachment();
11238 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11239
11240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11241
11242 BeginCommandBuffer();
11243 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11244 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11245 VkRect2D scissor = {{0, 0}, {16, 16}};
11246 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11247 // Bind pipeline to cmd buffer
11248 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11249 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11250 &descriptor_set, 0, nullptr);
11251 Draw(1, 0, 0, 0);
11252 EndCommandBuffer();
11253
11254 VkSubmitInfo submit_info = {};
11255 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11256 submit_info.commandBufferCount = 1;
11257 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11258 // Submit cmd buffer and then destroy bufferView while in-flight
11259 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11260
11261 vkDestroyBufferView(m_device->device(), view, nullptr);
11262 m_errorMonitor->VerifyFound();
11263 vkQueueWaitIdle(m_device->m_queue);
11264 // Now we can actually destroy bufferView
11265 vkDestroyBufferView(m_device->device(), view, NULL);
11266 vkDestroyBuffer(m_device->device(), buffer, NULL);
11267 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11268 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11269 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11270 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11271}
11272
Tobin Ehlis209532e2016-09-07 13:52:18 -060011273TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11274 TEST_DESCRIPTION("Delete in-use sampler.");
11275
11276 ASSERT_NO_FATAL_FAILURE(InitState());
11277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11278
11279 VkDescriptorPoolSize ds_type_count;
11280 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11281 ds_type_count.descriptorCount = 1;
11282
11283 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11284 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11285 ds_pool_ci.maxSets = 1;
11286 ds_pool_ci.poolSizeCount = 1;
11287 ds_pool_ci.pPoolSizes = &ds_type_count;
11288
11289 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011290 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011291 ASSERT_VK_SUCCESS(err);
11292
11293 VkSamplerCreateInfo sampler_ci = {};
11294 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11295 sampler_ci.pNext = NULL;
11296 sampler_ci.magFilter = VK_FILTER_NEAREST;
11297 sampler_ci.minFilter = VK_FILTER_NEAREST;
11298 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11299 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11300 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11301 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11302 sampler_ci.mipLodBias = 1.0;
11303 sampler_ci.anisotropyEnable = VK_FALSE;
11304 sampler_ci.maxAnisotropy = 1;
11305 sampler_ci.compareEnable = VK_FALSE;
11306 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11307 sampler_ci.minLod = 1.0;
11308 sampler_ci.maxLod = 1.0;
11309 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11310 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11311 VkSampler sampler;
11312
11313 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11314 ASSERT_VK_SUCCESS(err);
11315
11316 VkDescriptorSetLayoutBinding layout_binding;
11317 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011318 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011319 layout_binding.descriptorCount = 1;
11320 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11321 layout_binding.pImmutableSamplers = NULL;
11322
11323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11325 ds_layout_ci.bindingCount = 1;
11326 ds_layout_ci.pBindings = &layout_binding;
11327 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011328 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011329 ASSERT_VK_SUCCESS(err);
11330
11331 VkDescriptorSetAllocateInfo alloc_info = {};
11332 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11333 alloc_info.descriptorSetCount = 1;
11334 alloc_info.descriptorPool = ds_pool;
11335 alloc_info.pSetLayouts = &ds_layout;
11336 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011337 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011338 ASSERT_VK_SUCCESS(err);
11339
11340 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11341 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11342 pipeline_layout_ci.pNext = NULL;
11343 pipeline_layout_ci.setLayoutCount = 1;
11344 pipeline_layout_ci.pSetLayouts = &ds_layout;
11345
11346 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011347 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011348 ASSERT_VK_SUCCESS(err);
11349
11350 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011351 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 -060011352 ASSERT_TRUE(image.initialized());
11353
11354 VkImageView view;
11355 VkImageViewCreateInfo ivci = {};
11356 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11357 ivci.image = image.handle();
11358 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11359 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11360 ivci.subresourceRange.layerCount = 1;
11361 ivci.subresourceRange.baseMipLevel = 0;
11362 ivci.subresourceRange.levelCount = 1;
11363 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11364
11365 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11366 ASSERT_VK_SUCCESS(err);
11367
11368 VkDescriptorImageInfo image_info{};
11369 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11370 image_info.imageView = view;
11371 image_info.sampler = sampler;
11372
11373 VkWriteDescriptorSet descriptor_write = {};
11374 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11375 descriptor_write.dstSet = descriptor_set;
11376 descriptor_write.dstBinding = 0;
11377 descriptor_write.descriptorCount = 1;
11378 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11379 descriptor_write.pImageInfo = &image_info;
11380
11381 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11382
11383 // Create PSO to use the sampler
11384 char const *vsSource = "#version 450\n"
11385 "\n"
11386 "out gl_PerVertex { \n"
11387 " vec4 gl_Position;\n"
11388 "};\n"
11389 "void main(){\n"
11390 " gl_Position = vec4(1);\n"
11391 "}\n";
11392 char const *fsSource = "#version 450\n"
11393 "\n"
11394 "layout(set=0, binding=0) uniform sampler2D s;\n"
11395 "layout(location=0) out vec4 x;\n"
11396 "void main(){\n"
11397 " x = texture(s, vec2(1));\n"
11398 "}\n";
11399 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11400 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11401 VkPipelineObj pipe(m_device);
11402 pipe.AddShader(&vs);
11403 pipe.AddShader(&fs);
11404 pipe.AddColorAttachment();
11405 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11406
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011408
11409 BeginCommandBuffer();
11410 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011411 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11412 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11413 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011414 Draw(1, 0, 0, 0);
11415 EndCommandBuffer();
11416 // Submit cmd buffer then destroy sampler
11417 VkSubmitInfo submit_info = {};
11418 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11419 submit_info.commandBufferCount = 1;
11420 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11421 // Submit cmd buffer and then destroy sampler while in-flight
11422 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11423
11424 vkDestroySampler(m_device->device(), sampler, nullptr);
11425 m_errorMonitor->VerifyFound();
11426 vkQueueWaitIdle(m_device->m_queue);
11427 // Now we can actually destroy sampler
11428 vkDestroySampler(m_device->device(), sampler, nullptr);
11429 vkDestroyImageView(m_device->device(), view, NULL);
11430 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11431 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11432 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11433}
11434
Mark Mueller1cd9f412016-08-25 13:23:52 -060011435TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011436 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011437 "signaled but not waited on by the queue. Wait on a "
11438 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011439
11440 ASSERT_NO_FATAL_FAILURE(InitState());
11441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011443 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11444 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11445 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011446
11447 BeginCommandBuffer();
11448 EndCommandBuffer();
11449
11450 VkSemaphoreCreateInfo semaphore_create_info = {};
11451 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11452 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011453 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011454 VkSubmitInfo submit_info = {};
11455 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11456 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011457 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011458 submit_info.signalSemaphoreCount = 1;
11459 submit_info.pSignalSemaphores = &semaphore;
11460 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11461 m_errorMonitor->SetDesiredFailureMsg(0, "");
11462 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11463 BeginCommandBuffer();
11464 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011466 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11467 m_errorMonitor->VerifyFound();
11468
Mark Mueller1cd9f412016-08-25 13:23:52 -060011469 VkFenceCreateInfo fence_create_info = {};
11470 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11471 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011472 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011475 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11476 m_errorMonitor->VerifyFound();
11477
Mark Mueller4042b652016-09-05 22:52:21 -060011478 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011479 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011480 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11481}
11482
Tobin Ehlis4af23302016-07-19 10:50:30 -060011483TEST_F(VkLayerTest, FramebufferIncompatible) {
11484 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11485 "that does not match the framebuffer for the active "
11486 "renderpass.");
11487 ASSERT_NO_FATAL_FAILURE(InitState());
11488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11489
11490 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011491 VkAttachmentDescription attachment = {0,
11492 VK_FORMAT_B8G8R8A8_UNORM,
11493 VK_SAMPLE_COUNT_1_BIT,
11494 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11495 VK_ATTACHMENT_STORE_OP_STORE,
11496 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11497 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11498 VK_IMAGE_LAYOUT_UNDEFINED,
11499 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011501 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011503 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011505 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011506
11507 VkRenderPass rp;
11508 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11509 ASSERT_VK_SUCCESS(err);
11510
11511 // A compatible framebuffer.
11512 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011513 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 -060011514 ASSERT_TRUE(image.initialized());
11515
11516 VkImageViewCreateInfo ivci = {
11517 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11518 nullptr,
11519 0,
11520 image.handle(),
11521 VK_IMAGE_VIEW_TYPE_2D,
11522 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011523 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11524 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011525 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11526 };
11527 VkImageView view;
11528 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11529 ASSERT_VK_SUCCESS(err);
11530
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011531 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011532 VkFramebuffer fb;
11533 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11534 ASSERT_VK_SUCCESS(err);
11535
11536 VkCommandBufferAllocateInfo cbai = {};
11537 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11538 cbai.commandPool = m_commandPool;
11539 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11540 cbai.commandBufferCount = 1;
11541
11542 VkCommandBuffer sec_cb;
11543 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11544 ASSERT_VK_SUCCESS(err);
11545 VkCommandBufferBeginInfo cbbi = {};
11546 VkCommandBufferInheritanceInfo cbii = {};
11547 cbii.renderPass = renderPass();
11548 cbii.framebuffer = fb;
11549 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11550 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011551 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 -060011552 cbbi.pInheritanceInfo = &cbii;
11553 vkBeginCommandBuffer(sec_cb, &cbbi);
11554 vkEndCommandBuffer(sec_cb);
11555
Chris Forbes3400bc52016-09-13 18:10:34 +120011556 VkCommandBufferBeginInfo cbbi2 = {
11557 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11558 0, nullptr
11559 };
11560 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11561 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011564 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011565 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11566 m_errorMonitor->VerifyFound();
11567 // Cleanup
11568 vkDestroyImageView(m_device->device(), view, NULL);
11569 vkDestroyRenderPass(m_device->device(), rp, NULL);
11570 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11571}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011572
11573TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11574 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11575 "invalid value. If logicOp is not available, attempt to "
11576 "use it and verify that we see the correct error.");
11577 ASSERT_NO_FATAL_FAILURE(InitState());
11578 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11579
11580 auto features = m_device->phy().features();
11581 // Set the expected error depending on whether or not logicOp available
11582 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11584 "enabled, logicOpEnable must be "
11585 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011586 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011588 }
11589 // Create a pipeline using logicOp
11590 VkResult err;
11591
11592 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11593 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11594
11595 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011596 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011597 ASSERT_VK_SUCCESS(err);
11598
11599 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11600 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11601 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011602 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011603 vp_state_ci.pViewports = &vp;
11604 vp_state_ci.scissorCount = 1;
11605 VkRect2D scissors = {}; // Dummy scissors to point to
11606 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011607
11608 VkPipelineShaderStageCreateInfo shaderStages[2];
11609 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11610
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011611 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11612 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011613 shaderStages[0] = vs.GetStageCreateInfo();
11614 shaderStages[1] = fs.GetStageCreateInfo();
11615
11616 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11617 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11618
11619 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11620 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11621 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11622
11623 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11624 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011625 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011626
11627 VkPipelineColorBlendAttachmentState att = {};
11628 att.blendEnable = VK_FALSE;
11629 att.colorWriteMask = 0xf;
11630
11631 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11632 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11633 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11634 cb_ci.logicOpEnable = VK_TRUE;
11635 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11636 cb_ci.attachmentCount = 1;
11637 cb_ci.pAttachments = &att;
11638
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011639 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11640 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11641 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11642
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011643 VkGraphicsPipelineCreateInfo gp_ci = {};
11644 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11645 gp_ci.stageCount = 2;
11646 gp_ci.pStages = shaderStages;
11647 gp_ci.pVertexInputState = &vi_ci;
11648 gp_ci.pInputAssemblyState = &ia_ci;
11649 gp_ci.pViewportState = &vp_state_ci;
11650 gp_ci.pRasterizationState = &rs_ci;
11651 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011652 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011653 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11654 gp_ci.layout = pipeline_layout;
11655 gp_ci.renderPass = renderPass();
11656
11657 VkPipelineCacheCreateInfo pc_ci = {};
11658 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11659
11660 VkPipeline pipeline;
11661 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011662 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011663 ASSERT_VK_SUCCESS(err);
11664
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011665 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011666 m_errorMonitor->VerifyFound();
11667 if (VK_SUCCESS == err) {
11668 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11669 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011670 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11671 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11672}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011673#endif // DRAW_STATE_TESTS
11674
Tobin Ehlis0788f522015-05-26 16:11:58 -060011675#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011676#if GTEST_IS_THREADSAFE
11677struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011678 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011679 VkEvent event;
11680 bool bailout;
11681};
11682
Karl Schultz6addd812016-02-02 17:17:23 -070011683extern "C" void *AddToCommandBuffer(void *arg) {
11684 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011685
Mike Stroyana6d14942016-07-13 15:10:05 -060011686 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011687 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011688 if (data->bailout) {
11689 break;
11690 }
11691 }
11692 return NULL;
11693}
11694
Karl Schultz6addd812016-02-02 17:17:23 -070011695TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011696 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011697
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011699
Mike Stroyanaccf7692015-05-12 16:00:45 -060011700 ASSERT_NO_FATAL_FAILURE(InitState());
11701 ASSERT_NO_FATAL_FAILURE(InitViewport());
11702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11703
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011704 // Calls AllocateCommandBuffers
11705 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011706
11707 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011708 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011709
11710 VkEventCreateInfo event_info;
11711 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011712 VkResult err;
11713
11714 memset(&event_info, 0, sizeof(event_info));
11715 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11716
Chia-I Wuf7458c52015-10-26 21:10:41 +080011717 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011718 ASSERT_VK_SUCCESS(err);
11719
Mike Stroyanaccf7692015-05-12 16:00:45 -060011720 err = vkResetEvent(device(), event);
11721 ASSERT_VK_SUCCESS(err);
11722
11723 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011724 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011725 data.event = event;
11726 data.bailout = false;
11727 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011728
11729 // First do some correct operations using multiple threads.
11730 // Add many entries to command buffer from another thread.
11731 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11732 // Make non-conflicting calls from this thread at the same time.
11733 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011734 uint32_t count;
11735 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011736 }
11737 test_platform_thread_join(thread, NULL);
11738
11739 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011740 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011741 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011742 // Add many entries to command buffer from this thread at the same time.
11743 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011744
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011745 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011746 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011747
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011748 m_errorMonitor->SetBailout(NULL);
11749
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011750 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011751
Chia-I Wuf7458c52015-10-26 21:10:41 +080011752 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011753}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011754#endif // GTEST_IS_THREADSAFE
11755#endif // THREADING_TESTS
11756
Chris Forbes9f7ff632015-05-25 11:13:08 +120011757#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011758TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011759 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11760 "with an impossible code size");
11761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011763
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011764 ASSERT_NO_FATAL_FAILURE(InitState());
11765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11766
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011767 VkShaderModule module;
11768 VkShaderModuleCreateInfo moduleCreateInfo;
11769 struct icd_spv_header spv;
11770
11771 spv.magic = ICD_SPV_MAGIC;
11772 spv.version = ICD_SPV_VERSION;
11773 spv.gen_magic = 0;
11774
11775 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11776 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011777 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011778 moduleCreateInfo.codeSize = 4;
11779 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011780 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011781
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011782 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011783}
11784
Karl Schultz6addd812016-02-02 17:17:23 -070011785TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011786 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11787 "with a bad magic number");
11788
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011790
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011791 ASSERT_NO_FATAL_FAILURE(InitState());
11792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11793
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011794 VkShaderModule module;
11795 VkShaderModuleCreateInfo moduleCreateInfo;
11796 struct icd_spv_header spv;
11797
11798 spv.magic = ~ICD_SPV_MAGIC;
11799 spv.version = ICD_SPV_VERSION;
11800 spv.gen_magic = 0;
11801
11802 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11803 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011804 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011805 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11806 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011807 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011808
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011809 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011810}
11811
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011812#if 0
11813// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011814TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011816 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011817
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011818 ASSERT_NO_FATAL_FAILURE(InitState());
11819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11820
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011821 VkShaderModule module;
11822 VkShaderModuleCreateInfo moduleCreateInfo;
11823 struct icd_spv_header spv;
11824
11825 spv.magic = ICD_SPV_MAGIC;
11826 spv.version = ~ICD_SPV_VERSION;
11827 spv.gen_magic = 0;
11828
11829 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11830 moduleCreateInfo.pNext = NULL;
11831
Karl Schultz6addd812016-02-02 17:17:23 -070011832 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011833 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11834 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011835 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011836
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011837 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011838}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011839#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011840
Karl Schultz6addd812016-02-02 17:17:23 -070011841TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011842 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11843 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011845
Chris Forbes9f7ff632015-05-25 11:13:08 +120011846 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011848
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 char const *vsSource = "#version 450\n"
11850 "\n"
11851 "layout(location=0) out float x;\n"
11852 "out gl_PerVertex {\n"
11853 " vec4 gl_Position;\n"
11854 "};\n"
11855 "void main(){\n"
11856 " gl_Position = vec4(1);\n"
11857 " x = 0;\n"
11858 "}\n";
11859 char const *fsSource = "#version 450\n"
11860 "\n"
11861 "layout(location=0) out vec4 color;\n"
11862 "void main(){\n"
11863 " color = vec4(1);\n"
11864 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011865
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011866 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11867 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011868
11869 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011870 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011871 pipe.AddShader(&vs);
11872 pipe.AddShader(&fs);
11873
Chris Forbes9f7ff632015-05-25 11:13:08 +120011874 VkDescriptorSetObj descriptorSet(m_device);
11875 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011876 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011877
Tony Barbour5781e8f2015-08-04 16:23:11 -060011878 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011879
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011880 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011881}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011882
Mark Mueller098c9cb2016-09-08 09:01:57 -060011883TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11884 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11885
11886 ASSERT_NO_FATAL_FAILURE(InitState());
11887 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11888
11889 const char *bad_specialization_message =
11890 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11891
11892 char const *vsSource =
11893 "#version 450\n"
11894 "\n"
11895 "out gl_PerVertex {\n"
11896 " vec4 gl_Position;\n"
11897 "};\n"
11898 "void main(){\n"
11899 " gl_Position = vec4(1);\n"
11900 "}\n";
11901
11902 char const *fsSource =
11903 "#version 450\n"
11904 "\n"
11905 "layout (constant_id = 0) const float r = 0.0f;\n"
11906 "layout(location = 0) out vec4 uFragColor;\n"
11907 "void main(){\n"
11908 " uFragColor = vec4(r,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
11917 VkPipelineLayout pipeline_layout;
11918 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11919
11920 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11921 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11922 vp_state_create_info.viewportCount = 1;
11923 VkViewport viewport = {};
11924 vp_state_create_info.pViewports = &viewport;
11925 vp_state_create_info.scissorCount = 1;
11926 VkRect2D scissors = {};
11927 vp_state_create_info.pScissors = &scissors;
11928
11929 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11930
11931 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11932 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11933 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11934 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11935
11936 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11937 vs.GetStageCreateInfo(),
11938 fs.GetStageCreateInfo()
11939 };
11940
11941 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11942 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11943
11944 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11945 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11946 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11947
11948 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11949 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11950 rasterization_state_create_info.pNext = nullptr;
11951 rasterization_state_create_info.lineWidth = 1.0f;
11952 rasterization_state_create_info.rasterizerDiscardEnable = true;
11953
11954 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11955 color_blend_attachment_state.blendEnable = VK_FALSE;
11956 color_blend_attachment_state.colorWriteMask = 0xf;
11957
11958 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11959 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11960 color_blend_state_create_info.attachmentCount = 1;
11961 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11962
11963 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11964 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11965 graphicspipe_create_info.stageCount = 2;
11966 graphicspipe_create_info.pStages = shader_stage_create_info;
11967 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11968 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11969 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11970 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11971 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11972 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11973 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11974 graphicspipe_create_info.layout = pipeline_layout;
11975 graphicspipe_create_info.renderPass = renderPass();
11976
11977 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11978 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11979
11980 VkPipelineCache pipelineCache;
11981 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11982
11983 // This structure maps constant ids to data locations.
11984 const VkSpecializationMapEntry entry =
11985 // id, offset, size
11986 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11987
11988 uint32_t data = 1;
11989
11990 // Set up the info describing spec map and data
11991 const VkSpecializationInfo specialization_info = {
11992 1,
11993 &entry,
11994 1 * sizeof(float),
11995 &data,
11996 };
11997 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11998
11999 VkPipeline pipeline;
12000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12001 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12002 m_errorMonitor->VerifyFound();
12003
12004 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12005 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12006}
12007
12008TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12009 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12010
12011 ASSERT_NO_FATAL_FAILURE(InitState());
12012 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12013
12014 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12015
12016 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12017 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12018 descriptor_pool_type_count[0].descriptorCount = 1;
12019 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12020 descriptor_pool_type_count[1].descriptorCount = 1;
12021
12022 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12023 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12024 descriptor_pool_create_info.maxSets = 1;
12025 descriptor_pool_create_info.poolSizeCount = 2;
12026 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12027 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12028
12029 VkDescriptorPool descriptorset_pool;
12030 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12031
12032 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12033 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12034 descriptorset_layout_binding.descriptorCount = 1;
12035 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12036
12037 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12038 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12039 descriptorset_layout_create_info.bindingCount = 1;
12040 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12041
12042 VkDescriptorSetLayout descriptorset_layout;
12043 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12044
12045 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12046 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12047 descriptorset_allocate_info.descriptorSetCount = 1;
12048 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12049 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12050 VkDescriptorSet descriptorset;
12051 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12052
12053 // Challenge core_validation with a non uniform buffer type.
12054 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12055
Mark Mueller098c9cb2016-09-08 09:01:57 -060012056 char const *vsSource =
12057 "#version 450\n"
12058 "\n"
12059 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12060 " mat4 mvp;\n"
12061 "} ubuf;\n"
12062 "out gl_PerVertex {\n"
12063 " vec4 gl_Position;\n"
12064 "};\n"
12065 "void main(){\n"
12066 " gl_Position = ubuf.mvp * vec4(1);\n"
12067 "}\n";
12068
12069 char const *fsSource =
12070 "#version 450\n"
12071 "\n"
12072 "layout(location = 0) out vec4 uFragColor;\n"
12073 "void main(){\n"
12074 " uFragColor = vec4(0,1,0,1);\n"
12075 "}\n";
12076
12077 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12078 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12079
12080 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12081 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12082 pipeline_layout_create_info.setLayoutCount = 1;
12083 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12084
12085 VkPipelineLayout pipeline_layout;
12086 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12087
12088 VkPipelineObj pipe(m_device);
12089 pipe.AddColorAttachment();
12090 pipe.AddShader(&vs);
12091 pipe.AddShader(&fs);
12092
12093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12094 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12095 m_errorMonitor->VerifyFound();
12096
12097 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12098 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12099 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12100}
12101
12102TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12103 TEST_DESCRIPTION(
12104 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12105
12106 ASSERT_NO_FATAL_FAILURE(InitState());
12107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12108
12109 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12110
12111 VkDescriptorPoolSize descriptor_pool_type_count = {};
12112 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12113 descriptor_pool_type_count.descriptorCount = 1;
12114
12115 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12116 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12117 descriptor_pool_create_info.maxSets = 1;
12118 descriptor_pool_create_info.poolSizeCount = 1;
12119 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12120 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12121
12122 VkDescriptorPool descriptorset_pool;
12123 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12124
12125 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12126 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12127 descriptorset_layout_binding.descriptorCount = 1;
12128 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12129 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12130
12131 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12132 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12133 descriptorset_layout_create_info.bindingCount = 1;
12134 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12135
12136 VkDescriptorSetLayout descriptorset_layout;
12137 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12138 nullptr, &descriptorset_layout));
12139
12140 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12141 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12142 descriptorset_allocate_info.descriptorSetCount = 1;
12143 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12144 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12145 VkDescriptorSet descriptorset;
12146 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12147
12148 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12149
Mark Mueller098c9cb2016-09-08 09:01:57 -060012150 char const *vsSource =
12151 "#version 450\n"
12152 "\n"
12153 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12154 " mat4 mvp;\n"
12155 "} ubuf;\n"
12156 "out gl_PerVertex {\n"
12157 " vec4 gl_Position;\n"
12158 "};\n"
12159 "void main(){\n"
12160 " gl_Position = ubuf.mvp * vec4(1);\n"
12161 "}\n";
12162
12163 char const *fsSource =
12164 "#version 450\n"
12165 "\n"
12166 "layout(location = 0) out vec4 uFragColor;\n"
12167 "void main(){\n"
12168 " uFragColor = vec4(0,1,0,1);\n"
12169 "}\n";
12170
12171 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12172 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12173
12174 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12175 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12176 pipeline_layout_create_info.setLayoutCount = 1;
12177 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12178
12179 VkPipelineLayout pipeline_layout;
12180 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12181
12182 VkPipelineObj pipe(m_device);
12183 pipe.AddColorAttachment();
12184 pipe.AddShader(&vs);
12185 pipe.AddShader(&fs);
12186
12187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12188 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12189 m_errorMonitor->VerifyFound();
12190
12191 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12192 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12193 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12194}
12195
12196TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12197 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12198 "accessible from the current shader stage.");
12199
12200 ASSERT_NO_FATAL_FAILURE(InitState());
12201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12202
12203 const char *push_constant_not_accessible_message =
12204 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12205
12206 char const *vsSource =
12207 "#version 450\n"
12208 "\n"
12209 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12210 "out gl_PerVertex {\n"
12211 " vec4 gl_Position;\n"
12212 "};\n"
12213 "void main(){\n"
12214 " gl_Position = vec4(consts.x);\n"
12215 "}\n";
12216
12217 char const *fsSource =
12218 "#version 450\n"
12219 "\n"
12220 "layout(location = 0) out vec4 uFragColor;\n"
12221 "void main(){\n"
12222 " uFragColor = vec4(0,1,0,1);\n"
12223 "}\n";
12224
12225 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12226 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12227
12228 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12229 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12230
12231 // Set up a push constant range
12232 VkPushConstantRange push_constant_ranges = {};
12233 // Set to the wrong stage to challenge core_validation
12234 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12235 push_constant_ranges.size = 4;
12236
12237 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12238 pipeline_layout_create_info.pushConstantRangeCount = 1;
12239
12240 VkPipelineLayout pipeline_layout;
12241 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12242
12243 VkPipelineObj pipe(m_device);
12244 pipe.AddColorAttachment();
12245 pipe.AddShader(&vs);
12246 pipe.AddShader(&fs);
12247
12248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12249 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12250 m_errorMonitor->VerifyFound();
12251
12252 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12253}
12254
12255TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12256 TEST_DESCRIPTION(
12257 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12258
12259 ASSERT_NO_FATAL_FAILURE(InitState());
12260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12261
12262 const char *feature_not_enabled_message =
12263 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12264
12265 // Some awkward steps are required to test with custom device features.
12266 std::vector<const char *> device_extension_names;
12267 auto features = m_device->phy().features();
12268 // Disable support for 64 bit floats
12269 features.shaderFloat64 = false;
12270 // The sacrificial device object
12271 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12272
12273 char const *vsSource = "#version 450\n"
12274 "\n"
12275 "out gl_PerVertex {\n"
12276 " vec4 gl_Position;\n"
12277 "};\n"
12278 "void main(){\n"
12279 " gl_Position = vec4(1);\n"
12280 "}\n";
12281 char const *fsSource = "#version 450\n"
12282 "\n"
12283 "layout(location=0) out vec4 color;\n"
12284 "void main(){\n"
12285 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12286 " color = vec4(green);\n"
12287 "}\n";
12288
12289 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12290 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12291
12292 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012293
12294 VkPipelineObj pipe(&test_device);
12295 pipe.AddColorAttachment();
12296 pipe.AddShader(&vs);
12297 pipe.AddShader(&fs);
12298
12299 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12300 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12301 VkPipelineLayout pipeline_layout;
12302 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12303
12304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12305 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12306 m_errorMonitor->VerifyFound();
12307
12308 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12309}
12310
12311TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12312 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12313
12314 ASSERT_NO_FATAL_FAILURE(InitState());
12315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12316
12317 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12318
12319 char const *vsSource = "#version 450\n"
12320 "\n"
12321 "out gl_PerVertex {\n"
12322 " vec4 gl_Position;\n"
12323 "};\n"
12324 "layout(xfb_buffer = 1) out;"
12325 "void main(){\n"
12326 " gl_Position = vec4(1);\n"
12327 "}\n";
12328 char const *fsSource = "#version 450\n"
12329 "\n"
12330 "layout(location=0) out vec4 color;\n"
12331 "void main(){\n"
12332 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12333 " color = vec4(green);\n"
12334 "}\n";
12335
12336 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12337 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12338
12339 VkPipelineObj pipe(m_device);
12340 pipe.AddColorAttachment();
12341 pipe.AddShader(&vs);
12342 pipe.AddShader(&fs);
12343
12344 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12345 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12346 VkPipelineLayout pipeline_layout;
12347 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12348
12349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12350 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12351 m_errorMonitor->VerifyFound();
12352
12353 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12354}
12355
Karl Schultz6addd812016-02-02 17:17:23 -070012356TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012357 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12358 "which is not present in the outputs of the previous stage");
12359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012361
Chris Forbes59cb88d2015-05-25 11:13:13 +120012362 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012363 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012365 char const *vsSource = "#version 450\n"
12366 "\n"
12367 "out gl_PerVertex {\n"
12368 " vec4 gl_Position;\n"
12369 "};\n"
12370 "void main(){\n"
12371 " gl_Position = vec4(1);\n"
12372 "}\n";
12373 char const *fsSource = "#version 450\n"
12374 "\n"
12375 "layout(location=0) in float x;\n"
12376 "layout(location=0) out vec4 color;\n"
12377 "void main(){\n"
12378 " color = vec4(x);\n"
12379 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012380
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012381 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12382 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012383
12384 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012385 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012386 pipe.AddShader(&vs);
12387 pipe.AddShader(&fs);
12388
Chris Forbes59cb88d2015-05-25 11:13:13 +120012389 VkDescriptorSetObj descriptorSet(m_device);
12390 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012391 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012392
Tony Barbour5781e8f2015-08-04 16:23:11 -060012393 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012394
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012395 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012396}
12397
Karl Schultz6addd812016-02-02 17:17:23 -070012398TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012399 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12400 "within an interace block, which is not present in the outputs "
12401 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012403
12404 ASSERT_NO_FATAL_FAILURE(InitState());
12405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12406
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012407 char const *vsSource = "#version 450\n"
12408 "\n"
12409 "out gl_PerVertex {\n"
12410 " vec4 gl_Position;\n"
12411 "};\n"
12412 "void main(){\n"
12413 " gl_Position = vec4(1);\n"
12414 "}\n";
12415 char const *fsSource = "#version 450\n"
12416 "\n"
12417 "in block { layout(location=0) float x; } ins;\n"
12418 "layout(location=0) out vec4 color;\n"
12419 "void main(){\n"
12420 " color = vec4(ins.x);\n"
12421 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012422
12423 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12424 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12425
12426 VkPipelineObj pipe(m_device);
12427 pipe.AddColorAttachment();
12428 pipe.AddShader(&vs);
12429 pipe.AddShader(&fs);
12430
12431 VkDescriptorSetObj descriptorSet(m_device);
12432 descriptorSet.AppendDummy();
12433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12434
12435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12436
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012437 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012438}
12439
Karl Schultz6addd812016-02-02 17:17:23 -070012440TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012441 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012442 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12444 "output arr[2] of float32' vs 'ptr to "
12445 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012446
12447 ASSERT_NO_FATAL_FAILURE(InitState());
12448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012450 char const *vsSource = "#version 450\n"
12451 "\n"
12452 "layout(location=0) out float x[2];\n"
12453 "out gl_PerVertex {\n"
12454 " vec4 gl_Position;\n"
12455 "};\n"
12456 "void main(){\n"
12457 " x[0] = 0; x[1] = 0;\n"
12458 " gl_Position = vec4(1);\n"
12459 "}\n";
12460 char const *fsSource = "#version 450\n"
12461 "\n"
12462 "layout(location=0) in float x[3];\n"
12463 "layout(location=0) out vec4 color;\n"
12464 "void main(){\n"
12465 " color = vec4(x[0] + x[1] + x[2]);\n"
12466 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012467
12468 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12469 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12470
12471 VkPipelineObj pipe(m_device);
12472 pipe.AddColorAttachment();
12473 pipe.AddShader(&vs);
12474 pipe.AddShader(&fs);
12475
12476 VkDescriptorSetObj descriptorSet(m_device);
12477 descriptorSet.AppendDummy();
12478 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12479
12480 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12481
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012482 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012483}
12484
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012485
Karl Schultz6addd812016-02-02 17:17:23 -070012486TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012487 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012488 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012490
Chris Forbesb56af562015-05-25 11:13:17 +120012491 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012492 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012493
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012494 char const *vsSource = "#version 450\n"
12495 "\n"
12496 "layout(location=0) out int x;\n"
12497 "out gl_PerVertex {\n"
12498 " vec4 gl_Position;\n"
12499 "};\n"
12500 "void main(){\n"
12501 " x = 0;\n"
12502 " gl_Position = vec4(1);\n"
12503 "}\n";
12504 char const *fsSource = "#version 450\n"
12505 "\n"
12506 "layout(location=0) in float x;\n" /* VS writes int */
12507 "layout(location=0) out vec4 color;\n"
12508 "void main(){\n"
12509 " color = vec4(x);\n"
12510 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012511
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012512 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12513 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012514
12515 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012516 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012517 pipe.AddShader(&vs);
12518 pipe.AddShader(&fs);
12519
Chris Forbesb56af562015-05-25 11:13:17 +120012520 VkDescriptorSetObj descriptorSet(m_device);
12521 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012522 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012523
Tony Barbour5781e8f2015-08-04 16:23:11 -060012524 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012525
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012526 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012527}
12528
Karl Schultz6addd812016-02-02 17:17:23 -070012529TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012530 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012531 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012532 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012534
12535 ASSERT_NO_FATAL_FAILURE(InitState());
12536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012538 char const *vsSource = "#version 450\n"
12539 "\n"
12540 "out block { layout(location=0) int x; } outs;\n"
12541 "out gl_PerVertex {\n"
12542 " vec4 gl_Position;\n"
12543 "};\n"
12544 "void main(){\n"
12545 " outs.x = 0;\n"
12546 " gl_Position = vec4(1);\n"
12547 "}\n";
12548 char const *fsSource = "#version 450\n"
12549 "\n"
12550 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12551 "layout(location=0) out vec4 color;\n"
12552 "void main(){\n"
12553 " color = vec4(ins.x);\n"
12554 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012555
12556 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12557 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12558
12559 VkPipelineObj pipe(m_device);
12560 pipe.AddColorAttachment();
12561 pipe.AddShader(&vs);
12562 pipe.AddShader(&fs);
12563
12564 VkDescriptorSetObj descriptorSet(m_device);
12565 descriptorSet.AppendDummy();
12566 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12567
12568 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12569
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012570 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012571}
12572
12573TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012574 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012575 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012576 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012577 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 +130012578
12579 ASSERT_NO_FATAL_FAILURE(InitState());
12580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12581
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012582 char const *vsSource = "#version 450\n"
12583 "\n"
12584 "out block { layout(location=1) float x; } outs;\n"
12585 "out gl_PerVertex {\n"
12586 " vec4 gl_Position;\n"
12587 "};\n"
12588 "void main(){\n"
12589 " outs.x = 0;\n"
12590 " gl_Position = vec4(1);\n"
12591 "}\n";
12592 char const *fsSource = "#version 450\n"
12593 "\n"
12594 "in block { layout(location=0) float x; } ins;\n"
12595 "layout(location=0) out vec4 color;\n"
12596 "void main(){\n"
12597 " color = vec4(ins.x);\n"
12598 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012599
12600 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12601 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12602
12603 VkPipelineObj pipe(m_device);
12604 pipe.AddColorAttachment();
12605 pipe.AddShader(&vs);
12606 pipe.AddShader(&fs);
12607
12608 VkDescriptorSetObj descriptorSet(m_device);
12609 descriptorSet.AppendDummy();
12610 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12611
12612 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12613
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012614 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012615}
12616
12617TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012618 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012619 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012620 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012621 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 +130012622
12623 ASSERT_NO_FATAL_FAILURE(InitState());
12624 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012626 char const *vsSource = "#version 450\n"
12627 "\n"
12628 "out block { layout(location=0, component=0) float x; } outs;\n"
12629 "out gl_PerVertex {\n"
12630 " vec4 gl_Position;\n"
12631 "};\n"
12632 "void main(){\n"
12633 " outs.x = 0;\n"
12634 " gl_Position = vec4(1);\n"
12635 "}\n";
12636 char const *fsSource = "#version 450\n"
12637 "\n"
12638 "in block { layout(location=0, component=1) float x; } ins;\n"
12639 "layout(location=0) out vec4 color;\n"
12640 "void main(){\n"
12641 " color = vec4(ins.x);\n"
12642 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012643
12644 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12645 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12646
12647 VkPipelineObj pipe(m_device);
12648 pipe.AddColorAttachment();
12649 pipe.AddShader(&vs);
12650 pipe.AddShader(&fs);
12651
12652 VkDescriptorSetObj descriptorSet(m_device);
12653 descriptorSet.AppendDummy();
12654 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12655
12656 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12657
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012658 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012659}
12660
Karl Schultz6addd812016-02-02 17:17:23 -070012661TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012662 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12663 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012665
Chris Forbesde136e02015-05-25 11:13:28 +120012666 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012667 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012668
12669 VkVertexInputBindingDescription input_binding;
12670 memset(&input_binding, 0, sizeof(input_binding));
12671
12672 VkVertexInputAttributeDescription input_attrib;
12673 memset(&input_attrib, 0, sizeof(input_attrib));
12674 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12675
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012676 char const *vsSource = "#version 450\n"
12677 "\n"
12678 "out gl_PerVertex {\n"
12679 " vec4 gl_Position;\n"
12680 "};\n"
12681 "void main(){\n"
12682 " gl_Position = vec4(1);\n"
12683 "}\n";
12684 char const *fsSource = "#version 450\n"
12685 "\n"
12686 "layout(location=0) out vec4 color;\n"
12687 "void main(){\n"
12688 " color = vec4(1);\n"
12689 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012690
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012691 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12692 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012693
12694 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012695 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012696 pipe.AddShader(&vs);
12697 pipe.AddShader(&fs);
12698
12699 pipe.AddVertexInputBindings(&input_binding, 1);
12700 pipe.AddVertexInputAttribs(&input_attrib, 1);
12701
Chris Forbesde136e02015-05-25 11:13:28 +120012702 VkDescriptorSetObj descriptorSet(m_device);
12703 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012704 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012705
Tony Barbour5781e8f2015-08-04 16:23:11 -060012706 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012707
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012708 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012709}
12710
Karl Schultz6addd812016-02-02 17:17:23 -070012711TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012712 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12713 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012715
12716 ASSERT_NO_FATAL_FAILURE(InitState());
12717 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12718
12719 VkVertexInputBindingDescription input_binding;
12720 memset(&input_binding, 0, sizeof(input_binding));
12721
12722 VkVertexInputAttributeDescription input_attrib;
12723 memset(&input_attrib, 0, sizeof(input_attrib));
12724 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12725
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012726 char const *vsSource = "#version 450\n"
12727 "\n"
12728 "layout(location=1) in float x;\n"
12729 "out gl_PerVertex {\n"
12730 " vec4 gl_Position;\n"
12731 "};\n"
12732 "void main(){\n"
12733 " gl_Position = vec4(x);\n"
12734 "}\n";
12735 char const *fsSource = "#version 450\n"
12736 "\n"
12737 "layout(location=0) out vec4 color;\n"
12738 "void main(){\n"
12739 " color = vec4(1);\n"
12740 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012741
12742 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12743 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12744
12745 VkPipelineObj pipe(m_device);
12746 pipe.AddColorAttachment();
12747 pipe.AddShader(&vs);
12748 pipe.AddShader(&fs);
12749
12750 pipe.AddVertexInputBindings(&input_binding, 1);
12751 pipe.AddVertexInputAttribs(&input_attrib, 1);
12752
12753 VkDescriptorSetObj descriptorSet(m_device);
12754 descriptorSet.AppendDummy();
12755 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12756
12757 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12758
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012759 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012760}
12761
Karl Schultz6addd812016-02-02 17:17:23 -070012762TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012763 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012764 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012765 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 -060012766
Chris Forbes62e8e502015-05-25 11:13:29 +120012767 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012770 char const *vsSource = "#version 450\n"
12771 "\n"
12772 "layout(location=0) in vec4 x;\n" /* not provided */
12773 "out gl_PerVertex {\n"
12774 " vec4 gl_Position;\n"
12775 "};\n"
12776 "void main(){\n"
12777 " gl_Position = x;\n"
12778 "}\n";
12779 char const *fsSource = "#version 450\n"
12780 "\n"
12781 "layout(location=0) out vec4 color;\n"
12782 "void main(){\n"
12783 " color = vec4(1);\n"
12784 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012785
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012786 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12787 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012788
12789 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012790 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012791 pipe.AddShader(&vs);
12792 pipe.AddShader(&fs);
12793
Chris Forbes62e8e502015-05-25 11:13:29 +120012794 VkDescriptorSetObj descriptorSet(m_device);
12795 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012796 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012797
Tony Barbour5781e8f2015-08-04 16:23:11 -060012798 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012799
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012800 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012801}
12802
Karl Schultz6addd812016-02-02 17:17:23 -070012803TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012804 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12805 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012806 "vertex shader input that consumes it");
12807 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 -060012808
Chris Forbesc97d98e2015-05-25 11:13:31 +120012809 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012811
12812 VkVertexInputBindingDescription input_binding;
12813 memset(&input_binding, 0, sizeof(input_binding));
12814
12815 VkVertexInputAttributeDescription input_attrib;
12816 memset(&input_attrib, 0, sizeof(input_attrib));
12817 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12818
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012819 char const *vsSource = "#version 450\n"
12820 "\n"
12821 "layout(location=0) in int x;\n" /* attrib provided float */
12822 "out gl_PerVertex {\n"
12823 " vec4 gl_Position;\n"
12824 "};\n"
12825 "void main(){\n"
12826 " gl_Position = vec4(x);\n"
12827 "}\n";
12828 char const *fsSource = "#version 450\n"
12829 "\n"
12830 "layout(location=0) out vec4 color;\n"
12831 "void main(){\n"
12832 " color = vec4(1);\n"
12833 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012834
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012835 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12836 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012837
12838 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012839 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012840 pipe.AddShader(&vs);
12841 pipe.AddShader(&fs);
12842
12843 pipe.AddVertexInputBindings(&input_binding, 1);
12844 pipe.AddVertexInputAttribs(&input_attrib, 1);
12845
Chris Forbesc97d98e2015-05-25 11:13:31 +120012846 VkDescriptorSetObj descriptorSet(m_device);
12847 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012848 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012849
Tony Barbour5781e8f2015-08-04 16:23:11 -060012850 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012851
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012852 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012853}
12854
Chris Forbesc68b43c2016-04-06 11:18:47 +120012855TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012856 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12857 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12859 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012860
12861 ASSERT_NO_FATAL_FAILURE(InitState());
12862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12863
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012864 char const *vsSource = "#version 450\n"
12865 "\n"
12866 "out gl_PerVertex {\n"
12867 " vec4 gl_Position;\n"
12868 "};\n"
12869 "void main(){\n"
12870 " gl_Position = vec4(1);\n"
12871 "}\n";
12872 char const *fsSource = "#version 450\n"
12873 "\n"
12874 "layout(location=0) out vec4 color;\n"
12875 "void main(){\n"
12876 " color = vec4(1);\n"
12877 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012878
12879 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12880 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12881
12882 VkPipelineObj pipe(m_device);
12883 pipe.AddColorAttachment();
12884 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012885 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012886 pipe.AddShader(&fs);
12887
12888 VkDescriptorSetObj descriptorSet(m_device);
12889 descriptorSet.AppendDummy();
12890 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12891
12892 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12893
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012894 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012895}
12896
Chris Forbes82ff92a2016-09-09 10:50:24 +120012897TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12899 "No entrypoint found named `foo`");
12900
12901 ASSERT_NO_FATAL_FAILURE(InitState());
12902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12903
12904 char const *vsSource = "#version 450\n"
12905 "out gl_PerVertex {\n"
12906 " vec4 gl_Position;\n"
12907 "};\n"
12908 "void main(){\n"
12909 " gl_Position = vec4(0);\n"
12910 "}\n";
12911 char const *fsSource = "#version 450\n"
12912 "\n"
12913 "layout(location=0) out vec4 color;\n"
12914 "void main(){\n"
12915 " color = vec4(1);\n"
12916 "}\n";
12917
12918 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12919 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12920
12921 VkPipelineObj pipe(m_device);
12922 pipe.AddColorAttachment();
12923 pipe.AddShader(&vs);
12924 pipe.AddShader(&fs);
12925
12926 VkDescriptorSetObj descriptorSet(m_device);
12927 descriptorSet.AppendDummy();
12928 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12929
12930 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12931
12932 m_errorMonitor->VerifyFound();
12933}
12934
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012935TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12936 m_errorMonitor->SetDesiredFailureMsg(
12937 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12938 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12939 "uses a depth/stencil attachment");
12940
12941 ASSERT_NO_FATAL_FAILURE(InitState());
12942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12943
12944 char const *vsSource = "#version 450\n"
12945 "void main(){ gl_Position = vec4(0); }\n";
12946 char const *fsSource = "#version 450\n"
12947 "\n"
12948 "layout(location=0) out vec4 color;\n"
12949 "void main(){\n"
12950 " color = vec4(1);\n"
12951 "}\n";
12952
12953 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12954 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12955
12956 VkPipelineObj pipe(m_device);
12957 pipe.AddColorAttachment();
12958 pipe.AddShader(&vs);
12959 pipe.AddShader(&fs);
12960
12961 VkDescriptorSetObj descriptorSet(m_device);
12962 descriptorSet.AppendDummy();
12963 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12964
12965 VkAttachmentDescription attachments[] = {
12966 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12967 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12968 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12969 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12970 },
12971 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12972 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12973 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12974 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12975 },
12976 };
12977 VkAttachmentReference refs[] = {
12978 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12979 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12980 };
12981 VkSubpassDescription subpass = {
12982 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12983 1, &refs[0], nullptr, &refs[1],
12984 0, nullptr
12985 };
12986 VkRenderPassCreateInfo rpci = {
12987 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12988 0, 2, attachments, 1, &subpass, 0, nullptr
12989 };
12990 VkRenderPass rp;
12991 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12992 ASSERT_VK_SUCCESS(err);
12993
12994 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12995
12996 m_errorMonitor->VerifyFound();
12997
12998 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12999}
13000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013001TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013002 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13003 "the TCS without the patch decoration, but consumed in the TES "
13004 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13006 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013007
13008 ASSERT_NO_FATAL_FAILURE(InitState());
13009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13010
Chris Forbesc1e852d2016-04-04 19:26:42 +120013011 if (!m_device->phy().features().tessellationShader) {
13012 printf("Device does not support tessellation shaders; skipped.\n");
13013 return;
13014 }
13015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013016 char const *vsSource = "#version 450\n"
13017 "void main(){}\n";
13018 char const *tcsSource = "#version 450\n"
13019 "layout(location=0) out int x[];\n"
13020 "layout(vertices=3) out;\n"
13021 "void main(){\n"
13022 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13023 " gl_TessLevelInner[0] = 1;\n"
13024 " x[gl_InvocationID] = gl_InvocationID;\n"
13025 "}\n";
13026 char const *tesSource = "#version 450\n"
13027 "layout(triangles, equal_spacing, cw) in;\n"
13028 "layout(location=0) patch in int x;\n"
13029 "out gl_PerVertex { vec4 gl_Position; };\n"
13030 "void main(){\n"
13031 " gl_Position.xyz = gl_TessCoord;\n"
13032 " gl_Position.w = x;\n"
13033 "}\n";
13034 char const *fsSource = "#version 450\n"
13035 "layout(location=0) out vec4 color;\n"
13036 "void main(){\n"
13037 " color = vec4(1);\n"
13038 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013039
13040 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13041 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13042 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13043 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013045 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13046 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013049
13050 VkPipelineObj pipe(m_device);
13051 pipe.SetInputAssembly(&iasci);
13052 pipe.SetTessellation(&tsci);
13053 pipe.AddColorAttachment();
13054 pipe.AddShader(&vs);
13055 pipe.AddShader(&tcs);
13056 pipe.AddShader(&tes);
13057 pipe.AddShader(&fs);
13058
13059 VkDescriptorSetObj descriptorSet(m_device);
13060 descriptorSet.AppendDummy();
13061 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13062
13063 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13064
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013065 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013066}
13067
Karl Schultz6addd812016-02-02 17:17:23 -070013068TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013069 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13070 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13072 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013073
Chris Forbes280ba2c2015-06-12 11:16:41 +120013074 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013075 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013076
13077 /* Two binding descriptions for binding 0 */
13078 VkVertexInputBindingDescription input_bindings[2];
13079 memset(input_bindings, 0, sizeof(input_bindings));
13080
13081 VkVertexInputAttributeDescription input_attrib;
13082 memset(&input_attrib, 0, sizeof(input_attrib));
13083 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013085 char const *vsSource = "#version 450\n"
13086 "\n"
13087 "layout(location=0) in float x;\n" /* attrib provided float */
13088 "out gl_PerVertex {\n"
13089 " vec4 gl_Position;\n"
13090 "};\n"
13091 "void main(){\n"
13092 " gl_Position = vec4(x);\n"
13093 "}\n";
13094 char const *fsSource = "#version 450\n"
13095 "\n"
13096 "layout(location=0) out vec4 color;\n"
13097 "void main(){\n"
13098 " color = vec4(1);\n"
13099 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013100
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013101 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13102 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013103
13104 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013105 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013106 pipe.AddShader(&vs);
13107 pipe.AddShader(&fs);
13108
13109 pipe.AddVertexInputBindings(input_bindings, 2);
13110 pipe.AddVertexInputAttribs(&input_attrib, 1);
13111
Chris Forbes280ba2c2015-06-12 11:16:41 +120013112 VkDescriptorSetObj descriptorSet(m_device);
13113 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013114 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013115
Tony Barbour5781e8f2015-08-04 16:23:11 -060013116 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013117
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013118 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013119}
Chris Forbes8f68b562015-05-25 11:13:32 +120013120
Karl Schultz6addd812016-02-02 17:17:23 -070013121TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013122 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013123 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013125
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013126 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013128 char const *vsSource = "#version 450\n"
13129 "\n"
13130 "out gl_PerVertex {\n"
13131 " vec4 gl_Position;\n"
13132 "};\n"
13133 "void main(){\n"
13134 " gl_Position = vec4(1);\n"
13135 "}\n";
13136 char const *fsSource = "#version 450\n"
13137 "\n"
13138 "void main(){\n"
13139 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013140
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013141 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13142 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013143
13144 VkPipelineObj pipe(m_device);
13145 pipe.AddShader(&vs);
13146 pipe.AddShader(&fs);
13147
Chia-I Wu08accc62015-07-07 11:50:03 +080013148 /* set up CB 0, not written */
13149 pipe.AddColorAttachment();
13150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013151
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013152 VkDescriptorSetObj descriptorSet(m_device);
13153 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013154 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013155
Tony Barbour5781e8f2015-08-04 16:23:11 -060013156 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013157
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013158 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013159}
13160
Karl Schultz6addd812016-02-02 17:17:23 -070013161TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013162 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013163 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013165 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013166
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013167 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013169 char const *vsSource = "#version 450\n"
13170 "\n"
13171 "out gl_PerVertex {\n"
13172 " vec4 gl_Position;\n"
13173 "};\n"
13174 "void main(){\n"
13175 " gl_Position = vec4(1);\n"
13176 "}\n";
13177 char const *fsSource = "#version 450\n"
13178 "\n"
13179 "layout(location=0) out vec4 x;\n"
13180 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13181 "void main(){\n"
13182 " x = vec4(1);\n"
13183 " y = vec4(1);\n"
13184 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013185
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013186 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13187 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013188
13189 VkPipelineObj pipe(m_device);
13190 pipe.AddShader(&vs);
13191 pipe.AddShader(&fs);
13192
Chia-I Wu08accc62015-07-07 11:50:03 +080013193 /* set up CB 0, not written */
13194 pipe.AddColorAttachment();
13195 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013196 /* FS writes CB 1, but we don't configure it */
13197
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013198 VkDescriptorSetObj descriptorSet(m_device);
13199 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013200 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013201
Tony Barbour5781e8f2015-08-04 16:23:11 -060013202 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013203
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013204 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013205}
13206
Karl Schultz6addd812016-02-02 17:17:23 -070013207TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013208 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013209 "type of an fragment shader output variable, and the format of the corresponding attachment");
13210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013211
Chris Forbesa36d69e2015-05-25 11:13:44 +120013212 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013214 char const *vsSource = "#version 450\n"
13215 "\n"
13216 "out gl_PerVertex {\n"
13217 " vec4 gl_Position;\n"
13218 "};\n"
13219 "void main(){\n"
13220 " gl_Position = vec4(1);\n"
13221 "}\n";
13222 char const *fsSource = "#version 450\n"
13223 "\n"
13224 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13225 "void main(){\n"
13226 " x = ivec4(1);\n"
13227 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013228
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013229 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13230 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013231
13232 VkPipelineObj pipe(m_device);
13233 pipe.AddShader(&vs);
13234 pipe.AddShader(&fs);
13235
Chia-I Wu08accc62015-07-07 11:50:03 +080013236 /* set up CB 0; type is UNORM by default */
13237 pipe.AddColorAttachment();
13238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013239
Chris Forbesa36d69e2015-05-25 11:13:44 +120013240 VkDescriptorSetObj descriptorSet(m_device);
13241 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013242 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013243
Tony Barbour5781e8f2015-08-04 16:23:11 -060013244 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013245
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013246 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013247}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013248
Karl Schultz6addd812016-02-02 17:17:23 -070013249TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013250 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13251 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013253
Chris Forbes556c76c2015-08-14 12:04:59 +120013254 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013256 char const *vsSource = "#version 450\n"
13257 "\n"
13258 "out gl_PerVertex {\n"
13259 " vec4 gl_Position;\n"
13260 "};\n"
13261 "void main(){\n"
13262 " gl_Position = vec4(1);\n"
13263 "}\n";
13264 char const *fsSource = "#version 450\n"
13265 "\n"
13266 "layout(location=0) out vec4 x;\n"
13267 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13268 "void main(){\n"
13269 " x = vec4(bar.y);\n"
13270 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013271
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013272 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13273 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013274
Chris Forbes556c76c2015-08-14 12:04:59 +120013275 VkPipelineObj pipe(m_device);
13276 pipe.AddShader(&vs);
13277 pipe.AddShader(&fs);
13278
13279 /* set up CB 0; type is UNORM by default */
13280 pipe.AddColorAttachment();
13281 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13282
13283 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013284 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013285
13286 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13287
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013288 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013289}
13290
Chris Forbes5c59e902016-02-26 16:56:09 +130013291TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013292 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13293 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013295
13296 ASSERT_NO_FATAL_FAILURE(InitState());
13297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013298 char const *vsSource = "#version 450\n"
13299 "\n"
13300 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13301 "out gl_PerVertex {\n"
13302 " vec4 gl_Position;\n"
13303 "};\n"
13304 "void main(){\n"
13305 " gl_Position = vec4(consts.x);\n"
13306 "}\n";
13307 char const *fsSource = "#version 450\n"
13308 "\n"
13309 "layout(location=0) out vec4 x;\n"
13310 "void main(){\n"
13311 " x = vec4(1);\n"
13312 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013313
13314 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13315 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13316
13317 VkPipelineObj pipe(m_device);
13318 pipe.AddShader(&vs);
13319 pipe.AddShader(&fs);
13320
13321 /* set up CB 0; type is UNORM by default */
13322 pipe.AddColorAttachment();
13323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13324
13325 VkDescriptorSetObj descriptorSet(m_device);
13326 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13327
13328 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13329
13330 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013331 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013332}
13333
Chris Forbes3fb17902016-08-22 14:57:55 +120013334TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13335 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13336 "which is not included in the subpass description");
13337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13338 "consumes input attachment index 0 but not provided in subpass");
13339
13340 ASSERT_NO_FATAL_FAILURE(InitState());
13341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013342 char const *vsSource = "#version 450\n"
13343 "\n"
13344 "out gl_PerVertex {\n"
13345 " vec4 gl_Position;\n"
13346 "};\n"
13347 "void main(){\n"
13348 " gl_Position = vec4(1);\n"
13349 "}\n";
13350 char const *fsSource = "#version 450\n"
13351 "\n"
13352 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13353 "layout(location=0) out vec4 color;\n"
13354 "void main() {\n"
13355 " color = subpassLoad(x);\n"
13356 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013357
13358 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13359 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13360
13361 VkPipelineObj pipe(m_device);
13362 pipe.AddShader(&vs);
13363 pipe.AddShader(&fs);
13364 pipe.AddColorAttachment();
13365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013367 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13368 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013369 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013370 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013371 ASSERT_VK_SUCCESS(err);
13372
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013373 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013374 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013375 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013376 ASSERT_VK_SUCCESS(err);
13377
13378 // error here.
13379 pipe.CreateVKPipeline(pl, renderPass());
13380
13381 m_errorMonitor->VerifyFound();
13382
13383 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13384 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13385}
13386
Chris Forbes5a9a0472016-08-22 16:02:09 +120013387TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13388 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13389 "with a format having a different fundamental type");
13390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13391 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13392
13393 ASSERT_NO_FATAL_FAILURE(InitState());
13394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013395 char const *vsSource = "#version 450\n"
13396 "\n"
13397 "out gl_PerVertex {\n"
13398 " vec4 gl_Position;\n"
13399 "};\n"
13400 "void main(){\n"
13401 " gl_Position = vec4(1);\n"
13402 "}\n";
13403 char const *fsSource = "#version 450\n"
13404 "\n"
13405 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13406 "layout(location=0) out vec4 color;\n"
13407 "void main() {\n"
13408 " color = subpassLoad(x);\n"
13409 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013410
13411 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13412 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13413
13414 VkPipelineObj pipe(m_device);
13415 pipe.AddShader(&vs);
13416 pipe.AddShader(&fs);
13417 pipe.AddColorAttachment();
13418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013420 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13421 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013422 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013423 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013424 ASSERT_VK_SUCCESS(err);
13425
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013426 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013427 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013428 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013429 ASSERT_VK_SUCCESS(err);
13430
13431 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013432 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13433 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13434 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13435 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13436 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 +120013437 };
13438 VkAttachmentReference color = {
13439 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13440 };
13441 VkAttachmentReference input = {
13442 1, VK_IMAGE_LAYOUT_GENERAL,
13443 };
13444
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013445 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013447 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013448 VkRenderPass rp;
13449 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13450 ASSERT_VK_SUCCESS(err);
13451
13452 // error here.
13453 pipe.CreateVKPipeline(pl, rp);
13454
13455 m_errorMonitor->VerifyFound();
13456
13457 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13458 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13459 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13460}
13461
Chris Forbes541f7b02016-08-22 15:30:27 +120013462TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13463 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13464 "which is not included in the subpass description -- array case");
13465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13466 "consumes input attachment index 1 but not provided in subpass");
13467
13468 ASSERT_NO_FATAL_FAILURE(InitState());
13469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013470 char const *vsSource = "#version 450\n"
13471 "\n"
13472 "out gl_PerVertex {\n"
13473 " vec4 gl_Position;\n"
13474 "};\n"
13475 "void main(){\n"
13476 " gl_Position = vec4(1);\n"
13477 "}\n";
13478 char const *fsSource = "#version 450\n"
13479 "\n"
13480 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13481 "layout(location=0) out vec4 color;\n"
13482 "void main() {\n"
13483 " color = subpassLoad(xs[1]);\n"
13484 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013485
13486 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13487 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13488
13489 VkPipelineObj pipe(m_device);
13490 pipe.AddShader(&vs);
13491 pipe.AddShader(&fs);
13492 pipe.AddColorAttachment();
13493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013495 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13496 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013497 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013498 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013499 ASSERT_VK_SUCCESS(err);
13500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013501 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013502 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013503 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013504 ASSERT_VK_SUCCESS(err);
13505
13506 // error here.
13507 pipe.CreateVKPipeline(pl, renderPass());
13508
13509 m_errorMonitor->VerifyFound();
13510
13511 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13512 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13513}
13514
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013515TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013516 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13517 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013519
13520 ASSERT_NO_FATAL_FAILURE(InitState());
13521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013522 char const *csSource = "#version 450\n"
13523 "\n"
13524 "layout(local_size_x=1) in;\n"
13525 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13526 "void main(){\n"
13527 " x = vec4(1);\n"
13528 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013529
13530 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13531
13532 VkDescriptorSetObj descriptorSet(m_device);
13533 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013535 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13536 nullptr,
13537 0,
13538 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13539 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13540 descriptorSet.GetPipelineLayout(),
13541 VK_NULL_HANDLE,
13542 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013543
13544 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013545 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013546
13547 m_errorMonitor->VerifyFound();
13548
13549 if (err == VK_SUCCESS) {
13550 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13551 }
13552}
13553
Chris Forbes22a9b092016-07-19 14:34:05 +120013554TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013555 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13556 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13558 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013559
13560 ASSERT_NO_FATAL_FAILURE(InitState());
13561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013562 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13563 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013564 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013565 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013566 ASSERT_VK_SUCCESS(err);
13567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013568 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013569 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013570 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013571 ASSERT_VK_SUCCESS(err);
13572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013573 char const *csSource = "#version 450\n"
13574 "\n"
13575 "layout(local_size_x=1) in;\n"
13576 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13577 "void main() {\n"
13578 " x.x = 1.0f;\n"
13579 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013580 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13581
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013582 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13583 nullptr,
13584 0,
13585 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13586 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13587 pl,
13588 VK_NULL_HANDLE,
13589 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013590
13591 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013592 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013593
13594 m_errorMonitor->VerifyFound();
13595
13596 if (err == VK_SUCCESS) {
13597 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13598 }
13599
13600 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13601 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13602}
13603
Chris Forbes50020592016-07-27 13:52:41 +120013604TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13605 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13606 "does not match the dimensionality declared in the shader");
13607
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013608 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 +120013609
13610 ASSERT_NO_FATAL_FAILURE(InitState());
13611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013613 char const *vsSource = "#version 450\n"
13614 "\n"
13615 "out gl_PerVertex { vec4 gl_Position; };\n"
13616 "void main() { gl_Position = vec4(0); }\n";
13617 char const *fsSource = "#version 450\n"
13618 "\n"
13619 "layout(set=0, binding=0) uniform sampler3D s;\n"
13620 "layout(location=0) out vec4 color;\n"
13621 "void main() {\n"
13622 " color = texture(s, vec3(0));\n"
13623 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013624 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13625 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13626
13627 VkPipelineObj pipe(m_device);
13628 pipe.AddShader(&vs);
13629 pipe.AddShader(&fs);
13630 pipe.AddColorAttachment();
13631
13632 VkTextureObj texture(m_device, nullptr);
13633 VkSamplerObj sampler(m_device);
13634
13635 VkDescriptorSetObj descriptorSet(m_device);
13636 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13637 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13638
13639 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13640 ASSERT_VK_SUCCESS(err);
13641
13642 BeginCommandBuffer();
13643
13644 m_commandBuffer->BindPipeline(pipe);
13645 m_commandBuffer->BindDescriptorSet(descriptorSet);
13646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013647 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013648 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013649 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013650 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13651
13652 // error produced here.
13653 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13654
13655 m_errorMonitor->VerifyFound();
13656
13657 EndCommandBuffer();
13658}
13659
Chris Forbes5533bfc2016-07-27 14:12:34 +120013660TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13661 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13662 "are consumed via singlesample images types in the shader, or vice versa.");
13663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013665
13666 ASSERT_NO_FATAL_FAILURE(InitState());
13667 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13668
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013669 char const *vsSource = "#version 450\n"
13670 "\n"
13671 "out gl_PerVertex { vec4 gl_Position; };\n"
13672 "void main() { gl_Position = vec4(0); }\n";
13673 char const *fsSource = "#version 450\n"
13674 "\n"
13675 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13676 "layout(location=0) out vec4 color;\n"
13677 "void main() {\n"
13678 " color = texelFetch(s, ivec2(0), 0);\n"
13679 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013680 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13681 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13682
13683 VkPipelineObj pipe(m_device);
13684 pipe.AddShader(&vs);
13685 pipe.AddShader(&fs);
13686 pipe.AddColorAttachment();
13687
13688 VkTextureObj texture(m_device, nullptr);
13689 VkSamplerObj sampler(m_device);
13690
13691 VkDescriptorSetObj descriptorSet(m_device);
13692 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13693 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13694
13695 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13696 ASSERT_VK_SUCCESS(err);
13697
13698 BeginCommandBuffer();
13699
13700 m_commandBuffer->BindPipeline(pipe);
13701 m_commandBuffer->BindDescriptorSet(descriptorSet);
13702
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013703 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013704 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013705 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013706 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13707
13708 // error produced here.
13709 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13710
13711 m_errorMonitor->VerifyFound();
13712
13713 EndCommandBuffer();
13714}
13715
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013716#endif // SHADER_CHECKER_TESTS
13717
13718#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013719TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013721
13722 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013723
13724 // Create an image
13725 VkImage image;
13726
Karl Schultz6addd812016-02-02 17:17:23 -070013727 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13728 const int32_t tex_width = 32;
13729 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013730
13731 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013732 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13733 image_create_info.pNext = NULL;
13734 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13735 image_create_info.format = tex_format;
13736 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013737 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013738 image_create_info.extent.depth = 1;
13739 image_create_info.mipLevels = 1;
13740 image_create_info.arrayLayers = 1;
13741 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13742 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13743 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13744 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013745
13746 // Introduce error by sending down a bogus width extent
13747 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013748 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013749
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013750 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013751}
13752
Mark Youngc48c4c12016-04-11 14:26:49 -060013753TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13755 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013756
13757 ASSERT_NO_FATAL_FAILURE(InitState());
13758
13759 // Create an image
13760 VkImage image;
13761
13762 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13763 const int32_t tex_width = 32;
13764 const int32_t tex_height = 32;
13765
13766 VkImageCreateInfo image_create_info = {};
13767 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13768 image_create_info.pNext = NULL;
13769 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13770 image_create_info.format = tex_format;
13771 image_create_info.extent.width = tex_width;
13772 image_create_info.extent.height = tex_height;
13773 image_create_info.extent.depth = 1;
13774 image_create_info.mipLevels = 1;
13775 image_create_info.arrayLayers = 1;
13776 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13777 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13778 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13779 image_create_info.flags = 0;
13780
13781 // Introduce error by sending down a bogus width extent
13782 image_create_info.extent.width = 0;
13783 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13784
13785 m_errorMonitor->VerifyFound();
13786}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013787#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013788
Tobin Ehliscde08892015-09-22 10:11:37 -060013789#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013790
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013791TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13792 TEST_DESCRIPTION("Create a render pass with an attachment description "
13793 "format set to VK_FORMAT_UNDEFINED");
13794
13795 ASSERT_NO_FATAL_FAILURE(InitState());
13796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013799
13800 VkAttachmentReference color_attach = {};
13801 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13802 color_attach.attachment = 0;
13803 VkSubpassDescription subpass = {};
13804 subpass.colorAttachmentCount = 1;
13805 subpass.pColorAttachments = &color_attach;
13806
13807 VkRenderPassCreateInfo rpci = {};
13808 rpci.subpassCount = 1;
13809 rpci.pSubpasses = &subpass;
13810 rpci.attachmentCount = 1;
13811 VkAttachmentDescription attach_desc = {};
13812 attach_desc.format = VK_FORMAT_UNDEFINED;
13813 rpci.pAttachments = &attach_desc;
13814 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13815 VkRenderPass rp;
13816 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13817
13818 m_errorMonitor->VerifyFound();
13819
13820 if (result == VK_SUCCESS) {
13821 vkDestroyRenderPass(m_device->device(), rp, NULL);
13822 }
13823}
13824
Karl Schultz6addd812016-02-02 17:17:23 -070013825TEST_F(VkLayerTest, InvalidImageView) {
13826 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013829
Tobin Ehliscde08892015-09-22 10:11:37 -060013830 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013831
Mike Stroyana3082432015-09-25 13:39:21 -060013832 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013833 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013834
Karl Schultz6addd812016-02-02 17:17:23 -070013835 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13836 const int32_t tex_width = 32;
13837 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013838
13839 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013840 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13841 image_create_info.pNext = NULL;
13842 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13843 image_create_info.format = tex_format;
13844 image_create_info.extent.width = tex_width;
13845 image_create_info.extent.height = tex_height;
13846 image_create_info.extent.depth = 1;
13847 image_create_info.mipLevels = 1;
13848 image_create_info.arrayLayers = 1;
13849 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13850 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13851 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13852 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013853
Chia-I Wuf7458c52015-10-26 21:10:41 +080013854 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013855 ASSERT_VK_SUCCESS(err);
13856
13857 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013858 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13859 image_view_create_info.image = image;
13860 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13861 image_view_create_info.format = tex_format;
13862 image_view_create_info.subresourceRange.layerCount = 1;
13863 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13864 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013865 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013866
13867 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013868 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013869
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013870 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013871 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013872}
Mike Stroyana3082432015-09-25 13:39:21 -060013873
Mark Youngd339ba32016-05-30 13:28:35 -060013874TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13875 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013877 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013878
13879 ASSERT_NO_FATAL_FAILURE(InitState());
13880
13881 // Create an image and try to create a view with no memory backing the image
13882 VkImage image;
13883
13884 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13885 const int32_t tex_width = 32;
13886 const int32_t tex_height = 32;
13887
13888 VkImageCreateInfo image_create_info = {};
13889 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13890 image_create_info.pNext = NULL;
13891 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13892 image_create_info.format = tex_format;
13893 image_create_info.extent.width = tex_width;
13894 image_create_info.extent.height = tex_height;
13895 image_create_info.extent.depth = 1;
13896 image_create_info.mipLevels = 1;
13897 image_create_info.arrayLayers = 1;
13898 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13899 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13900 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13901 image_create_info.flags = 0;
13902
13903 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13904 ASSERT_VK_SUCCESS(err);
13905
13906 VkImageViewCreateInfo image_view_create_info = {};
13907 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13908 image_view_create_info.image = image;
13909 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13910 image_view_create_info.format = tex_format;
13911 image_view_create_info.subresourceRange.layerCount = 1;
13912 image_view_create_info.subresourceRange.baseMipLevel = 0;
13913 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013914 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013915
13916 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013917 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013918
13919 m_errorMonitor->VerifyFound();
13920 vkDestroyImage(m_device->device(), image, NULL);
13921 // If last error is success, it still created the view, so delete it.
13922 if (err == VK_SUCCESS) {
13923 vkDestroyImageView(m_device->device(), view, NULL);
13924 }
Mark Youngd339ba32016-05-30 13:28:35 -060013925}
13926
Karl Schultz6addd812016-02-02 17:17:23 -070013927TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013928 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013930 "formats must have ONLY the "
13931 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13933 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013934
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013935 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013936
Karl Schultz6addd812016-02-02 17:17:23 -070013937 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013938 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013939 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013940 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013941
13942 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013943 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013944 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013945 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13946 image_view_create_info.format = tex_format;
13947 image_view_create_info.subresourceRange.baseMipLevel = 0;
13948 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013949 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013950 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013951 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013952
13953 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013954 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013955
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013956 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013957}
13958
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013959TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013960 VkResult err;
13961 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13964 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013965
Mike Stroyana3082432015-09-25 13:39:21 -060013966 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013967
13968 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013969 VkImage srcImage;
13970 VkImage dstImage;
13971 VkDeviceMemory srcMem;
13972 VkDeviceMemory destMem;
13973 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013974
13975 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013976 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13977 image_create_info.pNext = NULL;
13978 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13979 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13980 image_create_info.extent.width = 32;
13981 image_create_info.extent.height = 32;
13982 image_create_info.extent.depth = 1;
13983 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013984 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013985 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13986 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13987 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13988 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013990 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013991 ASSERT_VK_SUCCESS(err);
13992
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013993 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013994 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013995 ASSERT_VK_SUCCESS(err);
13996
13997 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013998 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013999 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14000 memAlloc.pNext = NULL;
14001 memAlloc.allocationSize = 0;
14002 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014003
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014004 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014005 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014006 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014007 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014008 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014009 ASSERT_VK_SUCCESS(err);
14010
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014011 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014012 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014013 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014014 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014015 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014016 ASSERT_VK_SUCCESS(err);
14017
14018 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14019 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014020 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014021 ASSERT_VK_SUCCESS(err);
14022
14023 BeginCommandBuffer();
14024 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014025 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014026 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014027 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014028 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014029 copyRegion.srcOffset.x = 0;
14030 copyRegion.srcOffset.y = 0;
14031 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014032 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014033 copyRegion.dstSubresource.mipLevel = 0;
14034 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014035 // Introduce failure by forcing the dst layerCount to differ from src
14036 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014037 copyRegion.dstOffset.x = 0;
14038 copyRegion.dstOffset.y = 0;
14039 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014040 copyRegion.extent.width = 1;
14041 copyRegion.extent.height = 1;
14042 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014043 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014044 EndCommandBuffer();
14045
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014046 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014047
Chia-I Wuf7458c52015-10-26 21:10:41 +080014048 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014049 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014050 vkFreeMemory(m_device->device(), srcMem, NULL);
14051 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014052}
14053
Tony Barbourd6673642016-05-05 14:46:39 -060014054TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14055
14056 TEST_DESCRIPTION("Creating images with unsuported formats ");
14057
14058 ASSERT_NO_FATAL_FAILURE(InitState());
14059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14060 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014061 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 -060014062 VK_IMAGE_TILING_OPTIMAL, 0);
14063 ASSERT_TRUE(image.initialized());
14064
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014065 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
14066 VkImageCreateInfo image_create_info;
14067 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14068 image_create_info.pNext = NULL;
14069 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14070 image_create_info.format = VK_FORMAT_UNDEFINED;
14071 image_create_info.extent.width = 32;
14072 image_create_info.extent.height = 32;
14073 image_create_info.extent.depth = 1;
14074 image_create_info.mipLevels = 1;
14075 image_create_info.arrayLayers = 1;
14076 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14077 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14078 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14079 image_create_info.flags = 0;
14080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14082 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014083
14084 VkImage localImage;
14085 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14086 m_errorMonitor->VerifyFound();
14087
Tony Barbourd6673642016-05-05 14:46:39 -060014088 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014089 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014090 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14091 VkFormat format = static_cast<VkFormat>(f);
14092 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014093 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014094 unsupported = format;
14095 break;
14096 }
14097 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014098
Tony Barbourd6673642016-05-05 14:46:39 -060014099 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014100 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014102
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014103 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014104 m_errorMonitor->VerifyFound();
14105 }
14106}
14107
14108TEST_F(VkLayerTest, ImageLayerViewTests) {
14109 VkResult ret;
14110 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14111
14112 ASSERT_NO_FATAL_FAILURE(InitState());
14113
14114 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014115 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 -060014116 VK_IMAGE_TILING_OPTIMAL, 0);
14117 ASSERT_TRUE(image.initialized());
14118
14119 VkImageView imgView;
14120 VkImageViewCreateInfo imgViewInfo = {};
14121 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14122 imgViewInfo.image = image.handle();
14123 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14124 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14125 imgViewInfo.subresourceRange.layerCount = 1;
14126 imgViewInfo.subresourceRange.baseMipLevel = 0;
14127 imgViewInfo.subresourceRange.levelCount = 1;
14128 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060014131 // View can't have baseMipLevel >= image's mipLevels - Expect
14132 // VIEW_CREATE_ERROR
14133 imgViewInfo.subresourceRange.baseMipLevel = 1;
14134 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14135 m_errorMonitor->VerifyFound();
14136 imgViewInfo.subresourceRange.baseMipLevel = 0;
14137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060014139 // View can't have baseArrayLayer >= image's arraySize - Expect
14140 // VIEW_CREATE_ERROR
14141 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14142 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14143 m_errorMonitor->VerifyFound();
14144 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14147 "pCreateInfo->subresourceRange."
14148 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014149 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14150 imgViewInfo.subresourceRange.levelCount = 0;
14151 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14152 m_errorMonitor->VerifyFound();
14153 imgViewInfo.subresourceRange.levelCount = 1;
14154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14156 "pCreateInfo->subresourceRange."
14157 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014158 m_errorMonitor->SetDesiredFailureMsg(
14159 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14160 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014161 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14162 imgViewInfo.subresourceRange.layerCount = 0;
14163 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14164 m_errorMonitor->VerifyFound();
14165 imgViewInfo.subresourceRange.layerCount = 1;
14166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14169 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14170 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014171 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14172 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14173 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14174 m_errorMonitor->VerifyFound();
14175 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14178 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14179 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014180 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14181 // VIEW_CREATE_ERROR
14182 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14183 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14184 m_errorMonitor->VerifyFound();
14185 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14188 "differing formats but they must be "
14189 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014190 // TODO: Update framework to easily passing mutable flag into ImageObj init
14191 // For now just allowing image for this one test to not have memory bound
14192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14193 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014194 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14195 // VIEW_CREATE_ERROR
14196 VkImageCreateInfo mutImgInfo = image.create_info();
14197 VkImage mutImage;
14198 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014199 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014200 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14201 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14202 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14203 ASSERT_VK_SUCCESS(ret);
14204 imgViewInfo.image = mutImage;
14205 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14206 m_errorMonitor->VerifyFound();
14207 imgViewInfo.image = image.handle();
14208 vkDestroyImage(m_device->handle(), mutImage, NULL);
14209}
14210
14211TEST_F(VkLayerTest, MiscImageLayerTests) {
14212
14213 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14214
14215 ASSERT_NO_FATAL_FAILURE(InitState());
14216
14217 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014218 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 -060014219 VK_IMAGE_TILING_OPTIMAL, 0);
14220 ASSERT_TRUE(image.initialized());
14221
Tony Barbourd6673642016-05-05 14:46:39 -060014222 vk_testing::Buffer buffer;
14223 VkMemoryPropertyFlags reqs = 0;
14224 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14225 VkBufferImageCopy region = {};
14226 region.bufferRowLength = 128;
14227 region.bufferImageHeight = 128;
14228 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14229 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014230 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014231 region.imageExtent.height = 4;
14232 region.imageExtent.width = 4;
14233 region.imageExtent.depth = 1;
14234 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014235
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014236 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14237 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14238 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
14240 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14241 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014242 m_errorMonitor->VerifyFound();
14243
14244 // BufferOffset must be a multiple of 4
14245 // Introduce failure by setting bufferOffset to a value not divisible by 4
14246 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
14248 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14249 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014250 m_errorMonitor->VerifyFound();
14251
14252 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14253 region.bufferOffset = 0;
14254 region.imageExtent.height = 128;
14255 region.imageExtent.width = 128;
14256 // Introduce failure by setting bufferRowLength > 0 but less than width
14257 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14259 "must be zero or greater-than-or-equal-to imageExtent.width");
14260 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14261 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014262 m_errorMonitor->VerifyFound();
14263
14264 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14265 region.bufferRowLength = 128;
14266 // Introduce failure by setting bufferRowHeight > 0 but less than height
14267 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14269 "must be zero or greater-than-or-equal-to imageExtent.height");
14270 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14271 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014272 m_errorMonitor->VerifyFound();
14273
14274 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14276 "If the format of srcImage is a depth, stencil, depth stencil or "
14277 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014278 // Expect INVALID_FILTER
14279 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014280 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 -060014281 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014282 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 -060014283 VkImageBlit blitRegion = {};
14284 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14285 blitRegion.srcSubresource.baseArrayLayer = 0;
14286 blitRegion.srcSubresource.layerCount = 1;
14287 blitRegion.srcSubresource.mipLevel = 0;
14288 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14289 blitRegion.dstSubresource.baseArrayLayer = 0;
14290 blitRegion.dstSubresource.layerCount = 1;
14291 blitRegion.dstSubresource.mipLevel = 0;
14292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014293 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14294 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014295 m_errorMonitor->VerifyFound();
14296
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014297 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14299 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14300 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014301 m_errorMonitor->VerifyFound();
14302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014304 VkImageMemoryBarrier img_barrier;
14305 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14306 img_barrier.pNext = NULL;
14307 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14308 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14309 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14310 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14311 img_barrier.image = image.handle();
14312 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14313 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14314 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14315 img_barrier.subresourceRange.baseArrayLayer = 0;
14316 img_barrier.subresourceRange.baseMipLevel = 0;
14317 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14318 img_barrier.subresourceRange.layerCount = 0;
14319 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014320 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14321 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014322 m_errorMonitor->VerifyFound();
14323 img_barrier.subresourceRange.layerCount = 1;
14324}
14325
14326TEST_F(VkLayerTest, ImageFormatLimits) {
14327
14328 TEST_DESCRIPTION("Exceed the limits of image format ");
14329
Cody Northropc31a84f2016-08-22 10:41:47 -060014330 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014332 VkImageCreateInfo image_create_info = {};
14333 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14334 image_create_info.pNext = NULL;
14335 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14336 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14337 image_create_info.extent.width = 32;
14338 image_create_info.extent.height = 32;
14339 image_create_info.extent.depth = 1;
14340 image_create_info.mipLevels = 1;
14341 image_create_info.arrayLayers = 1;
14342 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14343 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14344 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14345 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14346 image_create_info.flags = 0;
14347
14348 VkImage nullImg;
14349 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014350 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14351 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014352 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14353 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14354 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14355 m_errorMonitor->VerifyFound();
14356 image_create_info.extent.depth = 1;
14357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014359 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14360 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14361 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14362 m_errorMonitor->VerifyFound();
14363 image_create_info.mipLevels = 1;
14364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014366 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14367 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14368 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14369 m_errorMonitor->VerifyFound();
14370 image_create_info.arrayLayers = 1;
14371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014373 int samples = imgFmtProps.sampleCounts >> 1;
14374 image_create_info.samples = (VkSampleCountFlagBits)samples;
14375 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14376 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14377 m_errorMonitor->VerifyFound();
14378 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14381 "VK_IMAGE_LAYOUT_UNDEFINED or "
14382 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014383 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14384 // Expect INVALID_LAYOUT
14385 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14386 m_errorMonitor->VerifyFound();
14387 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14388}
14389
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014390TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14391
14392 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014394
14395 ASSERT_NO_FATAL_FAILURE(InitState());
14396
14397 VkImageObj src_image(m_device);
14398 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14399 VkImageObj dst_image(m_device);
14400 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14401
14402 BeginCommandBuffer();
14403 VkImageCopy copy_region;
14404 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14405 copy_region.srcSubresource.mipLevel = 0;
14406 copy_region.srcSubresource.baseArrayLayer = 0;
14407 copy_region.srcSubresource.layerCount = 0;
14408 copy_region.srcOffset.x = 0;
14409 copy_region.srcOffset.y = 0;
14410 copy_region.srcOffset.z = 0;
14411 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14412 copy_region.dstSubresource.mipLevel = 0;
14413 copy_region.dstSubresource.baseArrayLayer = 0;
14414 copy_region.dstSubresource.layerCount = 0;
14415 copy_region.dstOffset.x = 0;
14416 copy_region.dstOffset.y = 0;
14417 copy_region.dstOffset.z = 0;
14418 copy_region.extent.width = 64;
14419 copy_region.extent.height = 64;
14420 copy_region.extent.depth = 1;
14421 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14422 &copy_region);
14423 EndCommandBuffer();
14424
14425 m_errorMonitor->VerifyFound();
14426}
14427
14428TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14429
14430 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014432
14433 ASSERT_NO_FATAL_FAILURE(InitState());
14434
14435 VkImageObj src_image(m_device);
14436 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14437 VkImageObj dst_image(m_device);
14438 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14439
14440 BeginCommandBuffer();
14441 VkImageCopy copy_region;
14442 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14443 copy_region.srcSubresource.mipLevel = 0;
14444 copy_region.srcSubresource.baseArrayLayer = 0;
14445 copy_region.srcSubresource.layerCount = 0;
14446 copy_region.srcOffset.x = 0;
14447 copy_region.srcOffset.y = 0;
14448 copy_region.srcOffset.z = 0;
14449 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14450 copy_region.dstSubresource.mipLevel = 0;
14451 copy_region.dstSubresource.baseArrayLayer = 0;
14452 copy_region.dstSubresource.layerCount = 0;
14453 copy_region.dstOffset.x = 0;
14454 copy_region.dstOffset.y = 0;
14455 copy_region.dstOffset.z = 0;
14456 copy_region.extent.width = 64;
14457 copy_region.extent.height = 64;
14458 copy_region.extent.depth = 1;
14459 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14460 &copy_region);
14461 EndCommandBuffer();
14462
14463 m_errorMonitor->VerifyFound();
14464}
14465
Karl Schultz6addd812016-02-02 17:17:23 -070014466TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014467 VkResult err;
14468 bool pass;
14469
14470 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14472 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014473
14474 ASSERT_NO_FATAL_FAILURE(InitState());
14475
14476 // Create two images of different types and try to copy between them
14477 VkImage srcImage;
14478 VkImage dstImage;
14479 VkDeviceMemory srcMem;
14480 VkDeviceMemory destMem;
14481 VkMemoryRequirements memReqs;
14482
14483 VkImageCreateInfo image_create_info = {};
14484 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14485 image_create_info.pNext = NULL;
14486 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14487 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14488 image_create_info.extent.width = 32;
14489 image_create_info.extent.height = 32;
14490 image_create_info.extent.depth = 1;
14491 image_create_info.mipLevels = 1;
14492 image_create_info.arrayLayers = 1;
14493 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14494 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14495 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14496 image_create_info.flags = 0;
14497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014498 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014499 ASSERT_VK_SUCCESS(err);
14500
14501 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14502 // Introduce failure by creating second image with a different-sized format.
14503 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014505 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014506 ASSERT_VK_SUCCESS(err);
14507
14508 // Allocate memory
14509 VkMemoryAllocateInfo memAlloc = {};
14510 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14511 memAlloc.pNext = NULL;
14512 memAlloc.allocationSize = 0;
14513 memAlloc.memoryTypeIndex = 0;
14514
14515 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14516 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014517 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014518 ASSERT_TRUE(pass);
14519 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14520 ASSERT_VK_SUCCESS(err);
14521
14522 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14523 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014524 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014525 ASSERT_TRUE(pass);
14526 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14527 ASSERT_VK_SUCCESS(err);
14528
14529 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14530 ASSERT_VK_SUCCESS(err);
14531 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14532 ASSERT_VK_SUCCESS(err);
14533
14534 BeginCommandBuffer();
14535 VkImageCopy copyRegion;
14536 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14537 copyRegion.srcSubresource.mipLevel = 0;
14538 copyRegion.srcSubresource.baseArrayLayer = 0;
14539 copyRegion.srcSubresource.layerCount = 0;
14540 copyRegion.srcOffset.x = 0;
14541 copyRegion.srcOffset.y = 0;
14542 copyRegion.srcOffset.z = 0;
14543 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14544 copyRegion.dstSubresource.mipLevel = 0;
14545 copyRegion.dstSubresource.baseArrayLayer = 0;
14546 copyRegion.dstSubresource.layerCount = 0;
14547 copyRegion.dstOffset.x = 0;
14548 copyRegion.dstOffset.y = 0;
14549 copyRegion.dstOffset.z = 0;
14550 copyRegion.extent.width = 1;
14551 copyRegion.extent.height = 1;
14552 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014553 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014554 EndCommandBuffer();
14555
14556 m_errorMonitor->VerifyFound();
14557
14558 vkDestroyImage(m_device->device(), srcImage, NULL);
14559 vkDestroyImage(m_device->device(), dstImage, NULL);
14560 vkFreeMemory(m_device->device(), srcMem, NULL);
14561 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014562}
14563
Karl Schultz6addd812016-02-02 17:17:23 -070014564TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14565 VkResult err;
14566 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014567
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014568 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14570 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014571
Mike Stroyana3082432015-09-25 13:39:21 -060014572 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014573
14574 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014575 VkImage srcImage;
14576 VkImage dstImage;
14577 VkDeviceMemory srcMem;
14578 VkDeviceMemory destMem;
14579 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014580
14581 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014582 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14583 image_create_info.pNext = NULL;
14584 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14585 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14586 image_create_info.extent.width = 32;
14587 image_create_info.extent.height = 32;
14588 image_create_info.extent.depth = 1;
14589 image_create_info.mipLevels = 1;
14590 image_create_info.arrayLayers = 1;
14591 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14592 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14593 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14594 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014596 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014597 ASSERT_VK_SUCCESS(err);
14598
Karl Schultzbdb75952016-04-19 11:36:49 -060014599 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14600
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014601 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014602 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014603 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014604 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014606 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014607 ASSERT_VK_SUCCESS(err);
14608
14609 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014610 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014611 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14612 memAlloc.pNext = NULL;
14613 memAlloc.allocationSize = 0;
14614 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014615
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014616 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014617 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014618 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014619 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014620 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014621 ASSERT_VK_SUCCESS(err);
14622
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014623 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014624 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014625 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014626 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014627 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014628 ASSERT_VK_SUCCESS(err);
14629
14630 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14631 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014632 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014633 ASSERT_VK_SUCCESS(err);
14634
14635 BeginCommandBuffer();
14636 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014637 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014638 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014639 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014640 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014641 copyRegion.srcOffset.x = 0;
14642 copyRegion.srcOffset.y = 0;
14643 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014644 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014645 copyRegion.dstSubresource.mipLevel = 0;
14646 copyRegion.dstSubresource.baseArrayLayer = 0;
14647 copyRegion.dstSubresource.layerCount = 0;
14648 copyRegion.dstOffset.x = 0;
14649 copyRegion.dstOffset.y = 0;
14650 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014651 copyRegion.extent.width = 1;
14652 copyRegion.extent.height = 1;
14653 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014654 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014655 EndCommandBuffer();
14656
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014657 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014658
Chia-I Wuf7458c52015-10-26 21:10:41 +080014659 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014660 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014661 vkFreeMemory(m_device->device(), srcMem, NULL);
14662 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014663}
14664
Karl Schultz6addd812016-02-02 17:17:23 -070014665TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14666 VkResult err;
14667 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014668
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14670 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014671
Mike Stroyana3082432015-09-25 13:39:21 -060014672 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014673
14674 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014675 VkImage srcImage;
14676 VkImage dstImage;
14677 VkDeviceMemory srcMem;
14678 VkDeviceMemory destMem;
14679 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014680
14681 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014682 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14683 image_create_info.pNext = NULL;
14684 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14685 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14686 image_create_info.extent.width = 32;
14687 image_create_info.extent.height = 1;
14688 image_create_info.extent.depth = 1;
14689 image_create_info.mipLevels = 1;
14690 image_create_info.arrayLayers = 1;
14691 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14692 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14693 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14694 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014695
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014696 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014697 ASSERT_VK_SUCCESS(err);
14698
Karl Schultz6addd812016-02-02 17:17:23 -070014699 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014700
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014701 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014702 ASSERT_VK_SUCCESS(err);
14703
14704 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014705 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014706 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14707 memAlloc.pNext = NULL;
14708 memAlloc.allocationSize = 0;
14709 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014710
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014711 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014712 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014713 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014714 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014715 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014716 ASSERT_VK_SUCCESS(err);
14717
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014718 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014719 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014720 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014721 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014722 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014723 ASSERT_VK_SUCCESS(err);
14724
14725 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14726 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014727 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014728 ASSERT_VK_SUCCESS(err);
14729
14730 BeginCommandBuffer();
14731 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014732 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14733 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014734 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014735 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014736 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014737 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014738 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014739 resolveRegion.srcOffset.x = 0;
14740 resolveRegion.srcOffset.y = 0;
14741 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014742 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014743 resolveRegion.dstSubresource.mipLevel = 0;
14744 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014745 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014746 resolveRegion.dstOffset.x = 0;
14747 resolveRegion.dstOffset.y = 0;
14748 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014749 resolveRegion.extent.width = 1;
14750 resolveRegion.extent.height = 1;
14751 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014752 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014753 EndCommandBuffer();
14754
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014755 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014756
Chia-I Wuf7458c52015-10-26 21:10:41 +080014757 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014758 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014759 vkFreeMemory(m_device->device(), srcMem, NULL);
14760 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014761}
14762
Karl Schultz6addd812016-02-02 17:17:23 -070014763TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14764 VkResult err;
14765 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014766
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14768 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014769
Mike Stroyana3082432015-09-25 13:39:21 -060014770 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014771
Chris Forbesa7530692016-05-08 12:35:39 +120014772 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014773 VkImage srcImage;
14774 VkImage dstImage;
14775 VkDeviceMemory srcMem;
14776 VkDeviceMemory destMem;
14777 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014778
14779 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014780 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14781 image_create_info.pNext = NULL;
14782 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14783 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14784 image_create_info.extent.width = 32;
14785 image_create_info.extent.height = 1;
14786 image_create_info.extent.depth = 1;
14787 image_create_info.mipLevels = 1;
14788 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014789 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014790 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14791 // Note: Some implementations expect color attachment usage for any
14792 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014793 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014794 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014795
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014796 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014797 ASSERT_VK_SUCCESS(err);
14798
Karl Schultz6addd812016-02-02 17:17:23 -070014799 // Note: Some implementations expect color attachment usage for any
14800 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014801 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014802
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014803 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014804 ASSERT_VK_SUCCESS(err);
14805
14806 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014807 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014808 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14809 memAlloc.pNext = NULL;
14810 memAlloc.allocationSize = 0;
14811 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014812
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014813 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014814 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014815 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014816 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014817 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014818 ASSERT_VK_SUCCESS(err);
14819
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014820 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014821 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014822 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014823 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014824 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014825 ASSERT_VK_SUCCESS(err);
14826
14827 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14828 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014829 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014830 ASSERT_VK_SUCCESS(err);
14831
14832 BeginCommandBuffer();
14833 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014834 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14835 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014836 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014837 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014838 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014839 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014840 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014841 resolveRegion.srcOffset.x = 0;
14842 resolveRegion.srcOffset.y = 0;
14843 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014844 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014845 resolveRegion.dstSubresource.mipLevel = 0;
14846 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014847 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014848 resolveRegion.dstOffset.x = 0;
14849 resolveRegion.dstOffset.y = 0;
14850 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014851 resolveRegion.extent.width = 1;
14852 resolveRegion.extent.height = 1;
14853 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014854 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014855 EndCommandBuffer();
14856
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014857 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014858
Chia-I Wuf7458c52015-10-26 21:10:41 +080014859 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014860 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014861 vkFreeMemory(m_device->device(), srcMem, NULL);
14862 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014863}
14864
Karl Schultz6addd812016-02-02 17:17:23 -070014865TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14866 VkResult err;
14867 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14870 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014871
Mike Stroyana3082432015-09-25 13:39:21 -060014872 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014873
14874 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014875 VkImage srcImage;
14876 VkImage dstImage;
14877 VkDeviceMemory srcMem;
14878 VkDeviceMemory destMem;
14879 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014880
14881 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014882 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14883 image_create_info.pNext = NULL;
14884 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14885 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14886 image_create_info.extent.width = 32;
14887 image_create_info.extent.height = 1;
14888 image_create_info.extent.depth = 1;
14889 image_create_info.mipLevels = 1;
14890 image_create_info.arrayLayers = 1;
14891 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14892 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14893 // Note: Some implementations expect color attachment usage for any
14894 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014895 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014896 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014897
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014898 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014899 ASSERT_VK_SUCCESS(err);
14900
Karl Schultz6addd812016-02-02 17:17:23 -070014901 // Set format to something other than source image
14902 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14903 // Note: Some implementations expect color attachment usage for any
14904 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014905 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014906 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014908 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014909 ASSERT_VK_SUCCESS(err);
14910
14911 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014912 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014913 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14914 memAlloc.pNext = NULL;
14915 memAlloc.allocationSize = 0;
14916 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014917
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014918 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014919 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014920 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014921 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014922 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014923 ASSERT_VK_SUCCESS(err);
14924
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014925 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014926 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014927 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014928 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014929 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014930 ASSERT_VK_SUCCESS(err);
14931
14932 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14933 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014934 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014935 ASSERT_VK_SUCCESS(err);
14936
14937 BeginCommandBuffer();
14938 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014939 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14940 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014941 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014942 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014943 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014944 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014945 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014946 resolveRegion.srcOffset.x = 0;
14947 resolveRegion.srcOffset.y = 0;
14948 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014949 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014950 resolveRegion.dstSubresource.mipLevel = 0;
14951 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014952 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014953 resolveRegion.dstOffset.x = 0;
14954 resolveRegion.dstOffset.y = 0;
14955 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014956 resolveRegion.extent.width = 1;
14957 resolveRegion.extent.height = 1;
14958 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014959 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014960 EndCommandBuffer();
14961
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014962 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014963
Chia-I Wuf7458c52015-10-26 21:10:41 +080014964 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014965 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014966 vkFreeMemory(m_device->device(), srcMem, NULL);
14967 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014968}
14969
Karl Schultz6addd812016-02-02 17:17:23 -070014970TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14971 VkResult err;
14972 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014973
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14975 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014976
Mike Stroyana3082432015-09-25 13:39:21 -060014977 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014978
14979 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014980 VkImage srcImage;
14981 VkImage dstImage;
14982 VkDeviceMemory srcMem;
14983 VkDeviceMemory destMem;
14984 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014985
14986 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014987 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14988 image_create_info.pNext = NULL;
14989 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14990 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14991 image_create_info.extent.width = 32;
14992 image_create_info.extent.height = 1;
14993 image_create_info.extent.depth = 1;
14994 image_create_info.mipLevels = 1;
14995 image_create_info.arrayLayers = 1;
14996 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14997 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14998 // Note: Some implementations expect color attachment usage for any
14999 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015000 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015001 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015003 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015004 ASSERT_VK_SUCCESS(err);
15005
Karl Schultz6addd812016-02-02 17:17:23 -070015006 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15007 // Note: Some implementations expect color attachment usage for any
15008 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015009 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015010 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015012 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015013 ASSERT_VK_SUCCESS(err);
15014
15015 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015016 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015017 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15018 memAlloc.pNext = NULL;
15019 memAlloc.allocationSize = 0;
15020 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015021
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015022 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015023 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015024 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015025 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015026 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015027 ASSERT_VK_SUCCESS(err);
15028
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015029 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015030 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015031 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015032 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015033 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015034 ASSERT_VK_SUCCESS(err);
15035
15036 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15037 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015038 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015039 ASSERT_VK_SUCCESS(err);
15040
15041 BeginCommandBuffer();
15042 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015043 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15044 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015045 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015046 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015047 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015048 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015049 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015050 resolveRegion.srcOffset.x = 0;
15051 resolveRegion.srcOffset.y = 0;
15052 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015053 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015054 resolveRegion.dstSubresource.mipLevel = 0;
15055 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015056 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015057 resolveRegion.dstOffset.x = 0;
15058 resolveRegion.dstOffset.y = 0;
15059 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015060 resolveRegion.extent.width = 1;
15061 resolveRegion.extent.height = 1;
15062 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015063 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060015064 EndCommandBuffer();
15065
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015066 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015067
Chia-I Wuf7458c52015-10-26 21:10:41 +080015068 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015069 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015070 vkFreeMemory(m_device->device(), srcMem, NULL);
15071 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015072}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015073
Karl Schultz6addd812016-02-02 17:17:23 -070015074TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015075 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015076 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15077 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015078 // The image format check comes 2nd in validation so we trigger it first,
15079 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015080 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015081
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15083 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015084
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015085 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015086
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015087 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015088 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15089 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015090
15091 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015092 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15093 ds_pool_ci.pNext = NULL;
15094 ds_pool_ci.maxSets = 1;
15095 ds_pool_ci.poolSizeCount = 1;
15096 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015097
15098 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015099 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015100 ASSERT_VK_SUCCESS(err);
15101
15102 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015103 dsl_binding.binding = 0;
15104 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15105 dsl_binding.descriptorCount = 1;
15106 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15107 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015108
15109 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015110 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15111 ds_layout_ci.pNext = NULL;
15112 ds_layout_ci.bindingCount = 1;
15113 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015114 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015115 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015116 ASSERT_VK_SUCCESS(err);
15117
15118 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015119 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015120 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015121 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015122 alloc_info.descriptorPool = ds_pool;
15123 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015124 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015125 ASSERT_VK_SUCCESS(err);
15126
Karl Schultz6addd812016-02-02 17:17:23 -070015127 VkImage image_bad;
15128 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015129 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015130 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015131 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015132 const int32_t tex_width = 32;
15133 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015134
15135 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015136 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15137 image_create_info.pNext = NULL;
15138 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15139 image_create_info.format = tex_format_bad;
15140 image_create_info.extent.width = tex_width;
15141 image_create_info.extent.height = tex_height;
15142 image_create_info.extent.depth = 1;
15143 image_create_info.mipLevels = 1;
15144 image_create_info.arrayLayers = 1;
15145 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15146 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015147 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015148 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015150 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015151 ASSERT_VK_SUCCESS(err);
15152 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015153 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15154 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015155 ASSERT_VK_SUCCESS(err);
15156
15157 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015158 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15159 image_view_create_info.image = image_bad;
15160 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15161 image_view_create_info.format = tex_format_bad;
15162 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15163 image_view_create_info.subresourceRange.baseMipLevel = 0;
15164 image_view_create_info.subresourceRange.layerCount = 1;
15165 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015166 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015167
15168 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015169 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015170
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015171 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015172
Chia-I Wuf7458c52015-10-26 21:10:41 +080015173 vkDestroyImage(m_device->device(), image_bad, NULL);
15174 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015175 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15176 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015177}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015178
15179TEST_F(VkLayerTest, ClearImageErrors) {
15180 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15181 "ClearDepthStencilImage with a color image.");
15182
15183 ASSERT_NO_FATAL_FAILURE(InitState());
15184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15185
15186 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15187 BeginCommandBuffer();
15188 m_commandBuffer->EndRenderPass();
15189
15190 // Color image
15191 VkClearColorValue clear_color;
15192 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15193 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15194 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15195 const int32_t img_width = 32;
15196 const int32_t img_height = 32;
15197 VkImageCreateInfo image_create_info = {};
15198 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15199 image_create_info.pNext = NULL;
15200 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15201 image_create_info.format = color_format;
15202 image_create_info.extent.width = img_width;
15203 image_create_info.extent.height = img_height;
15204 image_create_info.extent.depth = 1;
15205 image_create_info.mipLevels = 1;
15206 image_create_info.arrayLayers = 1;
15207 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15208 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15209 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15210
15211 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015212 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015214 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015215
15216 // Depth/Stencil image
15217 VkClearDepthStencilValue clear_value = {0};
15218 reqs = 0; // don't need HOST_VISIBLE DS image
15219 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15220 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15221 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15222 ds_image_create_info.extent.width = 64;
15223 ds_image_create_info.extent.height = 64;
15224 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15225 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15226
15227 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015228 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015230 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 -060015231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015234 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015235 &color_range);
15236
15237 m_errorMonitor->VerifyFound();
15238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15240 "image created without "
15241 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015243 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015244 &color_range);
15245
15246 m_errorMonitor->VerifyFound();
15247
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015248 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15250 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015251
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015252 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15253 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015254
15255 m_errorMonitor->VerifyFound();
15256}
Tobin Ehliscde08892015-09-22 10:11:37 -060015257#endif // IMAGE_TESTS
15258
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015259
15260// WSI Enabled Tests
15261//
Chris Forbes09368e42016-10-13 11:59:22 +130015262#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015263TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15264
15265#if defined(VK_USE_PLATFORM_XCB_KHR)
15266 VkSurfaceKHR surface = VK_NULL_HANDLE;
15267
15268 VkResult err;
15269 bool pass;
15270 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15271 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15272 // uint32_t swapchain_image_count = 0;
15273 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15274 // uint32_t image_index = 0;
15275 // VkPresentInfoKHR present_info = {};
15276
15277 ASSERT_NO_FATAL_FAILURE(InitState());
15278
15279 // Use the create function from one of the VK_KHR_*_surface extension in
15280 // order to create a surface, testing all known errors in the process,
15281 // before successfully creating a surface:
15282 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15284 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15285 pass = (err != VK_SUCCESS);
15286 ASSERT_TRUE(pass);
15287 m_errorMonitor->VerifyFound();
15288
15289 // Next, try to create a surface with the wrong
15290 // VkXcbSurfaceCreateInfoKHR::sType:
15291 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15292 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15294 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15295 pass = (err != VK_SUCCESS);
15296 ASSERT_TRUE(pass);
15297 m_errorMonitor->VerifyFound();
15298
15299 // Create a native window, and then correctly create a surface:
15300 xcb_connection_t *connection;
15301 xcb_screen_t *screen;
15302 xcb_window_t xcb_window;
15303 xcb_intern_atom_reply_t *atom_wm_delete_window;
15304
15305 const xcb_setup_t *setup;
15306 xcb_screen_iterator_t iter;
15307 int scr;
15308 uint32_t value_mask, value_list[32];
15309 int width = 1;
15310 int height = 1;
15311
15312 connection = xcb_connect(NULL, &scr);
15313 ASSERT_TRUE(connection != NULL);
15314 setup = xcb_get_setup(connection);
15315 iter = xcb_setup_roots_iterator(setup);
15316 while (scr-- > 0)
15317 xcb_screen_next(&iter);
15318 screen = iter.data;
15319
15320 xcb_window = xcb_generate_id(connection);
15321
15322 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15323 value_list[0] = screen->black_pixel;
15324 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15325
15326 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15327 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15328
15329 /* Magic code that will send notification when window is destroyed */
15330 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15331 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15332
15333 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15334 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15335 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15336 free(reply);
15337
15338 xcb_map_window(connection, xcb_window);
15339
15340 // Force the x/y coordinates to 100,100 results are identical in consecutive
15341 // runs
15342 const uint32_t coords[] = { 100, 100 };
15343 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15344
15345 // Finally, try to correctly create a surface:
15346 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15347 xcb_create_info.pNext = NULL;
15348 xcb_create_info.flags = 0;
15349 xcb_create_info.connection = connection;
15350 xcb_create_info.window = xcb_window;
15351 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15352 pass = (err == VK_SUCCESS);
15353 ASSERT_TRUE(pass);
15354
15355 // Check if surface supports presentation:
15356
15357 // 1st, do so without having queried the queue families:
15358 VkBool32 supported = false;
15359 // TODO: Get the following error to come out:
15360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15361 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15362 "function");
15363 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15364 pass = (err != VK_SUCCESS);
15365 // ASSERT_TRUE(pass);
15366 // m_errorMonitor->VerifyFound();
15367
15368 // Next, query a queue family index that's too large:
15369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15370 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15371 pass = (err != VK_SUCCESS);
15372 ASSERT_TRUE(pass);
15373 m_errorMonitor->VerifyFound();
15374
15375 // Finally, do so correctly:
15376 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15377 // SUPPORTED
15378 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15379 pass = (err == VK_SUCCESS);
15380 ASSERT_TRUE(pass);
15381
15382 // Before proceeding, try to create a swapchain without having called
15383 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15384 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15385 swapchain_create_info.pNext = NULL;
15386 swapchain_create_info.flags = 0;
15387 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15388 swapchain_create_info.surface = surface;
15389 swapchain_create_info.imageArrayLayers = 1;
15390 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15391 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15393 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15394 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15395 pass = (err != VK_SUCCESS);
15396 ASSERT_TRUE(pass);
15397 m_errorMonitor->VerifyFound();
15398
15399 // Get the surface capabilities:
15400 VkSurfaceCapabilitiesKHR surface_capabilities;
15401
15402 // Do so correctly (only error logged by this entrypoint is if the
15403 // extension isn't enabled):
15404 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15405 pass = (err == VK_SUCCESS);
15406 ASSERT_TRUE(pass);
15407
15408 // Get the surface formats:
15409 uint32_t surface_format_count;
15410
15411 // First, try without a pointer to surface_format_count:
15412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15413 "specified as NULL");
15414 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15415 pass = (err == VK_SUCCESS);
15416 ASSERT_TRUE(pass);
15417 m_errorMonitor->VerifyFound();
15418
15419 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15420 // correctly done a 1st try (to get the count):
15421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15422 surface_format_count = 0;
15423 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15424 pass = (err == VK_SUCCESS);
15425 ASSERT_TRUE(pass);
15426 m_errorMonitor->VerifyFound();
15427
15428 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15429 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15430 pass = (err == VK_SUCCESS);
15431 ASSERT_TRUE(pass);
15432
15433 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15434 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15435
15436 // Next, do a 2nd try with surface_format_count being set too high:
15437 surface_format_count += 5;
15438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15439 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15440 pass = (err == VK_SUCCESS);
15441 ASSERT_TRUE(pass);
15442 m_errorMonitor->VerifyFound();
15443
15444 // Finally, do a correct 1st and 2nd try:
15445 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15446 pass = (err == VK_SUCCESS);
15447 ASSERT_TRUE(pass);
15448 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15449 pass = (err == VK_SUCCESS);
15450 ASSERT_TRUE(pass);
15451
15452 // Get the surface present modes:
15453 uint32_t surface_present_mode_count;
15454
15455 // First, try without a pointer to surface_format_count:
15456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15457 "specified as NULL");
15458
15459 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15460 pass = (err == VK_SUCCESS);
15461 ASSERT_TRUE(pass);
15462 m_errorMonitor->VerifyFound();
15463
15464 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15465 // correctly done a 1st try (to get the count):
15466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15467 surface_present_mode_count = 0;
15468 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15469 (VkPresentModeKHR *)&surface_present_mode_count);
15470 pass = (err == VK_SUCCESS);
15471 ASSERT_TRUE(pass);
15472 m_errorMonitor->VerifyFound();
15473
15474 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15475 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15476 pass = (err == VK_SUCCESS);
15477 ASSERT_TRUE(pass);
15478
15479 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15480 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15481
15482 // Next, do a 2nd try with surface_format_count being set too high:
15483 surface_present_mode_count += 5;
15484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15485 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15486 pass = (err == VK_SUCCESS);
15487 ASSERT_TRUE(pass);
15488 m_errorMonitor->VerifyFound();
15489
15490 // Finally, do a correct 1st and 2nd try:
15491 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15492 pass = (err == VK_SUCCESS);
15493 ASSERT_TRUE(pass);
15494 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15495 pass = (err == VK_SUCCESS);
15496 ASSERT_TRUE(pass);
15497
15498 // Create a swapchain:
15499
15500 // First, try without a pointer to swapchain_create_info:
15501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15502 "specified as NULL");
15503
15504 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15505 pass = (err != VK_SUCCESS);
15506 ASSERT_TRUE(pass);
15507 m_errorMonitor->VerifyFound();
15508
15509 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15510 // sType:
15511 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15513
15514 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15515 pass = (err != VK_SUCCESS);
15516 ASSERT_TRUE(pass);
15517 m_errorMonitor->VerifyFound();
15518
15519 // Next, call with a NULL swapchain pointer:
15520 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15521 swapchain_create_info.pNext = NULL;
15522 swapchain_create_info.flags = 0;
15523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15524 "specified as NULL");
15525
15526 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15527 pass = (err != VK_SUCCESS);
15528 ASSERT_TRUE(pass);
15529 m_errorMonitor->VerifyFound();
15530
15531 // TODO: Enhance swapchain layer so that
15532 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15533
15534 // Next, call with a queue family index that's too large:
15535 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15536 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15537 swapchain_create_info.queueFamilyIndexCount = 2;
15538 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15540 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15541 pass = (err != VK_SUCCESS);
15542 ASSERT_TRUE(pass);
15543 m_errorMonitor->VerifyFound();
15544
15545 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15546 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15547 swapchain_create_info.queueFamilyIndexCount = 1;
15548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15549 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15550 "pCreateInfo->pQueueFamilyIndices).");
15551 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15552 pass = (err != VK_SUCCESS);
15553 ASSERT_TRUE(pass);
15554 m_errorMonitor->VerifyFound();
15555
15556 // Next, call with an invalid imageSharingMode:
15557 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15558 swapchain_create_info.queueFamilyIndexCount = 1;
15559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15560 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15561 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15562 pass = (err != VK_SUCCESS);
15563 ASSERT_TRUE(pass);
15564 m_errorMonitor->VerifyFound();
15565 // Fix for the future:
15566 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15567 // SUPPORTED
15568 swapchain_create_info.queueFamilyIndexCount = 0;
15569 queueFamilyIndex[0] = 0;
15570 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15571
15572 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15573 // Get the images from a swapchain:
15574 // Acquire an image from a swapchain:
15575 // Present an image to a swapchain:
15576 // Destroy the swapchain:
15577
15578 // TODOs:
15579 //
15580 // - Try destroying the device without first destroying the swapchain
15581 //
15582 // - Try destroying the device without first destroying the surface
15583 //
15584 // - Try destroying the surface without first destroying the swapchain
15585
15586 // Destroy the surface:
15587 vkDestroySurfaceKHR(instance(), surface, NULL);
15588
15589 // Tear down the window:
15590 xcb_destroy_window(connection, xcb_window);
15591 xcb_disconnect(connection);
15592
15593#else // VK_USE_PLATFORM_XCB_KHR
15594 return;
15595#endif // VK_USE_PLATFORM_XCB_KHR
15596}
Chris Forbes09368e42016-10-13 11:59:22 +130015597#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015598
15599//
15600// POSITIVE VALIDATION TESTS
15601//
15602// These tests do not expect to encounter ANY validation errors pass only if this is true
15603
Tobin Ehlise0006882016-11-03 10:14:28 -060015604TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15605 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15606 "by a transition in the primary.");
15607 VkResult err;
15608 m_errorMonitor->ExpectSuccess();
15609 ASSERT_NO_FATAL_FAILURE(InitState());
15610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15611 // Allocate a secondary and primary cmd buffer
15612 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15613 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15614 command_buffer_allocate_info.commandPool = m_commandPool;
15615 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15616 command_buffer_allocate_info.commandBufferCount = 1;
15617
15618 VkCommandBuffer secondary_command_buffer;
15619 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15620 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15621 VkCommandBuffer primary_command_buffer;
15622 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15623 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15624 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15625 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15626 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15627 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15628 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15629
15630 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15631 ASSERT_VK_SUCCESS(err);
15632 VkImageObj image(m_device);
15633 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15634 ASSERT_TRUE(image.initialized());
15635 VkImageMemoryBarrier img_barrier = {};
15636 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15637 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15638 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15639 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15640 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15641 img_barrier.image = image.handle();
15642 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15643 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15644 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15645 img_barrier.subresourceRange.baseArrayLayer = 0;
15646 img_barrier.subresourceRange.baseMipLevel = 0;
15647 img_barrier.subresourceRange.layerCount = 1;
15648 img_barrier.subresourceRange.levelCount = 1;
15649 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15650 0, nullptr, 1, &img_barrier);
15651 err = vkEndCommandBuffer(secondary_command_buffer);
15652 ASSERT_VK_SUCCESS(err);
15653
15654 // Now update primary cmd buffer to execute secondary and transitions image
15655 command_buffer_begin_info.pInheritanceInfo = nullptr;
15656 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15657 ASSERT_VK_SUCCESS(err);
15658 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15659 VkImageMemoryBarrier img_barrier2 = {};
15660 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15661 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15662 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15663 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15664 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15665 img_barrier2.image = image.handle();
15666 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15667 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15668 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15669 img_barrier2.subresourceRange.baseArrayLayer = 0;
15670 img_barrier2.subresourceRange.baseMipLevel = 0;
15671 img_barrier2.subresourceRange.layerCount = 1;
15672 img_barrier2.subresourceRange.levelCount = 1;
15673 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15674 nullptr, 1, &img_barrier2);
15675 err = vkEndCommandBuffer(primary_command_buffer);
15676 ASSERT_VK_SUCCESS(err);
15677 VkSubmitInfo submit_info = {};
15678 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15679 submit_info.commandBufferCount = 1;
15680 submit_info.pCommandBuffers = &primary_command_buffer;
15681 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15682 ASSERT_VK_SUCCESS(err);
15683 m_errorMonitor->VerifyNotFound();
15684 err = vkDeviceWaitIdle(m_device->device());
15685 ASSERT_VK_SUCCESS(err);
15686 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15687 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15688}
15689
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015690// This is a positive test. No failures are expected.
15691TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15692 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15693 "is ignoring VkWriteDescriptorSet members that are not "
15694 "related to the descriptor type specified by "
15695 "VkWriteDescriptorSet::descriptorType. Correct "
15696 "validation behavior will result in the test running to "
15697 "completion without validation errors.");
15698
15699 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15700
15701 ASSERT_NO_FATAL_FAILURE(InitState());
15702
15703 // Image Case
15704 {
15705 m_errorMonitor->ExpectSuccess();
15706
15707 VkImage image;
15708 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15709 const int32_t tex_width = 32;
15710 const int32_t tex_height = 32;
15711 VkImageCreateInfo image_create_info = {};
15712 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15713 image_create_info.pNext = NULL;
15714 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15715 image_create_info.format = tex_format;
15716 image_create_info.extent.width = tex_width;
15717 image_create_info.extent.height = tex_height;
15718 image_create_info.extent.depth = 1;
15719 image_create_info.mipLevels = 1;
15720 image_create_info.arrayLayers = 1;
15721 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15722 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15723 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15724 image_create_info.flags = 0;
15725 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15726 ASSERT_VK_SUCCESS(err);
15727
15728 VkMemoryRequirements memory_reqs;
15729 VkDeviceMemory image_memory;
15730 bool pass;
15731 VkMemoryAllocateInfo memory_info = {};
15732 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15733 memory_info.pNext = NULL;
15734 memory_info.allocationSize = 0;
15735 memory_info.memoryTypeIndex = 0;
15736 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15737 memory_info.allocationSize = memory_reqs.size;
15738 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15739 ASSERT_TRUE(pass);
15740 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15741 ASSERT_VK_SUCCESS(err);
15742 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15743 ASSERT_VK_SUCCESS(err);
15744
15745 VkImageViewCreateInfo image_view_create_info = {};
15746 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15747 image_view_create_info.image = image;
15748 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15749 image_view_create_info.format = tex_format;
15750 image_view_create_info.subresourceRange.layerCount = 1;
15751 image_view_create_info.subresourceRange.baseMipLevel = 0;
15752 image_view_create_info.subresourceRange.levelCount = 1;
15753 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15754
15755 VkImageView view;
15756 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15757 ASSERT_VK_SUCCESS(err);
15758
15759 VkDescriptorPoolSize ds_type_count = {};
15760 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15761 ds_type_count.descriptorCount = 1;
15762
15763 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15764 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15765 ds_pool_ci.pNext = NULL;
15766 ds_pool_ci.maxSets = 1;
15767 ds_pool_ci.poolSizeCount = 1;
15768 ds_pool_ci.pPoolSizes = &ds_type_count;
15769
15770 VkDescriptorPool ds_pool;
15771 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15772 ASSERT_VK_SUCCESS(err);
15773
15774 VkDescriptorSetLayoutBinding dsl_binding = {};
15775 dsl_binding.binding = 0;
15776 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15777 dsl_binding.descriptorCount = 1;
15778 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15779 dsl_binding.pImmutableSamplers = NULL;
15780
15781 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15782 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15783 ds_layout_ci.pNext = NULL;
15784 ds_layout_ci.bindingCount = 1;
15785 ds_layout_ci.pBindings = &dsl_binding;
15786 VkDescriptorSetLayout ds_layout;
15787 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15788 ASSERT_VK_SUCCESS(err);
15789
15790 VkDescriptorSet descriptor_set;
15791 VkDescriptorSetAllocateInfo alloc_info = {};
15792 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15793 alloc_info.descriptorSetCount = 1;
15794 alloc_info.descriptorPool = ds_pool;
15795 alloc_info.pSetLayouts = &ds_layout;
15796 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15797 ASSERT_VK_SUCCESS(err);
15798
15799 VkDescriptorImageInfo image_info = {};
15800 image_info.imageView = view;
15801 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15802
15803 VkWriteDescriptorSet descriptor_write;
15804 memset(&descriptor_write, 0, sizeof(descriptor_write));
15805 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15806 descriptor_write.dstSet = descriptor_set;
15807 descriptor_write.dstBinding = 0;
15808 descriptor_write.descriptorCount = 1;
15809 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15810 descriptor_write.pImageInfo = &image_info;
15811
15812 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15813 // be
15814 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15815 // This will most likely produce a crash if the parameter_validation
15816 // layer
15817 // does not correctly ignore pBufferInfo.
15818 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15819 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15820
15821 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15822
15823 m_errorMonitor->VerifyNotFound();
15824
15825 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15826 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15827 vkDestroyImageView(m_device->device(), view, NULL);
15828 vkDestroyImage(m_device->device(), image, NULL);
15829 vkFreeMemory(m_device->device(), image_memory, NULL);
15830 }
15831
15832 // Buffer Case
15833 {
15834 m_errorMonitor->ExpectSuccess();
15835
15836 VkBuffer buffer;
15837 uint32_t queue_family_index = 0;
15838 VkBufferCreateInfo buffer_create_info = {};
15839 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15840 buffer_create_info.size = 1024;
15841 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15842 buffer_create_info.queueFamilyIndexCount = 1;
15843 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15844
15845 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15846 ASSERT_VK_SUCCESS(err);
15847
15848 VkMemoryRequirements memory_reqs;
15849 VkDeviceMemory buffer_memory;
15850 bool pass;
15851 VkMemoryAllocateInfo memory_info = {};
15852 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15853 memory_info.pNext = NULL;
15854 memory_info.allocationSize = 0;
15855 memory_info.memoryTypeIndex = 0;
15856
15857 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15858 memory_info.allocationSize = memory_reqs.size;
15859 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15860 ASSERT_TRUE(pass);
15861
15862 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15863 ASSERT_VK_SUCCESS(err);
15864 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15865 ASSERT_VK_SUCCESS(err);
15866
15867 VkDescriptorPoolSize ds_type_count = {};
15868 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15869 ds_type_count.descriptorCount = 1;
15870
15871 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15872 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15873 ds_pool_ci.pNext = NULL;
15874 ds_pool_ci.maxSets = 1;
15875 ds_pool_ci.poolSizeCount = 1;
15876 ds_pool_ci.pPoolSizes = &ds_type_count;
15877
15878 VkDescriptorPool ds_pool;
15879 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15880 ASSERT_VK_SUCCESS(err);
15881
15882 VkDescriptorSetLayoutBinding dsl_binding = {};
15883 dsl_binding.binding = 0;
15884 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15885 dsl_binding.descriptorCount = 1;
15886 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15887 dsl_binding.pImmutableSamplers = NULL;
15888
15889 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15890 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15891 ds_layout_ci.pNext = NULL;
15892 ds_layout_ci.bindingCount = 1;
15893 ds_layout_ci.pBindings = &dsl_binding;
15894 VkDescriptorSetLayout ds_layout;
15895 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15896 ASSERT_VK_SUCCESS(err);
15897
15898 VkDescriptorSet descriptor_set;
15899 VkDescriptorSetAllocateInfo alloc_info = {};
15900 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15901 alloc_info.descriptorSetCount = 1;
15902 alloc_info.descriptorPool = ds_pool;
15903 alloc_info.pSetLayouts = &ds_layout;
15904 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15905 ASSERT_VK_SUCCESS(err);
15906
15907 VkDescriptorBufferInfo buffer_info = {};
15908 buffer_info.buffer = buffer;
15909 buffer_info.offset = 0;
15910 buffer_info.range = 1024;
15911
15912 VkWriteDescriptorSet descriptor_write;
15913 memset(&descriptor_write, 0, sizeof(descriptor_write));
15914 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15915 descriptor_write.dstSet = descriptor_set;
15916 descriptor_write.dstBinding = 0;
15917 descriptor_write.descriptorCount = 1;
15918 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15919 descriptor_write.pBufferInfo = &buffer_info;
15920
15921 // Set pImageInfo and pTexelBufferView to invalid values, which should
15922 // be
15923 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15924 // This will most likely produce a crash if the parameter_validation
15925 // layer
15926 // does not correctly ignore pImageInfo.
15927 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15928 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15929
15930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15931
15932 m_errorMonitor->VerifyNotFound();
15933
15934 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15937 vkDestroyBuffer(m_device->device(), buffer, NULL);
15938 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15939 }
15940
15941 // Texel Buffer Case
15942 {
15943 m_errorMonitor->ExpectSuccess();
15944
15945 VkBuffer buffer;
15946 uint32_t queue_family_index = 0;
15947 VkBufferCreateInfo buffer_create_info = {};
15948 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15949 buffer_create_info.size = 1024;
15950 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15951 buffer_create_info.queueFamilyIndexCount = 1;
15952 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15953
15954 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15955 ASSERT_VK_SUCCESS(err);
15956
15957 VkMemoryRequirements memory_reqs;
15958 VkDeviceMemory buffer_memory;
15959 bool pass;
15960 VkMemoryAllocateInfo memory_info = {};
15961 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15962 memory_info.pNext = NULL;
15963 memory_info.allocationSize = 0;
15964 memory_info.memoryTypeIndex = 0;
15965
15966 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15967 memory_info.allocationSize = memory_reqs.size;
15968 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15969 ASSERT_TRUE(pass);
15970
15971 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15972 ASSERT_VK_SUCCESS(err);
15973 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15974 ASSERT_VK_SUCCESS(err);
15975
15976 VkBufferViewCreateInfo buff_view_ci = {};
15977 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15978 buff_view_ci.buffer = buffer;
15979 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15980 buff_view_ci.range = VK_WHOLE_SIZE;
15981 VkBufferView buffer_view;
15982 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15983
15984 VkDescriptorPoolSize ds_type_count = {};
15985 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15986 ds_type_count.descriptorCount = 1;
15987
15988 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15989 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15990 ds_pool_ci.pNext = NULL;
15991 ds_pool_ci.maxSets = 1;
15992 ds_pool_ci.poolSizeCount = 1;
15993 ds_pool_ci.pPoolSizes = &ds_type_count;
15994
15995 VkDescriptorPool ds_pool;
15996 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15997 ASSERT_VK_SUCCESS(err);
15998
15999 VkDescriptorSetLayoutBinding dsl_binding = {};
16000 dsl_binding.binding = 0;
16001 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16002 dsl_binding.descriptorCount = 1;
16003 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16004 dsl_binding.pImmutableSamplers = NULL;
16005
16006 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16007 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16008 ds_layout_ci.pNext = NULL;
16009 ds_layout_ci.bindingCount = 1;
16010 ds_layout_ci.pBindings = &dsl_binding;
16011 VkDescriptorSetLayout ds_layout;
16012 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16013 ASSERT_VK_SUCCESS(err);
16014
16015 VkDescriptorSet descriptor_set;
16016 VkDescriptorSetAllocateInfo alloc_info = {};
16017 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16018 alloc_info.descriptorSetCount = 1;
16019 alloc_info.descriptorPool = ds_pool;
16020 alloc_info.pSetLayouts = &ds_layout;
16021 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16022 ASSERT_VK_SUCCESS(err);
16023
16024 VkWriteDescriptorSet descriptor_write;
16025 memset(&descriptor_write, 0, sizeof(descriptor_write));
16026 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16027 descriptor_write.dstSet = descriptor_set;
16028 descriptor_write.dstBinding = 0;
16029 descriptor_write.descriptorCount = 1;
16030 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16031 descriptor_write.pTexelBufferView = &buffer_view;
16032
16033 // Set pImageInfo and pBufferInfo to invalid values, which should be
16034 // ignored for descriptorType ==
16035 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16036 // This will most likely produce a crash if the parameter_validation
16037 // layer
16038 // does not correctly ignore pImageInfo and pBufferInfo.
16039 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16040 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16041
16042 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16043
16044 m_errorMonitor->VerifyNotFound();
16045
16046 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
16047 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16048 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16049 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16050 vkDestroyBuffer(m_device->device(), buffer, NULL);
16051 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16052 }
16053}
16054
Tobin Ehlisf7428442016-10-25 07:58:24 -060016055TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16056 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16057
16058 ASSERT_NO_FATAL_FAILURE(InitState());
16059 // Create layout where two binding #s are "1"
16060 static const uint32_t NUM_BINDINGS = 3;
16061 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16062 dsl_binding[0].binding = 1;
16063 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16064 dsl_binding[0].descriptorCount = 1;
16065 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16066 dsl_binding[0].pImmutableSamplers = NULL;
16067 dsl_binding[1].binding = 0;
16068 dsl_binding[1].descriptorCount = 1;
16069 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16070 dsl_binding[1].descriptorCount = 1;
16071 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16072 dsl_binding[1].pImmutableSamplers = NULL;
16073 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16074 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16075 dsl_binding[2].descriptorCount = 1;
16076 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16077 dsl_binding[2].pImmutableSamplers = NULL;
16078
16079 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16080 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16081 ds_layout_ci.pNext = NULL;
16082 ds_layout_ci.bindingCount = NUM_BINDINGS;
16083 ds_layout_ci.pBindings = dsl_binding;
16084 VkDescriptorSetLayout ds_layout;
16085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16086 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16087 m_errorMonitor->VerifyFound();
16088}
16089
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016090TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016091 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16092
16093 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016094
16095 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016096
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016097 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16098
16099 {
16100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16101 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16102 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16103 m_errorMonitor->VerifyFound();
16104 }
16105
16106 {
16107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16108 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16109 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16110 m_errorMonitor->VerifyFound();
16111 }
16112
16113 {
16114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16115 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16116 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16117 m_errorMonitor->VerifyFound();
16118 }
16119
16120 {
16121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16122 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16123 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16124 m_errorMonitor->VerifyFound();
16125 }
16126
16127 {
16128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16129 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16130 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16131 m_errorMonitor->VerifyFound();
16132 }
16133
16134 {
16135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16136 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16137 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16138 m_errorMonitor->VerifyFound();
16139 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016140
16141 {
16142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16143 VkRect2D scissor = {{-1, 0}, {16, 16}};
16144 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16145 m_errorMonitor->VerifyFound();
16146 }
16147
16148 {
16149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16150 VkRect2D scissor = {{0, -2}, {16, 16}};
16151 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16152 m_errorMonitor->VerifyFound();
16153 }
16154
16155 {
16156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16157 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16158 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16159 m_errorMonitor->VerifyFound();
16160 }
16161
16162 {
16163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16164 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16165 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16166 m_errorMonitor->VerifyFound();
16167 }
16168
16169 EndCommandBuffer();
16170}
16171
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016172// This is a positive test. No failures are expected.
16173TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16174 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16175 VkResult err;
16176
16177 ASSERT_NO_FATAL_FAILURE(InitState());
16178 m_errorMonitor->ExpectSuccess();
16179 VkDescriptorPoolSize ds_type_count = {};
16180 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16181 ds_type_count.descriptorCount = 2;
16182
16183 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16184 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16185 ds_pool_ci.pNext = NULL;
16186 ds_pool_ci.maxSets = 1;
16187 ds_pool_ci.poolSizeCount = 1;
16188 ds_pool_ci.pPoolSizes = &ds_type_count;
16189
16190 VkDescriptorPool ds_pool;
16191 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16192 ASSERT_VK_SUCCESS(err);
16193
16194 // Create layout with two uniform buffer descriptors w/ empty binding between them
16195 static const uint32_t NUM_BINDINGS = 3;
16196 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16197 dsl_binding[0].binding = 0;
16198 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16199 dsl_binding[0].descriptorCount = 1;
16200 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16201 dsl_binding[0].pImmutableSamplers = NULL;
16202 dsl_binding[1].binding = 1;
16203 dsl_binding[1].descriptorCount = 0; // empty binding
16204 dsl_binding[2].binding = 2;
16205 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16206 dsl_binding[2].descriptorCount = 1;
16207 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16208 dsl_binding[2].pImmutableSamplers = NULL;
16209
16210 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16211 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16212 ds_layout_ci.pNext = NULL;
16213 ds_layout_ci.bindingCount = NUM_BINDINGS;
16214 ds_layout_ci.pBindings = dsl_binding;
16215 VkDescriptorSetLayout ds_layout;
16216 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16217 ASSERT_VK_SUCCESS(err);
16218
16219 VkDescriptorSet descriptor_set = {};
16220 VkDescriptorSetAllocateInfo alloc_info = {};
16221 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16222 alloc_info.descriptorSetCount = 1;
16223 alloc_info.descriptorPool = ds_pool;
16224 alloc_info.pSetLayouts = &ds_layout;
16225 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16226 ASSERT_VK_SUCCESS(err);
16227
16228 // Create a buffer to be used for update
16229 VkBufferCreateInfo buff_ci = {};
16230 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16231 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16232 buff_ci.size = 256;
16233 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16234 VkBuffer buffer;
16235 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16236 ASSERT_VK_SUCCESS(err);
16237 // Have to bind memory to buffer before descriptor update
16238 VkMemoryAllocateInfo mem_alloc = {};
16239 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16240 mem_alloc.pNext = NULL;
16241 mem_alloc.allocationSize = 512; // one allocation for both buffers
16242 mem_alloc.memoryTypeIndex = 0;
16243
16244 VkMemoryRequirements mem_reqs;
16245 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16246 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16247 if (!pass) {
16248 vkDestroyBuffer(m_device->device(), buffer, NULL);
16249 return;
16250 }
16251
16252 VkDeviceMemory mem;
16253 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16254 ASSERT_VK_SUCCESS(err);
16255 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16256 ASSERT_VK_SUCCESS(err);
16257
16258 // Only update the descriptor at binding 2
16259 VkDescriptorBufferInfo buff_info = {};
16260 buff_info.buffer = buffer;
16261 buff_info.offset = 0;
16262 buff_info.range = VK_WHOLE_SIZE;
16263 VkWriteDescriptorSet descriptor_write = {};
16264 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16265 descriptor_write.dstBinding = 2;
16266 descriptor_write.descriptorCount = 1;
16267 descriptor_write.pTexelBufferView = nullptr;
16268 descriptor_write.pBufferInfo = &buff_info;
16269 descriptor_write.pImageInfo = nullptr;
16270 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16271 descriptor_write.dstSet = descriptor_set;
16272
16273 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16274
16275 m_errorMonitor->VerifyNotFound();
16276 // Cleanup
16277 vkFreeMemory(m_device->device(), mem, NULL);
16278 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16279 vkDestroyBuffer(m_device->device(), buffer, NULL);
16280 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16281}
16282
16283// This is a positive test. No failures are expected.
16284TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16285 VkResult err;
16286 bool pass;
16287
16288 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16289 "the buffer, create an image, and bind the same memory to "
16290 "it");
16291
16292 m_errorMonitor->ExpectSuccess();
16293
16294 ASSERT_NO_FATAL_FAILURE(InitState());
16295
16296 VkBuffer buffer;
16297 VkImage image;
16298 VkDeviceMemory mem;
16299 VkMemoryRequirements mem_reqs;
16300
16301 VkBufferCreateInfo buf_info = {};
16302 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16303 buf_info.pNext = NULL;
16304 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16305 buf_info.size = 256;
16306 buf_info.queueFamilyIndexCount = 0;
16307 buf_info.pQueueFamilyIndices = NULL;
16308 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16309 buf_info.flags = 0;
16310 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16311 ASSERT_VK_SUCCESS(err);
16312
16313 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16314
16315 VkMemoryAllocateInfo alloc_info = {};
16316 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16317 alloc_info.pNext = NULL;
16318 alloc_info.memoryTypeIndex = 0;
16319
16320 // Ensure memory is big enough for both bindings
16321 alloc_info.allocationSize = 0x10000;
16322
16323 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16324 if (!pass) {
16325 vkDestroyBuffer(m_device->device(), buffer, NULL);
16326 return;
16327 }
16328
16329 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16330 ASSERT_VK_SUCCESS(err);
16331
16332 uint8_t *pData;
16333 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16334 ASSERT_VK_SUCCESS(err);
16335
16336 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16337
16338 vkUnmapMemory(m_device->device(), mem);
16339
16340 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16341 ASSERT_VK_SUCCESS(err);
16342
16343 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16344 // memory. In fact, it was never used by the GPU.
16345 // Just be be sure, wait for idle.
16346 vkDestroyBuffer(m_device->device(), buffer, NULL);
16347 vkDeviceWaitIdle(m_device->device());
16348
16349 VkImageCreateInfo image_create_info = {};
16350 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16351 image_create_info.pNext = NULL;
16352 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16353 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16354 image_create_info.extent.width = 64;
16355 image_create_info.extent.height = 64;
16356 image_create_info.extent.depth = 1;
16357 image_create_info.mipLevels = 1;
16358 image_create_info.arrayLayers = 1;
16359 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16360 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16361 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16362 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16363 image_create_info.queueFamilyIndexCount = 0;
16364 image_create_info.pQueueFamilyIndices = NULL;
16365 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16366 image_create_info.flags = 0;
16367
16368 VkMemoryAllocateInfo mem_alloc = {};
16369 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16370 mem_alloc.pNext = NULL;
16371 mem_alloc.allocationSize = 0;
16372 mem_alloc.memoryTypeIndex = 0;
16373
16374 /* Create a mappable image. It will be the texture if linear images are ok
16375 * to be textures or it will be the staging image if they are not.
16376 */
16377 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16378 ASSERT_VK_SUCCESS(err);
16379
16380 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16381
16382 mem_alloc.allocationSize = mem_reqs.size;
16383
16384 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16385 if (!pass) {
16386 vkDestroyImage(m_device->device(), image, NULL);
16387 return;
16388 }
16389
16390 // VALIDATION FAILURE:
16391 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16392 ASSERT_VK_SUCCESS(err);
16393
16394 m_errorMonitor->VerifyNotFound();
16395
16396 vkFreeMemory(m_device->device(), mem, NULL);
16397 vkDestroyBuffer(m_device->device(), buffer, NULL);
16398 vkDestroyImage(m_device->device(), image, NULL);
16399}
16400
Tobin Ehlis953e8392016-11-17 10:54:13 -070016401TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
16402 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
16403 // We previously had a bug where dynamic offset of inactive bindings was still being used
16404 VkResult err;
16405 m_errorMonitor->ExpectSuccess();
16406
16407 ASSERT_NO_FATAL_FAILURE(InitState());
16408 ASSERT_NO_FATAL_FAILURE(InitViewport());
16409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16410
16411 VkDescriptorPoolSize ds_type_count = {};
16412 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16413 ds_type_count.descriptorCount = 3;
16414
16415 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16416 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16417 ds_pool_ci.pNext = NULL;
16418 ds_pool_ci.maxSets = 1;
16419 ds_pool_ci.poolSizeCount = 1;
16420 ds_pool_ci.pPoolSizes = &ds_type_count;
16421
16422 VkDescriptorPool ds_pool;
16423 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16424 ASSERT_VK_SUCCESS(err);
16425
16426 const uint32_t BINDING_COUNT = 3;
16427 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
16428 dsl_binding[0].binding = 0;
16429 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16430 dsl_binding[0].descriptorCount = 1;
16431 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16432 dsl_binding[0].pImmutableSamplers = NULL;
16433 dsl_binding[1].binding = 1;
16434 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16435 dsl_binding[1].descriptorCount = 1;
16436 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16437 dsl_binding[1].pImmutableSamplers = NULL;
16438 dsl_binding[2].binding = 2;
16439 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16440 dsl_binding[2].descriptorCount = 1;
16441 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16442 dsl_binding[2].pImmutableSamplers = NULL;
16443
16444 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16445 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16446 ds_layout_ci.pNext = NULL;
16447 ds_layout_ci.bindingCount = BINDING_COUNT;
16448 ds_layout_ci.pBindings = dsl_binding;
16449 VkDescriptorSetLayout ds_layout;
16450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16451 ASSERT_VK_SUCCESS(err);
16452
16453 VkDescriptorSet descriptor_set;
16454 VkDescriptorSetAllocateInfo alloc_info = {};
16455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16456 alloc_info.descriptorSetCount = 1;
16457 alloc_info.descriptorPool = ds_pool;
16458 alloc_info.pSetLayouts = &ds_layout;
16459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16460 ASSERT_VK_SUCCESS(err);
16461
16462 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
16463 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
16464 pipeline_layout_ci.pNext = NULL;
16465 pipeline_layout_ci.setLayoutCount = 1;
16466 pipeline_layout_ci.pSetLayouts = &ds_layout;
16467
16468 VkPipelineLayout pipeline_layout;
16469 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
16470 ASSERT_VK_SUCCESS(err);
16471
16472 // Create two buffers to update the descriptors with
16473 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
16474 uint32_t qfi = 0;
16475 VkBufferCreateInfo buffCI = {};
16476 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16477 buffCI.size = 2048;
16478 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16479 buffCI.queueFamilyIndexCount = 1;
16480 buffCI.pQueueFamilyIndices = &qfi;
16481
16482 VkBuffer dyub1;
16483 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
16484 ASSERT_VK_SUCCESS(err);
16485 // buffer2
16486 buffCI.size = 1024;
16487 VkBuffer dyub2;
16488 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
16489 ASSERT_VK_SUCCESS(err);
16490 // Allocate memory and bind to buffers
16491 VkMemoryAllocateInfo mem_alloc[2] = {};
16492 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16493 mem_alloc[0].pNext = NULL;
16494 mem_alloc[0].memoryTypeIndex = 0;
16495 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16496 mem_alloc[1].pNext = NULL;
16497 mem_alloc[1].memoryTypeIndex = 0;
16498
16499 VkMemoryRequirements mem_reqs1;
16500 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
16501 VkMemoryRequirements mem_reqs2;
16502 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
16503 mem_alloc[0].allocationSize = mem_reqs1.size;
16504 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
16505 mem_alloc[1].allocationSize = mem_reqs2.size;
16506 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
16507 if (!pass) {
16508 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16509 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16510 return;
16511 }
16512
16513 VkDeviceMemory mem1;
16514 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
16515 ASSERT_VK_SUCCESS(err);
16516 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
16517 ASSERT_VK_SUCCESS(err);
16518 VkDeviceMemory mem2;
16519 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
16520 ASSERT_VK_SUCCESS(err);
16521 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
16522 ASSERT_VK_SUCCESS(err);
16523 // Update descriptors
16524 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
16525 buff_info[0].buffer = dyub1;
16526 buff_info[0].offset = 0;
16527 buff_info[0].range = 256;
16528 buff_info[1].buffer = dyub1;
16529 buff_info[1].offset = 256;
16530 buff_info[1].range = 512;
16531 buff_info[2].buffer = dyub2;
16532 buff_info[2].offset = 0;
16533 buff_info[2].range = 512;
16534
16535 VkWriteDescriptorSet descriptor_write;
16536 memset(&descriptor_write, 0, sizeof(descriptor_write));
16537 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16538 descriptor_write.dstSet = descriptor_set;
16539 descriptor_write.dstBinding = 0;
16540 descriptor_write.descriptorCount = BINDING_COUNT;
16541 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
16542 descriptor_write.pBufferInfo = buff_info;
16543
16544 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16545
16546 BeginCommandBuffer();
16547
16548 // Create PSO to be used for draw-time errors below
16549 char const *vsSource = "#version 450\n"
16550 "\n"
16551 "out gl_PerVertex { \n"
16552 " vec4 gl_Position;\n"
16553 "};\n"
16554 "void main(){\n"
16555 " gl_Position = vec4(1);\n"
16556 "}\n";
16557 char const *fsSource = "#version 450\n"
16558 "\n"
16559 "layout(location=0) out vec4 x;\n"
16560 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
16561 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
16562 "void main(){\n"
16563 " x = vec4(bar1.y) + vec4(bar2.y);\n"
16564 "}\n";
16565 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16566 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16567 VkPipelineObj pipe(m_device);
16568 pipe.SetViewport(m_viewports);
16569 pipe.SetScissor(m_scissors);
16570 pipe.AddShader(&vs);
16571 pipe.AddShader(&fs);
16572 pipe.AddColorAttachment();
16573 pipe.CreateVKPipeline(pipeline_layout, renderPass());
16574
16575 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
16576 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
16577 // we used to have a bug in this case.
16578 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
16579 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
16580 &descriptor_set, BINDING_COUNT, dyn_off);
16581 Draw(1, 0, 0, 0);
16582 m_errorMonitor->VerifyNotFound();
16583
16584 vkDestroyBuffer(m_device->device(), dyub1, NULL);
16585 vkDestroyBuffer(m_device->device(), dyub2, NULL);
16586 vkFreeMemory(m_device->device(), mem1, NULL);
16587 vkFreeMemory(m_device->device(), mem2, NULL);
16588
16589 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
16590 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16591 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16592}
16593
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016594TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16595
16596 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16597 "mapping while using VK_WHOLE_SIZE does not cause access "
16598 "violations");
16599 VkResult err;
16600 uint8_t *pData;
16601 ASSERT_NO_FATAL_FAILURE(InitState());
16602
16603 VkDeviceMemory mem;
16604 VkMemoryRequirements mem_reqs;
16605 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16606 VkMemoryAllocateInfo alloc_info = {};
16607 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16608 alloc_info.pNext = NULL;
16609 alloc_info.memoryTypeIndex = 0;
16610
16611 static const VkDeviceSize allocation_size = 0x1000;
16612 alloc_info.allocationSize = allocation_size;
16613
16614 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16615 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16616 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16617 if (!pass) {
16618 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16619 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16620 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16621 if (!pass) {
16622 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16623 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16624 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16625 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16626 if (!pass) {
16627 return;
16628 }
16629 }
16630 }
16631
16632 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16633 ASSERT_VK_SUCCESS(err);
16634
16635 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16636 // mapped range
16637 m_errorMonitor->ExpectSuccess();
16638 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16639 ASSERT_VK_SUCCESS(err);
16640 VkMappedMemoryRange mmr = {};
16641 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16642 mmr.memory = mem;
16643 mmr.offset = 0;
16644 mmr.size = VK_WHOLE_SIZE;
16645 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16646 ASSERT_VK_SUCCESS(err);
16647 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16648 ASSERT_VK_SUCCESS(err);
16649 m_errorMonitor->VerifyNotFound();
16650 vkUnmapMemory(m_device->device(), mem);
16651
16652 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16653 // mapped range
16654 m_errorMonitor->ExpectSuccess();
16655 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16656 ASSERT_VK_SUCCESS(err);
16657 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16658 mmr.memory = mem;
16659 mmr.offset = 13;
16660 mmr.size = VK_WHOLE_SIZE;
16661 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16662 ASSERT_VK_SUCCESS(err);
16663 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16664 ASSERT_VK_SUCCESS(err);
16665 m_errorMonitor->VerifyNotFound();
16666 vkUnmapMemory(m_device->device(), mem);
16667
16668 // Map with prime offset and size
16669 // Flush/Invalidate subrange of mapped area with prime offset and size
16670 m_errorMonitor->ExpectSuccess();
16671 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16672 ASSERT_VK_SUCCESS(err);
16673 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16674 mmr.memory = mem;
16675 mmr.offset = allocation_size - 107;
16676 mmr.size = 61;
16677 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16678 ASSERT_VK_SUCCESS(err);
16679 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16680 ASSERT_VK_SUCCESS(err);
16681 m_errorMonitor->VerifyNotFound();
16682 vkUnmapMemory(m_device->device(), mem);
16683
16684 // Map without offset and flush WHOLE_SIZE with two separate offsets
16685 m_errorMonitor->ExpectSuccess();
16686 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16687 ASSERT_VK_SUCCESS(err);
16688 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16689 mmr.memory = mem;
16690 mmr.offset = allocation_size - 100;
16691 mmr.size = VK_WHOLE_SIZE;
16692 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16693 ASSERT_VK_SUCCESS(err);
16694 mmr.offset = allocation_size - 200;
16695 mmr.size = VK_WHOLE_SIZE;
16696 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16697 ASSERT_VK_SUCCESS(err);
16698 m_errorMonitor->VerifyNotFound();
16699 vkUnmapMemory(m_device->device(), mem);
16700
16701 vkFreeMemory(m_device->device(), mem, NULL);
16702}
16703
16704// This is a positive test. We used to expect error in this case but spec now allows it
16705TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16706 m_errorMonitor->ExpectSuccess();
16707 vk_testing::Fence testFence;
16708 VkFenceCreateInfo fenceInfo = {};
16709 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16710 fenceInfo.pNext = NULL;
16711
16712 ASSERT_NO_FATAL_FAILURE(InitState());
16713 testFence.init(*m_device, fenceInfo);
16714 VkFence fences[1] = { testFence.handle() };
16715 VkResult result = vkResetFences(m_device->device(), 1, fences);
16716 ASSERT_VK_SUCCESS(result);
16717
16718 m_errorMonitor->VerifyNotFound();
16719}
16720
16721TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16722 m_errorMonitor->ExpectSuccess();
16723
16724 ASSERT_NO_FATAL_FAILURE(InitState());
16725 VkResult err;
16726
16727 // Record (empty!) command buffer that can be submitted multiple times
16728 // simultaneously.
16729 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16730 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16731 m_commandBuffer->BeginCommandBuffer(&cbbi);
16732 m_commandBuffer->EndCommandBuffer();
16733
16734 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16735 VkFence fence;
16736 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16737 ASSERT_VK_SUCCESS(err);
16738
16739 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16740 VkSemaphore s1, s2;
16741 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16742 ASSERT_VK_SUCCESS(err);
16743 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16744 ASSERT_VK_SUCCESS(err);
16745
16746 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16747 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16748 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16749 ASSERT_VK_SUCCESS(err);
16750
16751 // Submit CB again, signaling s2.
16752 si.pSignalSemaphores = &s2;
16753 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16754 ASSERT_VK_SUCCESS(err);
16755
16756 // Wait for fence.
16757 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16758 ASSERT_VK_SUCCESS(err);
16759
16760 // CB is still in flight from second submission, but semaphore s1 is no
16761 // longer in flight. delete it.
16762 vkDestroySemaphore(m_device->device(), s1, nullptr);
16763
16764 m_errorMonitor->VerifyNotFound();
16765
16766 // Force device idle and clean up remaining objects
16767 vkDeviceWaitIdle(m_device->device());
16768 vkDestroySemaphore(m_device->device(), s2, nullptr);
16769 vkDestroyFence(m_device->device(), fence, nullptr);
16770}
16771
16772TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16773 m_errorMonitor->ExpectSuccess();
16774
16775 ASSERT_NO_FATAL_FAILURE(InitState());
16776 VkResult err;
16777
16778 // A fence created signaled
16779 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16780 VkFence f1;
16781 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16782 ASSERT_VK_SUCCESS(err);
16783
16784 // A fence created not
16785 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16786 VkFence f2;
16787 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16788 ASSERT_VK_SUCCESS(err);
16789
16790 // Submit the unsignaled fence
16791 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16792 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16793
16794 // Wait on both fences, with signaled first.
16795 VkFence fences[] = { f1, f2 };
16796 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16797
16798 // Should have both retired!
16799 vkDestroyFence(m_device->device(), f1, nullptr);
16800 vkDestroyFence(m_device->device(), f2, nullptr);
16801
16802 m_errorMonitor->VerifyNotFound();
16803}
16804
16805TEST_F(VkPositiveLayerTest, ValidUsage) {
16806 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16807 "doesn't generate validation errors");
16808
16809 ASSERT_NO_FATAL_FAILURE(InitState());
16810
16811 m_errorMonitor->ExpectSuccess();
16812 // Verify that we can create a view with usage INPUT_ATTACHMENT
16813 VkImageObj image(m_device);
16814 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16815 ASSERT_TRUE(image.initialized());
16816 VkImageView imageView;
16817 VkImageViewCreateInfo ivci = {};
16818 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16819 ivci.image = image.handle();
16820 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16821 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16822 ivci.subresourceRange.layerCount = 1;
16823 ivci.subresourceRange.baseMipLevel = 0;
16824 ivci.subresourceRange.levelCount = 1;
16825 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16826
16827 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16828 m_errorMonitor->VerifyNotFound();
16829 vkDestroyImageView(m_device->device(), imageView, NULL);
16830}
16831
16832// This is a positive test. No failures are expected.
16833TEST_F(VkPositiveLayerTest, BindSparse) {
16834 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16835 "and then free the memory");
16836
16837 ASSERT_NO_FATAL_FAILURE(InitState());
16838
16839 auto index = m_device->graphics_queue_node_index_;
16840 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16841 return;
16842
16843 m_errorMonitor->ExpectSuccess();
16844
16845 VkImage image;
16846 VkImageCreateInfo image_create_info = {};
16847 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16848 image_create_info.pNext = NULL;
16849 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16850 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16851 image_create_info.extent.width = 64;
16852 image_create_info.extent.height = 64;
16853 image_create_info.extent.depth = 1;
16854 image_create_info.mipLevels = 1;
16855 image_create_info.arrayLayers = 1;
16856 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16857 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16858 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16859 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16860 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16861 ASSERT_VK_SUCCESS(err);
16862
16863 VkMemoryRequirements memory_reqs;
16864 VkDeviceMemory memory_one, memory_two;
16865 bool pass;
16866 VkMemoryAllocateInfo memory_info = {};
16867 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16868 memory_info.pNext = NULL;
16869 memory_info.allocationSize = 0;
16870 memory_info.memoryTypeIndex = 0;
16871 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16872 // Find an image big enough to allow sparse mapping of 2 memory regions
16873 // Increase the image size until it is at least twice the
16874 // size of the required alignment, to ensure we can bind both
16875 // allocated memory blocks to the image on aligned offsets.
16876 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16877 vkDestroyImage(m_device->device(), image, nullptr);
16878 image_create_info.extent.width *= 2;
16879 image_create_info.extent.height *= 2;
16880 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16881 ASSERT_VK_SUCCESS(err);
16882 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16883 }
16884 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16885 // at the end of the first
16886 memory_info.allocationSize = memory_reqs.alignment;
16887 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16888 ASSERT_TRUE(pass);
16889 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16890 ASSERT_VK_SUCCESS(err);
16891 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16892 ASSERT_VK_SUCCESS(err);
16893 VkSparseMemoryBind binds[2];
16894 binds[0].flags = 0;
16895 binds[0].memory = memory_one;
16896 binds[0].memoryOffset = 0;
16897 binds[0].resourceOffset = 0;
16898 binds[0].size = memory_info.allocationSize;
16899 binds[1].flags = 0;
16900 binds[1].memory = memory_two;
16901 binds[1].memoryOffset = 0;
16902 binds[1].resourceOffset = memory_info.allocationSize;
16903 binds[1].size = memory_info.allocationSize;
16904
16905 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16906 opaqueBindInfo.image = image;
16907 opaqueBindInfo.bindCount = 2;
16908 opaqueBindInfo.pBinds = binds;
16909
16910 VkFence fence = VK_NULL_HANDLE;
16911 VkBindSparseInfo bindSparseInfo = {};
16912 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16913 bindSparseInfo.imageOpaqueBindCount = 1;
16914 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16915
16916 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16917 vkQueueWaitIdle(m_device->m_queue);
16918 vkDestroyImage(m_device->device(), image, NULL);
16919 vkFreeMemory(m_device->device(), memory_one, NULL);
16920 vkFreeMemory(m_device->device(), memory_two, NULL);
16921 m_errorMonitor->VerifyNotFound();
16922}
16923
16924TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16925 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16926 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16927 "the command buffer has prior knowledge of that "
16928 "attachment's layout.");
16929
16930 m_errorMonitor->ExpectSuccess();
16931
16932 ASSERT_NO_FATAL_FAILURE(InitState());
16933
16934 // A renderpass with one color attachment.
16935 VkAttachmentDescription attachment = { 0,
16936 VK_FORMAT_R8G8B8A8_UNORM,
16937 VK_SAMPLE_COUNT_1_BIT,
16938 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16939 VK_ATTACHMENT_STORE_OP_STORE,
16940 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16941 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16942 VK_IMAGE_LAYOUT_UNDEFINED,
16943 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16944
16945 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16946
16947 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16948
16949 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16950
16951 VkRenderPass rp;
16952 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16953 ASSERT_VK_SUCCESS(err);
16954
16955 // A compatible framebuffer.
16956 VkImageObj image(m_device);
16957 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16958 ASSERT_TRUE(image.initialized());
16959
16960 VkImageViewCreateInfo ivci = {
16961 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16962 nullptr,
16963 0,
16964 image.handle(),
16965 VK_IMAGE_VIEW_TYPE_2D,
16966 VK_FORMAT_R8G8B8A8_UNORM,
16967 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16968 VK_COMPONENT_SWIZZLE_IDENTITY },
16969 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16970 };
16971 VkImageView view;
16972 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16973 ASSERT_VK_SUCCESS(err);
16974
16975 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16976 VkFramebuffer fb;
16977 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16978 ASSERT_VK_SUCCESS(err);
16979
16980 // Record a single command buffer which uses this renderpass twice. The
16981 // bug is triggered at the beginning of the second renderpass, when the
16982 // command buffer already has a layout recorded for the attachment.
16983 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16984 BeginCommandBuffer();
16985 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16986 vkCmdEndRenderPass(m_commandBuffer->handle());
16987 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16988
16989 m_errorMonitor->VerifyNotFound();
16990
16991 vkCmdEndRenderPass(m_commandBuffer->handle());
16992 EndCommandBuffer();
16993
16994 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16995 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16996 vkDestroyImageView(m_device->device(), view, nullptr);
16997}
16998
16999TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17000 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17001 "command buffer, bind them together, then destroy "
17002 "command pool and framebuffer and verify there are no "
17003 "errors.");
17004
17005 m_errorMonitor->ExpectSuccess();
17006
17007 ASSERT_NO_FATAL_FAILURE(InitState());
17008
17009 // A renderpass with one color attachment.
17010 VkAttachmentDescription attachment = { 0,
17011 VK_FORMAT_R8G8B8A8_UNORM,
17012 VK_SAMPLE_COUNT_1_BIT,
17013 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17014 VK_ATTACHMENT_STORE_OP_STORE,
17015 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17016 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17017 VK_IMAGE_LAYOUT_UNDEFINED,
17018 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17019
17020 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17021
17022 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17023
17024 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17025
17026 VkRenderPass rp;
17027 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17028 ASSERT_VK_SUCCESS(err);
17029
17030 // A compatible framebuffer.
17031 VkImageObj image(m_device);
17032 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17033 ASSERT_TRUE(image.initialized());
17034
17035 VkImageViewCreateInfo ivci = {
17036 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17037 nullptr,
17038 0,
17039 image.handle(),
17040 VK_IMAGE_VIEW_TYPE_2D,
17041 VK_FORMAT_R8G8B8A8_UNORM,
17042 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17043 VK_COMPONENT_SWIZZLE_IDENTITY },
17044 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17045 };
17046 VkImageView view;
17047 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17048 ASSERT_VK_SUCCESS(err);
17049
17050 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17051 VkFramebuffer fb;
17052 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17053 ASSERT_VK_SUCCESS(err);
17054
17055 // Explicitly create a command buffer to bind the FB to so that we can then
17056 // destroy the command pool in order to implicitly free command buffer
17057 VkCommandPool command_pool;
17058 VkCommandPoolCreateInfo pool_create_info{};
17059 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17060 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17061 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17062 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17063
17064 VkCommandBuffer command_buffer;
17065 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17066 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17067 command_buffer_allocate_info.commandPool = command_pool;
17068 command_buffer_allocate_info.commandBufferCount = 1;
17069 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17070 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17071
17072 // Begin our cmd buffer with renderpass using our framebuffer
17073 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17074 VkCommandBufferBeginInfo begin_info{};
17075 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17076 vkBeginCommandBuffer(command_buffer, &begin_info);
17077
17078 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17079 vkCmdEndRenderPass(command_buffer);
17080 vkEndCommandBuffer(command_buffer);
17081 vkDestroyImageView(m_device->device(), view, nullptr);
17082 // Destroy command pool to implicitly free command buffer
17083 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17084 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17085 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17086 m_errorMonitor->VerifyNotFound();
17087}
17088
17089TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17090 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17091 "transitions for the first subpass");
17092
17093 m_errorMonitor->ExpectSuccess();
17094
17095 ASSERT_NO_FATAL_FAILURE(InitState());
17096
17097 // A renderpass with one color attachment.
17098 VkAttachmentDescription attachment = { 0,
17099 VK_FORMAT_R8G8B8A8_UNORM,
17100 VK_SAMPLE_COUNT_1_BIT,
17101 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17102 VK_ATTACHMENT_STORE_OP_STORE,
17103 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17104 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17105 VK_IMAGE_LAYOUT_UNDEFINED,
17106 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17107
17108 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17109
17110 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17111
17112 VkSubpassDependency dep = { 0,
17113 0,
17114 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17115 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17116 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17117 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17118 VK_DEPENDENCY_BY_REGION_BIT };
17119
17120 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17121
17122 VkResult err;
17123 VkRenderPass rp;
17124 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17125 ASSERT_VK_SUCCESS(err);
17126
17127 // A compatible framebuffer.
17128 VkImageObj image(m_device);
17129 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17130 ASSERT_TRUE(image.initialized());
17131
17132 VkImageViewCreateInfo ivci = {
17133 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17134 nullptr,
17135 0,
17136 image.handle(),
17137 VK_IMAGE_VIEW_TYPE_2D,
17138 VK_FORMAT_R8G8B8A8_UNORM,
17139 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17140 VK_COMPONENT_SWIZZLE_IDENTITY },
17141 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17142 };
17143 VkImageView view;
17144 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17145 ASSERT_VK_SUCCESS(err);
17146
17147 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17148 VkFramebuffer fb;
17149 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17150 ASSERT_VK_SUCCESS(err);
17151
17152 // Record a single command buffer which issues a pipeline barrier w/
17153 // image memory barrier for the attachment. This detects the previously
17154 // missing tracking of the subpass layout by throwing a validation error
17155 // if it doesn't occur.
17156 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17157 BeginCommandBuffer();
17158 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17159
17160 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17161 nullptr,
17162 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17163 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17164 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17165 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17166 VK_QUEUE_FAMILY_IGNORED,
17167 VK_QUEUE_FAMILY_IGNORED,
17168 image.handle(),
17169 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17170 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17171 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17172 &imb);
17173
17174 vkCmdEndRenderPass(m_commandBuffer->handle());
17175 m_errorMonitor->VerifyNotFound();
17176 EndCommandBuffer();
17177
17178 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17179 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17180 vkDestroyImageView(m_device->device(), view, nullptr);
17181}
17182
17183TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17184 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17185 "is used as a depth/stencil framebuffer attachment, the "
17186 "aspectMask is ignored and both depth and stencil image "
17187 "subresources are used.");
17188
17189 VkFormatProperties format_properties;
17190 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17191 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17192 return;
17193 }
17194
17195 m_errorMonitor->ExpectSuccess();
17196
17197 ASSERT_NO_FATAL_FAILURE(InitState());
17198
17199 VkAttachmentDescription attachment = { 0,
17200 VK_FORMAT_D32_SFLOAT_S8_UINT,
17201 VK_SAMPLE_COUNT_1_BIT,
17202 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17203 VK_ATTACHMENT_STORE_OP_STORE,
17204 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17205 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17206 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17207 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17208
17209 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17210
17211 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17212
17213 VkSubpassDependency dep = { 0,
17214 0,
17215 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17216 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17217 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17218 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17219 VK_DEPENDENCY_BY_REGION_BIT};
17220
17221 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17222
17223 VkResult err;
17224 VkRenderPass rp;
17225 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17226 ASSERT_VK_SUCCESS(err);
17227
17228 VkImageObj image(m_device);
17229 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17230 0x26, // usage
17231 VK_IMAGE_TILING_OPTIMAL, 0);
17232 ASSERT_TRUE(image.initialized());
17233 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17234
17235 VkImageViewCreateInfo ivci = {
17236 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17237 nullptr,
17238 0,
17239 image.handle(),
17240 VK_IMAGE_VIEW_TYPE_2D,
17241 VK_FORMAT_D32_SFLOAT_S8_UINT,
17242 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17243 { 0x2, 0, 1, 0, 1 },
17244 };
17245 VkImageView view;
17246 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17247 ASSERT_VK_SUCCESS(err);
17248
17249 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17250 VkFramebuffer fb;
17251 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17252 ASSERT_VK_SUCCESS(err);
17253
17254 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17255 BeginCommandBuffer();
17256 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17257
17258 VkImageMemoryBarrier imb = {};
17259 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17260 imb.pNext = nullptr;
17261 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17262 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17263 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17264 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17265 imb.srcQueueFamilyIndex = 0;
17266 imb.dstQueueFamilyIndex = 0;
17267 imb.image = image.handle();
17268 imb.subresourceRange.aspectMask = 0x6;
17269 imb.subresourceRange.baseMipLevel = 0;
17270 imb.subresourceRange.levelCount = 0x1;
17271 imb.subresourceRange.baseArrayLayer = 0;
17272 imb.subresourceRange.layerCount = 0x1;
17273
17274 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17275 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17276 &imb);
17277
17278 vkCmdEndRenderPass(m_commandBuffer->handle());
17279 EndCommandBuffer();
17280 QueueCommandBuffer(false);
17281 m_errorMonitor->VerifyNotFound();
17282
17283 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17284 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17285 vkDestroyImageView(m_device->device(), view, nullptr);
17286}
17287
17288TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
17289 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
17290 "errors, when an attachment reference is "
17291 "VK_ATTACHMENT_UNUSED");
17292
17293 m_errorMonitor->ExpectSuccess();
17294
17295 ASSERT_NO_FATAL_FAILURE(InitState());
17296
17297 // A renderpass with no attachments
17298 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17299
17300 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17301
17302 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
17303
17304 VkRenderPass rp;
17305 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17306 ASSERT_VK_SUCCESS(err);
17307
17308 // A compatible framebuffer.
17309 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
17310 VkFramebuffer fb;
17311 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17312 ASSERT_VK_SUCCESS(err);
17313
17314 // Record a command buffer which just begins and ends the renderpass. The
17315 // bug manifests in BeginRenderPass.
17316 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17317 BeginCommandBuffer();
17318 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17319 vkCmdEndRenderPass(m_commandBuffer->handle());
17320 m_errorMonitor->VerifyNotFound();
17321 EndCommandBuffer();
17322
17323 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17324 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17325}
17326
17327// This is a positive test. No errors are expected.
17328TEST_F(VkPositiveLayerTest, StencilLoadOp) {
17329 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
17330 "CLEAR. stencil[Load|Store]Op used to be ignored.");
17331 VkResult result = VK_SUCCESS;
17332 VkImageFormatProperties formatProps;
17333 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
17334 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
17335 &formatProps);
17336 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
17337 return;
17338 }
17339
17340 ASSERT_NO_FATAL_FAILURE(InitState());
17341 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
17342 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
17343 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
17344 VkAttachmentDescription att = {};
17345 VkAttachmentReference ref = {};
17346 att.format = depth_stencil_fmt;
17347 att.samples = VK_SAMPLE_COUNT_1_BIT;
17348 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17349 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17350 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17351 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17352 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17353 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17354
17355 VkClearValue clear;
17356 clear.depthStencil.depth = 1.0;
17357 clear.depthStencil.stencil = 0;
17358 ref.attachment = 0;
17359 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17360
17361 VkSubpassDescription subpass = {};
17362 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17363 subpass.flags = 0;
17364 subpass.inputAttachmentCount = 0;
17365 subpass.pInputAttachments = NULL;
17366 subpass.colorAttachmentCount = 0;
17367 subpass.pColorAttachments = NULL;
17368 subpass.pResolveAttachments = NULL;
17369 subpass.pDepthStencilAttachment = &ref;
17370 subpass.preserveAttachmentCount = 0;
17371 subpass.pPreserveAttachments = NULL;
17372
17373 VkRenderPass rp;
17374 VkRenderPassCreateInfo rp_info = {};
17375 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17376 rp_info.attachmentCount = 1;
17377 rp_info.pAttachments = &att;
17378 rp_info.subpassCount = 1;
17379 rp_info.pSubpasses = &subpass;
17380 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17381 ASSERT_VK_SUCCESS(result);
17382
17383 VkImageView *depthView = m_depthStencil->BindInfo();
17384 VkFramebufferCreateInfo fb_info = {};
17385 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17386 fb_info.pNext = NULL;
17387 fb_info.renderPass = rp;
17388 fb_info.attachmentCount = 1;
17389 fb_info.pAttachments = depthView;
17390 fb_info.width = 100;
17391 fb_info.height = 100;
17392 fb_info.layers = 1;
17393 VkFramebuffer fb;
17394 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17395 ASSERT_VK_SUCCESS(result);
17396
17397 VkRenderPassBeginInfo rpbinfo = {};
17398 rpbinfo.clearValueCount = 1;
17399 rpbinfo.pClearValues = &clear;
17400 rpbinfo.pNext = NULL;
17401 rpbinfo.renderPass = rp;
17402 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17403 rpbinfo.renderArea.extent.width = 100;
17404 rpbinfo.renderArea.extent.height = 100;
17405 rpbinfo.renderArea.offset.x = 0;
17406 rpbinfo.renderArea.offset.y = 0;
17407 rpbinfo.framebuffer = fb;
17408
17409 VkFence fence = {};
17410 VkFenceCreateInfo fence_ci = {};
17411 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17412 fence_ci.pNext = nullptr;
17413 fence_ci.flags = 0;
17414 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17415 ASSERT_VK_SUCCESS(result);
17416
17417 m_commandBuffer->BeginCommandBuffer();
17418 m_commandBuffer->BeginRenderPass(rpbinfo);
17419 m_commandBuffer->EndRenderPass();
17420 m_commandBuffer->EndCommandBuffer();
17421 m_commandBuffer->QueueCommandBuffer(fence);
17422
17423 VkImageObj destImage(m_device);
17424 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17425 VK_IMAGE_TILING_OPTIMAL, 0);
17426 VkImageMemoryBarrier barrier = {};
17427 VkImageSubresourceRange range;
17428 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17429 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17430 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17431 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17432 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17433 barrier.image = m_depthStencil->handle();
17434 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17435 range.baseMipLevel = 0;
17436 range.levelCount = 1;
17437 range.baseArrayLayer = 0;
17438 range.layerCount = 1;
17439 barrier.subresourceRange = range;
17440 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17441 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17442 cmdbuf.BeginCommandBuffer();
17443 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17444 &barrier);
17445 barrier.srcAccessMask = 0;
17446 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17447 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17448 barrier.image = destImage.handle();
17449 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17450 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17451 &barrier);
17452 VkImageCopy cregion;
17453 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17454 cregion.srcSubresource.mipLevel = 0;
17455 cregion.srcSubresource.baseArrayLayer = 0;
17456 cregion.srcSubresource.layerCount = 1;
17457 cregion.srcOffset.x = 0;
17458 cregion.srcOffset.y = 0;
17459 cregion.srcOffset.z = 0;
17460 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17461 cregion.dstSubresource.mipLevel = 0;
17462 cregion.dstSubresource.baseArrayLayer = 0;
17463 cregion.dstSubresource.layerCount = 1;
17464 cregion.dstOffset.x = 0;
17465 cregion.dstOffset.y = 0;
17466 cregion.dstOffset.z = 0;
17467 cregion.extent.width = 100;
17468 cregion.extent.height = 100;
17469 cregion.extent.depth = 1;
17470 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17471 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17472 cmdbuf.EndCommandBuffer();
17473
17474 VkSubmitInfo submit_info;
17475 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17476 submit_info.pNext = NULL;
17477 submit_info.waitSemaphoreCount = 0;
17478 submit_info.pWaitSemaphores = NULL;
17479 submit_info.pWaitDstStageMask = NULL;
17480 submit_info.commandBufferCount = 1;
17481 submit_info.pCommandBuffers = &cmdbuf.handle();
17482 submit_info.signalSemaphoreCount = 0;
17483 submit_info.pSignalSemaphores = NULL;
17484
17485 m_errorMonitor->ExpectSuccess();
17486 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17487 m_errorMonitor->VerifyNotFound();
17488
17489 vkQueueWaitIdle(m_device->m_queue);
17490 vkDestroyFence(m_device->device(), fence, nullptr);
17491 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17492 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17493}
17494
17495// This is a positive test. No errors should be generated.
17496TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17497 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17498
17499 m_errorMonitor->ExpectSuccess();
17500 ASSERT_NO_FATAL_FAILURE(InitState());
17501
17502 VkEvent event;
17503 VkEventCreateInfo event_create_info{};
17504 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17505 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17506
17507 VkCommandPool command_pool;
17508 VkCommandPoolCreateInfo pool_create_info{};
17509 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17510 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17511 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17512 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17513
17514 VkCommandBuffer command_buffer;
17515 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17516 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17517 command_buffer_allocate_info.commandPool = command_pool;
17518 command_buffer_allocate_info.commandBufferCount = 1;
17519 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17520 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17521
17522 VkQueue queue = VK_NULL_HANDLE;
17523 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17524
17525 {
17526 VkCommandBufferBeginInfo begin_info{};
17527 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17528 vkBeginCommandBuffer(command_buffer, &begin_info);
17529
17530 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17531 nullptr, 0, nullptr);
17532 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17533 vkEndCommandBuffer(command_buffer);
17534 }
17535 {
17536 VkSubmitInfo submit_info{};
17537 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17538 submit_info.commandBufferCount = 1;
17539 submit_info.pCommandBuffers = &command_buffer;
17540 submit_info.signalSemaphoreCount = 0;
17541 submit_info.pSignalSemaphores = nullptr;
17542 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17543 }
17544 { vkSetEvent(m_device->device(), event); }
17545
17546 vkQueueWaitIdle(queue);
17547
17548 vkDestroyEvent(m_device->device(), event, nullptr);
17549 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17550 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17551
17552 m_errorMonitor->VerifyNotFound();
17553}
17554// This is a positive test. No errors should be generated.
17555TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17556 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17557
17558 ASSERT_NO_FATAL_FAILURE(InitState());
17559 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17560 return;
17561
17562 m_errorMonitor->ExpectSuccess();
17563
17564 VkQueryPool query_pool;
17565 VkQueryPoolCreateInfo query_pool_create_info{};
17566 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17567 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17568 query_pool_create_info.queryCount = 1;
17569 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17570
17571 VkCommandPool command_pool;
17572 VkCommandPoolCreateInfo pool_create_info{};
17573 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17574 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17575 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17576 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17577
17578 VkCommandBuffer command_buffer;
17579 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17580 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17581 command_buffer_allocate_info.commandPool = command_pool;
17582 command_buffer_allocate_info.commandBufferCount = 1;
17583 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17584 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17585
17586 VkCommandBuffer secondary_command_buffer;
17587 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17588 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17589
17590 VkQueue queue = VK_NULL_HANDLE;
17591 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17592
17593 uint32_t qfi = 0;
17594 VkBufferCreateInfo buff_create_info = {};
17595 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17596 buff_create_info.size = 1024;
17597 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17598 buff_create_info.queueFamilyIndexCount = 1;
17599 buff_create_info.pQueueFamilyIndices = &qfi;
17600
17601 VkResult err;
17602 VkBuffer buffer;
17603 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17604 ASSERT_VK_SUCCESS(err);
17605 VkMemoryAllocateInfo mem_alloc = {};
17606 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17607 mem_alloc.pNext = NULL;
17608 mem_alloc.allocationSize = 1024;
17609 mem_alloc.memoryTypeIndex = 0;
17610
17611 VkMemoryRequirements memReqs;
17612 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17613 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17614 if (!pass) {
17615 vkDestroyBuffer(m_device->device(), buffer, NULL);
17616 return;
17617 }
17618
17619 VkDeviceMemory mem;
17620 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17621 ASSERT_VK_SUCCESS(err);
17622 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17623 ASSERT_VK_SUCCESS(err);
17624
17625 VkCommandBufferInheritanceInfo hinfo = {};
17626 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17627 hinfo.renderPass = VK_NULL_HANDLE;
17628 hinfo.subpass = 0;
17629 hinfo.framebuffer = VK_NULL_HANDLE;
17630 hinfo.occlusionQueryEnable = VK_FALSE;
17631 hinfo.queryFlags = 0;
17632 hinfo.pipelineStatistics = 0;
17633
17634 {
17635 VkCommandBufferBeginInfo begin_info{};
17636 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17637 begin_info.pInheritanceInfo = &hinfo;
17638 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17639
17640 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17641 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17642
17643 vkEndCommandBuffer(secondary_command_buffer);
17644
17645 begin_info.pInheritanceInfo = nullptr;
17646 vkBeginCommandBuffer(command_buffer, &begin_info);
17647
17648 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17649 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17650
17651 vkEndCommandBuffer(command_buffer);
17652 }
17653 {
17654 VkSubmitInfo submit_info{};
17655 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17656 submit_info.commandBufferCount = 1;
17657 submit_info.pCommandBuffers = &command_buffer;
17658 submit_info.signalSemaphoreCount = 0;
17659 submit_info.pSignalSemaphores = nullptr;
17660 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17661 }
17662
17663 vkQueueWaitIdle(queue);
17664
17665 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17666 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17667 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17668 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17669 vkDestroyBuffer(m_device->device(), buffer, NULL);
17670 vkFreeMemory(m_device->device(), mem, NULL);
17671
17672 m_errorMonitor->VerifyNotFound();
17673}
17674
17675// This is a positive test. No errors should be generated.
17676TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17677 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
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 VkQueryPool query_pool;
17686 VkQueryPoolCreateInfo query_pool_create_info{};
17687 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17688 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17689 query_pool_create_info.queryCount = 1;
17690 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17691
17692 VkCommandPool command_pool;
17693 VkCommandPoolCreateInfo pool_create_info{};
17694 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17695 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17696 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17697 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17698
17699 VkCommandBuffer command_buffer[2];
17700 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17701 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17702 command_buffer_allocate_info.commandPool = command_pool;
17703 command_buffer_allocate_info.commandBufferCount = 2;
17704 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17705 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17706
17707 VkQueue queue = VK_NULL_HANDLE;
17708 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17709
17710 uint32_t qfi = 0;
17711 VkBufferCreateInfo buff_create_info = {};
17712 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17713 buff_create_info.size = 1024;
17714 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17715 buff_create_info.queueFamilyIndexCount = 1;
17716 buff_create_info.pQueueFamilyIndices = &qfi;
17717
17718 VkResult err;
17719 VkBuffer buffer;
17720 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17721 ASSERT_VK_SUCCESS(err);
17722 VkMemoryAllocateInfo mem_alloc = {};
17723 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17724 mem_alloc.pNext = NULL;
17725 mem_alloc.allocationSize = 1024;
17726 mem_alloc.memoryTypeIndex = 0;
17727
17728 VkMemoryRequirements memReqs;
17729 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17730 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17731 if (!pass) {
17732 vkDestroyBuffer(m_device->device(), buffer, NULL);
17733 return;
17734 }
17735
17736 VkDeviceMemory mem;
17737 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17738 ASSERT_VK_SUCCESS(err);
17739 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17740 ASSERT_VK_SUCCESS(err);
17741
17742 {
17743 VkCommandBufferBeginInfo begin_info{};
17744 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17745 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17746
17747 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17748 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17749
17750 vkEndCommandBuffer(command_buffer[0]);
17751
17752 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17753
17754 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17755
17756 vkEndCommandBuffer(command_buffer[1]);
17757 }
17758 {
17759 VkSubmitInfo submit_info{};
17760 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17761 submit_info.commandBufferCount = 2;
17762 submit_info.pCommandBuffers = command_buffer;
17763 submit_info.signalSemaphoreCount = 0;
17764 submit_info.pSignalSemaphores = nullptr;
17765 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17766 }
17767
17768 vkQueueWaitIdle(queue);
17769
17770 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17771 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17772 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17773 vkDestroyBuffer(m_device->device(), buffer, NULL);
17774 vkFreeMemory(m_device->device(), mem, NULL);
17775
17776 m_errorMonitor->VerifyNotFound();
17777}
17778
Tony Barbourc46924f2016-11-04 11:49:52 -060017779TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017780 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17781
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017782 ASSERT_NO_FATAL_FAILURE(InitState());
17783 VkEvent event;
17784 VkEventCreateInfo event_create_info{};
17785 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17786 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17787
17788 VkCommandPool command_pool;
17789 VkCommandPoolCreateInfo pool_create_info{};
17790 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17791 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17792 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17793 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17794
17795 VkCommandBuffer command_buffer;
17796 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17797 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17798 command_buffer_allocate_info.commandPool = command_pool;
17799 command_buffer_allocate_info.commandBufferCount = 1;
17800 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17801 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17802
17803 VkQueue queue = VK_NULL_HANDLE;
17804 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17805
17806 {
17807 VkCommandBufferBeginInfo begin_info{};
17808 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17809 vkBeginCommandBuffer(command_buffer, &begin_info);
17810
17811 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017812 vkEndCommandBuffer(command_buffer);
17813 }
17814 {
17815 VkSubmitInfo submit_info{};
17816 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17817 submit_info.commandBufferCount = 1;
17818 submit_info.pCommandBuffers = &command_buffer;
17819 submit_info.signalSemaphoreCount = 0;
17820 submit_info.pSignalSemaphores = nullptr;
17821 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17822 }
17823 {
17824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17825 "command buffer.");
17826 vkSetEvent(m_device->device(), event);
17827 m_errorMonitor->VerifyFound();
17828 }
17829
17830 vkQueueWaitIdle(queue);
17831
17832 vkDestroyEvent(m_device->device(), event, nullptr);
17833 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17834 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17835}
17836
17837// This is a positive test. No errors should be generated.
17838TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17839 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17840 "run through a Submit & WaitForFences cycle 3 times. This "
17841 "previously revealed a bug so running this positive test "
17842 "to prevent a regression.");
17843 m_errorMonitor->ExpectSuccess();
17844
17845 ASSERT_NO_FATAL_FAILURE(InitState());
17846 VkQueue queue = VK_NULL_HANDLE;
17847 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17848
17849 static const uint32_t NUM_OBJECTS = 2;
17850 static const uint32_t NUM_FRAMES = 3;
17851 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17852 VkFence fences[NUM_OBJECTS] = {};
17853
17854 VkCommandPool cmd_pool;
17855 VkCommandPoolCreateInfo cmd_pool_ci = {};
17856 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17857 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17858 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17859 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17860 ASSERT_VK_SUCCESS(err);
17861
17862 VkCommandBufferAllocateInfo cmd_buf_info = {};
17863 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17864 cmd_buf_info.commandPool = cmd_pool;
17865 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17866 cmd_buf_info.commandBufferCount = 1;
17867
17868 VkFenceCreateInfo fence_ci = {};
17869 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17870 fence_ci.pNext = nullptr;
17871 fence_ci.flags = 0;
17872
17873 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17874 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17875 ASSERT_VK_SUCCESS(err);
17876 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17877 ASSERT_VK_SUCCESS(err);
17878 }
17879
17880 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17881 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17882 // Create empty cmd buffer
17883 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17884 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17885
17886 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17887 ASSERT_VK_SUCCESS(err);
17888 err = vkEndCommandBuffer(cmd_buffers[obj]);
17889 ASSERT_VK_SUCCESS(err);
17890
17891 VkSubmitInfo submit_info = {};
17892 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17893 submit_info.commandBufferCount = 1;
17894 submit_info.pCommandBuffers = &cmd_buffers[obj];
17895 // Submit cmd buffer and wait for fence
17896 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17897 ASSERT_VK_SUCCESS(err);
17898 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17899 ASSERT_VK_SUCCESS(err);
17900 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17901 ASSERT_VK_SUCCESS(err);
17902 }
17903 }
17904 m_errorMonitor->VerifyNotFound();
17905 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17906 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17907 vkDestroyFence(m_device->device(), fences[i], nullptr);
17908 }
17909}
17910// This is a positive test. No errors should be generated.
17911TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17912
17913 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17914 "submitted on separate queues followed by a QueueWaitIdle.");
17915
17916 ASSERT_NO_FATAL_FAILURE(InitState());
17917 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17918 return;
17919
17920 m_errorMonitor->ExpectSuccess();
17921
17922 VkSemaphore semaphore;
17923 VkSemaphoreCreateInfo semaphore_create_info{};
17924 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17925 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17926
17927 VkCommandPool command_pool;
17928 VkCommandPoolCreateInfo pool_create_info{};
17929 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17930 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17931 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17932 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17933
17934 VkCommandBuffer command_buffer[2];
17935 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17936 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17937 command_buffer_allocate_info.commandPool = command_pool;
17938 command_buffer_allocate_info.commandBufferCount = 2;
17939 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17940 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17941
17942 VkQueue queue = VK_NULL_HANDLE;
17943 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17944
17945 {
17946 VkCommandBufferBeginInfo begin_info{};
17947 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17948 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17949
17950 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17951 nullptr, 0, nullptr, 0, nullptr);
17952
17953 VkViewport viewport{};
17954 viewport.maxDepth = 1.0f;
17955 viewport.minDepth = 0.0f;
17956 viewport.width = 512;
17957 viewport.height = 512;
17958 viewport.x = 0;
17959 viewport.y = 0;
17960 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17961 vkEndCommandBuffer(command_buffer[0]);
17962 }
17963 {
17964 VkCommandBufferBeginInfo begin_info{};
17965 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17966 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17967
17968 VkViewport viewport{};
17969 viewport.maxDepth = 1.0f;
17970 viewport.minDepth = 0.0f;
17971 viewport.width = 512;
17972 viewport.height = 512;
17973 viewport.x = 0;
17974 viewport.y = 0;
17975 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17976 vkEndCommandBuffer(command_buffer[1]);
17977 }
17978 {
17979 VkSubmitInfo submit_info{};
17980 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17981 submit_info.commandBufferCount = 1;
17982 submit_info.pCommandBuffers = &command_buffer[0];
17983 submit_info.signalSemaphoreCount = 1;
17984 submit_info.pSignalSemaphores = &semaphore;
17985 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17986 }
17987 {
17988 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17989 VkSubmitInfo submit_info{};
17990 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17991 submit_info.commandBufferCount = 1;
17992 submit_info.pCommandBuffers = &command_buffer[1];
17993 submit_info.waitSemaphoreCount = 1;
17994 submit_info.pWaitSemaphores = &semaphore;
17995 submit_info.pWaitDstStageMask = flags;
17996 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17997 }
17998
17999 vkQueueWaitIdle(m_device->m_queue);
18000
18001 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18002 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18003 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18004
18005 m_errorMonitor->VerifyNotFound();
18006}
18007
18008// This is a positive test. No errors should be generated.
18009TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18010
18011 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18012 "submitted on separate queues, the second having a fence"
18013 "followed by a QueueWaitIdle.");
18014
18015 ASSERT_NO_FATAL_FAILURE(InitState());
18016 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18017 return;
18018
18019 m_errorMonitor->ExpectSuccess();
18020
18021 VkFence fence;
18022 VkFenceCreateInfo fence_create_info{};
18023 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18024 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18025
18026 VkSemaphore semaphore;
18027 VkSemaphoreCreateInfo semaphore_create_info{};
18028 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18029 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18030
18031 VkCommandPool command_pool;
18032 VkCommandPoolCreateInfo pool_create_info{};
18033 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18034 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18035 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18036 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18037
18038 VkCommandBuffer command_buffer[2];
18039 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18040 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18041 command_buffer_allocate_info.commandPool = command_pool;
18042 command_buffer_allocate_info.commandBufferCount = 2;
18043 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18044 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18045
18046 VkQueue queue = VK_NULL_HANDLE;
18047 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18048
18049 {
18050 VkCommandBufferBeginInfo begin_info{};
18051 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18052 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18053
18054 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18055 nullptr, 0, nullptr, 0, nullptr);
18056
18057 VkViewport viewport{};
18058 viewport.maxDepth = 1.0f;
18059 viewport.minDepth = 0.0f;
18060 viewport.width = 512;
18061 viewport.height = 512;
18062 viewport.x = 0;
18063 viewport.y = 0;
18064 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18065 vkEndCommandBuffer(command_buffer[0]);
18066 }
18067 {
18068 VkCommandBufferBeginInfo begin_info{};
18069 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18070 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18071
18072 VkViewport viewport{};
18073 viewport.maxDepth = 1.0f;
18074 viewport.minDepth = 0.0f;
18075 viewport.width = 512;
18076 viewport.height = 512;
18077 viewport.x = 0;
18078 viewport.y = 0;
18079 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18080 vkEndCommandBuffer(command_buffer[1]);
18081 }
18082 {
18083 VkSubmitInfo submit_info{};
18084 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18085 submit_info.commandBufferCount = 1;
18086 submit_info.pCommandBuffers = &command_buffer[0];
18087 submit_info.signalSemaphoreCount = 1;
18088 submit_info.pSignalSemaphores = &semaphore;
18089 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18090 }
18091 {
18092 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18093 VkSubmitInfo submit_info{};
18094 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18095 submit_info.commandBufferCount = 1;
18096 submit_info.pCommandBuffers = &command_buffer[1];
18097 submit_info.waitSemaphoreCount = 1;
18098 submit_info.pWaitSemaphores = &semaphore;
18099 submit_info.pWaitDstStageMask = flags;
18100 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18101 }
18102
18103 vkQueueWaitIdle(m_device->m_queue);
18104
18105 vkDestroyFence(m_device->device(), fence, nullptr);
18106 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18107 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18108 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18109
18110 m_errorMonitor->VerifyNotFound();
18111}
18112
18113// This is a positive test. No errors should be generated.
18114TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18115
18116 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18117 "submitted on separate queues, the second having a fence"
18118 "followed by two consecutive WaitForFences calls on the same fence.");
18119
18120 ASSERT_NO_FATAL_FAILURE(InitState());
18121 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18122 return;
18123
18124 m_errorMonitor->ExpectSuccess();
18125
18126 VkFence fence;
18127 VkFenceCreateInfo fence_create_info{};
18128 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18129 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18130
18131 VkSemaphore semaphore;
18132 VkSemaphoreCreateInfo semaphore_create_info{};
18133 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18134 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18135
18136 VkCommandPool command_pool;
18137 VkCommandPoolCreateInfo pool_create_info{};
18138 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18139 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18140 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18141 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18142
18143 VkCommandBuffer command_buffer[2];
18144 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18145 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18146 command_buffer_allocate_info.commandPool = command_pool;
18147 command_buffer_allocate_info.commandBufferCount = 2;
18148 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18149 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18150
18151 VkQueue queue = VK_NULL_HANDLE;
18152 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18153
18154 {
18155 VkCommandBufferBeginInfo begin_info{};
18156 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18157 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18158
18159 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18160 nullptr, 0, nullptr, 0, nullptr);
18161
18162 VkViewport viewport{};
18163 viewport.maxDepth = 1.0f;
18164 viewport.minDepth = 0.0f;
18165 viewport.width = 512;
18166 viewport.height = 512;
18167 viewport.x = 0;
18168 viewport.y = 0;
18169 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18170 vkEndCommandBuffer(command_buffer[0]);
18171 }
18172 {
18173 VkCommandBufferBeginInfo begin_info{};
18174 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18175 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18176
18177 VkViewport viewport{};
18178 viewport.maxDepth = 1.0f;
18179 viewport.minDepth = 0.0f;
18180 viewport.width = 512;
18181 viewport.height = 512;
18182 viewport.x = 0;
18183 viewport.y = 0;
18184 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18185 vkEndCommandBuffer(command_buffer[1]);
18186 }
18187 {
18188 VkSubmitInfo submit_info{};
18189 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18190 submit_info.commandBufferCount = 1;
18191 submit_info.pCommandBuffers = &command_buffer[0];
18192 submit_info.signalSemaphoreCount = 1;
18193 submit_info.pSignalSemaphores = &semaphore;
18194 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18195 }
18196 {
18197 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18198 VkSubmitInfo submit_info{};
18199 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18200 submit_info.commandBufferCount = 1;
18201 submit_info.pCommandBuffers = &command_buffer[1];
18202 submit_info.waitSemaphoreCount = 1;
18203 submit_info.pWaitSemaphores = &semaphore;
18204 submit_info.pWaitDstStageMask = flags;
18205 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18206 }
18207
18208 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18209 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18210
18211 vkDestroyFence(m_device->device(), fence, nullptr);
18212 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18213 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18214 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18215
18216 m_errorMonitor->VerifyNotFound();
18217}
18218
18219TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18220
18221 ASSERT_NO_FATAL_FAILURE(InitState());
18222 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18223 printf("Test requires two queues, skipping\n");
18224 return;
18225 }
18226
18227 VkResult err;
18228
18229 m_errorMonitor->ExpectSuccess();
18230
18231 VkQueue q0 = m_device->m_queue;
18232 VkQueue q1 = nullptr;
18233 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18234 ASSERT_NE(q1, nullptr);
18235
18236 // An (empty) command buffer. We must have work in the first submission --
18237 // the layer treats unfenced work differently from fenced work.
18238 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18239 VkCommandPool pool;
18240 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18241 ASSERT_VK_SUCCESS(err);
18242 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18243 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18244 VkCommandBuffer cb;
18245 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18246 ASSERT_VK_SUCCESS(err);
18247 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18248 err = vkBeginCommandBuffer(cb, &cbbi);
18249 ASSERT_VK_SUCCESS(err);
18250 err = vkEndCommandBuffer(cb);
18251 ASSERT_VK_SUCCESS(err);
18252
18253 // A semaphore
18254 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18255 VkSemaphore s;
18256 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18257 ASSERT_VK_SUCCESS(err);
18258
18259 // First submission, to q0
18260 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18261
18262 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18263 ASSERT_VK_SUCCESS(err);
18264
18265 // Second submission, to q1, waiting on s
18266 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18267 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18268
18269 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18270 ASSERT_VK_SUCCESS(err);
18271
18272 // Wait for q0 idle
18273 err = vkQueueWaitIdle(q0);
18274 ASSERT_VK_SUCCESS(err);
18275
18276 // Command buffer should have been completed (it was on q0); reset the pool.
18277 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18278
18279 m_errorMonitor->VerifyNotFound();
18280
18281 // Force device completely idle and clean up resources
18282 vkDeviceWaitIdle(m_device->device());
18283 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18284 vkDestroySemaphore(m_device->device(), s, nullptr);
18285}
18286
18287// This is a positive test. No errors should be generated.
18288TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
18289
18290 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18291 "submitted on separate queues, the second having a fence, "
18292 "followed by a WaitForFences call.");
18293
18294 ASSERT_NO_FATAL_FAILURE(InitState());
18295 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18296 return;
18297
18298 m_errorMonitor->ExpectSuccess();
18299
18300 ASSERT_NO_FATAL_FAILURE(InitState());
18301 VkFence fence;
18302 VkFenceCreateInfo fence_create_info{};
18303 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18304 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18305
18306 VkSemaphore semaphore;
18307 VkSemaphoreCreateInfo semaphore_create_info{};
18308 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18309 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18310
18311 VkCommandPool command_pool;
18312 VkCommandPoolCreateInfo pool_create_info{};
18313 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18314 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18315 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18316 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18317
18318 VkCommandBuffer command_buffer[2];
18319 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18320 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18321 command_buffer_allocate_info.commandPool = command_pool;
18322 command_buffer_allocate_info.commandBufferCount = 2;
18323 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18324 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18325
18326 VkQueue queue = VK_NULL_HANDLE;
18327 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18328
18329 {
18330 VkCommandBufferBeginInfo begin_info{};
18331 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18332 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18333
18334 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18335 nullptr, 0, nullptr, 0, nullptr);
18336
18337 VkViewport viewport{};
18338 viewport.maxDepth = 1.0f;
18339 viewport.minDepth = 0.0f;
18340 viewport.width = 512;
18341 viewport.height = 512;
18342 viewport.x = 0;
18343 viewport.y = 0;
18344 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18345 vkEndCommandBuffer(command_buffer[0]);
18346 }
18347 {
18348 VkCommandBufferBeginInfo begin_info{};
18349 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18350 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18351
18352 VkViewport viewport{};
18353 viewport.maxDepth = 1.0f;
18354 viewport.minDepth = 0.0f;
18355 viewport.width = 512;
18356 viewport.height = 512;
18357 viewport.x = 0;
18358 viewport.y = 0;
18359 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18360 vkEndCommandBuffer(command_buffer[1]);
18361 }
18362 {
18363 VkSubmitInfo submit_info{};
18364 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18365 submit_info.commandBufferCount = 1;
18366 submit_info.pCommandBuffers = &command_buffer[0];
18367 submit_info.signalSemaphoreCount = 1;
18368 submit_info.pSignalSemaphores = &semaphore;
18369 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18370 }
18371 {
18372 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18373 VkSubmitInfo submit_info{};
18374 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18375 submit_info.commandBufferCount = 1;
18376 submit_info.pCommandBuffers = &command_buffer[1];
18377 submit_info.waitSemaphoreCount = 1;
18378 submit_info.pWaitSemaphores = &semaphore;
18379 submit_info.pWaitDstStageMask = flags;
18380 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18381 }
18382
18383 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18384
18385 vkDestroyFence(m_device->device(), fence, nullptr);
18386 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18387 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18388 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18389
18390 m_errorMonitor->VerifyNotFound();
18391}
18392
18393// This is a positive test. No errors should be generated.
18394TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18395
18396 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18397 "on the same queue, sharing a signal/wait semaphore, the "
18398 "second having a fence, "
18399 "followed by a WaitForFences call.");
18400
18401 m_errorMonitor->ExpectSuccess();
18402
18403 ASSERT_NO_FATAL_FAILURE(InitState());
18404 VkFence fence;
18405 VkFenceCreateInfo fence_create_info{};
18406 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18407 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18408
18409 VkSemaphore semaphore;
18410 VkSemaphoreCreateInfo semaphore_create_info{};
18411 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18412 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18413
18414 VkCommandPool command_pool;
18415 VkCommandPoolCreateInfo pool_create_info{};
18416 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18417 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18418 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18419 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18420
18421 VkCommandBuffer command_buffer[2];
18422 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18423 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18424 command_buffer_allocate_info.commandPool = command_pool;
18425 command_buffer_allocate_info.commandBufferCount = 2;
18426 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18427 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18428
18429 {
18430 VkCommandBufferBeginInfo begin_info{};
18431 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18432 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18433
18434 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18435 nullptr, 0, nullptr, 0, nullptr);
18436
18437 VkViewport viewport{};
18438 viewport.maxDepth = 1.0f;
18439 viewport.minDepth = 0.0f;
18440 viewport.width = 512;
18441 viewport.height = 512;
18442 viewport.x = 0;
18443 viewport.y = 0;
18444 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18445 vkEndCommandBuffer(command_buffer[0]);
18446 }
18447 {
18448 VkCommandBufferBeginInfo begin_info{};
18449 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18450 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18451
18452 VkViewport viewport{};
18453 viewport.maxDepth = 1.0f;
18454 viewport.minDepth = 0.0f;
18455 viewport.width = 512;
18456 viewport.height = 512;
18457 viewport.x = 0;
18458 viewport.y = 0;
18459 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18460 vkEndCommandBuffer(command_buffer[1]);
18461 }
18462 {
18463 VkSubmitInfo submit_info{};
18464 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18465 submit_info.commandBufferCount = 1;
18466 submit_info.pCommandBuffers = &command_buffer[0];
18467 submit_info.signalSemaphoreCount = 1;
18468 submit_info.pSignalSemaphores = &semaphore;
18469 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18470 }
18471 {
18472 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18473 VkSubmitInfo submit_info{};
18474 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18475 submit_info.commandBufferCount = 1;
18476 submit_info.pCommandBuffers = &command_buffer[1];
18477 submit_info.waitSemaphoreCount = 1;
18478 submit_info.pWaitSemaphores = &semaphore;
18479 submit_info.pWaitDstStageMask = flags;
18480 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18481 }
18482
18483 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18484
18485 vkDestroyFence(m_device->device(), fence, nullptr);
18486 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18487 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18488 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18489
18490 m_errorMonitor->VerifyNotFound();
18491}
18492
18493// This is a positive test. No errors should be generated.
18494TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18495
18496 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18497 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18498 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18499
18500 m_errorMonitor->ExpectSuccess();
18501
18502 ASSERT_NO_FATAL_FAILURE(InitState());
18503 VkFence fence;
18504 VkFenceCreateInfo fence_create_info{};
18505 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18506 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18507
18508 VkCommandPool command_pool;
18509 VkCommandPoolCreateInfo pool_create_info{};
18510 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18511 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18512 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18513 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18514
18515 VkCommandBuffer command_buffer[2];
18516 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18517 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18518 command_buffer_allocate_info.commandPool = command_pool;
18519 command_buffer_allocate_info.commandBufferCount = 2;
18520 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18521 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18522
18523 {
18524 VkCommandBufferBeginInfo begin_info{};
18525 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18526 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18527
18528 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18529 nullptr, 0, nullptr, 0, nullptr);
18530
18531 VkViewport viewport{};
18532 viewport.maxDepth = 1.0f;
18533 viewport.minDepth = 0.0f;
18534 viewport.width = 512;
18535 viewport.height = 512;
18536 viewport.x = 0;
18537 viewport.y = 0;
18538 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18539 vkEndCommandBuffer(command_buffer[0]);
18540 }
18541 {
18542 VkCommandBufferBeginInfo begin_info{};
18543 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18544 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18545
18546 VkViewport viewport{};
18547 viewport.maxDepth = 1.0f;
18548 viewport.minDepth = 0.0f;
18549 viewport.width = 512;
18550 viewport.height = 512;
18551 viewport.x = 0;
18552 viewport.y = 0;
18553 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18554 vkEndCommandBuffer(command_buffer[1]);
18555 }
18556 {
18557 VkSubmitInfo submit_info{};
18558 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18559 submit_info.commandBufferCount = 1;
18560 submit_info.pCommandBuffers = &command_buffer[0];
18561 submit_info.signalSemaphoreCount = 0;
18562 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18563 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18564 }
18565 {
18566 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18567 VkSubmitInfo submit_info{};
18568 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18569 submit_info.commandBufferCount = 1;
18570 submit_info.pCommandBuffers = &command_buffer[1];
18571 submit_info.waitSemaphoreCount = 0;
18572 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18573 submit_info.pWaitDstStageMask = flags;
18574 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18575 }
18576
18577 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18578
18579 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18580 ASSERT_VK_SUCCESS(err);
18581
18582 vkDestroyFence(m_device->device(), fence, nullptr);
18583 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18584 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18585
18586 m_errorMonitor->VerifyNotFound();
18587}
18588
18589// This is a positive test. No errors should be generated.
18590TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18591
18592 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18593 "on the same queue, the second having a fence, followed "
18594 "by a WaitForFences call.");
18595
18596 m_errorMonitor->ExpectSuccess();
18597
18598 ASSERT_NO_FATAL_FAILURE(InitState());
18599 VkFence fence;
18600 VkFenceCreateInfo fence_create_info{};
18601 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18602 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18603
18604 VkCommandPool command_pool;
18605 VkCommandPoolCreateInfo pool_create_info{};
18606 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18607 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18608 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18609 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18610
18611 VkCommandBuffer command_buffer[2];
18612 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18613 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18614 command_buffer_allocate_info.commandPool = command_pool;
18615 command_buffer_allocate_info.commandBufferCount = 2;
18616 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18617 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18618
18619 {
18620 VkCommandBufferBeginInfo begin_info{};
18621 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18622 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18623
18624 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18625 nullptr, 0, nullptr, 0, nullptr);
18626
18627 VkViewport viewport{};
18628 viewport.maxDepth = 1.0f;
18629 viewport.minDepth = 0.0f;
18630 viewport.width = 512;
18631 viewport.height = 512;
18632 viewport.x = 0;
18633 viewport.y = 0;
18634 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18635 vkEndCommandBuffer(command_buffer[0]);
18636 }
18637 {
18638 VkCommandBufferBeginInfo begin_info{};
18639 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18640 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18641
18642 VkViewport viewport{};
18643 viewport.maxDepth = 1.0f;
18644 viewport.minDepth = 0.0f;
18645 viewport.width = 512;
18646 viewport.height = 512;
18647 viewport.x = 0;
18648 viewport.y = 0;
18649 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18650 vkEndCommandBuffer(command_buffer[1]);
18651 }
18652 {
18653 VkSubmitInfo submit_info{};
18654 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18655 submit_info.commandBufferCount = 1;
18656 submit_info.pCommandBuffers = &command_buffer[0];
18657 submit_info.signalSemaphoreCount = 0;
18658 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18659 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18660 }
18661 {
18662 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18663 VkSubmitInfo submit_info{};
18664 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18665 submit_info.commandBufferCount = 1;
18666 submit_info.pCommandBuffers = &command_buffer[1];
18667 submit_info.waitSemaphoreCount = 0;
18668 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18669 submit_info.pWaitDstStageMask = flags;
18670 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18671 }
18672
18673 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18674
18675 vkDestroyFence(m_device->device(), fence, nullptr);
18676 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18677 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18678
18679 m_errorMonitor->VerifyNotFound();
18680}
18681
18682// This is a positive test. No errors should be generated.
18683TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18684
18685 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18686 "QueueSubmit call followed by a WaitForFences call.");
18687 ASSERT_NO_FATAL_FAILURE(InitState());
18688
18689 m_errorMonitor->ExpectSuccess();
18690
18691 VkFence fence;
18692 VkFenceCreateInfo fence_create_info{};
18693 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18694 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18695
18696 VkSemaphore semaphore;
18697 VkSemaphoreCreateInfo semaphore_create_info{};
18698 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18699 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18700
18701 VkCommandPool command_pool;
18702 VkCommandPoolCreateInfo pool_create_info{};
18703 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18704 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18705 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18706 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18707
18708 VkCommandBuffer command_buffer[2];
18709 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18710 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18711 command_buffer_allocate_info.commandPool = command_pool;
18712 command_buffer_allocate_info.commandBufferCount = 2;
18713 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18714 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18715
18716 {
18717 VkCommandBufferBeginInfo begin_info{};
18718 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18719 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18720
18721 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18722 nullptr, 0, nullptr, 0, nullptr);
18723
18724 VkViewport viewport{};
18725 viewport.maxDepth = 1.0f;
18726 viewport.minDepth = 0.0f;
18727 viewport.width = 512;
18728 viewport.height = 512;
18729 viewport.x = 0;
18730 viewport.y = 0;
18731 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18732 vkEndCommandBuffer(command_buffer[0]);
18733 }
18734 {
18735 VkCommandBufferBeginInfo begin_info{};
18736 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18737 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18738
18739 VkViewport viewport{};
18740 viewport.maxDepth = 1.0f;
18741 viewport.minDepth = 0.0f;
18742 viewport.width = 512;
18743 viewport.height = 512;
18744 viewport.x = 0;
18745 viewport.y = 0;
18746 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18747 vkEndCommandBuffer(command_buffer[1]);
18748 }
18749 {
18750 VkSubmitInfo submit_info[2];
18751 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18752
18753 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18754 submit_info[0].pNext = NULL;
18755 submit_info[0].commandBufferCount = 1;
18756 submit_info[0].pCommandBuffers = &command_buffer[0];
18757 submit_info[0].signalSemaphoreCount = 1;
18758 submit_info[0].pSignalSemaphores = &semaphore;
18759 submit_info[0].waitSemaphoreCount = 0;
18760 submit_info[0].pWaitSemaphores = NULL;
18761 submit_info[0].pWaitDstStageMask = 0;
18762
18763 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18764 submit_info[1].pNext = NULL;
18765 submit_info[1].commandBufferCount = 1;
18766 submit_info[1].pCommandBuffers = &command_buffer[1];
18767 submit_info[1].waitSemaphoreCount = 1;
18768 submit_info[1].pWaitSemaphores = &semaphore;
18769 submit_info[1].pWaitDstStageMask = flags;
18770 submit_info[1].signalSemaphoreCount = 0;
18771 submit_info[1].pSignalSemaphores = NULL;
18772 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18773 }
18774
18775 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18776
18777 vkDestroyFence(m_device->device(), fence, nullptr);
18778 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18779 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18780 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18781
18782 m_errorMonitor->VerifyNotFound();
18783}
18784
18785TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18786 m_errorMonitor->ExpectSuccess();
18787
18788 ASSERT_NO_FATAL_FAILURE(InitState());
18789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18790
18791 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18792 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18793
18794 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18795 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18796 m_errorMonitor->VerifyNotFound();
18797 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18798 m_errorMonitor->VerifyNotFound();
18799 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18800 m_errorMonitor->VerifyNotFound();
18801
18802 m_commandBuffer->EndCommandBuffer();
18803 m_errorMonitor->VerifyNotFound();
18804}
18805
18806TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18807 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18808 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18809 "has a valid layout, and a second subpass then uses a "
18810 "valid *READ_ONLY* layout.");
18811 m_errorMonitor->ExpectSuccess();
18812 ASSERT_NO_FATAL_FAILURE(InitState());
18813
18814 VkAttachmentReference attach[2] = {};
18815 attach[0].attachment = 0;
18816 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18817 attach[1].attachment = 0;
18818 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18819 VkSubpassDescription subpasses[2] = {};
18820 // First subpass clears DS attach on load
18821 subpasses[0].pDepthStencilAttachment = &attach[0];
18822 // 2nd subpass reads in DS as input attachment
18823 subpasses[1].inputAttachmentCount = 1;
18824 subpasses[1].pInputAttachments = &attach[1];
18825 VkAttachmentDescription attach_desc = {};
18826 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18827 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18828 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18829 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18830 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18831 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18832 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18833 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18834 VkRenderPassCreateInfo rpci = {};
18835 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18836 rpci.attachmentCount = 1;
18837 rpci.pAttachments = &attach_desc;
18838 rpci.subpassCount = 2;
18839 rpci.pSubpasses = subpasses;
18840
18841 // Now create RenderPass and verify no errors
18842 VkRenderPass rp;
18843 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18844 m_errorMonitor->VerifyNotFound();
18845
18846 vkDestroyRenderPass(m_device->device(), rp, NULL);
18847}
18848
18849TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18850 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18851 "as vertex attributes");
18852 m_errorMonitor->ExpectSuccess();
18853
18854 ASSERT_NO_FATAL_FAILURE(InitState());
18855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18856
18857 VkVertexInputBindingDescription input_binding;
18858 memset(&input_binding, 0, sizeof(input_binding));
18859
18860 VkVertexInputAttributeDescription input_attribs[2];
18861 memset(input_attribs, 0, sizeof(input_attribs));
18862
18863 for (int i = 0; i < 2; i++) {
18864 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18865 input_attribs[i].location = i;
18866 }
18867
18868 char const *vsSource = "#version 450\n"
18869 "\n"
18870 "layout(location=0) in mat2x4 x;\n"
18871 "out gl_PerVertex {\n"
18872 " vec4 gl_Position;\n"
18873 "};\n"
18874 "void main(){\n"
18875 " gl_Position = x[0] + x[1];\n"
18876 "}\n";
18877 char const *fsSource = "#version 450\n"
18878 "\n"
18879 "layout(location=0) out vec4 color;\n"
18880 "void main(){\n"
18881 " color = vec4(1);\n"
18882 "}\n";
18883
18884 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18885 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18886
18887 VkPipelineObj pipe(m_device);
18888 pipe.AddColorAttachment();
18889 pipe.AddShader(&vs);
18890 pipe.AddShader(&fs);
18891
18892 pipe.AddVertexInputBindings(&input_binding, 1);
18893 pipe.AddVertexInputAttribs(input_attribs, 2);
18894
18895 VkDescriptorSetObj descriptorSet(m_device);
18896 descriptorSet.AppendDummy();
18897 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18898
18899 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18900
18901 /* expect success */
18902 m_errorMonitor->VerifyNotFound();
18903}
18904
18905TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18906 m_errorMonitor->ExpectSuccess();
18907
18908 ASSERT_NO_FATAL_FAILURE(InitState());
18909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18910
18911 VkVertexInputBindingDescription input_binding;
18912 memset(&input_binding, 0, sizeof(input_binding));
18913
18914 VkVertexInputAttributeDescription input_attribs[2];
18915 memset(input_attribs, 0, sizeof(input_attribs));
18916
18917 for (int i = 0; i < 2; i++) {
18918 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18919 input_attribs[i].location = i;
18920 }
18921
18922 char const *vsSource = "#version 450\n"
18923 "\n"
18924 "layout(location=0) in vec4 x[2];\n"
18925 "out gl_PerVertex {\n"
18926 " vec4 gl_Position;\n"
18927 "};\n"
18928 "void main(){\n"
18929 " gl_Position = x[0] + x[1];\n"
18930 "}\n";
18931 char const *fsSource = "#version 450\n"
18932 "\n"
18933 "layout(location=0) out vec4 color;\n"
18934 "void main(){\n"
18935 " color = vec4(1);\n"
18936 "}\n";
18937
18938 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18939 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18940
18941 VkPipelineObj pipe(m_device);
18942 pipe.AddColorAttachment();
18943 pipe.AddShader(&vs);
18944 pipe.AddShader(&fs);
18945
18946 pipe.AddVertexInputBindings(&input_binding, 1);
18947 pipe.AddVertexInputAttribs(input_attribs, 2);
18948
18949 VkDescriptorSetObj descriptorSet(m_device);
18950 descriptorSet.AppendDummy();
18951 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18952
18953 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18954
18955 m_errorMonitor->VerifyNotFound();
18956}
18957
18958TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18959 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18960 "through multiple vertex shader inputs, each consuming a different "
18961 "subset of the components.");
18962 m_errorMonitor->ExpectSuccess();
18963
18964 ASSERT_NO_FATAL_FAILURE(InitState());
18965 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18966
18967 VkVertexInputBindingDescription input_binding;
18968 memset(&input_binding, 0, sizeof(input_binding));
18969
18970 VkVertexInputAttributeDescription input_attribs[3];
18971 memset(input_attribs, 0, sizeof(input_attribs));
18972
18973 for (int i = 0; i < 3; i++) {
18974 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18975 input_attribs[i].location = i;
18976 }
18977
18978 char const *vsSource = "#version 450\n"
18979 "\n"
18980 "layout(location=0) in vec4 x;\n"
18981 "layout(location=1) in vec3 y1;\n"
18982 "layout(location=1, component=3) in float y2;\n"
18983 "layout(location=2) in vec4 z;\n"
18984 "out gl_PerVertex {\n"
18985 " vec4 gl_Position;\n"
18986 "};\n"
18987 "void main(){\n"
18988 " gl_Position = x + vec4(y1, y2) + z;\n"
18989 "}\n";
18990 char const *fsSource = "#version 450\n"
18991 "\n"
18992 "layout(location=0) out vec4 color;\n"
18993 "void main(){\n"
18994 " color = vec4(1);\n"
18995 "}\n";
18996
18997 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18998 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18999
19000 VkPipelineObj pipe(m_device);
19001 pipe.AddColorAttachment();
19002 pipe.AddShader(&vs);
19003 pipe.AddShader(&fs);
19004
19005 pipe.AddVertexInputBindings(&input_binding, 1);
19006 pipe.AddVertexInputAttribs(input_attribs, 3);
19007
19008 VkDescriptorSetObj descriptorSet(m_device);
19009 descriptorSet.AppendDummy();
19010 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19011
19012 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19013
19014 m_errorMonitor->VerifyNotFound();
19015}
19016
19017TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19018 m_errorMonitor->ExpectSuccess();
19019
19020 ASSERT_NO_FATAL_FAILURE(InitState());
19021 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19022
19023 char const *vsSource = "#version 450\n"
19024 "out gl_PerVertex {\n"
19025 " vec4 gl_Position;\n"
19026 "};\n"
19027 "void main(){\n"
19028 " gl_Position = vec4(0);\n"
19029 "}\n";
19030 char const *fsSource = "#version 450\n"
19031 "\n"
19032 "layout(location=0) out vec4 color;\n"
19033 "void main(){\n"
19034 " color = vec4(1);\n"
19035 "}\n";
19036
19037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19039
19040 VkPipelineObj pipe(m_device);
19041 pipe.AddColorAttachment();
19042 pipe.AddShader(&vs);
19043 pipe.AddShader(&fs);
19044
19045 VkDescriptorSetObj descriptorSet(m_device);
19046 descriptorSet.AppendDummy();
19047 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19048
19049 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19050
19051 m_errorMonitor->VerifyNotFound();
19052}
19053
19054TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19055 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19056 "set out in 14.1.3: fundamental type must match, and producer side must "
19057 "have at least as many components");
19058 m_errorMonitor->ExpectSuccess();
19059
19060 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19061
19062 ASSERT_NO_FATAL_FAILURE(InitState());
19063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19064
19065 char const *vsSource = "#version 450\n"
19066 "out gl_PerVertex {\n"
19067 " vec4 gl_Position;\n"
19068 "};\n"
19069 "layout(location=0) out vec3 x;\n"
19070 "layout(location=1) out ivec3 y;\n"
19071 "layout(location=2) out vec3 z;\n"
19072 "void main(){\n"
19073 " gl_Position = vec4(0);\n"
19074 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19075 "}\n";
19076 char const *fsSource = "#version 450\n"
19077 "\n"
19078 "layout(location=0) out vec4 color;\n"
19079 "layout(location=0) in float x;\n"
19080 "layout(location=1) flat in int y;\n"
19081 "layout(location=2) in vec2 z;\n"
19082 "void main(){\n"
19083 " color = vec4(1 + x + y + z.x);\n"
19084 "}\n";
19085
19086 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19087 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19088
19089 VkPipelineObj pipe(m_device);
19090 pipe.AddColorAttachment();
19091 pipe.AddShader(&vs);
19092 pipe.AddShader(&fs);
19093
19094 VkDescriptorSetObj descriptorSet(m_device);
19095 descriptorSet.AppendDummy();
19096 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19097
19098 VkResult err = VK_SUCCESS;
19099 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19100 ASSERT_VK_SUCCESS(err);
19101
19102 m_errorMonitor->VerifyNotFound();
19103}
19104
19105TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19106 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19107 "passed between the TCS and TES stages");
19108 m_errorMonitor->ExpectSuccess();
19109
19110 ASSERT_NO_FATAL_FAILURE(InitState());
19111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19112
19113 if (!m_device->phy().features().tessellationShader) {
19114 printf("Device does not support tessellation shaders; skipped.\n");
19115 return;
19116 }
19117
19118 char const *vsSource = "#version 450\n"
19119 "void main(){}\n";
19120 char const *tcsSource = "#version 450\n"
19121 "layout(location=0) out int x[];\n"
19122 "layout(vertices=3) out;\n"
19123 "void main(){\n"
19124 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19125 " gl_TessLevelInner[0] = 1;\n"
19126 " x[gl_InvocationID] = gl_InvocationID;\n"
19127 "}\n";
19128 char const *tesSource = "#version 450\n"
19129 "layout(triangles, equal_spacing, cw) in;\n"
19130 "layout(location=0) in int x[];\n"
19131 "out gl_PerVertex { vec4 gl_Position; };\n"
19132 "void main(){\n"
19133 " gl_Position.xyz = gl_TessCoord;\n"
19134 " gl_Position.w = x[0] + x[1] + x[2];\n"
19135 "}\n";
19136 char const *fsSource = "#version 450\n"
19137 "layout(location=0) out vec4 color;\n"
19138 "void main(){\n"
19139 " color = vec4(1);\n"
19140 "}\n";
19141
19142 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19143 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19144 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19145 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19146
19147 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19148 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19149
19150 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19151
19152 VkPipelineObj pipe(m_device);
19153 pipe.SetInputAssembly(&iasci);
19154 pipe.SetTessellation(&tsci);
19155 pipe.AddColorAttachment();
19156 pipe.AddShader(&vs);
19157 pipe.AddShader(&tcs);
19158 pipe.AddShader(&tes);
19159 pipe.AddShader(&fs);
19160
19161 VkDescriptorSetObj descriptorSet(m_device);
19162 descriptorSet.AppendDummy();
19163 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19164
19165 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19166
19167 m_errorMonitor->VerifyNotFound();
19168}
19169
19170TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19171 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19172 "interface block passed into the geometry shader. This "
19173 "is interesting because the 'extra' array level is not "
19174 "present on the member type, but on the block instance.");
19175 m_errorMonitor->ExpectSuccess();
19176
19177 ASSERT_NO_FATAL_FAILURE(InitState());
19178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19179
19180 if (!m_device->phy().features().geometryShader) {
19181 printf("Device does not support geometry shaders; skipped.\n");
19182 return;
19183 }
19184
19185 char const *vsSource = "#version 450\n"
19186 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19187 "void main(){\n"
19188 " vs_out.x = vec4(1);\n"
19189 "}\n";
19190 char const *gsSource = "#version 450\n"
19191 "layout(triangles) in;\n"
19192 "layout(triangle_strip, max_vertices=3) out;\n"
19193 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19194 "out gl_PerVertex { vec4 gl_Position; };\n"
19195 "void main() {\n"
19196 " gl_Position = gs_in[0].x;\n"
19197 " EmitVertex();\n"
19198 "}\n";
19199 char const *fsSource = "#version 450\n"
19200 "layout(location=0) out vec4 color;\n"
19201 "void main(){\n"
19202 " color = vec4(1);\n"
19203 "}\n";
19204
19205 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19206 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19207 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19208
19209 VkPipelineObj pipe(m_device);
19210 pipe.AddColorAttachment();
19211 pipe.AddShader(&vs);
19212 pipe.AddShader(&gs);
19213 pipe.AddShader(&fs);
19214
19215 VkDescriptorSetObj descriptorSet(m_device);
19216 descriptorSet.AppendDummy();
19217 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19218
19219 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19220
19221 m_errorMonitor->VerifyNotFound();
19222}
19223
19224TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19225 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19226 "attributes. This is interesting because they consume multiple "
19227 "locations.");
19228 m_errorMonitor->ExpectSuccess();
19229
19230 ASSERT_NO_FATAL_FAILURE(InitState());
19231 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19232
19233 if (!m_device->phy().features().shaderFloat64) {
19234 printf("Device does not support 64bit vertex attributes; skipped.\n");
19235 return;
19236 }
19237
19238 VkVertexInputBindingDescription input_bindings[1];
19239 memset(input_bindings, 0, sizeof(input_bindings));
19240
19241 VkVertexInputAttributeDescription input_attribs[4];
19242 memset(input_attribs, 0, sizeof(input_attribs));
19243 input_attribs[0].location = 0;
19244 input_attribs[0].offset = 0;
19245 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19246 input_attribs[1].location = 2;
19247 input_attribs[1].offset = 32;
19248 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19249 input_attribs[2].location = 4;
19250 input_attribs[2].offset = 64;
19251 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19252 input_attribs[3].location = 6;
19253 input_attribs[3].offset = 96;
19254 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19255
19256 char const *vsSource = "#version 450\n"
19257 "\n"
19258 "layout(location=0) in dmat4 x;\n"
19259 "out gl_PerVertex {\n"
19260 " vec4 gl_Position;\n"
19261 "};\n"
19262 "void main(){\n"
19263 " gl_Position = vec4(x[0][0]);\n"
19264 "}\n";
19265 char const *fsSource = "#version 450\n"
19266 "\n"
19267 "layout(location=0) out vec4 color;\n"
19268 "void main(){\n"
19269 " color = vec4(1);\n"
19270 "}\n";
19271
19272 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19273 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19274
19275 VkPipelineObj pipe(m_device);
19276 pipe.AddColorAttachment();
19277 pipe.AddShader(&vs);
19278 pipe.AddShader(&fs);
19279
19280 pipe.AddVertexInputBindings(input_bindings, 1);
19281 pipe.AddVertexInputAttribs(input_attribs, 4);
19282
19283 VkDescriptorSetObj descriptorSet(m_device);
19284 descriptorSet.AppendDummy();
19285 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19286
19287 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19288
19289 m_errorMonitor->VerifyNotFound();
19290}
19291
19292TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
19293 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
19294 m_errorMonitor->ExpectSuccess();
19295
19296 ASSERT_NO_FATAL_FAILURE(InitState());
19297
19298 char const *vsSource = "#version 450\n"
19299 "\n"
19300 "out gl_PerVertex {\n"
19301 " vec4 gl_Position;\n"
19302 "};\n"
19303 "void main(){\n"
19304 " gl_Position = vec4(1);\n"
19305 "}\n";
19306 char const *fsSource = "#version 450\n"
19307 "\n"
19308 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
19309 "layout(location=0) out vec4 color;\n"
19310 "void main() {\n"
19311 " color = subpassLoad(x);\n"
19312 "}\n";
19313
19314 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19315 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19316
19317 VkPipelineObj pipe(m_device);
19318 pipe.AddShader(&vs);
19319 pipe.AddShader(&fs);
19320 pipe.AddColorAttachment();
19321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19322
19323 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
19324 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
19325 VkDescriptorSetLayout dsl;
19326 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19327 ASSERT_VK_SUCCESS(err);
19328
19329 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19330 VkPipelineLayout pl;
19331 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19332 ASSERT_VK_SUCCESS(err);
19333
19334 VkAttachmentDescription descs[2] = {
19335 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19336 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19337 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
19338 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
19339 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
19340 };
19341 VkAttachmentReference color = {
19342 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19343 };
19344 VkAttachmentReference input = {
19345 1, VK_IMAGE_LAYOUT_GENERAL,
19346 };
19347
19348 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19349
19350 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19351 VkRenderPass rp;
19352 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19353 ASSERT_VK_SUCCESS(err);
19354
19355 // should be OK. would go wrong here if it's going to...
19356 pipe.CreateVKPipeline(pl, rp);
19357
19358 m_errorMonitor->VerifyNotFound();
19359
19360 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19361 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19362 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19363}
19364
19365TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19366 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19367 "descriptor-backed resource which is not provided, but the shader does not "
19368 "statically use it. This is interesting because it requires compute pipelines "
19369 "to have a proper descriptor use walk, which they didn't for some time.");
19370 m_errorMonitor->ExpectSuccess();
19371
19372 ASSERT_NO_FATAL_FAILURE(InitState());
19373
19374 char const *csSource = "#version 450\n"
19375 "\n"
19376 "layout(local_size_x=1) in;\n"
19377 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19378 "void main(){\n"
19379 " // x is not used.\n"
19380 "}\n";
19381
19382 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19383
19384 VkDescriptorSetObj descriptorSet(m_device);
19385 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19386
19387 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19388 nullptr,
19389 0,
19390 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19391 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19392 descriptorSet.GetPipelineLayout(),
19393 VK_NULL_HANDLE,
19394 -1 };
19395
19396 VkPipeline pipe;
19397 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19398
19399 m_errorMonitor->VerifyNotFound();
19400
19401 if (err == VK_SUCCESS) {
19402 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19403 }
19404}
19405
19406TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19407 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19408 "sampler portion of a combined image + sampler");
19409 m_errorMonitor->ExpectSuccess();
19410
19411 ASSERT_NO_FATAL_FAILURE(InitState());
19412
19413 VkDescriptorSetLayoutBinding bindings[] = {
19414 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19415 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19416 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19417 };
19418 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19419 VkDescriptorSetLayout dsl;
19420 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19421 ASSERT_VK_SUCCESS(err);
19422
19423 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19424 VkPipelineLayout pl;
19425 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19426 ASSERT_VK_SUCCESS(err);
19427
19428 char const *csSource = "#version 450\n"
19429 "\n"
19430 "layout(local_size_x=1) in;\n"
19431 "layout(set=0, binding=0) uniform sampler s;\n"
19432 "layout(set=0, binding=1) uniform texture2D t;\n"
19433 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19434 "void main() {\n"
19435 " x = texture(sampler2D(t, s), vec2(0));\n"
19436 "}\n";
19437 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19438
19439 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19440 nullptr,
19441 0,
19442 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19443 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19444 pl,
19445 VK_NULL_HANDLE,
19446 -1 };
19447
19448 VkPipeline pipe;
19449 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19450
19451 m_errorMonitor->VerifyNotFound();
19452
19453 if (err == VK_SUCCESS) {
19454 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19455 }
19456
19457 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19458 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19459}
19460
19461TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19462 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19463 "image portion of a combined image + sampler");
19464 m_errorMonitor->ExpectSuccess();
19465
19466 ASSERT_NO_FATAL_FAILURE(InitState());
19467
19468 VkDescriptorSetLayoutBinding bindings[] = {
19469 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19470 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19471 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19472 };
19473 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19474 VkDescriptorSetLayout dsl;
19475 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19476 ASSERT_VK_SUCCESS(err);
19477
19478 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19479 VkPipelineLayout pl;
19480 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19481 ASSERT_VK_SUCCESS(err);
19482
19483 char const *csSource = "#version 450\n"
19484 "\n"
19485 "layout(local_size_x=1) in;\n"
19486 "layout(set=0, binding=0) uniform texture2D t;\n"
19487 "layout(set=0, binding=1) uniform sampler s;\n"
19488 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19489 "void main() {\n"
19490 " x = texture(sampler2D(t, s), vec2(0));\n"
19491 "}\n";
19492 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19493
19494 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19495 nullptr,
19496 0,
19497 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19498 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19499 pl,
19500 VK_NULL_HANDLE,
19501 -1 };
19502
19503 VkPipeline pipe;
19504 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19505
19506 m_errorMonitor->VerifyNotFound();
19507
19508 if (err == VK_SUCCESS) {
19509 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19510 }
19511
19512 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19513 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19514}
19515
19516TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19517 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19518 "both the sampler and the image of a combined image+sampler "
19519 "but via separate variables");
19520 m_errorMonitor->ExpectSuccess();
19521
19522 ASSERT_NO_FATAL_FAILURE(InitState());
19523
19524 VkDescriptorSetLayoutBinding bindings[] = {
19525 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19526 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19527 };
19528 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19529 VkDescriptorSetLayout dsl;
19530 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19531 ASSERT_VK_SUCCESS(err);
19532
19533 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19534 VkPipelineLayout pl;
19535 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19536 ASSERT_VK_SUCCESS(err);
19537
19538 char const *csSource = "#version 450\n"
19539 "\n"
19540 "layout(local_size_x=1) in;\n"
19541 "layout(set=0, binding=0) uniform texture2D t;\n"
19542 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19543 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19544 "void main() {\n"
19545 " x = texture(sampler2D(t, s), vec2(0));\n"
19546 "}\n";
19547 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19548
19549 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19550 nullptr,
19551 0,
19552 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19553 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19554 pl,
19555 VK_NULL_HANDLE,
19556 -1 };
19557
19558 VkPipeline pipe;
19559 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19560
19561 m_errorMonitor->VerifyNotFound();
19562
19563 if (err == VK_SUCCESS) {
19564 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19565 }
19566
19567 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19568 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19569}
19570
19571TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19572 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19573
19574 ASSERT_NO_FATAL_FAILURE(InitState());
19575
19576 // Positive test to check parameter_validation and unique_objects support
19577 // for NV_dedicated_allocation
19578 uint32_t extension_count = 0;
19579 bool supports_nv_dedicated_allocation = false;
19580 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19581 ASSERT_VK_SUCCESS(err);
19582
19583 if (extension_count > 0) {
19584 std::vector<VkExtensionProperties> available_extensions(extension_count);
19585
19586 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19587 ASSERT_VK_SUCCESS(err);
19588
19589 for (const auto &extension_props : available_extensions) {
19590 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19591 supports_nv_dedicated_allocation = true;
19592 }
19593 }
19594 }
19595
19596 if (supports_nv_dedicated_allocation) {
19597 m_errorMonitor->ExpectSuccess();
19598
19599 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19600 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19601 dedicated_buffer_create_info.pNext = nullptr;
19602 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19603
19604 uint32_t queue_family_index = 0;
19605 VkBufferCreateInfo buffer_create_info = {};
19606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19607 buffer_create_info.pNext = &dedicated_buffer_create_info;
19608 buffer_create_info.size = 1024;
19609 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19610 buffer_create_info.queueFamilyIndexCount = 1;
19611 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19612
19613 VkBuffer buffer;
19614 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19615 ASSERT_VK_SUCCESS(err);
19616
19617 VkMemoryRequirements memory_reqs;
19618 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19619
19620 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19621 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19622 dedicated_memory_info.pNext = nullptr;
19623 dedicated_memory_info.buffer = buffer;
19624 dedicated_memory_info.image = VK_NULL_HANDLE;
19625
19626 VkMemoryAllocateInfo memory_info = {};
19627 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19628 memory_info.pNext = &dedicated_memory_info;
19629 memory_info.allocationSize = memory_reqs.size;
19630
19631 bool pass;
19632 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19633 ASSERT_TRUE(pass);
19634
19635 VkDeviceMemory buffer_memory;
19636 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19637 ASSERT_VK_SUCCESS(err);
19638
19639 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19640 ASSERT_VK_SUCCESS(err);
19641
19642 vkDestroyBuffer(m_device->device(), buffer, NULL);
19643 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19644
19645 m_errorMonitor->VerifyNotFound();
19646 }
19647}
19648
19649TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19650 VkResult err;
19651
19652 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19653
19654 ASSERT_NO_FATAL_FAILURE(InitState());
19655 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19656
19657 std::vector<const char *> device_extension_names;
19658 auto features = m_device->phy().features();
19659 // Artificially disable support for non-solid fill modes
19660 features.fillModeNonSolid = false;
19661 // The sacrificial device object
19662 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19663
19664 VkRenderpassObj render_pass(&test_device);
19665
19666 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19667 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19668 pipeline_layout_ci.setLayoutCount = 0;
19669 pipeline_layout_ci.pSetLayouts = NULL;
19670
19671 VkPipelineLayout pipeline_layout;
19672 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19673 ASSERT_VK_SUCCESS(err);
19674
19675 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19676 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19677 rs_ci.pNext = nullptr;
19678 rs_ci.lineWidth = 1.0f;
19679 rs_ci.rasterizerDiscardEnable = true;
19680
19681 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19682 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19683
19684 // Set polygonMode=FILL. No error is expected
19685 m_errorMonitor->ExpectSuccess();
19686 {
19687 VkPipelineObj pipe(&test_device);
19688 pipe.AddShader(&vs);
19689 pipe.AddShader(&fs);
19690 pipe.AddColorAttachment();
19691 // Set polygonMode to a good value
19692 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19693 pipe.SetRasterization(&rs_ci);
19694 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19695 }
19696 m_errorMonitor->VerifyNotFound();
19697
19698 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19699}
19700
19701TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19702 VkResult err;
19703 ASSERT_NO_FATAL_FAILURE(InitState());
19704 ASSERT_NO_FATAL_FAILURE(InitViewport());
19705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19706
19707 VkPipelineLayout pipeline_layout;
19708 VkPushConstantRange pc_range = {};
19709 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19710 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19711 pipeline_layout_ci.pushConstantRangeCount = 1;
19712 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19713
19714 //
19715 // Check for invalid push constant ranges in pipeline layouts.
19716 //
19717 struct PipelineLayoutTestCase {
19718 VkPushConstantRange const range;
19719 char const *msg;
19720 };
19721
19722 // Check for overlapping ranges
19723 const uint32_t ranges_per_test = 5;
19724 struct OverlappingRangeTestCase {
19725 VkPushConstantRange const ranges[ranges_per_test];
19726 char const *msg;
19727 };
19728
19729 // Run some positive tests to make sure overlap checking in the layer is OK
19730 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19731 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19732 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19733 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19734 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19735 "" },
19736 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19737 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19738 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19739 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19740 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19741 "" } } };
19742 for (const auto &iter : overlapping_range_tests_pos) {
19743 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19744 m_errorMonitor->ExpectSuccess();
19745 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19746 m_errorMonitor->VerifyNotFound();
19747 if (VK_SUCCESS == err) {
19748 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19749 }
19750 }
19751
19752 //
19753 // CmdPushConstants tests
19754 //
19755 const uint8_t dummy_values[100] = {};
19756
19757 BeginCommandBuffer();
19758
19759 // positive overlapping range tests with cmd
19760 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19761 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19762 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19763 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19764 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19765 } };
19766
19767 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19768 const VkPushConstantRange pc_range4[] = {
19769 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19770 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19771 };
19772
19773 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19774 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19775 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19776 ASSERT_VK_SUCCESS(err);
19777 for (const auto &iter : cmd_overlap_tests_pos) {
19778 m_errorMonitor->ExpectSuccess();
19779 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19780 iter.range.size, dummy_values);
19781 m_errorMonitor->VerifyNotFound();
19782 }
19783 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19784
19785 EndCommandBuffer();
19786}
19787
19788
19789
19790
19791
19792
19793
19794#if 0 // A few devices have issues with this test so disabling for now
19795TEST_F(VkPositiveLayerTest, LongFenceChain)
19796{
19797 m_errorMonitor->ExpectSuccess();
19798
19799 ASSERT_NO_FATAL_FAILURE(InitState());
19800 VkResult err;
19801
19802 std::vector<VkFence> fences;
19803
19804 const int chainLength = 32768;
19805
19806 for (int i = 0; i < chainLength; i++) {
19807 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19808 VkFence fence;
19809 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19810 ASSERT_VK_SUCCESS(err);
19811
19812 fences.push_back(fence);
19813
19814 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19815 0, nullptr, 0, nullptr };
19816 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19817 ASSERT_VK_SUCCESS(err);
19818
19819 }
19820
19821 // BOOM, stack overflow.
19822 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19823
19824 for (auto fence : fences)
19825 vkDestroyFence(m_device->device(), fence, nullptr);
19826
19827 m_errorMonitor->VerifyNotFound();
19828}
19829#endif
19830
19831
Cody Northrop1242dfd2016-07-13 17:24:59 -060019832#if defined(ANDROID) && defined(VALIDATION_APK)
19833static bool initialized = false;
19834static bool active = false;
19835
19836// Convert Intents to argv
19837// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019838std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019839 std::vector<std::string> args;
19840 JavaVM &vm = *app.activity->vm;
19841 JNIEnv *p_env;
19842 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19843 return args;
19844
19845 JNIEnv &env = *p_env;
19846 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019847 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019848 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019849 jmethodID get_string_extra_method =
19850 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019851 jvalue get_string_extra_args;
19852 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019853 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019854
19855 std::string args_str;
19856 if (extra_str) {
19857 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19858 args_str = extra_utf;
19859 env.ReleaseStringUTFChars(extra_str, extra_utf);
19860 env.DeleteLocalRef(extra_str);
19861 }
19862
19863 env.DeleteLocalRef(get_string_extra_args.l);
19864 env.DeleteLocalRef(intent);
19865 vm.DetachCurrentThread();
19866
19867 // split args_str
19868 std::stringstream ss(args_str);
19869 std::string arg;
19870 while (std::getline(ss, arg, ' ')) {
19871 if (!arg.empty())
19872 args.push_back(arg);
19873 }
19874
19875 return args;
19876}
19877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019878static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019880static void processCommand(struct android_app *app, int32_t cmd) {
19881 switch (cmd) {
19882 case APP_CMD_INIT_WINDOW: {
19883 if (app->window) {
19884 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019885 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019886 break;
19887 }
19888 case APP_CMD_GAINED_FOCUS: {
19889 active = true;
19890 break;
19891 }
19892 case APP_CMD_LOST_FOCUS: {
19893 active = false;
19894 break;
19895 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019896 }
19897}
19898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019899void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019900 app_dummy();
19901
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019902 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019903
19904 int vulkanSupport = InitVulkan();
19905 if (vulkanSupport == 0) {
19906 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19907 return;
19908 }
19909
19910 app->onAppCmd = processCommand;
19911 app->onInputEvent = processInput;
19912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019913 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019914 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019915 struct android_poll_source *source;
19916 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019917 if (source) {
19918 source->process(app, source);
19919 }
19920
19921 if (app->destroyRequested != 0) {
19922 VkTestFramework::Finish();
19923 return;
19924 }
19925 }
19926
19927 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019928 // Use the following key to send arguments to gtest, i.e.
19929 // --es args "--gtest_filter=-VkLayerTest.foo"
19930 const char key[] = "args";
19931 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019932
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019933 std::string filter = "";
19934 if (args.size() > 0) {
19935 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19936 filter += args[0];
19937 } else {
19938 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19939 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019941 int argc = 2;
19942 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19943 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019944
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019945 // Route output to files until we can override the gtest output
19946 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19947 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019949 ::testing::InitGoogleTest(&argc, argv);
19950 VkTestFramework::InitArgs(&argc, argv);
19951 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019952
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019953 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019955 if (result != 0) {
19956 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19957 } else {
19958 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19959 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019961 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019963 fclose(stdout);
19964 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019966 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019968 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019969 }
19970 }
19971}
19972#endif
19973
Tony Barbour300a6082015-04-07 13:44:53 -060019974int main(int argc, char **argv) {
19975 int result;
19976
Cody Northrop8e54a402016-03-08 22:25:52 -070019977#ifdef ANDROID
19978 int vulkanSupport = InitVulkan();
19979 if (vulkanSupport == 0)
19980 return 1;
19981#endif
19982
Tony Barbour300a6082015-04-07 13:44:53 -060019983 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019984 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019985
19986 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19987
19988 result = RUN_ALL_TESTS();
19989
Tony Barbour6918cd52015-04-09 12:58:51 -060019990 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019991 return result;
19992}