blob: 0ba0800e6f3bcd7bd55aec142838df674089dcdd [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
175 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600176 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600177 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600178 m_msgFound = VK_TRUE;
179 result = VK_TRUE;
180 // We only want one match for each expected error so remove from set here
181 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600182 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186 for (auto desired_id : m_desired_message_ids) {
187 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
188 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
189 // Return true to avoid calling layers/driver with this error.
190 result = VK_TRUE;
191 } else if (desired_id == message_code) {
192 // Double-check that the string matches the error enum
193 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
194 found_expected = true;
195 result = VK_TRUE;
196 m_msgFound = VK_TRUE;
197 m_desired_message_ids.erase(desired_id);
198 break;
199 } else {
200 // Treat this message as a regular unexpected error, but print a warning jic
201 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
202 errorString.c_str(), desired_id, validation_error_map[desired_id]);
203 }
204 }
205 }
206
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200208 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600209 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600210 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600212 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600213 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600217 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
218
Karl Schultz6addd812016-02-02 17:17:23 -0700219 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220
Karl Schultz6addd812016-02-02 17:17:23 -0700221 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600222
Karl Schultz6addd812016-02-02 17:17:23 -0700223 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600225 if (otherMsgs.size()) {
226 cout << "Other error messages logged for this test were:" << endl;
227 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
228 cout << " " << *iter << endl;
229 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600230 }
231 }
232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200234
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
236 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
237 m_msgFlags = message_flag_mask;
238 // Match ANY message matching specified type
239 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200240 }
241
242 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600243 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244 if (!DesiredMsgFound()) {
245 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600246 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600247 FAIL() << "Did not receive expected error '" << desired_msg << "'";
248 }
Tony Barbour59b42282016-11-03 13:31:28 -0600249 for (auto desired_id : m_desired_message_ids) {
250 FAIL() << "Did not receive expected error '" << desired_id << "'";
251 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 }
253 }
254
255 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 if (DesiredMsgFound()) {
258 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600259 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600260 FAIL() << "Expected to succeed but got error: " << msg;
261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
263 }
264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 private:
266 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600267 std::unordered_set<uint32_t>m_desired_message_ids;
268 std::unordered_set<string> m_desired_message_strings;
269 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700270 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600271 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700272 bool *m_bailout;
273 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600274};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500275
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600276static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
277 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
278 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
280 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600281 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600282 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600283 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600284}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500285
Karl Schultz6addd812016-02-02 17:17:23 -0700286class VkLayerTest : public VkRenderFramework {
287 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
289 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
291 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700292 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
294 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700295 }
Tony Barbour300a6082015-04-07 13:44:53 -0600296
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
301 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700302 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
308 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
309 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700310 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
311 }
312 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
313 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
314 }
315
316 protected:
317 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600318 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
320 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600321 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600322 std::vector<const char *> instance_extension_names;
323 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600324
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600326 /*
327 * Since CreateDbgMsgCallback is an instance level extension call
328 * any extension / layer that utilizes that feature also needs
329 * to be enabled at create instance time.
330 */
Karl Schultz6addd812016-02-02 17:17:23 -0700331 // Use Threading layer first to protect others from
332 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600334 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700336 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800337 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600338 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700339 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600340
Ian Elliott2c1daf52016-05-12 09:41:46 -0600341 if (m_enableWSI) {
342 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
343 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
344#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
345#if defined(VK_USE_PLATFORM_ANDROID_KHR)
346 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_ANDROID_KHR
348#if defined(VK_USE_PLATFORM_MIR_KHR)
349 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_MIR_KHR
351#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
352 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_WAYLAND_KHR
354#if defined(VK_USE_PLATFORM_WIN32_KHR)
355 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WIN32_KHR
357#endif // NEED_TO_TEST_THIS_ON_PLATFORM
358#if defined(VK_USE_PLATFORM_XCB_KHR)
359 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
360#elif defined(VK_USE_PLATFORM_XLIB_KHR)
361 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
362#endif // VK_USE_PLATFORM_XLIB_KHR
363 }
364
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600366 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800367 this->app_info.pApplicationName = "layer_tests";
368 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pEngineName = "unittest";
370 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600371 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600372
Tony Barbour15524c32015-04-29 17:34:29 -0600373 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
376
377 virtual void TearDown() {
378 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600379 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600380 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600381 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600382
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600384};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385
Karl Schultz6addd812016-02-02 17:17:23 -0700386VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600390
391 /*
392 * For render test all drawing happens in a single render pass
393 * on a single command buffer.
394 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200395 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600397 }
398
399 return result;
400}
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600404
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200405 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200407 }
Tony Barbour300a6082015-04-07 13:44:53 -0600408
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600410
411 return result;
412}
413
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600414void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500415 // Create identity matrix
416 int i;
417 struct vktriangle_vs_uniform data;
418
419 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700420 glm::mat4 View = glm::mat4(1.0f);
421 glm::mat4 Model = glm::mat4(1.0f);
422 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700424 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425
426 memcpy(&data.mvp, &MVP[0][0], matrixSize);
427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430 };
431
Karl Schultz6addd812016-02-02 17:17:23 -0700432 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 data.position[i][0] = tri_data[i].posX;
434 data.position[i][1] = tri_data[i].posY;
435 data.position[i][2] = tri_data[i].posZ;
436 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700437 data.color[i][0] = tri_data[i].r;
438 data.color[i][1] = tri_data[i].g;
439 data.color[i][2] = tri_data[i].b;
440 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441 }
442
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 ASSERT_NO_FATAL_FAILURE(InitViewport());
444
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200445 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
446 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Karl Schultz6addd812016-02-02 17:17:23 -0700448 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600449 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800452 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 pipelineobj.AddShader(&vs);
454 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 if (failMask & BsoFailLineWidth) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600458 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
460 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBias) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600464 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600466 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600467 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 }
Karl Schultz6addd812016-02-02 17:17:23 -0700470 // Viewport and scissors must stay in synch or other errors will occur than
471 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 if (failMask & BsoFailViewport) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
474 }
475 if (failMask & BsoFailScissor) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
477 }
478 if (failMask & BsoFailBlend) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 VkPipelineColorBlendAttachmentState att_state = {};
481 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
482 att_state.blendEnable = VK_TRUE;
483 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 }
485 if (failMask & BsoFailDepthBounds) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
487 }
488 if (failMask & BsoFailStencilReadMask) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
490 }
491 if (failMask & BsoFailStencilWriteMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
493 }
494 if (failMask & BsoFailStencilReference) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
496 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
498 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600502 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Tony Barbourfe3351b2015-07-28 10:17:20 -0600504 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505
506 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600507 if (failMask & BsoFailIndexBuffer) {
508 // Use DrawIndexed w/o an index buffer bound
509 DrawIndexed(3, 1, 0, 0, 0);
510 } else {
511 Draw(3, 1, 0, 0);
512 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mark Muellerd4914412016-06-13 17:52:06 -0600514 if (failMask & BsoFailCmdClearAttachments) {
515 VkClearAttachment color_attachment = {};
516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
517 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
518 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
519
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600521 }
522
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Tony Barbourfe3351b2015-07-28 10:17:20 -0600526 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527}
528
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
530 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700538 // Make sure depthWriteEnable is set so that Depth fail test will work
539 // correctly
540 // Make sure stencilTestEnable is set so that Stencil fail test will work
541 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600542 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800543 stencil.failOp = VK_STENCIL_OP_KEEP;
544 stencil.passOp = VK_STENCIL_OP_KEEP;
545 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
546 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600547
548 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
549 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.pNext = NULL;
551 ds_ci.depthTestEnable = VK_FALSE;
552 ds_ci.depthWriteEnable = VK_TRUE;
553 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
554 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600555 if (failMask & BsoFailDepthBounds) {
556 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600557 ds_ci.maxDepthBounds = 0.0f;
558 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600559 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600560 ds_ci.stencilTestEnable = VK_TRUE;
561 ds_ci.front = stencil;
562 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600563
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600564 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600565 pipelineobj.SetViewport(m_viewports);
566 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800567 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 commandBuffer->BindPipeline(pipelineobj);
571 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500572}
573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600574class VkPositiveLayerTest : public VkLayerTest {
575 public:
576 protected:
577};
578
Ian Elliott2c1daf52016-05-12 09:41:46 -0600579class VkWsiEnabledLayerTest : public VkLayerTest {
580 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 protected:
582 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600583};
584
Mark Muellerdfe37552016-07-07 14:47:42 -0600585class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600587 enum eTestEnFlags {
588 eDoubleDelete,
589 eInvalidDeviceOffset,
590 eInvalidMemoryOffset,
591 eBindNullBuffer,
592 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600593 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 };
595
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
599 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 return true;
601 }
602 VkDeviceSize offset_limit = 0;
603 if (eInvalidMemoryOffset == aTestFlag) {
604 VkBuffer vulkanBuffer;
605 VkBufferCreateInfo buffer_create_info = {};
606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
607 buffer_create_info.size = 32;
608 buffer_create_info.usage = aBufferUsage;
609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600611 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
615 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
617 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600618 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 }
623 if (eOffsetAlignment < offset_limit) {
624 return true;
625 }
626 return false;
627 }
628
629 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
631 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 if (eBindNullBuffer == aTestFlag) {
634 VulkanMemory = 0;
635 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
636 } else {
637 VkBufferCreateInfo buffer_create_info = {};
638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 buffer_create_info.size = 32;
640 buffer_create_info.usage = aBufferUsage;
641
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 CreateCurrent = true;
645
646 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648
649 VkMemoryAllocateInfo memory_allocate_info = {};
650 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
651 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
653 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 if (!pass) {
655 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
656 return;
657 }
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 AllocateCurrent = true;
661 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
663 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 BoundCurrent = true;
665
666 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
667 }
668 }
669
670 ~VkBufferTest() {
671 if (CreateCurrent) {
672 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
673 }
674 if (AllocateCurrent) {
675 if (InvalidDeleteEn) {
676 union {
677 VkDeviceMemory device_memory;
678 unsigned long long index_access;
679 } bad_index;
680
681 bad_index.device_memory = VulkanMemory;
682 bad_index.index_access++;
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 }
686 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
687 }
688 }
689
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600690 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600693
694 void TestDoubleDestroy() {
695 // Destroy the buffer but leave the flag set, which will cause
696 // the buffer to be destroyed again in the destructor.
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600701 bool AllocateCurrent;
702 bool BoundCurrent;
703 bool CreateCurrent;
704 bool InvalidDeleteEn;
705
706 VkBuffer VulkanBuffer;
707 VkDevice VulkanDevice;
708 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709};
710
711class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 public:
713 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
718 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BindIdGenerator++; // NB: This can wrap w/misuse
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
722 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
725 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
726 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
727 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
728 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729
730 unsigned i = 0;
731 do {
732 VertexInputAttributeDescription[i].binding = BindId;
733 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
735 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (AttributeCount < i);
738
739 i = 0;
740 do {
741 VertexInputBindingDescription[i].binding = BindId;
742 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 i++;
745 } while (BindingCount < i);
746 }
747
748 ~VkVerticesObj() {
749 if (VertexInputAttributeDescription) {
750 delete[] VertexInputAttributeDescription;
751 }
752 if (VertexInputBindingDescription) {
753 delete[] VertexInputBindingDescription;
754 }
755 }
756
757 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
759 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 return true;
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 VkDeviceSize *offsetList;
765 unsigned offsetCount;
766
767 if (aOffsetCount) {
768 offsetList = aOffsetList;
769 offsetCount = aOffsetCount;
770 } else {
771 offsetList = new VkDeviceSize[1]();
772 offsetCount = 1;
773 }
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 BoundCurrent = true;
777
778 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600780 }
781 }
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600784 static uint32_t BindIdGenerator;
785
786 bool BoundCurrent;
787 unsigned AttributeCount;
788 unsigned BindingCount;
789 uint32_t BindId;
790
791 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
792 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
793 VkVertexInputBindingDescription *VertexInputBindingDescription;
794 VkConstantBufferObj VulkanMemoryBuffer;
795};
796
797uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500798// ********************************************************************************************************************
799// ********************************************************************************************************************
800// ********************************************************************************************************************
801// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802#if PARAMETER_VALIDATION_TESTS
803TEST_F(VkLayerTest, RequiredParameter) {
804 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
805 "pointer, array, and array count parameters");
806
807 ASSERT_NO_FATAL_FAILURE(InitState());
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600810 // Specify NULL for a pointer to a handle
811 // Expected to trigger an error with
812 // parameter_validation::validate_required_pointer
813 vkGetPhysicalDeviceFeatures(gpu(), NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
817 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify NULL for pointer to array count
819 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600820 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify 0 for a required array count
825 // Expected to trigger an error with parameter_validation::validate_array
826 VkViewport view_port = {};
827 m_commandBuffer->SetViewport(0, 0, &view_port);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for a required array
832 // Expected to trigger an error with parameter_validation::validate_array
833 m_commandBuffer->SetViewport(0, 1, NULL);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify VK_NULL_HANDLE for a required handle
838 // Expected to trigger an error with
839 // parameter_validation::validate_required_handle
840 vkUnmapMemory(device(), VK_NULL_HANDLE);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify VK_NULL_HANDLE for a required handle array entry
846 // Expected to trigger an error with
847 // parameter_validation::validate_required_handle_array
848 VkFence fence = VK_NULL_HANDLE;
849 vkResetFences(device(), 1, &fence);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600853 // Specify NULL for a required struct pointer
854 // Expected to trigger an error with
855 // parameter_validation::validate_struct_type
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), NULL, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required VkFlags parameter
862 // Expected to trigger an error with parameter_validation::validate_flags
863 m_commandBuffer->SetStencilReference(0, 0);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600867 // Specify 0 for a required VkFlags array entry
868 // Expected to trigger an error with
869 // parameter_validation::validate_flags_array
870 VkSemaphore semaphore = VK_NULL_HANDLE;
871 VkPipelineStageFlags stageFlags = 0;
872 VkSubmitInfo submitInfo = {};
873 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
874 submitInfo.waitSemaphoreCount = 1;
875 submitInfo.pWaitSemaphores = &semaphore;
876 submitInfo.pWaitDstStageMask = &stageFlags;
877 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600880
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881TEST_F(VkLayerTest, ReservedParameter) {
882 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600887 // Specify 0 for a reserved VkFlags parameter
888 // Expected to trigger an error with
889 // parameter_validation::validate_reserved_flags
890 VkEvent event_handle = VK_NULL_HANDLE;
891 VkEventCreateInfo event_info = {};
892 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
893 event_info.flags = 1;
894 vkCreateEvent(device(), &event_info, NULL, &event_handle);
895 m_errorMonitor->VerifyFound();
896}
897
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600898TEST_F(VkLayerTest, InvalidStructSType) {
899 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
900 "structure's sType field");
901
902 ASSERT_NO_FATAL_FAILURE(InitState());
903
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600905 // Zero struct memory, effectively setting sType to
906 // VK_STRUCTURE_TYPE_APPLICATION_INFO
907 // Expected to trigger an error with
908 // parameter_validation::validate_struct_type
909 VkMemoryAllocateInfo alloc_info = {};
910 VkDeviceMemory memory = VK_NULL_HANDLE;
911 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
912 m_errorMonitor->VerifyFound();
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915 // Zero struct memory, effectively setting sType to
916 // VK_STRUCTURE_TYPE_APPLICATION_INFO
917 // Expected to trigger an error with
918 // parameter_validation::validate_struct_type_array
919 VkSubmitInfo submit_info = {};
920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
921 m_errorMonitor->VerifyFound();
922}
923
924TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600925 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600931 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600932 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600933 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600934 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600935 // Zero-initialization will provide the correct sType
936 VkApplicationInfo app_info = {};
937 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
938 event_alloc_info.pNext = &app_info;
939 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
943 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
945 // a function that has allowed pNext structure types and specify
946 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600949 VkMemoryAllocateInfo memory_alloc_info = {};
950 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
951 memory_alloc_info.pNext = &app_info;
952 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600954}
Dustin Graves5d33d532016-05-09 16:21:12 -0600955
956TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959 ASSERT_NO_FATAL_FAILURE(InitState());
960
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
962 "range of the core VkFormat "
963 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 // Specify an invalid VkFormat value
965 // Expected to trigger an error with
966 // parameter_validation::validate_ranged_enum
967 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600968 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 // Specify an invalid VkFlags bitmask value
973 // Expected to trigger an error with parameter_validation::validate_flags
974 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
976 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 m_errorMonitor->VerifyFound();
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 // Specify an invalid VkFlags array entry
981 // Expected to trigger an error with
982 // parameter_validation::validate_flags_array
983 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 VkSubmitInfo submit_info = {};
986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
987 submit_info.waitSemaphoreCount = 1;
988 submit_info.pWaitSemaphores = &semaphore;
989 submit_info.pWaitDstStageMask = &stage_flags;
990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkBool32 value
995 // Expected to trigger a warning with
996 // parameter_validation::validate_bool32
997 VkSampler sampler = VK_NULL_HANDLE;
998 VkSamplerCreateInfo sampler_info = {};
999 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1000 sampler_info.pNext = NULL;
1001 sampler_info.magFilter = VK_FILTER_NEAREST;
1002 sampler_info.minFilter = VK_FILTER_NEAREST;
1003 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1004 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1005 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1006 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1007 sampler_info.mipLodBias = 1.0;
1008 sampler_info.maxAnisotropy = 1;
1009 sampler_info.compareEnable = VK_FALSE;
1010 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1011 sampler_info.minLod = 1.0;
1012 sampler_info.maxLod = 1.0;
1013 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1014 sampler_info.unnormalizedCoordinates = VK_FALSE;
1015 // Not VK_TRUE or VK_FALSE
1016 sampler_info.anisotropyEnable = 3;
1017 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1018 m_errorMonitor->VerifyFound();
1019}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001020
1021TEST_F(VkLayerTest, FailedReturnValue) {
1022 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 // Find an unsupported image format
1027 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1028 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1029 VkFormat format = static_cast<VkFormat>(f);
1030 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001031 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 unsupported = format;
1033 break;
1034 }
1035 }
1036
1037 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1039 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Specify an unsupported VkFormat value to generate a
1041 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1042 // Expected to trigger a warning from
1043 // parameter_validation::validate_result
1044 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1046 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1048 m_errorMonitor->VerifyFound();
1049 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001051
1052TEST_F(VkLayerTest, UpdateBufferAlignment) {
1053 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055
1056 ASSERT_NO_FATAL_FAILURE(InitState());
1057
1058 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1059 vk_testing::Buffer buffer;
1060 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1061
1062 BeginCommandBuffer();
1063 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is < 0
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 // Introduce failure by using dataSize that is > 65536
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1083 m_errorMonitor->VerifyFound();
1084
1085 EndCommandBuffer();
1086}
1087
1088TEST_F(VkLayerTest, FillBufferAlignment) {
1089 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1090
1091 ASSERT_NO_FATAL_FAILURE(InitState());
1092
1093 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1094 vk_testing::Buffer buffer;
1095 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1096
1097 BeginCommandBuffer();
1098
1099 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1112 m_errorMonitor->VerifyFound();
1113
1114 EndCommandBuffer();
1115}
Dustin Graves40f35822016-06-23 11:12:53 -06001116
Cortd889ff92016-07-27 09:51:27 -07001117TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1118 VkResult err;
1119
1120 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1125
1126 std::vector<const char *> device_extension_names;
1127 auto features = m_device->phy().features();
1128 // Artificially disable support for non-solid fill modes
1129 features.fillModeNonSolid = false;
1130 // The sacrificial device object
1131 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1132
1133 VkRenderpassObj render_pass(&test_device);
1134
1135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1137 pipeline_layout_ci.setLayoutCount = 0;
1138 pipeline_layout_ci.pSetLayouts = NULL;
1139
1140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001141 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001142 ASSERT_VK_SUCCESS(err);
1143
1144 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1145 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1146 rs_ci.pNext = nullptr;
1147 rs_ci.lineWidth = 1.0f;
1148 rs_ci.rasterizerDiscardEnable = true;
1149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1151 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001152
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001153 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1155 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001156 {
1157 VkPipelineObj pipe(&test_device);
1158 pipe.AddShader(&vs);
1159 pipe.AddShader(&fs);
1160 pipe.AddColorAttachment();
1161 // Introduce failure by setting unsupported polygon mode
1162 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1163 pipe.SetRasterization(&rs_ci);
1164 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1165 }
1166 m_errorMonitor->VerifyFound();
1167
1168 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1170 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001171 {
1172 VkPipelineObj pipe(&test_device);
1173 pipe.AddShader(&vs);
1174 pipe.AddShader(&fs);
1175 pipe.AddColorAttachment();
1176 // Introduce failure by setting unsupported polygon mode
1177 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1178 pipe.SetRasterization(&rs_ci);
1179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1180 }
1181 m_errorMonitor->VerifyFound();
1182
Cortd889ff92016-07-27 09:51:27 -07001183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1184}
1185
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001186#endif // PARAMETER_VALIDATION_TESTS
1187
Tobin Ehlis0788f522015-05-26 16:11:58 -06001188#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001191{
1192 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193 VkFenceCreateInfo fenceInfo = {};
1194 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195 fenceInfo.pNext = NULL;
1196 fenceInfo.flags = 0;
1197
Mike Weiblencce7ec72016-10-17 19:33:05 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001201
1202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1203 vk_testing::Buffer buffer;
1204 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
Tony Barbourfe3351b2015-07-28 10:17:20 -06001206 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001207 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001208 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209
1210 testFence.init(*m_device, fenceInfo);
1211
1212 // Bypass framework since it does the waits automatically
1213 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1216 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001219 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001222 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001223 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001224
1225 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226 ASSERT_VK_SUCCESS( err );
1227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001231 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232}
1233
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235{
1236 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237 VkFenceCreateInfo fenceInfo = {};
1238 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1239 fenceInfo.pNext = NULL;
1240 fenceInfo.flags = 0;
1241
Mike Weiblencce7ec72016-10-17 19:33:05 -06001242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 ASSERT_NO_FATAL_FAILURE(InitViewport());
1246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251
1252 testFence.init(*m_device, fenceInfo);
1253
1254 // Bypass framework since it does the waits automatically
1255 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1258 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001261 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001264 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001265 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001266
1267 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268 ASSERT_VK_SUCCESS( err );
1269
Jon Ashburnf19916e2016-01-11 13:12:43 -07001270 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271 VkCommandBufferBeginInfo info = {};
1272 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1273 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274 info.renderPass = VK_NULL_HANDLE;
1275 info.subpass = 0;
1276 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001277 info.occlusionQueryEnable = VK_FALSE;
1278 info.queryFlags = 0;
1279 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280
1281 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001284 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001286#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287
Tobin Ehlisf11be982016-05-11 13:52:53 -06001288TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1289 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1290 "buffer and image to memory such that they will alias.");
1291 VkResult err;
1292 bool pass;
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001297 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001298 VkDeviceMemory mem; // buffer will be bound first
1299 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001300 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301
1302 VkBufferCreateInfo buf_info = {};
1303 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1304 buf_info.pNext = NULL;
1305 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1306 buf_info.size = 256;
1307 buf_info.queueFamilyIndexCount = 0;
1308 buf_info.pQueueFamilyIndices = NULL;
1309 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1310 buf_info.flags = 0;
1311 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001315
1316 VkImageCreateInfo image_create_info = {};
1317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1318 image_create_info.pNext = NULL;
1319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1320 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1321 image_create_info.extent.width = 64;
1322 image_create_info.extent.height = 64;
1323 image_create_info.extent.depth = 1;
1324 image_create_info.mipLevels = 1;
1325 image_create_info.arrayLayers = 1;
1326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001327 // Image tiling must be optimal to trigger error when aliasing linear buffer
1328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001329 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1331 image_create_info.queueFamilyIndexCount = 0;
1332 image_create_info.pQueueFamilyIndices = NULL;
1333 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 image_create_info.flags = 0;
1335
Tobin Ehlisf11be982016-05-11 13:52:53 -06001336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1337 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1339 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1342
1343 VkMemoryAllocateInfo alloc_info = {};
1344 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1345 alloc_info.pNext = NULL;
1346 alloc_info.memoryTypeIndex = 0;
1347 // Ensure memory is big enough for both bindings
1348 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1350 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001352 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 vkDestroyImage(m_device->device(), image, NULL);
1354 return;
1355 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1357 ASSERT_VK_SUCCESS(err);
1358 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1359 ASSERT_VK_SUCCESS(err);
1360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1364 m_errorMonitor->VerifyFound();
1365
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 // aliasing buffer2
1368 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1369 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001372 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001375 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 m_errorMonitor->VerifyFound();
1377
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001381 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 vkFreeMemory(m_device->device(), mem, NULL);
1383 vkFreeMemory(m_device->device(), mem_img, NULL);
1384}
1385
Tobin Ehlis35372522016-05-12 08:32:31 -06001386TEST_F(VkLayerTest, InvalidMemoryMapping) {
1387 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1388 VkResult err;
1389 bool pass;
1390 ASSERT_NO_FATAL_FAILURE(InitState());
1391
1392 VkBuffer buffer;
1393 VkDeviceMemory mem;
1394 VkMemoryRequirements mem_reqs;
1395
1396 VkBufferCreateInfo buf_info = {};
1397 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1398 buf_info.pNext = NULL;
1399 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1400 buf_info.size = 256;
1401 buf_info.queueFamilyIndexCount = 0;
1402 buf_info.pQueueFamilyIndices = NULL;
1403 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1404 buf_info.flags = 0;
1405 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1406 ASSERT_VK_SUCCESS(err);
1407
1408 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1409 VkMemoryAllocateInfo alloc_info = {};
1410 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1411 alloc_info.pNext = NULL;
1412 alloc_info.memoryTypeIndex = 0;
1413
1414 // Ensure memory is big enough for both bindings
1415 static const VkDeviceSize allocation_size = 0x10000;
1416 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001417 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001418 if (!pass) {
1419 vkDestroyBuffer(m_device->device(), buffer, NULL);
1420 return;
1421 }
1422 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1423 ASSERT_VK_SUCCESS(err);
1424
1425 uint8_t *pData;
1426 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001428 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1429 m_errorMonitor->VerifyFound();
1430 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001431 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001432 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1434 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1435 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001436 m_errorMonitor->VerifyFound();
1437
1438 // Unmap the memory to avoid re-map error
1439 vkUnmapMemory(m_device->device(), mem);
1440 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1442 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1443 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001444 m_errorMonitor->VerifyFound();
1445 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1447 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001448 m_errorMonitor->VerifyFound();
1449 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001451 vkUnmapMemory(m_device->device(), mem);
1452 m_errorMonitor->VerifyFound();
1453 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001454 err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001455 ASSERT_VK_SUCCESS(err);
1456 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001457 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 mmr.memory = mem;
1459 mmr.offset = 15; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") is less than Memory Object's offset (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1462 m_errorMonitor->VerifyFound();
1463 // Now flush range that oversteps mapped range
1464 vkUnmapMemory(m_device->device(), mem);
1465 err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData);
1466 ASSERT_VK_SUCCESS(err);
1467 mmr.offset = 16;
1468 mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, ") exceeds the Memory Object's upper-bound (");
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1471 m_errorMonitor->VerifyFound();
1472
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001473 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1474 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001475 if (!pass) {
1476 vkFreeMemory(m_device->device(), mem, NULL);
1477 vkDestroyBuffer(m_device->device(), buffer, NULL);
1478 return;
1479 }
1480 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1481 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1482
1483 vkDestroyBuffer(m_device->device(), buffer, NULL);
1484 vkFreeMemory(m_device->device(), mem, NULL);
1485}
1486
Ian Elliott1c32c772016-04-28 14:47:13 -06001487TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1488 VkResult err;
1489 bool pass;
1490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001491 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1492 // following declaration (which is temporarily being moved below):
1493 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001494 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
1495 VkSwapchainCreateInfoKHR swapchain_create_info = {};
1496 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001497 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001498 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001499 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001500
1501 ASSERT_NO_FATAL_FAILURE(InitState());
1502
Ian Elliott3f06ce52016-04-29 14:46:21 -06001503#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1504#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1505 // Use the functions from the VK_KHR_android_surface extension without
1506 // enabling that extension:
1507
1508 // Create a surface:
1509 VkAndroidSurfaceCreateInfoKHR android_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1511 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001512 pass = (err != VK_SUCCESS);
1513 ASSERT_TRUE(pass);
1514 m_errorMonitor->VerifyFound();
1515#endif // VK_USE_PLATFORM_ANDROID_KHR
1516
Ian Elliott3f06ce52016-04-29 14:46:21 -06001517#if defined(VK_USE_PLATFORM_MIR_KHR)
1518 // Use the functions from the VK_KHR_mir_surface extension without enabling
1519 // that extension:
1520
1521 // Create a surface:
1522 VkMirSurfaceCreateInfoKHR mir_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001524 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1525 pass = (err != VK_SUCCESS);
1526 ASSERT_TRUE(pass);
1527 m_errorMonitor->VerifyFound();
1528
1529 // Tell whether an mir_connection supports presentation:
1530 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1532 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001533 m_errorMonitor->VerifyFound();
1534#endif // VK_USE_PLATFORM_MIR_KHR
1535
Ian Elliott3f06ce52016-04-29 14:46:21 -06001536#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1537 // Use the functions from the VK_KHR_wayland_surface extension without
1538 // enabling that extension:
1539
1540 // Create a surface:
1541 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1543 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001544 pass = (err != VK_SUCCESS);
1545 ASSERT_TRUE(pass);
1546 m_errorMonitor->VerifyFound();
1547
1548 // Tell whether an wayland_display supports presentation:
1549 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1551 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001552 m_errorMonitor->VerifyFound();
1553#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001554#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001555
Ian Elliott3f06ce52016-04-29 14:46:21 -06001556#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001557 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1558 // TO NON-LINUX PLATFORMS:
1559 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001560 // Use the functions from the VK_KHR_win32_surface extension without
1561 // enabling that extension:
1562
1563 // Create a surface:
1564 VkWin32SurfaceCreateInfoKHR win32_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1566 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001567 pass = (err != VK_SUCCESS);
1568 ASSERT_TRUE(pass);
1569 m_errorMonitor->VerifyFound();
1570
1571 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001573 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001574 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001575// Set this (for now, until all platforms are supported and tested):
1576#define NEED_TO_TEST_THIS_ON_PLATFORM
1577#endif // VK_USE_PLATFORM_WIN32_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001578
Ian Elliott1c32c772016-04-28 14:47:13 -06001579#if defined(VK_USE_PLATFORM_XCB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001580 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1581 // TO NON-LINUX PLATFORMS:
1582 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001583 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1584 // that extension:
1585
1586 // Create a surface:
1587 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001589 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1590 pass = (err != VK_SUCCESS);
1591 ASSERT_TRUE(pass);
1592 m_errorMonitor->VerifyFound();
1593
1594 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001595 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001596 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1598 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001599 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001600// Set this (for now, until all platforms are supported and tested):
1601#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001602#endif // VK_USE_PLATFORM_XCB_KHR
1603
Ian Elliott12630812016-04-29 14:35:43 -06001604#if defined(VK_USE_PLATFORM_XLIB_KHR)
1605 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1606 // that extension:
1607
1608 // Create a surface:
1609 VkXlibSurfaceCreateInfoKHR xlib_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001611 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1612 pass = (err != VK_SUCCESS);
1613 ASSERT_TRUE(pass);
1614 m_errorMonitor->VerifyFound();
1615
1616 // Tell whether an Xlib VisualID supports presentation:
1617 Display *dpy = NULL;
1618 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001620 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1621 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001622// Set this (for now, until all platforms are supported and tested):
1623#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001624#endif // VK_USE_PLATFORM_XLIB_KHR
1625
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001626// Use the functions from the VK_KHR_surface extension without enabling
1627// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001628
Ian Elliott489eec02016-05-05 14:12:44 -06001629#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001630 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001632 vkDestroySurfaceKHR(instance(), surface, NULL);
1633 m_errorMonitor->VerifyFound();
1634
1635 // Check if surface supports presentation:
1636 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001638 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1639 pass = (err != VK_SUCCESS);
1640 ASSERT_TRUE(pass);
1641 m_errorMonitor->VerifyFound();
1642
1643 // Check surface capabilities:
1644 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1646 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001647 pass = (err != VK_SUCCESS);
1648 ASSERT_TRUE(pass);
1649 m_errorMonitor->VerifyFound();
1650
1651 // Check surface formats:
1652 uint32_t format_count = 0;
1653 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1655 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001656 pass = (err != VK_SUCCESS);
1657 ASSERT_TRUE(pass);
1658 m_errorMonitor->VerifyFound();
1659
1660 // Check surface present modes:
1661 uint32_t present_mode_count = 0;
1662 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1664 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001665 pass = (err != VK_SUCCESS);
1666 ASSERT_TRUE(pass);
1667 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001668#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001669
Ian Elliott1c32c772016-04-28 14:47:13 -06001670 // Use the functions from the VK_KHR_swapchain extension without enabling
1671 // that extension:
1672
1673 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001675 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1676 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001678 pass = (err != VK_SUCCESS);
1679 ASSERT_TRUE(pass);
1680 m_errorMonitor->VerifyFound();
1681
1682 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1684 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001685 pass = (err != VK_SUCCESS);
1686 ASSERT_TRUE(pass);
1687 m_errorMonitor->VerifyFound();
1688
Chris Forbeseb7d5502016-09-13 18:19:21 +12001689 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1690 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1691 VkFence fence;
1692 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1693
Ian Elliott1c32c772016-04-28 14:47:13 -06001694 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001696 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001697 pass = (err != VK_SUCCESS);
1698 ASSERT_TRUE(pass);
1699 m_errorMonitor->VerifyFound();
1700
Chris Forbeseb7d5502016-09-13 18:19:21 +12001701 vkDestroyFence(m_device->device(), fence, nullptr);
1702
Ian Elliott1c32c772016-04-28 14:47:13 -06001703 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001704 //
1705 // NOTE: Currently can't test this because a real swapchain is needed (as
1706 // opposed to the fake one we created) in order for the layer to lookup the
1707 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001708
1709 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001711 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1712 m_errorMonitor->VerifyFound();
1713}
1714
Karl Schultz6addd812016-02-02 17:17:23 -07001715TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1716 VkResult err;
1717 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1720 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001721
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001722 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001723
1724 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001725 VkImage image;
1726 VkDeviceMemory mem;
1727 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001728
Karl Schultz6addd812016-02-02 17:17:23 -07001729 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1730 const int32_t tex_width = 32;
1731 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001732
Tony Barboureb254902015-07-15 12:50:33 -06001733 VkImageCreateInfo image_create_info = {};
1734 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001735 image_create_info.pNext = NULL;
1736 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1737 image_create_info.format = tex_format;
1738 image_create_info.extent.width = tex_width;
1739 image_create_info.extent.height = tex_height;
1740 image_create_info.extent.depth = 1;
1741 image_create_info.mipLevels = 1;
1742 image_create_info.arrayLayers = 1;
1743 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1744 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1745 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1746 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001747 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001748
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001749 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001750 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001751 mem_alloc.pNext = NULL;
1752 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001753
Chia-I Wuf7458c52015-10-26 21:10:41 +08001754 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001755 ASSERT_VK_SUCCESS(err);
1756
Karl Schultz6addd812016-02-02 17:17:23 -07001757 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001758
Mark Lobodzinski23065352015-05-29 09:32:35 -05001759 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001761 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07001762 if (!pass) { // If we can't find any unmappable memory this test doesn't
1763 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001764 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001765 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001766 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001767
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001768 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001769 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001770 ASSERT_VK_SUCCESS(err);
1771
1772 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001773 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001774 ASSERT_VK_SUCCESS(err);
1775
1776 // Map memory as if to initialize the image
1777 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001778 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001779
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001780 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001781
Chia-I Wuf7458c52015-10-26 21:10:41 +08001782 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001783 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001784}
1785
Karl Schultz6addd812016-02-02 17:17:23 -07001786TEST_F(VkLayerTest, RebindMemory) {
1787 VkResult err;
1788 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001791
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001792 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001793
1794 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001795 VkImage image;
1796 VkDeviceMemory mem1;
1797 VkDeviceMemory mem2;
1798 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001799
Karl Schultz6addd812016-02-02 17:17:23 -07001800 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1801 const int32_t tex_width = 32;
1802 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001803
Tony Barboureb254902015-07-15 12:50:33 -06001804 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001805 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1806 image_create_info.pNext = NULL;
1807 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1808 image_create_info.format = tex_format;
1809 image_create_info.extent.width = tex_width;
1810 image_create_info.extent.height = tex_height;
1811 image_create_info.extent.depth = 1;
1812 image_create_info.mipLevels = 1;
1813 image_create_info.arrayLayers = 1;
1814 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1815 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1816 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1817 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001818
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001819 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001820 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1821 mem_alloc.pNext = NULL;
1822 mem_alloc.allocationSize = 0;
1823 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001824
Karl Schultz6addd812016-02-02 17:17:23 -07001825 // Introduce failure, do NOT set memProps to
1826 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001827 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001828 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001829 ASSERT_VK_SUCCESS(err);
1830
Karl Schultz6addd812016-02-02 17:17:23 -07001831 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001832
1833 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001834 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001835 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001836
1837 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001838 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001839 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001840 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001841 ASSERT_VK_SUCCESS(err);
1842
1843 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001844 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001845 ASSERT_VK_SUCCESS(err);
1846
Karl Schultz6addd812016-02-02 17:17:23 -07001847 // Introduce validation failure, try to bind a different memory object to
1848 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001849 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001850
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001851 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001852
Chia-I Wuf7458c52015-10-26 21:10:41 +08001853 vkDestroyImage(m_device->device(), image, NULL);
1854 vkFreeMemory(m_device->device(), mem1, NULL);
1855 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001856}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001857
Karl Schultz6addd812016-02-02 17:17:23 -07001858TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001859 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001860
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1862 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001863
1864 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001865 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1866 fenceInfo.pNext = NULL;
1867 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001868
Tony Barbour300a6082015-04-07 13:44:53 -06001869 ASSERT_NO_FATAL_FAILURE(InitState());
1870 ASSERT_NO_FATAL_FAILURE(InitViewport());
1871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1872
Tony Barbourfe3351b2015-07-28 10:17:20 -06001873 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001875 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001876
1877 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001878
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001879 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001880 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1881 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001882 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001883 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001884 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001885 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001886 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001887 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001888 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001889
1890 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001891 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001892
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001893 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001894}
Chris Forbes4e44c912016-06-16 10:20:00 +12001895
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896TEST_F(VkLayerTest, InvalidUsageBits) {
1897 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1898 "Initialize buffer with wrong usage then perform copy expecting errors "
1899 "from both the image and the buffer (2 calls)");
1900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001901
1902 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001903 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001904 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001905 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001906 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001907
Tony Barbourf92621a2016-05-02 14:28:12 -06001908 VkImageView dsv;
1909 VkImageViewCreateInfo dsvci = {};
1910 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1911 dsvci.image = image.handle();
1912 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1913 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1914 dsvci.subresourceRange.layerCount = 1;
1915 dsvci.subresourceRange.baseMipLevel = 0;
1916 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001917 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001918
Tony Barbourf92621a2016-05-02 14:28:12 -06001919 // Create a view with depth / stencil aspect for image with different usage
1920 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001921
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001922 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001923
1924 // Initialize buffer with TRANSFER_DST usage
1925 vk_testing::Buffer buffer;
1926 VkMemoryPropertyFlags reqs = 0;
1927 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1928 VkBufferImageCopy region = {};
1929 region.bufferRowLength = 128;
1930 region.bufferImageHeight = 128;
1931 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1932 region.imageSubresource.layerCount = 1;
1933 region.imageExtent.height = 16;
1934 region.imageExtent.width = 16;
1935 region.imageExtent.depth = 1;
1936
Tony Barbourf92621a2016-05-02 14:28:12 -06001937 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1938 // TRANSFER_DST
1939 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001940
Chris Forbesda581202016-10-06 18:25:26 +13001941 // two separate errors from this call:
1942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1944
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001945 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1946 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001947 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001948}
Tony Barbour75d79f02016-08-30 09:39:07 -06001949
Tony Barbour75d79f02016-08-30 09:39:07 -06001950
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001951#endif // MEM_TRACKER_TESTS
1952
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001953#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001954
1955TEST_F(VkLayerTest, LeakAnObject) {
1956 VkResult err;
1957
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001958 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001959
1960 // Note that we have to create a new device since destroying the
1961 // framework's device causes Teardown() to fail and just calling Teardown
1962 // will destroy the errorMonitor.
1963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001965
1966 ASSERT_NO_FATAL_FAILURE(InitState());
1967
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001968 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001969 std::vector<VkDeviceQueueCreateInfo> queue_info;
1970 queue_info.reserve(queue_props.size());
1971 std::vector<std::vector<float>> queue_priorities;
1972 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
1973 VkDeviceQueueCreateInfo qi = {};
1974 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
1975 qi.pNext = NULL;
1976 qi.queueFamilyIndex = i;
1977 qi.queueCount = queue_props[i].queueCount;
1978 queue_priorities.emplace_back(qi.queueCount, 0.0f);
1979 qi.pQueuePriorities = queue_priorities[i].data();
1980 queue_info.push_back(qi);
1981 }
1982
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001983 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001984
1985 // The sacrificial device object
1986 VkDevice testDevice;
1987 VkDeviceCreateInfo device_create_info = {};
1988 auto features = m_device->phy().features();
1989 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
1990 device_create_info.pNext = NULL;
1991 device_create_info.queueCreateInfoCount = queue_info.size();
1992 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06001993 device_create_info.enabledLayerCount = 0;
1994 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001995 device_create_info.pEnabledFeatures = &features;
1996 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
1997 ASSERT_VK_SUCCESS(err);
1998
1999 VkFence fence;
2000 VkFenceCreateInfo fence_create_info = {};
2001 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2002 fence_create_info.pNext = NULL;
2003 fence_create_info.flags = 0;
2004 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2005 ASSERT_VK_SUCCESS(err);
2006
2007 // Induce failure by not calling vkDestroyFence
2008 vkDestroyDevice(testDevice, NULL);
2009 m_errorMonitor->VerifyFound();
2010}
2011
2012TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2013
2014 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2015 "attempt to delete them from another.");
2016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002018
Cody Northropc31a84f2016-08-22 10:41:47 -06002019 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002020 VkCommandPool command_pool_one;
2021 VkCommandPool command_pool_two;
2022
2023 VkCommandPoolCreateInfo pool_create_info{};
2024 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2025 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2026 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002028 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002029
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002030 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002031
2032 VkCommandBuffer command_buffer[9];
2033 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002034 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002035 command_buffer_allocate_info.commandPool = command_pool_one;
2036 command_buffer_allocate_info.commandBufferCount = 9;
2037 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002039
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002040 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002041
2042 m_errorMonitor->VerifyFound();
2043
2044 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2045 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2046}
2047
2048TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2049 VkResult err;
2050
2051 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002052 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002053
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002055
2056 ASSERT_NO_FATAL_FAILURE(InitState());
2057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2058
2059 VkDescriptorPoolSize ds_type_count = {};
2060 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2061 ds_type_count.descriptorCount = 1;
2062
2063 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2064 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2065 ds_pool_ci.pNext = NULL;
2066 ds_pool_ci.flags = 0;
2067 ds_pool_ci.maxSets = 1;
2068 ds_pool_ci.poolSizeCount = 1;
2069 ds_pool_ci.pPoolSizes = &ds_type_count;
2070
2071 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002072 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002073 ASSERT_VK_SUCCESS(err);
2074
2075 // Create a second descriptor pool
2076 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002077 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002078 ASSERT_VK_SUCCESS(err);
2079
2080 VkDescriptorSetLayoutBinding dsl_binding = {};
2081 dsl_binding.binding = 0;
2082 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2083 dsl_binding.descriptorCount = 1;
2084 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2085 dsl_binding.pImmutableSamplers = NULL;
2086
2087 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2088 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2089 ds_layout_ci.pNext = NULL;
2090 ds_layout_ci.bindingCount = 1;
2091 ds_layout_ci.pBindings = &dsl_binding;
2092
2093 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002095 ASSERT_VK_SUCCESS(err);
2096
2097 VkDescriptorSet descriptorSet;
2098 VkDescriptorSetAllocateInfo alloc_info = {};
2099 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2100 alloc_info.descriptorSetCount = 1;
2101 alloc_info.descriptorPool = ds_pool_one;
2102 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002103 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002104 ASSERT_VK_SUCCESS(err);
2105
2106 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2107
2108 m_errorMonitor->VerifyFound();
2109
2110 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2111 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2112 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2113}
2114
2115TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002118 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002119
2120 ASSERT_NO_FATAL_FAILURE(InitState());
2121
2122 // Pass bogus handle into GetImageMemoryRequirements
2123 VkMemoryRequirements mem_reqs;
2124 uint64_t fakeImageHandle = 0xCADECADE;
2125 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2126
2127 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2128
2129 m_errorMonitor->VerifyFound();
2130}
2131
Karl Schultz6addd812016-02-02 17:17:23 -07002132TEST_F(VkLayerTest, PipelineNotBound) {
2133 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002134
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002135 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002136
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002138
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002139 ASSERT_NO_FATAL_FAILURE(InitState());
2140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002141
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002142 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002143 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2144 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002145
2146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2148 ds_pool_ci.pNext = NULL;
2149 ds_pool_ci.maxSets = 1;
2150 ds_pool_ci.poolSizeCount = 1;
2151 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002152
2153 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002154 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002155 ASSERT_VK_SUCCESS(err);
2156
2157 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002158 dsl_binding.binding = 0;
2159 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2160 dsl_binding.descriptorCount = 1;
2161 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2162 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002163
2164 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002165 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2166 ds_layout_ci.pNext = NULL;
2167 ds_layout_ci.bindingCount = 1;
2168 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002169
2170 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002171 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002172 ASSERT_VK_SUCCESS(err);
2173
2174 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002175 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002176 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002177 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002178 alloc_info.descriptorPool = ds_pool;
2179 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002180 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002181 ASSERT_VK_SUCCESS(err);
2182
2183 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002184 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2185 pipeline_layout_ci.pNext = NULL;
2186 pipeline_layout_ci.setLayoutCount = 1;
2187 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002188
2189 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002190 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002191 ASSERT_VK_SUCCESS(err);
2192
Mark Youngad779052016-01-06 14:26:04 -07002193 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002194
2195 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002196 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002197
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002198 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002199
Chia-I Wuf7458c52015-10-26 21:10:41 +08002200 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2201 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2202 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002203}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002204
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002205TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2206 VkResult err;
2207
2208 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2209 "during bind[Buffer|Image]Memory time");
2210
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002211 ASSERT_NO_FATAL_FAILURE(InitState());
2212
2213 // Create an image, allocate memory, set a bad typeIndex and then try to
2214 // bind it
2215 VkImage image;
2216 VkDeviceMemory mem;
2217 VkMemoryRequirements mem_reqs;
2218 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2219 const int32_t tex_width = 32;
2220 const int32_t tex_height = 32;
2221
2222 VkImageCreateInfo image_create_info = {};
2223 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2224 image_create_info.pNext = NULL;
2225 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2226 image_create_info.format = tex_format;
2227 image_create_info.extent.width = tex_width;
2228 image_create_info.extent.height = tex_height;
2229 image_create_info.extent.depth = 1;
2230 image_create_info.mipLevels = 1;
2231 image_create_info.arrayLayers = 1;
2232 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2233 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2234 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2235 image_create_info.flags = 0;
2236
2237 VkMemoryAllocateInfo mem_alloc = {};
2238 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2239 mem_alloc.pNext = NULL;
2240 mem_alloc.allocationSize = 0;
2241 mem_alloc.memoryTypeIndex = 0;
2242
2243 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2244 ASSERT_VK_SUCCESS(err);
2245
2246 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2247 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002248
2249 // Introduce Failure, select invalid TypeIndex
2250 VkPhysicalDeviceMemoryProperties memory_info;
2251
2252 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2253 unsigned int i;
2254 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2255 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2256 mem_alloc.memoryTypeIndex = i;
2257 break;
2258 }
2259 }
2260 if (i >= memory_info.memoryTypeCount) {
2261 printf("No invalid memory type index could be found; skipped.\n");
2262 vkDestroyImage(m_device->device(), image, NULL);
2263 return;
2264 }
2265
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002267
2268 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2269 ASSERT_VK_SUCCESS(err);
2270
2271 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2272 (void)err;
2273
2274 m_errorMonitor->VerifyFound();
2275
2276 vkDestroyImage(m_device->device(), image, NULL);
2277 vkFreeMemory(m_device->device(), mem, NULL);
2278}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002279
Karl Schultz6addd812016-02-02 17:17:23 -07002280TEST_F(VkLayerTest, BindInvalidMemory) {
2281 VkResult err;
2282 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002283
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002285
Tobin Ehlisec598302015-09-15 15:02:17 -06002286 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002287
2288 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002289 VkImage image;
2290 VkDeviceMemory mem;
2291 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002292
Karl Schultz6addd812016-02-02 17:17:23 -07002293 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2294 const int32_t tex_width = 32;
2295 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002296
2297 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002298 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2299 image_create_info.pNext = NULL;
2300 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2301 image_create_info.format = tex_format;
2302 image_create_info.extent.width = tex_width;
2303 image_create_info.extent.height = tex_height;
2304 image_create_info.extent.depth = 1;
2305 image_create_info.mipLevels = 1;
2306 image_create_info.arrayLayers = 1;
2307 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2308 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2309 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2310 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002311
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002312 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002313 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2314 mem_alloc.pNext = NULL;
2315 mem_alloc.allocationSize = 0;
2316 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002317
Chia-I Wuf7458c52015-10-26 21:10:41 +08002318 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002319 ASSERT_VK_SUCCESS(err);
2320
Karl Schultz6addd812016-02-02 17:17:23 -07002321 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002322
2323 mem_alloc.allocationSize = mem_reqs.size;
2324
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002325 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002326 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002327
2328 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002329 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002330 ASSERT_VK_SUCCESS(err);
2331
2332 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002333 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002334
2335 // Try to bind free memory that has been freed
2336 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2337 // This may very well return an error.
2338 (void)err;
2339
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002340 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002341
Chia-I Wuf7458c52015-10-26 21:10:41 +08002342 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002343}
2344
Karl Schultz6addd812016-02-02 17:17:23 -07002345TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2346 VkResult err;
2347 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002348
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002350
Tobin Ehlisec598302015-09-15 15:02:17 -06002351 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002352
Karl Schultz6addd812016-02-02 17:17:23 -07002353 // Create an image object, allocate memory, destroy the object and then try
2354 // to bind it
2355 VkImage image;
2356 VkDeviceMemory mem;
2357 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002358
Karl Schultz6addd812016-02-02 17:17:23 -07002359 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2360 const int32_t tex_width = 32;
2361 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002362
2363 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002364 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2365 image_create_info.pNext = NULL;
2366 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2367 image_create_info.format = tex_format;
2368 image_create_info.extent.width = tex_width;
2369 image_create_info.extent.height = tex_height;
2370 image_create_info.extent.depth = 1;
2371 image_create_info.mipLevels = 1;
2372 image_create_info.arrayLayers = 1;
2373 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2374 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2375 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2376 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002377
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002378 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002379 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2380 mem_alloc.pNext = NULL;
2381 mem_alloc.allocationSize = 0;
2382 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002383
Chia-I Wuf7458c52015-10-26 21:10:41 +08002384 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002385 ASSERT_VK_SUCCESS(err);
2386
Karl Schultz6addd812016-02-02 17:17:23 -07002387 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002388
2389 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002390 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002391 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002392
2393 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002394 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002395 ASSERT_VK_SUCCESS(err);
2396
2397 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002398 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002399 ASSERT_VK_SUCCESS(err);
2400
2401 // Now Try to bind memory to this destroyed object
2402 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2403 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002404 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002405
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002406 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002407
Chia-I Wuf7458c52015-10-26 21:10:41 +08002408 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002409}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002410
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002411#endif // OBJ_TRACKER_TESTS
2412
Tobin Ehlis0788f522015-05-26 16:11:58 -06002413#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002414
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002415TEST_F(VkLayerTest, ImageSampleCounts) {
2416
2417 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2418 "validation errors.");
2419 ASSERT_NO_FATAL_FAILURE(InitState());
2420
2421 VkMemoryPropertyFlags reqs = 0;
2422 VkImageCreateInfo image_create_info = {};
2423 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2424 image_create_info.pNext = NULL;
2425 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2426 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2427 image_create_info.extent.width = 256;
2428 image_create_info.extent.height = 256;
2429 image_create_info.extent.depth = 1;
2430 image_create_info.mipLevels = 1;
2431 image_create_info.arrayLayers = 1;
2432 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2433 image_create_info.flags = 0;
2434
2435 VkImageBlit blit_region = {};
2436 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2437 blit_region.srcSubresource.baseArrayLayer = 0;
2438 blit_region.srcSubresource.layerCount = 1;
2439 blit_region.srcSubresource.mipLevel = 0;
2440 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2441 blit_region.dstSubresource.baseArrayLayer = 0;
2442 blit_region.dstSubresource.layerCount = 1;
2443 blit_region.dstSubresource.mipLevel = 0;
2444
2445 // Create two images, the source with sampleCount = 2, and attempt to blit
2446 // between them
2447 {
2448 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002449 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002450 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002451 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002452 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002453 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002454 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002455 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002456 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2458 "of VK_SAMPLE_COUNT_2_BIT but "
2459 "must be VK_SAMPLE_COUNT_1_BIT");
2460 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2461 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002462 m_errorMonitor->VerifyFound();
2463 m_commandBuffer->EndCommandBuffer();
2464 }
2465
2466 // Create two images, the dest with sampleCount = 4, and attempt to blit
2467 // between them
2468 {
2469 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002471 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002472 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002473 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002474 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002475 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002476 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002477 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2479 "of VK_SAMPLE_COUNT_4_BIT but "
2480 "must be VK_SAMPLE_COUNT_1_BIT");
2481 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2482 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002483 m_errorMonitor->VerifyFound();
2484 m_commandBuffer->EndCommandBuffer();
2485 }
2486
2487 VkBufferImageCopy copy_region = {};
2488 copy_region.bufferRowLength = 128;
2489 copy_region.bufferImageHeight = 128;
2490 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2491 copy_region.imageSubresource.layerCount = 1;
2492 copy_region.imageExtent.height = 64;
2493 copy_region.imageExtent.width = 64;
2494 copy_region.imageExtent.depth = 1;
2495
2496 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2497 // buffer to image
2498 {
2499 vk_testing::Buffer src_buffer;
2500 VkMemoryPropertyFlags reqs = 0;
2501 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2502 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002504 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002505 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002506 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2508 "of VK_SAMPLE_COUNT_8_BIT but "
2509 "must be VK_SAMPLE_COUNT_1_BIT");
2510 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2511 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002512 m_errorMonitor->VerifyFound();
2513 m_commandBuffer->EndCommandBuffer();
2514 }
2515
2516 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2517 // image to buffer
2518 {
2519 vk_testing::Buffer dst_buffer;
2520 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2521 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002522 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002523 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002524 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002525 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2527 "of VK_SAMPLE_COUNT_2_BIT but "
2528 "must be VK_SAMPLE_COUNT_1_BIT");
2529 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002530 dst_buffer.handle(), 1, &copy_region);
2531 m_errorMonitor->VerifyFound();
2532 m_commandBuffer->EndCommandBuffer();
2533 }
2534}
2535
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002536TEST_F(VkLayerTest, BlitImageFormats) {
2537
2538 // Image blit with mismatched formats
2539 const char * expected_message =
2540 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2541 " the other one must also have signed/unsigned integer format";
2542
2543 ASSERT_NO_FATAL_FAILURE(InitState());
2544
2545 VkImageObj src_image(m_device);
2546 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2547 VkImageObj dst_image(m_device);
2548 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2549 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002550 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002551
2552 VkImageBlit blitRegion = {};
2553 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2554 blitRegion.srcSubresource.baseArrayLayer = 0;
2555 blitRegion.srcSubresource.layerCount = 1;
2556 blitRegion.srcSubresource.mipLevel = 0;
2557 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2558 blitRegion.dstSubresource.baseArrayLayer = 0;
2559 blitRegion.dstSubresource.layerCount = 1;
2560 blitRegion.dstSubresource.mipLevel = 0;
2561
2562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2563
2564 // Unsigned int vs not an int
2565 BeginCommandBuffer();
2566 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2567 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2568
2569 m_errorMonitor->VerifyFound();
2570
2571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2572
2573 // Unsigned int vs signed int
2574 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2575 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2576
2577 m_errorMonitor->VerifyFound();
2578
2579 EndCommandBuffer();
2580}
2581
2582
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002583TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2584 VkResult err;
2585 bool pass;
2586
2587 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2588 ASSERT_NO_FATAL_FAILURE(InitState());
2589
2590 // If w/d/h granularity is 1, test is not meaningful
2591 // TODO: When virtual device limits are available, create a set of limits for this test that
2592 // will always have a granularity of > 1 for w, h, and d
2593 auto index = m_device->graphics_queue_node_index_;
2594 auto queue_family_properties = m_device->phy().queue_properties();
2595
2596 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2597 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2598 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2599 return;
2600 }
2601
2602 // Create two images of different types and try to copy between them
2603 VkImage srcImage;
2604 VkImage dstImage;
2605 VkDeviceMemory srcMem;
2606 VkDeviceMemory destMem;
2607 VkMemoryRequirements memReqs;
2608
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002609 VkImageCreateInfo image_create_info = {};
2610 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2611 image_create_info.pNext = NULL;
2612 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2613 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2614 image_create_info.extent.width = 32;
2615 image_create_info.extent.height = 32;
2616 image_create_info.extent.depth = 1;
2617 image_create_info.mipLevels = 1;
2618 image_create_info.arrayLayers = 4;
2619 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2620 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2621 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2622 image_create_info.flags = 0;
2623
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002624 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002625 ASSERT_VK_SUCCESS(err);
2626
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002627 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002628 ASSERT_VK_SUCCESS(err);
2629
2630 // Allocate memory
2631 VkMemoryAllocateInfo memAlloc = {};
2632 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2633 memAlloc.pNext = NULL;
2634 memAlloc.allocationSize = 0;
2635 memAlloc.memoryTypeIndex = 0;
2636
2637 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2638 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002639 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002640 ASSERT_TRUE(pass);
2641 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2642 ASSERT_VK_SUCCESS(err);
2643
2644 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2645 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002646 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002647 ASSERT_VK_SUCCESS(err);
2648 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2649 ASSERT_VK_SUCCESS(err);
2650
2651 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2652 ASSERT_VK_SUCCESS(err);
2653 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2654 ASSERT_VK_SUCCESS(err);
2655
2656 BeginCommandBuffer();
2657 VkImageCopy copyRegion;
2658 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2659 copyRegion.srcSubresource.mipLevel = 0;
2660 copyRegion.srcSubresource.baseArrayLayer = 0;
2661 copyRegion.srcSubresource.layerCount = 1;
2662 copyRegion.srcOffset.x = 0;
2663 copyRegion.srcOffset.y = 0;
2664 copyRegion.srcOffset.z = 0;
2665 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2666 copyRegion.dstSubresource.mipLevel = 0;
2667 copyRegion.dstSubresource.baseArrayLayer = 0;
2668 copyRegion.dstSubresource.layerCount = 1;
2669 copyRegion.dstOffset.x = 0;
2670 copyRegion.dstOffset.y = 0;
2671 copyRegion.dstOffset.z = 0;
2672 copyRegion.extent.width = 1;
2673 copyRegion.extent.height = 1;
2674 copyRegion.extent.depth = 1;
2675
2676 // Introduce failure by setting srcOffset to a bad granularity value
2677 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2679 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002680 m_errorMonitor->VerifyFound();
2681
2682 // Introduce failure by setting extent to a bad granularity value
2683 copyRegion.srcOffset.y = 0;
2684 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2686 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002687 m_errorMonitor->VerifyFound();
2688
2689 // Now do some buffer/image copies
2690 vk_testing::Buffer buffer;
2691 VkMemoryPropertyFlags reqs = 0;
2692 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2693 VkBufferImageCopy region = {};
2694 region.bufferOffset = 0;
2695 region.bufferRowLength = 3;
2696 region.bufferImageHeight = 128;
2697 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2698 region.imageSubresource.layerCount = 1;
2699 region.imageExtent.height = 16;
2700 region.imageExtent.width = 16;
2701 region.imageExtent.depth = 1;
2702 region.imageOffset.x = 0;
2703 region.imageOffset.y = 0;
2704 region.imageOffset.z = 0;
2705
2706 // Introduce failure by setting bufferRowLength to a bad granularity value
2707 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2709 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2710 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002711 m_errorMonitor->VerifyFound();
2712 region.bufferRowLength = 128;
2713
2714 // Introduce failure by setting bufferOffset to a bad granularity value
2715 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2717 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2718 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002719 m_errorMonitor->VerifyFound();
2720 region.bufferOffset = 0;
2721
2722 // Introduce failure by setting bufferImageHeight to a bad granularity value
2723 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2725 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2726 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002727 m_errorMonitor->VerifyFound();
2728 region.bufferImageHeight = 128;
2729
2730 // Introduce failure by setting imageExtent to a bad granularity value
2731 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2733 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2734 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002735 m_errorMonitor->VerifyFound();
2736 region.imageExtent.width = 16;
2737
2738 // Introduce failure by setting imageOffset to a bad granularity value
2739 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2741 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2742 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002743 m_errorMonitor->VerifyFound();
2744
2745 EndCommandBuffer();
2746
2747 vkDestroyImage(m_device->device(), srcImage, NULL);
2748 vkDestroyImage(m_device->device(), dstImage, NULL);
2749 vkFreeMemory(m_device->device(), srcMem, NULL);
2750 vkFreeMemory(m_device->device(), destMem, NULL);
2751}
2752
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002753TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002754 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2755 "attempt to submit them on a queue created in a different "
2756 "queue family.");
2757
Cody Northropc31a84f2016-08-22 10:41:47 -06002758 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002759 // This test is meaningless unless we have multiple queue families
2760 auto queue_family_properties = m_device->phy().queue_properties();
2761 if (queue_family_properties.size() < 2) {
2762 return;
2763 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002765 // Get safe index of another queue family
2766 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2767 ASSERT_NO_FATAL_FAILURE(InitState());
2768 // Create a second queue using a different queue family
2769 VkQueue other_queue;
2770 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2771
2772 // Record an empty cmd buffer
2773 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2774 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2775 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2776 vkEndCommandBuffer(m_commandBuffer->handle());
2777
2778 // And submit on the wrong queue
2779 VkSubmitInfo submit_info = {};
2780 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2781 submit_info.commandBufferCount = 1;
2782 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002783 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002784
2785 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002786}
2787
Chris Forbesa58c4522016-09-28 15:19:39 +13002788TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2789 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2790 ASSERT_NO_FATAL_FAILURE(InitState());
2791
2792 // A renderpass with two subpasses, both writing the same attachment.
2793 VkAttachmentDescription attach[] = {
2794 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2795 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2796 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2797 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2798 },
2799 };
2800 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2801 VkSubpassDescription subpasses[] = {
2802 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2803 1, &ref, nullptr, nullptr, 0, nullptr },
2804 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2805 1, &ref, nullptr, nullptr, 0, nullptr },
2806 };
2807 VkSubpassDependency dep = {
2808 0, 1,
2809 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2810 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2811 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2812 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2813 VK_DEPENDENCY_BY_REGION_BIT
2814 };
2815 VkRenderPassCreateInfo rpci = {
2816 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2817 0, 1, attach, 2, subpasses, 1, &dep
2818 };
2819 VkRenderPass rp;
2820 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2821 ASSERT_VK_SUCCESS(err);
2822
2823 VkImageObj image(m_device);
2824 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2825 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2826 VK_IMAGE_TILING_OPTIMAL, 0);
2827 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2828
2829 VkFramebufferCreateInfo fbci = {
2830 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2831 0, rp, 1, &imageView, 32, 32, 1
2832 };
2833 VkFramebuffer fb;
2834 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2835 ASSERT_VK_SUCCESS(err);
2836
2837 char const *vsSource =
2838 "#version 450\n"
2839 "void main() { gl_Position = vec4(1); }\n";
2840 char const *fsSource =
2841 "#version 450\n"
2842 "layout(location=0) out vec4 color;\n"
2843 "void main() { color = vec4(1); }\n";
2844
2845 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2846 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2847 VkPipelineObj pipe(m_device);
2848 pipe.AddColorAttachment();
2849 pipe.AddShader(&vs);
2850 pipe.AddShader(&fs);
2851 VkViewport view_port = {};
2852 m_viewports.push_back(view_port);
2853 pipe.SetViewport(m_viewports);
2854 VkRect2D rect = {};
2855 m_scissors.push_back(rect);
2856 pipe.SetScissor(m_scissors);
2857
2858 VkPipelineLayoutCreateInfo plci = {
2859 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2860 0, 0, nullptr, 0, nullptr
2861 };
2862 VkPipelineLayout pl;
2863 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2864 ASSERT_VK_SUCCESS(err);
2865 pipe.CreateVKPipeline(pl, rp);
2866
2867 BeginCommandBuffer();
2868
2869 VkRenderPassBeginInfo rpbi = {
2870 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2871 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2872 };
2873
2874 // subtest 1: bind in the wrong subpass
2875 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2876 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2878 "built for subpass 0 but used in subpass 1");
2879 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2880 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2881 m_errorMonitor->VerifyFound();
2882
2883 vkCmdEndRenderPass(m_commandBuffer->handle());
2884
2885 // subtest 2: bind in correct subpass, then transition to next subpass
2886 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2887 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2888 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2890 "built for subpass 0 but used in subpass 1");
2891 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2892 m_errorMonitor->VerifyFound();
2893
2894 vkCmdEndRenderPass(m_commandBuffer->handle());
2895
2896 EndCommandBuffer();
2897
2898 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
2899 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2900 vkDestroyRenderPass(m_device->device(), rp, nullptr);
2901}
2902
Tony Barbour4e919972016-08-09 13:27:40 -06002903TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
2904 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
2905 "with extent outside of framebuffer");
2906 ASSERT_NO_FATAL_FAILURE(InitState());
2907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
2910 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06002911
2912 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
2913 m_renderPassBeginInfo.renderArea.extent.width = 257;
2914 m_renderPassBeginInfo.renderArea.extent.height = 257;
2915 BeginCommandBuffer();
2916 m_errorMonitor->VerifyFound();
2917}
2918
2919TEST_F(VkLayerTest, DisabledIndependentBlend) {
2920 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
2921 "blend and then specifying different blend states for two "
2922 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06002923 VkPhysicalDeviceFeatures features = {};
2924 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06002925 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06002926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2928 "Invalid Pipeline CreateInfo: If independent blend feature not "
2929 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06002930
Cody Northropc31a84f2016-08-22 10:41:47 -06002931 VkDescriptorSetObj descriptorSet(m_device);
2932 descriptorSet.AppendDummy();
2933 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06002934
Cody Northropc31a84f2016-08-22 10:41:47 -06002935 VkPipelineObj pipeline(m_device);
2936 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002937 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06002938 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06002939
Cody Northropc31a84f2016-08-22 10:41:47 -06002940 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
2941 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2942 att_state1.blendEnable = VK_TRUE;
2943 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
2944 att_state2.blendEnable = VK_FALSE;
2945 pipeline.AddColorAttachment(0, &att_state1);
2946 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002947 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06002948 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06002949}
2950
2951TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
2952 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
2953 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06002954 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06002955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2957 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06002958
2959 // Create a renderPass with a single color attachment
2960 VkAttachmentReference attach = {};
2961 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2962 VkSubpassDescription subpass = {};
2963 VkRenderPassCreateInfo rpci = {};
2964 rpci.subpassCount = 1;
2965 rpci.pSubpasses = &subpass;
2966 rpci.attachmentCount = 1;
2967 VkAttachmentDescription attach_desc = {};
2968 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
2969 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
2970 rpci.pAttachments = &attach_desc;
2971 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
2972 VkRenderPass rp;
2973 subpass.pDepthStencilAttachment = &attach;
2974 subpass.pColorAttachments = NULL;
2975 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
2976 m_errorMonitor->VerifyFound();
2977}
2978
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002979TEST_F(VkLayerTest, UnusedPreserveAttachment) {
2980 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
2981 "attachment reference of VK_ATTACHMENT_UNUSED");
2982
2983 ASSERT_NO_FATAL_FAILURE(InitState());
2984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2985
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06002987
2988 VkAttachmentReference color_attach = {};
2989 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
2990 color_attach.attachment = 0;
2991 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
2992 VkSubpassDescription subpass = {};
2993 subpass.colorAttachmentCount = 1;
2994 subpass.pColorAttachments = &color_attach;
2995 subpass.preserveAttachmentCount = 1;
2996 subpass.pPreserveAttachments = &preserve_attachment;
2997
2998 VkRenderPassCreateInfo rpci = {};
2999 rpci.subpassCount = 1;
3000 rpci.pSubpasses = &subpass;
3001 rpci.attachmentCount = 1;
3002 VkAttachmentDescription attach_desc = {};
3003 attach_desc.format = VK_FORMAT_UNDEFINED;
3004 rpci.pAttachments = &attach_desc;
3005 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3006 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003007 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003008
3009 m_errorMonitor->VerifyFound();
3010
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003011 if (result == VK_SUCCESS) {
3012 vkDestroyRenderPass(m_device->device(), rp, NULL);
3013 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003014}
3015
Chris Forbesc5389742016-06-29 11:49:23 +12003016TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003017 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3018 "when the source of a subpass multisample resolve "
3019 "does not have multiple samples.");
3020
Chris Forbesc5389742016-06-29 11:49:23 +12003021 ASSERT_NO_FATAL_FAILURE(InitState());
3022
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3024 "Subpass 0 requests multisample resolve from attachment 0 which has "
3025 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003026
3027 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003028 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3029 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3030 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3031 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3032 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3033 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003034 };
3035
3036 VkAttachmentReference color = {
3037 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3038 };
3039
3040 VkAttachmentReference resolve = {
3041 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3042 };
3043
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003044 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003045
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003046 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003047
3048 VkRenderPass rp;
3049 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3050
3051 m_errorMonitor->VerifyFound();
3052
3053 if (err == VK_SUCCESS)
3054 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3055}
3056
3057TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003058 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3059 "when a subpass multisample resolve operation is "
3060 "requested, and the destination of that resolve has "
3061 "multiple samples.");
3062
Chris Forbesc5389742016-06-29 11:49:23 +12003063 ASSERT_NO_FATAL_FAILURE(InitState());
3064
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3066 "Subpass 0 requests multisample resolve into attachment 1, which "
3067 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003068
3069 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003070 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3071 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3072 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3073 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3074 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3075 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003076 };
3077
3078 VkAttachmentReference color = {
3079 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3080 };
3081
3082 VkAttachmentReference resolve = {
3083 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3084 };
3085
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003086 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003087
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003088 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003089
3090 VkRenderPass rp;
3091 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3092
3093 m_errorMonitor->VerifyFound();
3094
3095 if (err == VK_SUCCESS)
3096 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3097}
3098
Chris Forbes3f128ef2016-06-29 14:58:53 +12003099TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003100 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3101 "when the color and depth attachments used by a subpass "
3102 "have inconsistent sample counts");
3103
Chris Forbes3f128ef2016-06-29 14:58:53 +12003104 ASSERT_NO_FATAL_FAILURE(InitState());
3105
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003108
3109 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003110 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3111 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3112 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3113 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3114 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3115 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003116 };
3117
3118 VkAttachmentReference color[] = {
3119 {
3120 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3121 },
3122 {
3123 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3124 },
3125 };
3126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003127 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003129 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003130
3131 VkRenderPass rp;
3132 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3133
3134 m_errorMonitor->VerifyFound();
3135
3136 if (err == VK_SUCCESS)
3137 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3138}
3139
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003140TEST_F(VkLayerTest, FramebufferCreateErrors) {
3141 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003142 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003143 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003144 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3145 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3146 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3147 " 6. Framebuffer attachment where dimensions don't match\n"
3148 " 7. Framebuffer attachment w/o identity swizzle\n"
3149 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003150
3151 ASSERT_NO_FATAL_FAILURE(InitState());
3152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3153
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3155 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3156 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003157
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003158 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003159 VkAttachmentReference attach = {};
3160 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3161 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003162 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003163 VkRenderPassCreateInfo rpci = {};
3164 rpci.subpassCount = 1;
3165 rpci.pSubpasses = &subpass;
3166 rpci.attachmentCount = 1;
3167 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003168 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003169 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003170 rpci.pAttachments = &attach_desc;
3171 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3172 VkRenderPass rp;
3173 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3174 ASSERT_VK_SUCCESS(err);
3175
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003176 VkImageView ivs[2];
3177 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3178 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003179 VkFramebufferCreateInfo fb_info = {};
3180 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3181 fb_info.pNext = NULL;
3182 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003183 // Set mis-matching attachmentCount
3184 fb_info.attachmentCount = 2;
3185 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003186 fb_info.width = 100;
3187 fb_info.height = 100;
3188 fb_info.layers = 1;
3189
3190 VkFramebuffer fb;
3191 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3192
3193 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003194 if (err == VK_SUCCESS) {
3195 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3196 }
3197 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003198
3199 // Create a renderPass with a depth-stencil attachment created with
3200 // IMAGE_USAGE_COLOR_ATTACHMENT
3201 // Add our color attachment to pDepthStencilAttachment
3202 subpass.pDepthStencilAttachment = &attach;
3203 subpass.pColorAttachments = NULL;
3204 VkRenderPass rp_ds;
3205 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3206 ASSERT_VK_SUCCESS(err);
3207 // Set correct attachment count, but attachment has COLOR usage bit set
3208 fb_info.attachmentCount = 1;
3209 fb_info.renderPass = rp_ds;
3210
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003212 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3213
3214 m_errorMonitor->VerifyFound();
3215 if (err == VK_SUCCESS) {
3216 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3217 }
3218 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003219
3220 // Create new renderpass with alternate attachment format from fb
3221 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3222 subpass.pDepthStencilAttachment = NULL;
3223 subpass.pColorAttachments = &attach;
3224 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3225 ASSERT_VK_SUCCESS(err);
3226
3227 // Cause error due to mis-matched formats between rp & fb
3228 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3229 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3231 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003232 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3233
3234 m_errorMonitor->VerifyFound();
3235 if (err == VK_SUCCESS) {
3236 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3237 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003238 vkDestroyRenderPass(m_device->device(), rp, NULL);
3239
3240 // Create new renderpass with alternate sample count from fb
3241 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3242 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3243 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3244 ASSERT_VK_SUCCESS(err);
3245
3246 // Cause error due to mis-matched sample count between rp & fb
3247 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3249 "that do not match the "
3250 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003251 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3252
3253 m_errorMonitor->VerifyFound();
3254 if (err == VK_SUCCESS) {
3255 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3256 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003257
3258 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003259
3260 // Create a custom imageView with non-1 mip levels
3261 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003262 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003263 ASSERT_TRUE(image.initialized());
3264
3265 VkImageView view;
3266 VkImageViewCreateInfo ivci = {};
3267 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3268 ivci.image = image.handle();
3269 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3270 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3271 ivci.subresourceRange.layerCount = 1;
3272 ivci.subresourceRange.baseMipLevel = 0;
3273 // Set level count 2 (only 1 is allowed for FB attachment)
3274 ivci.subresourceRange.levelCount = 2;
3275 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3276 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3277 ASSERT_VK_SUCCESS(err);
3278 // Re-create renderpass to have matching sample count
3279 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3280 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3281 ASSERT_VK_SUCCESS(err);
3282
3283 fb_info.renderPass = rp;
3284 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003286 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3287
3288 m_errorMonitor->VerifyFound();
3289 if (err == VK_SUCCESS) {
3290 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3291 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003292 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003293 // Update view to original color buffer and grow FB dimensions too big
3294 fb_info.pAttachments = ivs;
3295 fb_info.height = 1024;
3296 fb_info.width = 1024;
3297 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3299 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003300 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3301
3302 m_errorMonitor->VerifyFound();
3303 if (err == VK_SUCCESS) {
3304 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3305 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003306 // Create view attachment with non-identity swizzle
3307 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3308 ivci.image = image.handle();
3309 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3310 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3311 ivci.subresourceRange.layerCount = 1;
3312 ivci.subresourceRange.baseMipLevel = 0;
3313 ivci.subresourceRange.levelCount = 1;
3314 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3315 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3316 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3317 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3318 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3319 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3320 ASSERT_VK_SUCCESS(err);
3321
3322 fb_info.pAttachments = &view;
3323 fb_info.height = 100;
3324 fb_info.width = 100;
3325 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3327 "framebuffer attachments must have "
3328 "been created with the identity "
3329 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003330 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3331
3332 m_errorMonitor->VerifyFound();
3333 if (err == VK_SUCCESS) {
3334 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3335 }
3336 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003337 // Request fb that exceeds max dimensions
3338 // reset attachment to color attachment
3339 fb_info.pAttachments = ivs;
3340 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3341 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3342 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3344 "dimensions exceed physical device "
3345 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003346 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3347
3348 m_errorMonitor->VerifyFound();
3349 if (err == VK_SUCCESS) {
3350 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3351 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003352
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003353 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003354}
3355
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003356TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003357 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3358 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003359
Cody Northropc31a84f2016-08-22 10:41:47 -06003360 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003361 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3363 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003364 m_errorMonitor->VerifyFound();
3365}
3366
3367TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003368 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3369 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003370
Cody Northropc31a84f2016-08-22 10:41:47 -06003371 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003372 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3374 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003375 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003376}
3377
3378TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003379 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3380 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003381
Cody Northropc31a84f2016-08-22 10:41:47 -06003382 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003383 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003385 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003386 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003387}
3388
3389TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003390 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3391 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003392
Cody Northropc31a84f2016-08-22 10:41:47 -06003393 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003394 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003396 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003397 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003398}
3399
Cortd713fe82016-07-27 09:51:27 -07003400TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003401 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3402 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003403
3404 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003405 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3407 "Dynamic blend constants state not set for this command buffer");
3408 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003409 m_errorMonitor->VerifyFound();
3410}
3411
3412TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3414 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003415
3416 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003417 if (!m_device->phy().features().depthBounds) {
3418 printf("Device does not support depthBounds test; skipped.\n");
3419 return;
3420 }
3421 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3423 "Dynamic depth bounds state not set for this command buffer");
3424 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003425 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003426}
3427
3428TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003429 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3430 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003431
3432 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003433 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3435 "Dynamic stencil read mask state not set for this command buffer");
3436 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003437 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003438}
3439
3440TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003441 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3442 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003443
3444 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003445 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3447 "Dynamic stencil write mask state not set for this command buffer");
3448 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003449 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003450}
3451
3452TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003453 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3454 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003455
3456 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003457 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3459 "Dynamic stencil reference state not set for this command buffer");
3460 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003461 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003462}
3463
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003464TEST_F(VkLayerTest, IndexBufferNotBound) {
3465 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003466
3467 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3469 "Index buffer object not bound to this command buffer when Indexed ");
3470 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003471 m_errorMonitor->VerifyFound();
3472}
3473
Karl Schultz6addd812016-02-02 17:17:23 -07003474TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3476 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3477 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003478
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003479 ASSERT_NO_FATAL_FAILURE(InitState());
3480 ASSERT_NO_FATAL_FAILURE(InitViewport());
3481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3482
Karl Schultz6addd812016-02-02 17:17:23 -07003483 // We luck out b/c by default the framework creates CB w/ the
3484 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003485 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003486 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003487 EndCommandBuffer();
3488
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003489 // Bypass framework since it does the waits automatically
3490 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003491 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003492 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3493 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003494 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003495 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003496 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003497 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003498 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003499 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003500 submit_info.pSignalSemaphores = NULL;
3501
Chris Forbes40028e22016-06-13 09:59:34 +12003502 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003503 ASSERT_VK_SUCCESS(err);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003504
Karl Schultz6addd812016-02-02 17:17:23 -07003505 // Cause validation error by re-submitting cmd buffer that should only be
3506 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003507 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003508
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003509 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003510}
3511
Karl Schultz6addd812016-02-02 17:17:23 -07003512TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003513 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003514 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003515
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3517 "type "
3518 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003519
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003520 ASSERT_NO_FATAL_FAILURE(InitState());
3521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003522
Karl Schultz6addd812016-02-02 17:17:23 -07003523 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3524 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003525 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003526 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3527 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003528
3529 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003530 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3531 ds_pool_ci.pNext = NULL;
3532 ds_pool_ci.flags = 0;
3533 ds_pool_ci.maxSets = 1;
3534 ds_pool_ci.poolSizeCount = 1;
3535 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003536
3537 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003538 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003539 ASSERT_VK_SUCCESS(err);
3540
3541 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003542 dsl_binding.binding = 0;
3543 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3544 dsl_binding.descriptorCount = 1;
3545 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3546 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003547
3548 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003549 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3550 ds_layout_ci.pNext = NULL;
3551 ds_layout_ci.bindingCount = 1;
3552 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003553
3554 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003555 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003556 ASSERT_VK_SUCCESS(err);
3557
3558 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003559 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003560 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003561 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003562 alloc_info.descriptorPool = ds_pool;
3563 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003564 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003565
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003566 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003567
Chia-I Wuf7458c52015-10-26 21:10:41 +08003568 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3569 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003570}
3571
Karl Schultz6addd812016-02-02 17:17:23 -07003572TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3573 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3576 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3577 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003578
Tobin Ehlise735c692015-10-08 13:13:50 -06003579 ASSERT_NO_FATAL_FAILURE(InitState());
3580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003581
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003582 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003583 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3584 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003585
3586 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003587 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3588 ds_pool_ci.pNext = NULL;
3589 ds_pool_ci.maxSets = 1;
3590 ds_pool_ci.poolSizeCount = 1;
3591 ds_pool_ci.flags = 0;
3592 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3593 // app can only call vkResetDescriptorPool on this pool.;
3594 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003595
3596 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003597 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003598 ASSERT_VK_SUCCESS(err);
3599
3600 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003601 dsl_binding.binding = 0;
3602 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3603 dsl_binding.descriptorCount = 1;
3604 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3605 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003606
3607 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003608 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3609 ds_layout_ci.pNext = NULL;
3610 ds_layout_ci.bindingCount = 1;
3611 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003612
3613 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003614 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003615 ASSERT_VK_SUCCESS(err);
3616
3617 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003618 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003619 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003620 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003621 alloc_info.descriptorPool = ds_pool;
3622 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003623 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003624 ASSERT_VK_SUCCESS(err);
3625
3626 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003627 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003628
Chia-I Wuf7458c52015-10-26 21:10:41 +08003629 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3630 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003631}
3632
Karl Schultz6addd812016-02-02 17:17:23 -07003633TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003634 // Attempt to clear Descriptor Pool with bad object.
3635 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003636
3637 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003639 uint64_t fake_pool_handle = 0xbaad6001;
3640 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3641 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003642 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003643}
3644
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003645TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003646 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3647 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003648 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003649 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003650
3651 uint64_t fake_set_handle = 0xbaad6001;
3652 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003653 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003655
3656 ASSERT_NO_FATAL_FAILURE(InitState());
3657
3658 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3659 layout_bindings[0].binding = 0;
3660 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3661 layout_bindings[0].descriptorCount = 1;
3662 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3663 layout_bindings[0].pImmutableSamplers = NULL;
3664
3665 VkDescriptorSetLayout descriptor_set_layout;
3666 VkDescriptorSetLayoutCreateInfo dslci = {};
3667 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3668 dslci.pNext = NULL;
3669 dslci.bindingCount = 1;
3670 dslci.pBindings = layout_bindings;
3671 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003672 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003673
3674 VkPipelineLayout pipeline_layout;
3675 VkPipelineLayoutCreateInfo plci = {};
3676 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3677 plci.pNext = NULL;
3678 plci.setLayoutCount = 1;
3679 plci.pSetLayouts = &descriptor_set_layout;
3680 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003681 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003682
3683 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003684 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3685 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003686 m_errorMonitor->VerifyFound();
3687 EndCommandBuffer();
3688 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3689 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003690}
3691
Karl Schultz6addd812016-02-02 17:17:23 -07003692TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003693 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3694 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003695 uint64_t fake_layout_handle = 0xbaad6001;
3696 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003698 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003699 VkPipelineLayout pipeline_layout;
3700 VkPipelineLayoutCreateInfo plci = {};
3701 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3702 plci.pNext = NULL;
3703 plci.setLayoutCount = 1;
3704 plci.pSetLayouts = &bad_layout;
3705 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3706
3707 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003708}
3709
Mark Muellerd4914412016-06-13 17:52:06 -06003710TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3711 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3712 "1) A uniform buffer update must have a valid buffer index."
3713 "2) When using an array of descriptors in a single WriteDescriptor,"
3714 " the descriptor types and stageflags must all be the same."
3715 "3) Immutable Sampler state must match across descriptors");
3716
3717 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003718 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3719 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3720 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3721 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3722 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003723
Mark Muellerd4914412016-06-13 17:52:06 -06003724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3725
3726 ASSERT_NO_FATAL_FAILURE(InitState());
3727 VkDescriptorPoolSize ds_type_count[4] = {};
3728 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3729 ds_type_count[0].descriptorCount = 1;
3730 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3731 ds_type_count[1].descriptorCount = 1;
3732 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3733 ds_type_count[2].descriptorCount = 1;
3734 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3735 ds_type_count[3].descriptorCount = 1;
3736
3737 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3738 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3739 ds_pool_ci.maxSets = 1;
3740 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3741 ds_pool_ci.pPoolSizes = ds_type_count;
3742
3743 VkDescriptorPool ds_pool;
3744 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3745 ASSERT_VK_SUCCESS(err);
3746
Mark Muellerb9896722016-06-16 09:54:29 -06003747 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003748 layout_binding[0].binding = 0;
3749 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3750 layout_binding[0].descriptorCount = 1;
3751 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3752 layout_binding[0].pImmutableSamplers = NULL;
3753
3754 layout_binding[1].binding = 1;
3755 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3756 layout_binding[1].descriptorCount = 1;
3757 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3758 layout_binding[1].pImmutableSamplers = NULL;
3759
3760 VkSamplerCreateInfo sampler_ci = {};
3761 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3762 sampler_ci.pNext = NULL;
3763 sampler_ci.magFilter = VK_FILTER_NEAREST;
3764 sampler_ci.minFilter = VK_FILTER_NEAREST;
3765 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3766 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3767 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3768 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3769 sampler_ci.mipLodBias = 1.0;
3770 sampler_ci.anisotropyEnable = VK_FALSE;
3771 sampler_ci.maxAnisotropy = 1;
3772 sampler_ci.compareEnable = VK_FALSE;
3773 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3774 sampler_ci.minLod = 1.0;
3775 sampler_ci.maxLod = 1.0;
3776 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3777 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3778 VkSampler sampler;
3779
3780 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3781 ASSERT_VK_SUCCESS(err);
3782
3783 layout_binding[2].binding = 2;
3784 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3785 layout_binding[2].descriptorCount = 1;
3786 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3787 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3788
Mark Muellerd4914412016-06-13 17:52:06 -06003789 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3790 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3791 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3792 ds_layout_ci.pBindings = layout_binding;
3793 VkDescriptorSetLayout ds_layout;
3794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3795 ASSERT_VK_SUCCESS(err);
3796
3797 VkDescriptorSetAllocateInfo alloc_info = {};
3798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3799 alloc_info.descriptorSetCount = 1;
3800 alloc_info.descriptorPool = ds_pool;
3801 alloc_info.pSetLayouts = &ds_layout;
3802 VkDescriptorSet descriptorSet;
3803 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3804 ASSERT_VK_SUCCESS(err);
3805
3806 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3807 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3808 pipeline_layout_ci.pNext = NULL;
3809 pipeline_layout_ci.setLayoutCount = 1;
3810 pipeline_layout_ci.pSetLayouts = &ds_layout;
3811
3812 VkPipelineLayout pipeline_layout;
3813 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3814 ASSERT_VK_SUCCESS(err);
3815
Mark Mueller5c838ce2016-06-16 09:54:29 -06003816 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003817 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3818 descriptor_write.dstSet = descriptorSet;
3819 descriptor_write.dstBinding = 0;
3820 descriptor_write.descriptorCount = 1;
3821 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3822
Mark Mueller5c838ce2016-06-16 09:54:29 -06003823 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003824 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3825 m_errorMonitor->VerifyFound();
3826
3827 // Create a buffer to update the descriptor with
3828 uint32_t qfi = 0;
3829 VkBufferCreateInfo buffCI = {};
3830 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3831 buffCI.size = 1024;
3832 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3833 buffCI.queueFamilyIndexCount = 1;
3834 buffCI.pQueueFamilyIndices = &qfi;
3835
3836 VkBuffer dyub;
3837 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3838 ASSERT_VK_SUCCESS(err);
3839 VkDescriptorBufferInfo buffInfo = {};
3840 buffInfo.buffer = dyub;
3841 buffInfo.offset = 0;
3842 buffInfo.range = 1024;
3843
3844 descriptor_write.pBufferInfo = &buffInfo;
3845 descriptor_write.descriptorCount = 2;
3846
Mark Mueller5c838ce2016-06-16 09:54:29 -06003847 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3849 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3850 m_errorMonitor->VerifyFound();
3851
Mark Mueller5c838ce2016-06-16 09:54:29 -06003852 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3853 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003854 descriptor_write.dstBinding = 1;
3855 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003856
Mark Mueller5c838ce2016-06-16 09:54:29 -06003857 // Make pImageInfo index non-null to avoid complaints of it missing
3858 VkDescriptorImageInfo imageInfo = {};
3859 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3860 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3862 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3863 m_errorMonitor->VerifyFound();
3864
Mark Muellerd4914412016-06-13 17:52:06 -06003865 vkDestroyBuffer(m_device->device(), dyub, NULL);
3866 vkDestroySampler(m_device->device(), sampler, NULL);
3867 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3868 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3869 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3870}
3871
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003872TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3873 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3874 "due to a buffer dependency being destroyed.");
3875 ASSERT_NO_FATAL_FAILURE(InitState());
3876
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003877 VkBuffer buffer;
3878 VkDeviceMemory mem;
3879 VkMemoryRequirements mem_reqs;
3880
3881 VkBufferCreateInfo buf_info = {};
3882 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12003883 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003884 buf_info.size = 256;
3885 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3886 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
3887 ASSERT_VK_SUCCESS(err);
3888
3889 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
3890
3891 VkMemoryAllocateInfo alloc_info = {};
3892 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3893 alloc_info.allocationSize = 256;
3894 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003895 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 -06003896 if (!pass) {
3897 vkDestroyBuffer(m_device->device(), buffer, NULL);
3898 return;
3899 }
3900 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
3901 ASSERT_VK_SUCCESS(err);
3902
3903 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
3904 ASSERT_VK_SUCCESS(err);
3905
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003906 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12003907 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003908 m_commandBuffer->EndCommandBuffer();
3909
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003911 // Destroy buffer dependency prior to submit to cause ERROR
3912 vkDestroyBuffer(m_device->device(), buffer, NULL);
3913
3914 VkSubmitInfo submit_info = {};
3915 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3916 submit_info.commandBufferCount = 1;
3917 submit_info.pCommandBuffers = &m_commandBuffer->handle();
3918 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
3919
3920 m_errorMonitor->VerifyFound();
3921 vkFreeMemory(m_device->handle(), mem, NULL);
3922}
3923
Tobin Ehlisea413442016-09-28 10:23:59 -06003924TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
3925 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
3926
3927 ASSERT_NO_FATAL_FAILURE(InitState());
3928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3929
3930 VkDescriptorPoolSize ds_type_count;
3931 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3932 ds_type_count.descriptorCount = 1;
3933
3934 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3935 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3936 ds_pool_ci.maxSets = 1;
3937 ds_pool_ci.poolSizeCount = 1;
3938 ds_pool_ci.pPoolSizes = &ds_type_count;
3939
3940 VkDescriptorPool ds_pool;
3941 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3942 ASSERT_VK_SUCCESS(err);
3943
3944 VkDescriptorSetLayoutBinding layout_binding;
3945 layout_binding.binding = 0;
3946 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
3947 layout_binding.descriptorCount = 1;
3948 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3949 layout_binding.pImmutableSamplers = NULL;
3950
3951 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3952 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3953 ds_layout_ci.bindingCount = 1;
3954 ds_layout_ci.pBindings = &layout_binding;
3955 VkDescriptorSetLayout ds_layout;
3956 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3957 ASSERT_VK_SUCCESS(err);
3958
3959 VkDescriptorSetAllocateInfo alloc_info = {};
3960 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3961 alloc_info.descriptorSetCount = 1;
3962 alloc_info.descriptorPool = ds_pool;
3963 alloc_info.pSetLayouts = &ds_layout;
3964 VkDescriptorSet descriptor_set;
3965 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
3966 ASSERT_VK_SUCCESS(err);
3967
3968 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3969 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3970 pipeline_layout_ci.pNext = NULL;
3971 pipeline_layout_ci.setLayoutCount = 1;
3972 pipeline_layout_ci.pSetLayouts = &ds_layout;
3973
3974 VkPipelineLayout pipeline_layout;
3975 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3976 ASSERT_VK_SUCCESS(err);
3977
3978 VkBuffer buffer;
3979 uint32_t queue_family_index = 0;
3980 VkBufferCreateInfo buffer_create_info = {};
3981 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3982 buffer_create_info.size = 1024;
3983 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
3984 buffer_create_info.queueFamilyIndexCount = 1;
3985 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
3986
3987 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
3988 ASSERT_VK_SUCCESS(err);
3989
3990 VkMemoryRequirements memory_reqs;
3991 VkDeviceMemory buffer_memory;
3992
3993 VkMemoryAllocateInfo memory_info = {};
3994 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3995 memory_info.allocationSize = 0;
3996 memory_info.memoryTypeIndex = 0;
3997
3998 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
3999 memory_info.allocationSize = memory_reqs.size;
4000 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4001 ASSERT_TRUE(pass);
4002
4003 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4004 ASSERT_VK_SUCCESS(err);
4005 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4006 ASSERT_VK_SUCCESS(err);
4007
4008 VkBufferView view;
4009 VkBufferViewCreateInfo bvci = {};
4010 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4011 bvci.buffer = buffer;
4012 bvci.format = VK_FORMAT_R8_UNORM;
4013 bvci.range = VK_WHOLE_SIZE;
4014
4015 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4016 ASSERT_VK_SUCCESS(err);
4017
4018 VkWriteDescriptorSet descriptor_write = {};
4019 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4020 descriptor_write.dstSet = descriptor_set;
4021 descriptor_write.dstBinding = 0;
4022 descriptor_write.descriptorCount = 1;
4023 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4024 descriptor_write.pTexelBufferView = &view;
4025
4026 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4027
4028 char const *vsSource = "#version 450\n"
4029 "\n"
4030 "out gl_PerVertex { \n"
4031 " vec4 gl_Position;\n"
4032 "};\n"
4033 "void main(){\n"
4034 " gl_Position = vec4(1);\n"
4035 "}\n";
4036 char const *fsSource = "#version 450\n"
4037 "\n"
4038 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4039 "layout(location=0) out vec4 x;\n"
4040 "void main(){\n"
4041 " x = imageLoad(s, 0);\n"
4042 "}\n";
4043 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4044 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4045 VkPipelineObj pipe(m_device);
4046 pipe.AddShader(&vs);
4047 pipe.AddShader(&fs);
4048 pipe.AddColorAttachment();
4049 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4050
4051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4053
4054 BeginCommandBuffer();
4055 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4056 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4057 VkRect2D scissor = {{0, 0}, {16, 16}};
4058 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4059 // Bind pipeline to cmd buffer
4060 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4061 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4062 &descriptor_set, 0, nullptr);
4063 Draw(1, 0, 0, 0);
4064 EndCommandBuffer();
4065
4066 // Delete BufferView in order to invalidate cmd buffer
4067 vkDestroyBufferView(m_device->device(), view, NULL);
4068 // Now attempt submit of cmd buffer
4069 VkSubmitInfo submit_info = {};
4070 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4071 submit_info.commandBufferCount = 1;
4072 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4073 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4074 m_errorMonitor->VerifyFound();
4075
4076 // Clean-up
4077 vkDestroyBuffer(m_device->device(), buffer, NULL);
4078 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4079 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4080 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4081 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4082}
4083
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004084TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4085 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4086 "due to an image dependency being destroyed.");
4087 ASSERT_NO_FATAL_FAILURE(InitState());
4088
4089 VkImage image;
4090 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4091 VkImageCreateInfo image_create_info = {};
4092 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4093 image_create_info.pNext = NULL;
4094 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4095 image_create_info.format = tex_format;
4096 image_create_info.extent.width = 32;
4097 image_create_info.extent.height = 32;
4098 image_create_info.extent.depth = 1;
4099 image_create_info.mipLevels = 1;
4100 image_create_info.arrayLayers = 1;
4101 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4102 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004103 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004104 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004105 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004106 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004107 // Have to bind memory to image before recording cmd in cmd buffer using it
4108 VkMemoryRequirements mem_reqs;
4109 VkDeviceMemory image_mem;
4110 bool pass;
4111 VkMemoryAllocateInfo mem_alloc = {};
4112 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4113 mem_alloc.pNext = NULL;
4114 mem_alloc.memoryTypeIndex = 0;
4115 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4116 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004117 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004118 ASSERT_TRUE(pass);
4119 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4120 ASSERT_VK_SUCCESS(err);
4121 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4122 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004123
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004124 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004125 VkClearColorValue ccv;
4126 ccv.float32[0] = 1.0f;
4127 ccv.float32[1] = 1.0f;
4128 ccv.float32[2] = 1.0f;
4129 ccv.float32[3] = 1.0f;
4130 VkImageSubresourceRange isr = {};
4131 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004132 isr.baseArrayLayer = 0;
4133 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004134 isr.layerCount = 1;
4135 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004136 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004137 m_commandBuffer->EndCommandBuffer();
4138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004140 // Destroy image dependency prior to submit to cause ERROR
4141 vkDestroyImage(m_device->device(), image, NULL);
4142
4143 VkSubmitInfo submit_info = {};
4144 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4145 submit_info.commandBufferCount = 1;
4146 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4147 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4148
4149 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004150 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004151}
4152
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004153TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4154 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4155 "due to a framebuffer image dependency being destroyed.");
4156 VkFormatProperties format_properties;
4157 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004158 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4159 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004160 return;
4161 }
4162
4163 ASSERT_NO_FATAL_FAILURE(InitState());
4164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4165
4166 VkImageCreateInfo image_ci = {};
4167 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4168 image_ci.pNext = NULL;
4169 image_ci.imageType = VK_IMAGE_TYPE_2D;
4170 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4171 image_ci.extent.width = 32;
4172 image_ci.extent.height = 32;
4173 image_ci.extent.depth = 1;
4174 image_ci.mipLevels = 1;
4175 image_ci.arrayLayers = 1;
4176 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4177 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004178 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004179 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4180 image_ci.flags = 0;
4181 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004182 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004183
4184 VkMemoryRequirements memory_reqs;
4185 VkDeviceMemory image_memory;
4186 bool pass;
4187 VkMemoryAllocateInfo memory_info = {};
4188 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4189 memory_info.pNext = NULL;
4190 memory_info.allocationSize = 0;
4191 memory_info.memoryTypeIndex = 0;
4192 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4193 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004194 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004195 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004196 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004197 ASSERT_VK_SUCCESS(err);
4198 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4199 ASSERT_VK_SUCCESS(err);
4200
4201 VkImageViewCreateInfo ivci = {
4202 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4203 nullptr,
4204 0,
4205 image,
4206 VK_IMAGE_VIEW_TYPE_2D,
4207 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004208 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004209 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4210 };
4211 VkImageView view;
4212 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4213 ASSERT_VK_SUCCESS(err);
4214
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004215 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004216 VkFramebuffer fb;
4217 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4218 ASSERT_VK_SUCCESS(err);
4219
4220 // Just use default renderpass with our framebuffer
4221 m_renderPassBeginInfo.framebuffer = fb;
4222 // Create Null cmd buffer for submit
4223 BeginCommandBuffer();
4224 EndCommandBuffer();
4225 // Destroy image attached to framebuffer to invalidate cmd buffer
4226 vkDestroyImage(m_device->device(), image, NULL);
4227 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004229 QueueCommandBuffer(false);
4230 m_errorMonitor->VerifyFound();
4231
4232 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4233 vkDestroyImageView(m_device->device(), view, nullptr);
4234 vkFreeMemory(m_device->device(), image_memory, nullptr);
4235}
4236
Tobin Ehlisb329f992016-10-12 13:20:29 -06004237TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4238 TEST_DESCRIPTION("Delete in-use framebuffer.");
4239 VkFormatProperties format_properties;
4240 VkResult err = VK_SUCCESS;
4241 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4242
4243 ASSERT_NO_FATAL_FAILURE(InitState());
4244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4245
4246 VkImageObj image(m_device);
4247 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4248 ASSERT_TRUE(image.initialized());
4249 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4250
4251 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4252 VkFramebuffer fb;
4253 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4254 ASSERT_VK_SUCCESS(err);
4255
4256 // Just use default renderpass with our framebuffer
4257 m_renderPassBeginInfo.framebuffer = fb;
4258 // Create Null cmd buffer for submit
4259 BeginCommandBuffer();
4260 EndCommandBuffer();
4261 // Submit cmd buffer to put it in-flight
4262 VkSubmitInfo submit_info = {};
4263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4264 submit_info.commandBufferCount = 1;
4265 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4266 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4267 // Destroy framebuffer while in-flight
4268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4269 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4270 m_errorMonitor->VerifyFound();
4271 // Wait for queue to complete so we can safely destroy everything
4272 vkQueueWaitIdle(m_device->m_queue);
4273 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4274}
4275
Tobin Ehlis88becd72016-09-21 14:33:41 -06004276TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4277 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4278 VkFormatProperties format_properties;
4279 VkResult err = VK_SUCCESS;
4280 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004281
4282 ASSERT_NO_FATAL_FAILURE(InitState());
4283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4284
4285 VkImageCreateInfo image_ci = {};
4286 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4287 image_ci.pNext = NULL;
4288 image_ci.imageType = VK_IMAGE_TYPE_2D;
4289 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4290 image_ci.extent.width = 256;
4291 image_ci.extent.height = 256;
4292 image_ci.extent.depth = 1;
4293 image_ci.mipLevels = 1;
4294 image_ci.arrayLayers = 1;
4295 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4296 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004297 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004298 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4299 image_ci.flags = 0;
4300 VkImage image;
4301 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4302
4303 VkMemoryRequirements memory_reqs;
4304 VkDeviceMemory image_memory;
4305 bool pass;
4306 VkMemoryAllocateInfo memory_info = {};
4307 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4308 memory_info.pNext = NULL;
4309 memory_info.allocationSize = 0;
4310 memory_info.memoryTypeIndex = 0;
4311 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4312 memory_info.allocationSize = memory_reqs.size;
4313 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4314 ASSERT_TRUE(pass);
4315 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4316 ASSERT_VK_SUCCESS(err);
4317 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4318 ASSERT_VK_SUCCESS(err);
4319
4320 VkImageViewCreateInfo ivci = {
4321 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4322 nullptr,
4323 0,
4324 image,
4325 VK_IMAGE_VIEW_TYPE_2D,
4326 VK_FORMAT_B8G8R8A8_UNORM,
4327 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4328 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4329 };
4330 VkImageView view;
4331 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4332 ASSERT_VK_SUCCESS(err);
4333
4334 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4335 VkFramebuffer fb;
4336 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4337 ASSERT_VK_SUCCESS(err);
4338
4339 // Just use default renderpass with our framebuffer
4340 m_renderPassBeginInfo.framebuffer = fb;
4341 // Create Null cmd buffer for submit
4342 BeginCommandBuffer();
4343 EndCommandBuffer();
4344 // Submit cmd buffer to put it (and attached imageView) in-flight
4345 VkSubmitInfo submit_info = {};
4346 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4347 submit_info.commandBufferCount = 1;
4348 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4349 // Submit cmd buffer to put framebuffer and children in-flight
4350 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4351 // Destroy image attached to framebuffer while in-flight
4352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4353 vkDestroyImage(m_device->device(), image, NULL);
4354 m_errorMonitor->VerifyFound();
4355 // Wait for queue to complete so we can safely destroy image and other objects
4356 vkQueueWaitIdle(m_device->m_queue);
4357 vkDestroyImage(m_device->device(), image, NULL);
4358 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4359 vkDestroyImageView(m_device->device(), view, nullptr);
4360 vkFreeMemory(m_device->device(), image_memory, nullptr);
4361}
4362
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004363TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4364 TEST_DESCRIPTION("Delete in-use renderPass.");
4365
4366 ASSERT_NO_FATAL_FAILURE(InitState());
4367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4368
4369 // Create simple renderpass
4370 VkAttachmentReference attach = {};
4371 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4372 VkSubpassDescription subpass = {};
4373 subpass.pColorAttachments = &attach;
4374 VkRenderPassCreateInfo rpci = {};
4375 rpci.subpassCount = 1;
4376 rpci.pSubpasses = &subpass;
4377 rpci.attachmentCount = 1;
4378 VkAttachmentDescription attach_desc = {};
4379 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4380 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4381 rpci.pAttachments = &attach_desc;
4382 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4383 VkRenderPass rp;
4384 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4385 ASSERT_VK_SUCCESS(err);
4386
4387 // Create a pipeline that uses the given renderpass
4388 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4389 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4390
4391 VkPipelineLayout pipeline_layout;
4392 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4393 ASSERT_VK_SUCCESS(err);
4394
4395 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4396 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4397 vp_state_ci.viewportCount = 1;
4398 VkViewport vp = {}; // Just need dummy vp to point to
4399 vp_state_ci.pViewports = &vp;
4400 vp_state_ci.scissorCount = 1;
4401 VkRect2D scissors = {}; // Dummy scissors to point to
4402 vp_state_ci.pScissors = &scissors;
4403
4404 VkPipelineShaderStageCreateInfo shaderStages[2];
4405 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4406
4407 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4408 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4409 // but add it to be able to run on more devices
4410 shaderStages[0] = vs.GetStageCreateInfo();
4411 shaderStages[1] = fs.GetStageCreateInfo();
4412
4413 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4414 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4415
4416 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4417 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4418 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4419
4420 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4421 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4422 rs_ci.rasterizerDiscardEnable = true;
4423 rs_ci.lineWidth = 1.0f;
4424
4425 VkPipelineColorBlendAttachmentState att = {};
4426 att.blendEnable = VK_FALSE;
4427 att.colorWriteMask = 0xf;
4428
4429 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4430 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4431 cb_ci.attachmentCount = 1;
4432 cb_ci.pAttachments = &att;
4433
4434 VkGraphicsPipelineCreateInfo gp_ci = {};
4435 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4436 gp_ci.stageCount = 2;
4437 gp_ci.pStages = shaderStages;
4438 gp_ci.pVertexInputState = &vi_ci;
4439 gp_ci.pInputAssemblyState = &ia_ci;
4440 gp_ci.pViewportState = &vp_state_ci;
4441 gp_ci.pRasterizationState = &rs_ci;
4442 gp_ci.pColorBlendState = &cb_ci;
4443 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4444 gp_ci.layout = pipeline_layout;
4445 gp_ci.renderPass = rp;
4446
4447 VkPipelineCacheCreateInfo pc_ci = {};
4448 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4449
4450 VkPipeline pipeline;
4451 VkPipelineCache pipe_cache;
4452 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4453 ASSERT_VK_SUCCESS(err);
4454
4455 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4456 ASSERT_VK_SUCCESS(err);
4457 // Bind pipeline to cmd buffer, will also bind renderpass
4458 m_commandBuffer->BeginCommandBuffer();
4459 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4460 m_commandBuffer->EndCommandBuffer();
4461
4462 VkSubmitInfo submit_info = {};
4463 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4464 submit_info.commandBufferCount = 1;
4465 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4466 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4467
4468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4469 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4470 m_errorMonitor->VerifyFound();
4471
4472 // Wait for queue to complete so we can safely destroy everything
4473 vkQueueWaitIdle(m_device->m_queue);
4474 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4475 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4476 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4477 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4478}
4479
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004480TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004481 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004482 ASSERT_NO_FATAL_FAILURE(InitState());
4483
4484 VkImage image;
4485 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4486 VkImageCreateInfo image_create_info = {};
4487 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4488 image_create_info.pNext = NULL;
4489 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4490 image_create_info.format = tex_format;
4491 image_create_info.extent.width = 32;
4492 image_create_info.extent.height = 32;
4493 image_create_info.extent.depth = 1;
4494 image_create_info.mipLevels = 1;
4495 image_create_info.arrayLayers = 1;
4496 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4497 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004498 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004499 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004500 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004501 ASSERT_VK_SUCCESS(err);
4502 // Have to bind memory to image before recording cmd in cmd buffer using it
4503 VkMemoryRequirements mem_reqs;
4504 VkDeviceMemory image_mem;
4505 bool pass;
4506 VkMemoryAllocateInfo mem_alloc = {};
4507 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4508 mem_alloc.pNext = NULL;
4509 mem_alloc.memoryTypeIndex = 0;
4510 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4511 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004512 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004513 ASSERT_TRUE(pass);
4514 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4515 ASSERT_VK_SUCCESS(err);
4516
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004517 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004519 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004520
4521 m_commandBuffer->BeginCommandBuffer();
4522 VkClearColorValue ccv;
4523 ccv.float32[0] = 1.0f;
4524 ccv.float32[1] = 1.0f;
4525 ccv.float32[2] = 1.0f;
4526 ccv.float32[3] = 1.0f;
4527 VkImageSubresourceRange isr = {};
4528 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4529 isr.baseArrayLayer = 0;
4530 isr.baseMipLevel = 0;
4531 isr.layerCount = 1;
4532 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004533 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004534 m_commandBuffer->EndCommandBuffer();
4535
4536 m_errorMonitor->VerifyFound();
4537 vkDestroyImage(m_device->device(), image, NULL);
4538 vkFreeMemory(m_device->device(), image_mem, nullptr);
4539}
4540
4541TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004542 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004543 ASSERT_NO_FATAL_FAILURE(InitState());
4544
4545 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004546 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 -06004547 VK_IMAGE_TILING_OPTIMAL, 0);
4548 ASSERT_TRUE(image.initialized());
4549
4550 VkBuffer buffer;
4551 VkDeviceMemory mem;
4552 VkMemoryRequirements mem_reqs;
4553
4554 VkBufferCreateInfo buf_info = {};
4555 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004556 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004557 buf_info.size = 256;
4558 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4559 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4560 ASSERT_VK_SUCCESS(err);
4561
4562 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4563
4564 VkMemoryAllocateInfo alloc_info = {};
4565 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4566 alloc_info.allocationSize = 256;
4567 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004568 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 -06004569 if (!pass) {
4570 vkDestroyBuffer(m_device->device(), buffer, NULL);
4571 return;
4572 }
4573 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4574 ASSERT_VK_SUCCESS(err);
4575
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004576 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004578 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004579 VkBufferImageCopy region = {};
4580 region.bufferRowLength = 128;
4581 region.bufferImageHeight = 128;
4582 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4583
4584 region.imageSubresource.layerCount = 1;
4585 region.imageExtent.height = 4;
4586 region.imageExtent.width = 4;
4587 region.imageExtent.depth = 1;
4588 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004589 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4590 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004591 m_commandBuffer->EndCommandBuffer();
4592
4593 m_errorMonitor->VerifyFound();
4594
4595 vkDestroyBuffer(m_device->device(), buffer, NULL);
4596 vkFreeMemory(m_device->handle(), mem, NULL);
4597}
4598
Tobin Ehlis85940f52016-07-07 16:57:21 -06004599TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4600 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4601 "due to an event dependency being destroyed.");
4602 ASSERT_NO_FATAL_FAILURE(InitState());
4603
4604 VkEvent event;
4605 VkEventCreateInfo evci = {};
4606 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4607 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4608 ASSERT_VK_SUCCESS(result);
4609
4610 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004611 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004612 m_commandBuffer->EndCommandBuffer();
4613
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004615 // Destroy event dependency prior to submit to cause ERROR
4616 vkDestroyEvent(m_device->device(), event, NULL);
4617
4618 VkSubmitInfo submit_info = {};
4619 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4620 submit_info.commandBufferCount = 1;
4621 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4622 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4623
4624 m_errorMonitor->VerifyFound();
4625}
4626
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004627TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4628 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4629 "due to a query pool dependency being destroyed.");
4630 ASSERT_NO_FATAL_FAILURE(InitState());
4631
4632 VkQueryPool query_pool;
4633 VkQueryPoolCreateInfo qpci{};
4634 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4635 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4636 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004637 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004638 ASSERT_VK_SUCCESS(result);
4639
4640 m_commandBuffer->BeginCommandBuffer();
4641 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4642 m_commandBuffer->EndCommandBuffer();
4643
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004645 // Destroy query pool dependency prior to submit to cause ERROR
4646 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4647
4648 VkSubmitInfo submit_info = {};
4649 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4650 submit_info.commandBufferCount = 1;
4651 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4652 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4653
4654 m_errorMonitor->VerifyFound();
4655}
4656
Tobin Ehlis24130d92016-07-08 15:50:53 -06004657TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4658 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4659 "due to a pipeline dependency being destroyed.");
4660 ASSERT_NO_FATAL_FAILURE(InitState());
4661 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4662
4663 VkResult err;
4664
4665 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4666 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4667
4668 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004669 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004670 ASSERT_VK_SUCCESS(err);
4671
4672 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4673 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4674 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004675 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004676 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004677 vp_state_ci.scissorCount = 1;
4678 VkRect2D scissors = {}; // Dummy scissors to point to
4679 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004680
4681 VkPipelineShaderStageCreateInfo shaderStages[2];
4682 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4683
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004684 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4685 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4686 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004687 shaderStages[0] = vs.GetStageCreateInfo();
4688 shaderStages[1] = fs.GetStageCreateInfo();
4689
4690 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4691 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4692
4693 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4694 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4695 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4696
4697 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4698 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004699 rs_ci.rasterizerDiscardEnable = true;
4700 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004701
4702 VkPipelineColorBlendAttachmentState att = {};
4703 att.blendEnable = VK_FALSE;
4704 att.colorWriteMask = 0xf;
4705
4706 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4707 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4708 cb_ci.attachmentCount = 1;
4709 cb_ci.pAttachments = &att;
4710
4711 VkGraphicsPipelineCreateInfo gp_ci = {};
4712 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4713 gp_ci.stageCount = 2;
4714 gp_ci.pStages = shaderStages;
4715 gp_ci.pVertexInputState = &vi_ci;
4716 gp_ci.pInputAssemblyState = &ia_ci;
4717 gp_ci.pViewportState = &vp_state_ci;
4718 gp_ci.pRasterizationState = &rs_ci;
4719 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004720 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4721 gp_ci.layout = pipeline_layout;
4722 gp_ci.renderPass = renderPass();
4723
4724 VkPipelineCacheCreateInfo pc_ci = {};
4725 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4726
4727 VkPipeline pipeline;
4728 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004729 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004730 ASSERT_VK_SUCCESS(err);
4731
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004732 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004733 ASSERT_VK_SUCCESS(err);
4734
4735 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004736 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004737 m_commandBuffer->EndCommandBuffer();
4738 // Now destroy pipeline in order to cause error when submitting
4739 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004742
4743 VkSubmitInfo submit_info = {};
4744 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4745 submit_info.commandBufferCount = 1;
4746 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4747 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4748
4749 m_errorMonitor->VerifyFound();
4750 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4751 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4752}
4753
Tobin Ehlis31289162016-08-17 14:57:58 -06004754TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4755 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4756 "due to a bound descriptor set with a buffer dependency "
4757 "being destroyed.");
4758 ASSERT_NO_FATAL_FAILURE(InitState());
4759 ASSERT_NO_FATAL_FAILURE(InitViewport());
4760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4761
4762 VkDescriptorPoolSize ds_type_count = {};
4763 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4764 ds_type_count.descriptorCount = 1;
4765
4766 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4767 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4768 ds_pool_ci.pNext = NULL;
4769 ds_pool_ci.maxSets = 1;
4770 ds_pool_ci.poolSizeCount = 1;
4771 ds_pool_ci.pPoolSizes = &ds_type_count;
4772
4773 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004774 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004775 ASSERT_VK_SUCCESS(err);
4776
4777 VkDescriptorSetLayoutBinding dsl_binding = {};
4778 dsl_binding.binding = 0;
4779 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4780 dsl_binding.descriptorCount = 1;
4781 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4782 dsl_binding.pImmutableSamplers = NULL;
4783
4784 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4785 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4786 ds_layout_ci.pNext = NULL;
4787 ds_layout_ci.bindingCount = 1;
4788 ds_layout_ci.pBindings = &dsl_binding;
4789 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004790 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004791 ASSERT_VK_SUCCESS(err);
4792
4793 VkDescriptorSet descriptorSet;
4794 VkDescriptorSetAllocateInfo alloc_info = {};
4795 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4796 alloc_info.descriptorSetCount = 1;
4797 alloc_info.descriptorPool = ds_pool;
4798 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004799 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004800 ASSERT_VK_SUCCESS(err);
4801
4802 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4803 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4804 pipeline_layout_ci.pNext = NULL;
4805 pipeline_layout_ci.setLayoutCount = 1;
4806 pipeline_layout_ci.pSetLayouts = &ds_layout;
4807
4808 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004809 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004810 ASSERT_VK_SUCCESS(err);
4811
4812 // Create a buffer to update the descriptor with
4813 uint32_t qfi = 0;
4814 VkBufferCreateInfo buffCI = {};
4815 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4816 buffCI.size = 1024;
4817 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4818 buffCI.queueFamilyIndexCount = 1;
4819 buffCI.pQueueFamilyIndices = &qfi;
4820
4821 VkBuffer buffer;
4822 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4823 ASSERT_VK_SUCCESS(err);
4824 // Allocate memory and bind to buffer so we can make it to the appropriate
4825 // error
4826 VkMemoryAllocateInfo mem_alloc = {};
4827 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4828 mem_alloc.pNext = NULL;
4829 mem_alloc.allocationSize = 1024;
4830 mem_alloc.memoryTypeIndex = 0;
4831
4832 VkMemoryRequirements memReqs;
4833 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004834 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004835 if (!pass) {
4836 vkDestroyBuffer(m_device->device(), buffer, NULL);
4837 return;
4838 }
4839
4840 VkDeviceMemory mem;
4841 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4842 ASSERT_VK_SUCCESS(err);
4843 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4844 ASSERT_VK_SUCCESS(err);
4845 // Correctly update descriptor to avoid "NOT_UPDATED" error
4846 VkDescriptorBufferInfo buffInfo = {};
4847 buffInfo.buffer = buffer;
4848 buffInfo.offset = 0;
4849 buffInfo.range = 1024;
4850
4851 VkWriteDescriptorSet descriptor_write;
4852 memset(&descriptor_write, 0, sizeof(descriptor_write));
4853 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4854 descriptor_write.dstSet = descriptorSet;
4855 descriptor_write.dstBinding = 0;
4856 descriptor_write.descriptorCount = 1;
4857 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4858 descriptor_write.pBufferInfo = &buffInfo;
4859
4860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4861
4862 // Create PSO to be used for draw-time errors below
4863 char const *vsSource = "#version 450\n"
4864 "\n"
4865 "out gl_PerVertex { \n"
4866 " vec4 gl_Position;\n"
4867 "};\n"
4868 "void main(){\n"
4869 " gl_Position = vec4(1);\n"
4870 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004871 char const *fsSource = "#version 450\n"
4872 "\n"
4873 "layout(location=0) out vec4 x;\n"
4874 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4875 "void main(){\n"
4876 " x = vec4(bar.y);\n"
4877 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004878 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4879 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4880 VkPipelineObj pipe(m_device);
4881 pipe.AddShader(&vs);
4882 pipe.AddShader(&fs);
4883 pipe.AddColorAttachment();
4884 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4885
4886 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4888 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4889 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06004890 Draw(1, 0, 0, 0);
4891 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06004893 // Destroy buffer should invalidate the cmd buffer, causing error on submit
4894 vkDestroyBuffer(m_device->device(), buffer, NULL);
4895 // Attempt to submit cmd buffer
4896 VkSubmitInfo submit_info = {};
4897 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4898 submit_info.commandBufferCount = 1;
4899 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4900 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4901 m_errorMonitor->VerifyFound();
4902 // Cleanup
4903 vkFreeMemory(m_device->device(), mem, NULL);
4904
4905 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4907 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4908}
4909
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004910TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
4911 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4912 "due to a bound descriptor sets with a combined image "
4913 "sampler having their image, sampler, and descriptor set "
4914 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06004915 "submit associated cmd buffers. Attempt to destroy a "
4916 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004917 ASSERT_NO_FATAL_FAILURE(InitState());
4918 ASSERT_NO_FATAL_FAILURE(InitViewport());
4919 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4920
4921 VkDescriptorPoolSize ds_type_count = {};
4922 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4923 ds_type_count.descriptorCount = 1;
4924
4925 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4926 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4927 ds_pool_ci.pNext = NULL;
4928 ds_pool_ci.maxSets = 1;
4929 ds_pool_ci.poolSizeCount = 1;
4930 ds_pool_ci.pPoolSizes = &ds_type_count;
4931
4932 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004933 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004934 ASSERT_VK_SUCCESS(err);
4935
4936 VkDescriptorSetLayoutBinding dsl_binding = {};
4937 dsl_binding.binding = 0;
4938 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
4939 dsl_binding.descriptorCount = 1;
4940 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4941 dsl_binding.pImmutableSamplers = NULL;
4942
4943 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4944 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4945 ds_layout_ci.pNext = NULL;
4946 ds_layout_ci.bindingCount = 1;
4947 ds_layout_ci.pBindings = &dsl_binding;
4948 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004950 ASSERT_VK_SUCCESS(err);
4951
4952 VkDescriptorSet descriptorSet;
4953 VkDescriptorSetAllocateInfo alloc_info = {};
4954 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4955 alloc_info.descriptorSetCount = 1;
4956 alloc_info.descriptorPool = ds_pool;
4957 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004958 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004959 ASSERT_VK_SUCCESS(err);
4960
4961 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4962 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4963 pipeline_layout_ci.pNext = NULL;
4964 pipeline_layout_ci.setLayoutCount = 1;
4965 pipeline_layout_ci.pSetLayouts = &ds_layout;
4966
4967 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004968 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06004969 ASSERT_VK_SUCCESS(err);
4970
4971 // Create images to update the descriptor with
4972 VkImage image;
4973 VkImage image2;
4974 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4975 const int32_t tex_width = 32;
4976 const int32_t tex_height = 32;
4977 VkImageCreateInfo image_create_info = {};
4978 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4979 image_create_info.pNext = NULL;
4980 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4981 image_create_info.format = tex_format;
4982 image_create_info.extent.width = tex_width;
4983 image_create_info.extent.height = tex_height;
4984 image_create_info.extent.depth = 1;
4985 image_create_info.mipLevels = 1;
4986 image_create_info.arrayLayers = 1;
4987 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4988 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
4989 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
4990 image_create_info.flags = 0;
4991 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
4992 ASSERT_VK_SUCCESS(err);
4993 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
4994 ASSERT_VK_SUCCESS(err);
4995
4996 VkMemoryRequirements memory_reqs;
4997 VkDeviceMemory image_memory;
4998 bool pass;
4999 VkMemoryAllocateInfo memory_info = {};
5000 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5001 memory_info.pNext = NULL;
5002 memory_info.allocationSize = 0;
5003 memory_info.memoryTypeIndex = 0;
5004 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5005 // Allocate enough memory for both images
5006 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005007 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005008 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005009 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005010 ASSERT_VK_SUCCESS(err);
5011 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5012 ASSERT_VK_SUCCESS(err);
5013 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005014 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005015 ASSERT_VK_SUCCESS(err);
5016
5017 VkImageViewCreateInfo image_view_create_info = {};
5018 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5019 image_view_create_info.image = image;
5020 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5021 image_view_create_info.format = tex_format;
5022 image_view_create_info.subresourceRange.layerCount = 1;
5023 image_view_create_info.subresourceRange.baseMipLevel = 0;
5024 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005025 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005026
5027 VkImageView view;
5028 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005029 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005030 ASSERT_VK_SUCCESS(err);
5031 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005032 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005033 ASSERT_VK_SUCCESS(err);
5034 // Create Samplers
5035 VkSamplerCreateInfo sampler_ci = {};
5036 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5037 sampler_ci.pNext = NULL;
5038 sampler_ci.magFilter = VK_FILTER_NEAREST;
5039 sampler_ci.minFilter = VK_FILTER_NEAREST;
5040 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5041 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5042 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5043 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5044 sampler_ci.mipLodBias = 1.0;
5045 sampler_ci.anisotropyEnable = VK_FALSE;
5046 sampler_ci.maxAnisotropy = 1;
5047 sampler_ci.compareEnable = VK_FALSE;
5048 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5049 sampler_ci.minLod = 1.0;
5050 sampler_ci.maxLod = 1.0;
5051 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5052 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5053 VkSampler sampler;
5054 VkSampler sampler2;
5055 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5056 ASSERT_VK_SUCCESS(err);
5057 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5058 ASSERT_VK_SUCCESS(err);
5059 // Update descriptor with image and sampler
5060 VkDescriptorImageInfo img_info = {};
5061 img_info.sampler = sampler;
5062 img_info.imageView = view;
5063 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5064
5065 VkWriteDescriptorSet descriptor_write;
5066 memset(&descriptor_write, 0, sizeof(descriptor_write));
5067 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5068 descriptor_write.dstSet = descriptorSet;
5069 descriptor_write.dstBinding = 0;
5070 descriptor_write.descriptorCount = 1;
5071 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5072 descriptor_write.pImageInfo = &img_info;
5073
5074 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5075
5076 // Create PSO to be used for draw-time errors below
5077 char const *vsSource = "#version 450\n"
5078 "\n"
5079 "out gl_PerVertex { \n"
5080 " vec4 gl_Position;\n"
5081 "};\n"
5082 "void main(){\n"
5083 " gl_Position = vec4(1);\n"
5084 "}\n";
5085 char const *fsSource = "#version 450\n"
5086 "\n"
5087 "layout(set=0, binding=0) uniform sampler2D s;\n"
5088 "layout(location=0) out vec4 x;\n"
5089 "void main(){\n"
5090 " x = texture(s, vec2(1));\n"
5091 "}\n";
5092 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5093 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5094 VkPipelineObj pipe(m_device);
5095 pipe.AddShader(&vs);
5096 pipe.AddShader(&fs);
5097 pipe.AddColorAttachment();
5098 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5099
5100 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005102 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005103 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5104 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5105 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005106 Draw(1, 0, 0, 0);
5107 EndCommandBuffer();
5108 // Destroy sampler invalidates the cmd buffer, causing error on submit
5109 vkDestroySampler(m_device->device(), sampler, NULL);
5110 // Attempt to submit cmd buffer
5111 VkSubmitInfo submit_info = {};
5112 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5113 submit_info.commandBufferCount = 1;
5114 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5115 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5116 m_errorMonitor->VerifyFound();
5117 // Now re-update descriptor with valid sampler and delete image
5118 img_info.sampler = sampler2;
5119 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005121 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005122 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5123 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5124 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005125 Draw(1, 0, 0, 0);
5126 EndCommandBuffer();
5127 // Destroy image invalidates the cmd buffer, causing error on submit
5128 vkDestroyImage(m_device->device(), image, NULL);
5129 // Attempt to submit cmd buffer
5130 submit_info = {};
5131 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5132 submit_info.commandBufferCount = 1;
5133 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5134 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5135 m_errorMonitor->VerifyFound();
5136 // Now update descriptor to be valid, but then free descriptor
5137 img_info.imageView = view2;
5138 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005140 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005141 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5142 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5143 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005144 Draw(1, 0, 0, 0);
5145 EndCommandBuffer();
5146 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005148 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005149 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005150 // Attempt to submit cmd buffer
5151 submit_info = {};
5152 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5153 submit_info.commandBufferCount = 1;
5154 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5155 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5156 m_errorMonitor->VerifyFound();
5157 // Cleanup
5158 vkFreeMemory(m_device->device(), image_memory, NULL);
5159 vkDestroySampler(m_device->device(), sampler2, NULL);
5160 vkDestroyImage(m_device->device(), image2, NULL);
5161 vkDestroyImageView(m_device->device(), view, NULL);
5162 vkDestroyImageView(m_device->device(), view2, NULL);
5163 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5164 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5165 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5166}
5167
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005168TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5169 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5170 ASSERT_NO_FATAL_FAILURE(InitState());
5171 ASSERT_NO_FATAL_FAILURE(InitViewport());
5172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5173
5174 VkDescriptorPoolSize ds_type_count = {};
5175 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5176 ds_type_count.descriptorCount = 1;
5177
5178 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5179 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5180 ds_pool_ci.pNext = NULL;
5181 ds_pool_ci.maxSets = 1;
5182 ds_pool_ci.poolSizeCount = 1;
5183 ds_pool_ci.pPoolSizes = &ds_type_count;
5184
5185 VkDescriptorPool ds_pool;
5186 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5187 ASSERT_VK_SUCCESS(err);
5188
5189 VkDescriptorSetLayoutBinding dsl_binding = {};
5190 dsl_binding.binding = 0;
5191 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5192 dsl_binding.descriptorCount = 1;
5193 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5194 dsl_binding.pImmutableSamplers = NULL;
5195
5196 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5197 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5198 ds_layout_ci.pNext = NULL;
5199 ds_layout_ci.bindingCount = 1;
5200 ds_layout_ci.pBindings = &dsl_binding;
5201 VkDescriptorSetLayout ds_layout;
5202 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5203 ASSERT_VK_SUCCESS(err);
5204
5205 VkDescriptorSet descriptor_set;
5206 VkDescriptorSetAllocateInfo alloc_info = {};
5207 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5208 alloc_info.descriptorSetCount = 1;
5209 alloc_info.descriptorPool = ds_pool;
5210 alloc_info.pSetLayouts = &ds_layout;
5211 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5212 ASSERT_VK_SUCCESS(err);
5213
5214 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5215 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5216 pipeline_layout_ci.pNext = NULL;
5217 pipeline_layout_ci.setLayoutCount = 1;
5218 pipeline_layout_ci.pSetLayouts = &ds_layout;
5219
5220 VkPipelineLayout pipeline_layout;
5221 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5222 ASSERT_VK_SUCCESS(err);
5223
5224 // Create image to update the descriptor with
5225 VkImageObj image(m_device);
5226 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5227 ASSERT_TRUE(image.initialized());
5228
5229 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5230 // Create Sampler
5231 VkSamplerCreateInfo sampler_ci = {};
5232 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5233 sampler_ci.pNext = NULL;
5234 sampler_ci.magFilter = VK_FILTER_NEAREST;
5235 sampler_ci.minFilter = VK_FILTER_NEAREST;
5236 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5237 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5238 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5239 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5240 sampler_ci.mipLodBias = 1.0;
5241 sampler_ci.anisotropyEnable = VK_FALSE;
5242 sampler_ci.maxAnisotropy = 1;
5243 sampler_ci.compareEnable = VK_FALSE;
5244 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5245 sampler_ci.minLod = 1.0;
5246 sampler_ci.maxLod = 1.0;
5247 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5248 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5249 VkSampler sampler;
5250 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5251 ASSERT_VK_SUCCESS(err);
5252 // Update descriptor with image and sampler
5253 VkDescriptorImageInfo img_info = {};
5254 img_info.sampler = sampler;
5255 img_info.imageView = view;
5256 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5257
5258 VkWriteDescriptorSet descriptor_write;
5259 memset(&descriptor_write, 0, sizeof(descriptor_write));
5260 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5261 descriptor_write.dstSet = descriptor_set;
5262 descriptor_write.dstBinding = 0;
5263 descriptor_write.descriptorCount = 1;
5264 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5265 descriptor_write.pImageInfo = &img_info;
5266
5267 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5268
5269 // Create PSO to be used for draw-time errors below
5270 char const *vsSource = "#version 450\n"
5271 "\n"
5272 "out gl_PerVertex { \n"
5273 " vec4 gl_Position;\n"
5274 "};\n"
5275 "void main(){\n"
5276 " gl_Position = vec4(1);\n"
5277 "}\n";
5278 char const *fsSource = "#version 450\n"
5279 "\n"
5280 "layout(set=0, binding=0) uniform sampler2D s;\n"
5281 "layout(location=0) out vec4 x;\n"
5282 "void main(){\n"
5283 " x = texture(s, vec2(1));\n"
5284 "}\n";
5285 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5286 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5287 VkPipelineObj pipe(m_device);
5288 pipe.AddShader(&vs);
5289 pipe.AddShader(&fs);
5290 pipe.AddColorAttachment();
5291 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5292
5293 BeginCommandBuffer();
5294 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5295 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5296 &descriptor_set, 0, NULL);
5297 Draw(1, 0, 0, 0);
5298 EndCommandBuffer();
5299 // Submit cmd buffer to put pool in-flight
5300 VkSubmitInfo submit_info = {};
5301 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5302 submit_info.commandBufferCount = 1;
5303 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5304 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5305 // Destroy pool while in-flight, causing error
5306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5307 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5308 m_errorMonitor->VerifyFound();
5309 vkQueueWaitIdle(m_device->m_queue);
5310 // Cleanup
5311 vkDestroySampler(m_device->device(), sampler, NULL);
5312 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5313 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5314 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5315}
5316
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005317TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5318 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5319 ASSERT_NO_FATAL_FAILURE(InitState());
5320 ASSERT_NO_FATAL_FAILURE(InitViewport());
5321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5322
5323 VkDescriptorPoolSize ds_type_count = {};
5324 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5325 ds_type_count.descriptorCount = 1;
5326
5327 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5328 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5329 ds_pool_ci.pNext = NULL;
5330 ds_pool_ci.maxSets = 1;
5331 ds_pool_ci.poolSizeCount = 1;
5332 ds_pool_ci.pPoolSizes = &ds_type_count;
5333
5334 VkDescriptorPool ds_pool;
5335 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5336 ASSERT_VK_SUCCESS(err);
5337
5338 VkDescriptorSetLayoutBinding dsl_binding = {};
5339 dsl_binding.binding = 0;
5340 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5341 dsl_binding.descriptorCount = 1;
5342 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5343 dsl_binding.pImmutableSamplers = NULL;
5344
5345 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5346 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5347 ds_layout_ci.pNext = NULL;
5348 ds_layout_ci.bindingCount = 1;
5349 ds_layout_ci.pBindings = &dsl_binding;
5350 VkDescriptorSetLayout ds_layout;
5351 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5352 ASSERT_VK_SUCCESS(err);
5353
5354 VkDescriptorSet descriptorSet;
5355 VkDescriptorSetAllocateInfo alloc_info = {};
5356 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5357 alloc_info.descriptorSetCount = 1;
5358 alloc_info.descriptorPool = ds_pool;
5359 alloc_info.pSetLayouts = &ds_layout;
5360 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5361 ASSERT_VK_SUCCESS(err);
5362
5363 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5364 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5365 pipeline_layout_ci.pNext = NULL;
5366 pipeline_layout_ci.setLayoutCount = 1;
5367 pipeline_layout_ci.pSetLayouts = &ds_layout;
5368
5369 VkPipelineLayout pipeline_layout;
5370 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5371 ASSERT_VK_SUCCESS(err);
5372
5373 // Create images to update the descriptor with
5374 VkImage image;
5375 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5376 const int32_t tex_width = 32;
5377 const int32_t tex_height = 32;
5378 VkImageCreateInfo image_create_info = {};
5379 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5380 image_create_info.pNext = NULL;
5381 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5382 image_create_info.format = tex_format;
5383 image_create_info.extent.width = tex_width;
5384 image_create_info.extent.height = tex_height;
5385 image_create_info.extent.depth = 1;
5386 image_create_info.mipLevels = 1;
5387 image_create_info.arrayLayers = 1;
5388 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5389 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5390 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5391 image_create_info.flags = 0;
5392 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5393 ASSERT_VK_SUCCESS(err);
5394 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5395 VkMemoryRequirements memory_reqs;
5396 VkDeviceMemory image_memory;
5397 bool pass;
5398 VkMemoryAllocateInfo memory_info = {};
5399 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5400 memory_info.pNext = NULL;
5401 memory_info.allocationSize = 0;
5402 memory_info.memoryTypeIndex = 0;
5403 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5404 // Allocate enough memory for image
5405 memory_info.allocationSize = memory_reqs.size;
5406 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5407 ASSERT_TRUE(pass);
5408 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5409 ASSERT_VK_SUCCESS(err);
5410 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5411 ASSERT_VK_SUCCESS(err);
5412
5413 VkImageViewCreateInfo image_view_create_info = {};
5414 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5415 image_view_create_info.image = image;
5416 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5417 image_view_create_info.format = tex_format;
5418 image_view_create_info.subresourceRange.layerCount = 1;
5419 image_view_create_info.subresourceRange.baseMipLevel = 0;
5420 image_view_create_info.subresourceRange.levelCount = 1;
5421 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5422
5423 VkImageView view;
5424 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5425 ASSERT_VK_SUCCESS(err);
5426 // Create Samplers
5427 VkSamplerCreateInfo sampler_ci = {};
5428 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5429 sampler_ci.pNext = NULL;
5430 sampler_ci.magFilter = VK_FILTER_NEAREST;
5431 sampler_ci.minFilter = VK_FILTER_NEAREST;
5432 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5433 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5434 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5435 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5436 sampler_ci.mipLodBias = 1.0;
5437 sampler_ci.anisotropyEnable = VK_FALSE;
5438 sampler_ci.maxAnisotropy = 1;
5439 sampler_ci.compareEnable = VK_FALSE;
5440 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5441 sampler_ci.minLod = 1.0;
5442 sampler_ci.maxLod = 1.0;
5443 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5444 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5445 VkSampler sampler;
5446 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5447 ASSERT_VK_SUCCESS(err);
5448 // Update descriptor with image and sampler
5449 VkDescriptorImageInfo img_info = {};
5450 img_info.sampler = sampler;
5451 img_info.imageView = view;
5452 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5453
5454 VkWriteDescriptorSet descriptor_write;
5455 memset(&descriptor_write, 0, sizeof(descriptor_write));
5456 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5457 descriptor_write.dstSet = descriptorSet;
5458 descriptor_write.dstBinding = 0;
5459 descriptor_write.descriptorCount = 1;
5460 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5461 descriptor_write.pImageInfo = &img_info;
5462 // Break memory binding and attempt update
5463 vkFreeMemory(m_device->device(), image_memory, nullptr);
5464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005465 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5467 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5468 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5469 m_errorMonitor->VerifyFound();
5470 // Cleanup
5471 vkDestroyImage(m_device->device(), image, NULL);
5472 vkDestroySampler(m_device->device(), sampler, NULL);
5473 vkDestroyImageView(m_device->device(), view, NULL);
5474 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5475 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5476 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5477}
5478
Karl Schultz6addd812016-02-02 17:17:23 -07005479TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005480 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5481 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005482 // Create a valid cmd buffer
5483 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005484 uint64_t fake_pipeline_handle = 0xbaad6001;
5485 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005486 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5488
5489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005490 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005491 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005492 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005493
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005494 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005496 Draw(1, 0, 0, 0);
5497 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005498
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005499 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005500 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 +12005501 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005502 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5503 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005504}
5505
Karl Schultz6addd812016-02-02 17:17:23 -07005506TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005507 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005508 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005511
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005512 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005513 ASSERT_NO_FATAL_FAILURE(InitViewport());
5514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005515 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005516 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5517 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005518
5519 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005520 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5521 ds_pool_ci.pNext = NULL;
5522 ds_pool_ci.maxSets = 1;
5523 ds_pool_ci.poolSizeCount = 1;
5524 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005525
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005526 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005527 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005528 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005529
Tony Barboureb254902015-07-15 12:50:33 -06005530 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005531 dsl_binding.binding = 0;
5532 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5533 dsl_binding.descriptorCount = 1;
5534 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5535 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005536
Tony Barboureb254902015-07-15 12:50:33 -06005537 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005538 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5539 ds_layout_ci.pNext = NULL;
5540 ds_layout_ci.bindingCount = 1;
5541 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005542 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005543 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005544 ASSERT_VK_SUCCESS(err);
5545
5546 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005547 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005548 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005549 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005550 alloc_info.descriptorPool = ds_pool;
5551 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005552 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005553 ASSERT_VK_SUCCESS(err);
5554
Tony Barboureb254902015-07-15 12:50:33 -06005555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5557 pipeline_layout_ci.pNext = NULL;
5558 pipeline_layout_ci.setLayoutCount = 1;
5559 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005560
5561 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005563 ASSERT_VK_SUCCESS(err);
5564
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005565 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005566 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005567 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005568 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005569
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005570 VkPipelineObj pipe(m_device);
5571 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005572 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005573 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005574 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005575
5576 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005577 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5578 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5579 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005580
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005581 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005582
Chia-I Wuf7458c52015-10-26 21:10:41 +08005583 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5584 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5585 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005586}
5587
Karl Schultz6addd812016-02-02 17:17:23 -07005588TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005589 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005590 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005591
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5593 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005594
5595 ASSERT_NO_FATAL_FAILURE(InitState());
5596 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005597 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5598 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005599
5600 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005601 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5602 ds_pool_ci.pNext = NULL;
5603 ds_pool_ci.maxSets = 1;
5604 ds_pool_ci.poolSizeCount = 1;
5605 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005606
5607 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005608 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005609 ASSERT_VK_SUCCESS(err);
5610
5611 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005612 dsl_binding.binding = 0;
5613 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5614 dsl_binding.descriptorCount = 1;
5615 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5616 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005617
5618 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005619 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5620 ds_layout_ci.pNext = NULL;
5621 ds_layout_ci.bindingCount = 1;
5622 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005623 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005624 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005625 ASSERT_VK_SUCCESS(err);
5626
5627 VkDescriptorSet descriptorSet;
5628 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005629 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005630 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005631 alloc_info.descriptorPool = ds_pool;
5632 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005633 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005634 ASSERT_VK_SUCCESS(err);
5635
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005636 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005637 VkWriteDescriptorSet descriptor_write;
5638 memset(&descriptor_write, 0, sizeof(descriptor_write));
5639 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5640 descriptor_write.dstSet = descriptorSet;
5641 descriptor_write.dstBinding = 0;
5642 descriptor_write.descriptorCount = 1;
5643 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5644 descriptor_write.pTexelBufferView = &view;
5645
5646 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5647
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005648 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005649
5650 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5651 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5652}
5653
Mark Youngd339ba32016-05-30 13:28:35 -06005654TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005655 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 -06005656
5657 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005659 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005660
5661 ASSERT_NO_FATAL_FAILURE(InitState());
5662
5663 // Create a buffer with no bound memory and then attempt to create
5664 // a buffer view.
5665 VkBufferCreateInfo buff_ci = {};
5666 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005667 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005668 buff_ci.size = 256;
5669 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5670 VkBuffer buffer;
5671 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5672 ASSERT_VK_SUCCESS(err);
5673
5674 VkBufferViewCreateInfo buff_view_ci = {};
5675 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5676 buff_view_ci.buffer = buffer;
5677 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5678 buff_view_ci.range = VK_WHOLE_SIZE;
5679 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005680 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005681
5682 m_errorMonitor->VerifyFound();
5683 vkDestroyBuffer(m_device->device(), buffer, NULL);
5684 // If last error is success, it still created the view, so delete it.
5685 if (err == VK_SUCCESS) {
5686 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5687 }
5688}
5689
Karl Schultz6addd812016-02-02 17:17:23 -07005690TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5691 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5692 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005693 // 1. No dynamicOffset supplied
5694 // 2. Too many dynamicOffsets supplied
5695 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005696 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5698 "0 dynamicOffsets are left in "
5699 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005700
5701 ASSERT_NO_FATAL_FAILURE(InitState());
5702 ASSERT_NO_FATAL_FAILURE(InitViewport());
5703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5704
5705 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005706 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5707 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005708
5709 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005710 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5711 ds_pool_ci.pNext = NULL;
5712 ds_pool_ci.maxSets = 1;
5713 ds_pool_ci.poolSizeCount = 1;
5714 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005715
5716 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005717 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005718 ASSERT_VK_SUCCESS(err);
5719
5720 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005721 dsl_binding.binding = 0;
5722 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5723 dsl_binding.descriptorCount = 1;
5724 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5725 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005726
5727 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005728 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5729 ds_layout_ci.pNext = NULL;
5730 ds_layout_ci.bindingCount = 1;
5731 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005732 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005733 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005734 ASSERT_VK_SUCCESS(err);
5735
5736 VkDescriptorSet descriptorSet;
5737 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005738 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005739 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005740 alloc_info.descriptorPool = ds_pool;
5741 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005742 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005743 ASSERT_VK_SUCCESS(err);
5744
5745 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005746 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5747 pipeline_layout_ci.pNext = NULL;
5748 pipeline_layout_ci.setLayoutCount = 1;
5749 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005750
5751 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005752 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005753 ASSERT_VK_SUCCESS(err);
5754
5755 // Create a buffer to update the descriptor with
5756 uint32_t qfi = 0;
5757 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005758 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5759 buffCI.size = 1024;
5760 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5761 buffCI.queueFamilyIndexCount = 1;
5762 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005763
5764 VkBuffer dyub;
5765 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5766 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005767 // Allocate memory and bind to buffer so we can make it to the appropriate
5768 // error
5769 VkMemoryAllocateInfo mem_alloc = {};
5770 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5771 mem_alloc.pNext = NULL;
5772 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005773 mem_alloc.memoryTypeIndex = 0;
5774
5775 VkMemoryRequirements memReqs;
5776 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005777 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005778 if (!pass) {
5779 vkDestroyBuffer(m_device->device(), dyub, NULL);
5780 return;
5781 }
5782
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005783 VkDeviceMemory mem;
5784 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5785 ASSERT_VK_SUCCESS(err);
5786 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5787 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005788 // Correctly update descriptor to avoid "NOT_UPDATED" error
5789 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005790 buffInfo.buffer = dyub;
5791 buffInfo.offset = 0;
5792 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005793
5794 VkWriteDescriptorSet descriptor_write;
5795 memset(&descriptor_write, 0, sizeof(descriptor_write));
5796 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5797 descriptor_write.dstSet = descriptorSet;
5798 descriptor_write.dstBinding = 0;
5799 descriptor_write.descriptorCount = 1;
5800 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5801 descriptor_write.pBufferInfo = &buffInfo;
5802
5803 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5804
5805 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005806 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5807 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005808 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005809 uint32_t pDynOff[2] = {512, 756};
5810 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5812 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5813 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5814 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005815 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005816 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5818 "offset 0 and range 1024 that "
5819 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005820 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005821 char const *vsSource = "#version 450\n"
5822 "\n"
5823 "out gl_PerVertex { \n"
5824 " vec4 gl_Position;\n"
5825 "};\n"
5826 "void main(){\n"
5827 " gl_Position = vec4(1);\n"
5828 "}\n";
5829 char const *fsSource = "#version 450\n"
5830 "\n"
5831 "layout(location=0) out vec4 x;\n"
5832 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5833 "void main(){\n"
5834 " x = vec4(bar.y);\n"
5835 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005836 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5837 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5838 VkPipelineObj pipe(m_device);
5839 pipe.AddShader(&vs);
5840 pipe.AddShader(&fs);
5841 pipe.AddColorAttachment();
5842 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5843
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005844 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005845 // This update should succeed, but offset size of 512 will overstep buffer
5846 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005847 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5848 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005849 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005850 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005851
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005852 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005853 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005854
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005855 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005856 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005857 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5858}
5859
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005860TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5861 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5862 "that doesn't have memory bound");
5863 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005865 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5867 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005868
5869 ASSERT_NO_FATAL_FAILURE(InitState());
5870 ASSERT_NO_FATAL_FAILURE(InitViewport());
5871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5872
5873 VkDescriptorPoolSize ds_type_count = {};
5874 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5875 ds_type_count.descriptorCount = 1;
5876
5877 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5878 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5879 ds_pool_ci.pNext = NULL;
5880 ds_pool_ci.maxSets = 1;
5881 ds_pool_ci.poolSizeCount = 1;
5882 ds_pool_ci.pPoolSizes = &ds_type_count;
5883
5884 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005885 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005886 ASSERT_VK_SUCCESS(err);
5887
5888 VkDescriptorSetLayoutBinding dsl_binding = {};
5889 dsl_binding.binding = 0;
5890 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5891 dsl_binding.descriptorCount = 1;
5892 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5893 dsl_binding.pImmutableSamplers = NULL;
5894
5895 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5896 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5897 ds_layout_ci.pNext = NULL;
5898 ds_layout_ci.bindingCount = 1;
5899 ds_layout_ci.pBindings = &dsl_binding;
5900 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005901 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005902 ASSERT_VK_SUCCESS(err);
5903
5904 VkDescriptorSet descriptorSet;
5905 VkDescriptorSetAllocateInfo alloc_info = {};
5906 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5907 alloc_info.descriptorSetCount = 1;
5908 alloc_info.descriptorPool = ds_pool;
5909 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005910 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005911 ASSERT_VK_SUCCESS(err);
5912
5913 // Create a buffer to update the descriptor with
5914 uint32_t qfi = 0;
5915 VkBufferCreateInfo buffCI = {};
5916 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5917 buffCI.size = 1024;
5918 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5919 buffCI.queueFamilyIndexCount = 1;
5920 buffCI.pQueueFamilyIndices = &qfi;
5921
5922 VkBuffer dyub;
5923 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5924 ASSERT_VK_SUCCESS(err);
5925
5926 // Attempt to update descriptor without binding memory to it
5927 VkDescriptorBufferInfo buffInfo = {};
5928 buffInfo.buffer = dyub;
5929 buffInfo.offset = 0;
5930 buffInfo.range = 1024;
5931
5932 VkWriteDescriptorSet descriptor_write;
5933 memset(&descriptor_write, 0, sizeof(descriptor_write));
5934 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5935 descriptor_write.dstSet = descriptorSet;
5936 descriptor_write.dstBinding = 0;
5937 descriptor_write.descriptorCount = 1;
5938 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5939 descriptor_write.pBufferInfo = &buffInfo;
5940
5941 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5942 m_errorMonitor->VerifyFound();
5943
5944 vkDestroyBuffer(m_device->device(), dyub, NULL);
5945 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5946 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5947}
5948
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005949TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005950 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005951 ASSERT_NO_FATAL_FAILURE(InitState());
5952 ASSERT_NO_FATAL_FAILURE(InitViewport());
5953 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5954
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005955 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005956 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005957 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5958 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5959 pipeline_layout_ci.pushConstantRangeCount = 1;
5960 pipeline_layout_ci.pPushConstantRanges = &pc_range;
5961
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005962 //
5963 // Check for invalid push constant ranges in pipeline layouts.
5964 //
5965 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06005966 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06005967 char const *msg;
5968 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07005969
Karl Schultzc81037d2016-05-12 08:11:23 -06005970 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
5971 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
5972 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
5973 "vkCreatePipelineLayout() call has push constants index 0 with "
5974 "size 0."},
5975 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
5976 "vkCreatePipelineLayout() call has push constants index 0 with "
5977 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005978 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06005979 "vkCreatePipelineLayout() call has push constants index 0 with "
5980 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005981 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06005982 "vkCreatePipelineLayout() call has push constants index 0 with "
5983 "size 0."},
5984 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
5985 "vkCreatePipelineLayout() call has push constants index 0 with "
5986 "offset 1. Offset must"},
5987 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
5988 "vkCreatePipelineLayout() call has push constants index 0 "
5989 "with offset "},
5990 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
5991 "vkCreatePipelineLayout() call has push constants "
5992 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06005993 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06005994 "vkCreatePipelineLayout() call has push constants index 0 "
5995 "with offset "},
5996 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
5997 "vkCreatePipelineLayout() call has push "
5998 "constants index 0 with offset "},
5999 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6000 "vkCreatePipelineLayout() call has push "
6001 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006002 }};
6003
6004 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006005 for (const auto &iter : range_tests) {
6006 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6008 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006009 m_errorMonitor->VerifyFound();
6010 if (VK_SUCCESS == err) {
6011 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6012 }
6013 }
6014
6015 // Check for invalid stage flag
6016 pc_range.offset = 0;
6017 pc_range.size = 16;
6018 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006019 m_errorMonitor->SetDesiredFailureMsg(
6020 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6021 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006022 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006023 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006024 if (VK_SUCCESS == err) {
6025 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6026 }
6027
6028 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006029 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006030 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006031 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006032 char const *msg;
6033 };
6034
Karl Schultzc81037d2016-05-12 08:11:23 -06006035 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006036 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6037 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6038 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6039 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6040 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006041 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006042 {
6043 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6044 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6045 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6046 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6047 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006048 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006049 },
6050 {
6051 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6052 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6053 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6054 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6055 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006056 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006057 },
6058 {
6059 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6060 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6061 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6062 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6063 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006064 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006065 },
6066 {
6067 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6068 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6069 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6070 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6071 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006072 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006073 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006074
Karl Schultzc81037d2016-05-12 08:11:23 -06006075 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006076 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006077 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6079 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006080 m_errorMonitor->VerifyFound();
6081 if (VK_SUCCESS == err) {
6082 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6083 }
6084 }
6085
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006086 //
6087 // CmdPushConstants tests
6088 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006089 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006090
6091 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006092 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6093 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006094 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6095 "vkCmdPushConstants() call has push constants with size 1. Size "
6096 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006097 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006098 "vkCmdPushConstants() call has push constants with size 1. Size "
6099 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006100 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006101 "vkCmdPushConstants() call has push constants with offset 1. "
6102 "Offset must be a multiple of 4."},
6103 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6104 "vkCmdPushConstants() call has push constants with offset 1. "
6105 "Offset must be a multiple of 4."},
6106 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6107 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6108 "0x1 not within flag-matching ranges in pipeline layout"},
6109 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6110 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6111 "0x1 not within flag-matching ranges in pipeline layout"},
6112 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6113 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6114 "0x1 not within flag-matching ranges in pipeline layout"},
6115 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6116 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6117 "0x1 not within flag-matching ranges in pipeline layout"},
6118 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6119 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6120 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006121 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006122 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6123 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006124 }};
6125
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006126 BeginCommandBuffer();
6127
6128 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006129 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006130 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006131 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006132 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006133 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006134 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006135 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006136 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6138 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006139 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006140 m_errorMonitor->VerifyFound();
6141 }
6142
6143 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006145 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006146 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006147 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006148
Karl Schultzc81037d2016-05-12 08:11:23 -06006149 // overlapping range tests with cmd
6150 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6151 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6152 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6153 "0x1 not within flag-matching ranges in pipeline layout"},
6154 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6155 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6156 "0x1 not within flag-matching ranges in pipeline layout"},
6157 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6158 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6159 "0x1 not within flag-matching ranges in pipeline layout"},
6160 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006161 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006162 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006163 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6164 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006165 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006166 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006167 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006168 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006169 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006170 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6172 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006173 iter.range.size, dummy_values);
6174 m_errorMonitor->VerifyFound();
6175 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006176 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6177
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006178 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006179}
6180
Karl Schultz6addd812016-02-02 17:17:23 -07006181TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006182 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006183 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006184
6185 ASSERT_NO_FATAL_FAILURE(InitState());
6186 ASSERT_NO_FATAL_FAILURE(InitViewport());
6187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6188
Mike Stroyanb8a61002016-06-20 16:00:28 -06006189 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6190 VkImageTiling tiling;
6191 VkFormatProperties format_properties;
6192 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006193 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006194 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006195 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006196 tiling = VK_IMAGE_TILING_OPTIMAL;
6197 } else {
6198 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6199 "skipped.\n");
6200 return;
6201 }
6202
Tobin Ehlis559c6382015-11-05 09:52:49 -07006203 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6204 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006205 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6206 ds_type_count[0].descriptorCount = 10;
6207 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6208 ds_type_count[1].descriptorCount = 2;
6209 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6210 ds_type_count[2].descriptorCount = 2;
6211 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6212 ds_type_count[3].descriptorCount = 5;
6213 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6214 // type
6215 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6216 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6217 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006218
6219 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006220 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6221 ds_pool_ci.pNext = NULL;
6222 ds_pool_ci.maxSets = 5;
6223 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6224 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006225
6226 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006227 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006228 ASSERT_VK_SUCCESS(err);
6229
6230 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6231 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006232 dsl_binding[0].binding = 0;
6233 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6234 dsl_binding[0].descriptorCount = 5;
6235 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6236 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006237
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006238 // Create layout identical to set0 layout but w/ different stageFlags
6239 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006240 dsl_fs_stage_only.binding = 0;
6241 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6242 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006243 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6244 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006245 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006246 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006247 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6248 ds_layout_ci.pNext = NULL;
6249 ds_layout_ci.bindingCount = 1;
6250 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006251 static const uint32_t NUM_LAYOUTS = 4;
6252 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006253 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006254 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6255 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006256 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006257 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006258 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006259 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006260 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006261 dsl_binding[0].binding = 0;
6262 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006263 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006264 dsl_binding[1].binding = 1;
6265 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6266 dsl_binding[1].descriptorCount = 2;
6267 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6268 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006269 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006270 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006271 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006272 ASSERT_VK_SUCCESS(err);
6273 dsl_binding[0].binding = 0;
6274 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006275 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006276 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006277 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006278 ASSERT_VK_SUCCESS(err);
6279 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006280 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006281 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006282 ASSERT_VK_SUCCESS(err);
6283
6284 static const uint32_t NUM_SETS = 4;
6285 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6286 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006287 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006288 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006289 alloc_info.descriptorPool = ds_pool;
6290 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006291 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006292 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006293 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006294 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006295 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006296 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006297 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006298
6299 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006300 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6301 pipeline_layout_ci.pNext = NULL;
6302 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6303 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006304
6305 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006306 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006307 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006308 // Create pipelineLayout with only one setLayout
6309 pipeline_layout_ci.setLayoutCount = 1;
6310 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006311 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006312 ASSERT_VK_SUCCESS(err);
6313 // Create pipelineLayout with 2 descriptor setLayout at index 0
6314 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6315 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006316 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006317 ASSERT_VK_SUCCESS(err);
6318 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6319 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6320 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006321 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006322 ASSERT_VK_SUCCESS(err);
6323 // Create pipelineLayout with UB type, but stageFlags for FS only
6324 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6325 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006326 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006327 ASSERT_VK_SUCCESS(err);
6328 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6329 VkDescriptorSetLayout pl_bad_s0[2] = {};
6330 pl_bad_s0[0] = ds_layout_fs_only;
6331 pl_bad_s0[1] = ds_layout[1];
6332 pipeline_layout_ci.setLayoutCount = 2;
6333 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6334 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006335 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006336 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006337
6338 // Create a buffer to update the descriptor with
6339 uint32_t qfi = 0;
6340 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006341 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6342 buffCI.size = 1024;
6343 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6344 buffCI.queueFamilyIndexCount = 1;
6345 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006346
6347 VkBuffer dyub;
6348 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6349 ASSERT_VK_SUCCESS(err);
6350 // Correctly update descriptor to avoid "NOT_UPDATED" error
6351 static const uint32_t NUM_BUFFS = 5;
6352 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006353 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006354 buffInfo[i].buffer = dyub;
6355 buffInfo[i].offset = 0;
6356 buffInfo[i].range = 1024;
6357 }
Karl Schultz6addd812016-02-02 17:17:23 -07006358 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006359 const int32_t tex_width = 32;
6360 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006361 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006362 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6363 image_create_info.pNext = NULL;
6364 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6365 image_create_info.format = tex_format;
6366 image_create_info.extent.width = tex_width;
6367 image_create_info.extent.height = tex_height;
6368 image_create_info.extent.depth = 1;
6369 image_create_info.mipLevels = 1;
6370 image_create_info.arrayLayers = 1;
6371 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006372 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006373 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006374 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006375 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6376 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006377
Karl Schultz6addd812016-02-02 17:17:23 -07006378 VkMemoryRequirements memReqs;
6379 VkDeviceMemory imageMem;
6380 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006381 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006382 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6383 memAlloc.pNext = NULL;
6384 memAlloc.allocationSize = 0;
6385 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006386 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6387 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006388 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006389 ASSERT_TRUE(pass);
6390 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6391 ASSERT_VK_SUCCESS(err);
6392 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6393 ASSERT_VK_SUCCESS(err);
6394
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006395 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006396 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6397 image_view_create_info.image = image;
6398 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6399 image_view_create_info.format = tex_format;
6400 image_view_create_info.subresourceRange.layerCount = 1;
6401 image_view_create_info.subresourceRange.baseMipLevel = 0;
6402 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006403 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006404
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006405 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006406 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006407 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006408 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006409 imageInfo[0].imageView = view;
6410 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6411 imageInfo[1].imageView = view;
6412 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006413 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006414 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006415 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006416 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006417
6418 static const uint32_t NUM_SET_UPDATES = 3;
6419 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6420 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6421 descriptor_write[0].dstSet = descriptorSet[0];
6422 descriptor_write[0].dstBinding = 0;
6423 descriptor_write[0].descriptorCount = 5;
6424 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6425 descriptor_write[0].pBufferInfo = buffInfo;
6426 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6427 descriptor_write[1].dstSet = descriptorSet[1];
6428 descriptor_write[1].dstBinding = 0;
6429 descriptor_write[1].descriptorCount = 2;
6430 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6431 descriptor_write[1].pImageInfo = imageInfo;
6432 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6433 descriptor_write[2].dstSet = descriptorSet[1];
6434 descriptor_write[2].dstBinding = 1;
6435 descriptor_write[2].descriptorCount = 2;
6436 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006437 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006438
6439 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006440
Tobin Ehlis88452832015-12-03 09:40:56 -07006441 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006442 char const *vsSource = "#version 450\n"
6443 "\n"
6444 "out gl_PerVertex {\n"
6445 " vec4 gl_Position;\n"
6446 "};\n"
6447 "void main(){\n"
6448 " gl_Position = vec4(1);\n"
6449 "}\n";
6450 char const *fsSource = "#version 450\n"
6451 "\n"
6452 "layout(location=0) out vec4 x;\n"
6453 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6454 "void main(){\n"
6455 " x = vec4(bar.y);\n"
6456 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006457 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6458 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006459 VkPipelineObj pipe(m_device);
6460 pipe.AddShader(&vs);
6461 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006462 pipe.AddColorAttachment();
6463 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006464
6465 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006466
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006467 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006468 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6469 // of PSO
6470 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6471 // cmd_pipeline.c
6472 // due to the fact that cmd_alloc_dset_data() has not been called in
6473 // cmd_bind_graphics_pipeline()
6474 // TODO : Want to cause various binding incompatibility issues here to test
6475 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006476 // First cause various verify_layout_compatibility() fails
6477 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006478 // verify_set_layout_compatibility fail cases:
6479 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6481 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6482 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006483 m_errorMonitor->VerifyFound();
6484
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006485 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6487 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6488 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006489 m_errorMonitor->VerifyFound();
6490
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006491 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006492 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6493 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6495 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6496 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006497 m_errorMonitor->VerifyFound();
6498
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006499 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6500 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6502 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6503 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006504 m_errorMonitor->VerifyFound();
6505
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006506 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6507 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6509 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6510 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6511 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006512 m_errorMonitor->VerifyFound();
6513
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006514 // Cause INFO messages due to disturbing previously bound Sets
6515 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006516 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6517 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006518 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6520 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6521 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006522 m_errorMonitor->VerifyFound();
6523
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006524 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6525 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006526 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6528 "any subsequent sets were disturbed ");
6529 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6530 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006531 m_errorMonitor->VerifyFound();
6532
Tobin Ehlis10fad692016-07-07 12:00:36 -06006533 // Now that we're done actively using the pipelineLayout that gfx pipeline
6534 // was created with, we should be able to delete it. Do that now to verify
6535 // that validation obeys pipelineLayout lifetime
6536 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6537
Tobin Ehlis88452832015-12-03 09:40:56 -07006538 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006539 // 1. Error due to not binding required set (we actually use same code as
6540 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006541 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6542 &descriptorSet[0], 0, NULL);
6543 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6544 &descriptorSet[1], 0, NULL);
6545 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 -07006546 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006547 m_errorMonitor->VerifyFound();
6548
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006549 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006550 // 2. Error due to bound set not being compatible with PSO's
6551 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006552 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6553 &descriptorSet[0], 0, NULL);
6554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006555 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006556 m_errorMonitor->VerifyFound();
6557
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006558 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006559 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006560 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6561 }
6562 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006563 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006564 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6565 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006566 vkFreeMemory(m_device->device(), imageMem, NULL);
6567 vkDestroyImage(m_device->device(), image, NULL);
6568 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006569}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006570
Karl Schultz6addd812016-02-02 17:17:23 -07006571TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6574 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006575
6576 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006577 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006578 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006579 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006580
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006581 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006582}
6583
Karl Schultz6addd812016-02-02 17:17:23 -07006584TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6585 VkResult err;
6586 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006587
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006589
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006590 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006591
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006592 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006593 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006594 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006595 cmd.commandPool = m_commandPool;
6596 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006597 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006598
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006599 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006600 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006601
6602 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006603 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006604 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006605 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006606 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006607 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 -07006608 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006609
6610 // The error should be caught by validation of the BeginCommandBuffer call
6611 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6612
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006613 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006614 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006615}
6616
Karl Schultz6addd812016-02-02 17:17:23 -07006617TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006618 // Cause error due to Begin while recording CB
6619 // Then cause 2 errors for attempting to reset CB w/o having
6620 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6621 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006623
6624 ASSERT_NO_FATAL_FAILURE(InitState());
6625
6626 // Calls AllocateCommandBuffers
6627 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6628
Karl Schultz6addd812016-02-02 17:17:23 -07006629 // Force the failure by setting the Renderpass and Framebuffer fields with
6630 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006631 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006632 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006633 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6634 cmd_buf_info.pNext = NULL;
6635 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006636 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006637
6638 // Begin CB to transition to recording state
6639 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6640 // Can't re-begin. This should trigger error
6641 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006642 m_errorMonitor->VerifyFound();
6643
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006645 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6646 // Reset attempt will trigger error due to incorrect CommandPool state
6647 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006648 m_errorMonitor->VerifyFound();
6649
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006651 // Transition CB to RECORDED state
6652 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6653 // Now attempting to Begin will implicitly reset, which triggers error
6654 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006655 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006656}
6657
Karl Schultz6addd812016-02-02 17:17:23 -07006658TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006659 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006660 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006661
Mike Weiblencce7ec72016-10-17 19:33:05 -06006662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006663
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006664 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006665 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006666
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006667 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006668 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6669 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006670
6671 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006672 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6673 ds_pool_ci.pNext = NULL;
6674 ds_pool_ci.maxSets = 1;
6675 ds_pool_ci.poolSizeCount = 1;
6676 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006677
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006678 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006679 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006680 ASSERT_VK_SUCCESS(err);
6681
Tony Barboureb254902015-07-15 12:50:33 -06006682 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006683 dsl_binding.binding = 0;
6684 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6685 dsl_binding.descriptorCount = 1;
6686 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6687 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006688
Tony Barboureb254902015-07-15 12:50:33 -06006689 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006690 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6691 ds_layout_ci.pNext = NULL;
6692 ds_layout_ci.bindingCount = 1;
6693 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006694
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006695 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006697 ASSERT_VK_SUCCESS(err);
6698
6699 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006700 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006702 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006703 alloc_info.descriptorPool = ds_pool;
6704 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006706 ASSERT_VK_SUCCESS(err);
6707
Tony Barboureb254902015-07-15 12:50:33 -06006708 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006709 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6710 pipeline_layout_ci.setLayoutCount = 1;
6711 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006712
6713 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006714 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006715 ASSERT_VK_SUCCESS(err);
6716
Tobin Ehlise68360f2015-10-01 11:15:13 -06006717 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006718 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006719
6720 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006721 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6722 vp_state_ci.scissorCount = 1;
6723 vp_state_ci.pScissors = &sc;
6724 vp_state_ci.viewportCount = 1;
6725 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006726
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006727 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6728 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6729 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6730 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6731 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6732 rs_state_ci.depthClampEnable = VK_FALSE;
6733 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6734 rs_state_ci.depthBiasEnable = VK_FALSE;
6735
Tony Barboureb254902015-07-15 12:50:33 -06006736 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006737 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6738 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006739 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006740 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6741 gp_ci.layout = pipeline_layout;
6742 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006743
6744 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006745 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6746 pc_ci.initialDataSize = 0;
6747 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006748
6749 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006750 VkPipelineCache pipelineCache;
6751
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006752 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006753 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006754 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006755
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006756 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006757
Chia-I Wuf7458c52015-10-26 21:10:41 +08006758 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6759 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6760 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6761 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006762}
Tobin Ehlis912df022015-09-17 08:46:18 -06006763/*// TODO : This test should be good, but needs Tess support in compiler to run
6764TEST_F(VkLayerTest, InvalidPatchControlPoints)
6765{
6766 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006767 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006768
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006770 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6771primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006772
Tobin Ehlis912df022015-09-17 08:46:18 -06006773 ASSERT_NO_FATAL_FAILURE(InitState());
6774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006775
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006776 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006777 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006778 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006779
6780 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6781 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6782 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006783 ds_pool_ci.poolSizeCount = 1;
6784 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006785
6786 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006787 err = vkCreateDescriptorPool(m_device->device(),
6788VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006789 ASSERT_VK_SUCCESS(err);
6790
6791 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006792 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006793 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006794 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006795 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6796 dsl_binding.pImmutableSamplers = NULL;
6797
6798 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006799 ds_layout_ci.sType =
6800VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006801 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006802 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006803 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006804
6805 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006806 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6807&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006808 ASSERT_VK_SUCCESS(err);
6809
6810 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006811 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6812VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006813 ASSERT_VK_SUCCESS(err);
6814
6815 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006816 pipeline_layout_ci.sType =
6817VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006818 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006819 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006820 pipeline_layout_ci.pSetLayouts = &ds_layout;
6821
6822 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006823 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6824&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006825 ASSERT_VK_SUCCESS(err);
6826
6827 VkPipelineShaderStageCreateInfo shaderStages[3];
6828 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6829
Karl Schultz6addd812016-02-02 17:17:23 -07006830 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6831this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006832 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006833 VkShaderObj
6834tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6835this);
6836 VkShaderObj
6837te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6838this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006839
Karl Schultz6addd812016-02-02 17:17:23 -07006840 shaderStages[0].sType =
6841VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006842 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006843 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006844 shaderStages[1].sType =
6845VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006846 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006847 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006848 shaderStages[2].sType =
6849VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006850 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006851 shaderStages[2].shader = te.handle();
6852
6853 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006854 iaCI.sType =
6855VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006856 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006857
6858 VkPipelineTessellationStateCreateInfo tsCI = {};
6859 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6860 tsCI.patchControlPoints = 0; // This will cause an error
6861
6862 VkGraphicsPipelineCreateInfo gp_ci = {};
6863 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6864 gp_ci.pNext = NULL;
6865 gp_ci.stageCount = 3;
6866 gp_ci.pStages = shaderStages;
6867 gp_ci.pVertexInputState = NULL;
6868 gp_ci.pInputAssemblyState = &iaCI;
6869 gp_ci.pTessellationState = &tsCI;
6870 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006871 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006872 gp_ci.pMultisampleState = NULL;
6873 gp_ci.pDepthStencilState = NULL;
6874 gp_ci.pColorBlendState = NULL;
6875 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6876 gp_ci.layout = pipeline_layout;
6877 gp_ci.renderPass = renderPass();
6878
6879 VkPipelineCacheCreateInfo pc_ci = {};
6880 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6881 pc_ci.pNext = NULL;
6882 pc_ci.initialSize = 0;
6883 pc_ci.initialData = 0;
6884 pc_ci.maxSize = 0;
6885
6886 VkPipeline pipeline;
6887 VkPipelineCache pipelineCache;
6888
Karl Schultz6addd812016-02-02 17:17:23 -07006889 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6890&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006891 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006892 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6893&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006894
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006895 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006896
Chia-I Wuf7458c52015-10-26 21:10:41 +08006897 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6898 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6899 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6900 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006901}
6902*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06006903// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07006904TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07006905 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6908 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006909
Tobin Ehlise68360f2015-10-01 11:15:13 -06006910 ASSERT_NO_FATAL_FAILURE(InitState());
6911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06006912
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006913 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006914 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6915 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006916
6917 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006918 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6919 ds_pool_ci.maxSets = 1;
6920 ds_pool_ci.poolSizeCount = 1;
6921 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006922
6923 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006924 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006925 ASSERT_VK_SUCCESS(err);
6926
6927 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006928 dsl_binding.binding = 0;
6929 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6930 dsl_binding.descriptorCount = 1;
6931 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006932
6933 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006934 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6935 ds_layout_ci.bindingCount = 1;
6936 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006937
6938 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006939 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006940 ASSERT_VK_SUCCESS(err);
6941
6942 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006943 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006944 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006945 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006946 alloc_info.descriptorPool = ds_pool;
6947 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006948 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006949 ASSERT_VK_SUCCESS(err);
6950
6951 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006952 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6953 pipeline_layout_ci.setLayoutCount = 1;
6954 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006955
6956 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006957 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06006958 ASSERT_VK_SUCCESS(err);
6959
6960 VkViewport vp = {}; // Just need dummy vp to point to
6961
6962 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006963 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6964 vp_state_ci.scissorCount = 0;
6965 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
6966 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006967
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006968 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6969 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6970 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6971 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6972 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6973 rs_state_ci.depthClampEnable = VK_FALSE;
6974 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6975 rs_state_ci.depthBiasEnable = VK_FALSE;
6976
Cody Northropeb3a6c12015-10-05 14:44:45 -06006977 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07006978 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06006979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006980 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6981 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
6982 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08006983 shaderStages[0] = vs.GetStageCreateInfo();
6984 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006985
6986 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006987 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6988 gp_ci.stageCount = 2;
6989 gp_ci.pStages = shaderStages;
6990 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006991 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006992 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6993 gp_ci.layout = pipeline_layout;
6994 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06006995
6996 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006997 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006998
6999 VkPipeline pipeline;
7000 VkPipelineCache pipelineCache;
7001
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007002 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007003 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007004 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007005
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007006 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007007
Chia-I Wuf7458c52015-10-26 21:10:41 +08007008 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7009 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7010 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7011 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007012}
Karl Schultz6addd812016-02-02 17:17:23 -07007013// Don't set viewport state in PSO. This is an error b/c we always need this
7014// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007015// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007016TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007017 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007018 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007019
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007021
Tobin Ehlise68360f2015-10-01 11:15:13 -06007022 ASSERT_NO_FATAL_FAILURE(InitState());
7023 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007024
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007025 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007026 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7027 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007028
7029 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007030 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7031 ds_pool_ci.maxSets = 1;
7032 ds_pool_ci.poolSizeCount = 1;
7033 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007034
7035 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007036 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007037 ASSERT_VK_SUCCESS(err);
7038
7039 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007040 dsl_binding.binding = 0;
7041 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7042 dsl_binding.descriptorCount = 1;
7043 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007044
7045 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007046 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7047 ds_layout_ci.bindingCount = 1;
7048 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007049
7050 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007051 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007052 ASSERT_VK_SUCCESS(err);
7053
7054 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007055 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007056 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007057 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007058 alloc_info.descriptorPool = ds_pool;
7059 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007060 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007061 ASSERT_VK_SUCCESS(err);
7062
7063 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007064 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7065 pipeline_layout_ci.setLayoutCount = 1;
7066 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007067
7068 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007069 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007070 ASSERT_VK_SUCCESS(err);
7071
7072 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7073 // Set scissor as dynamic to avoid second error
7074 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007075 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7076 dyn_state_ci.dynamicStateCount = 1;
7077 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007078
Cody Northropeb3a6c12015-10-05 14:44:45 -06007079 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007080 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007081
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007082 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7083 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7084 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007085 shaderStages[0] = vs.GetStageCreateInfo();
7086 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007087
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007088 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7089 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7090 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7091 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7092 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7093 rs_state_ci.depthClampEnable = VK_FALSE;
7094 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7095 rs_state_ci.depthBiasEnable = VK_FALSE;
7096
Tobin Ehlise68360f2015-10-01 11:15:13 -06007097 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007098 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7099 gp_ci.stageCount = 2;
7100 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007101 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007102 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7103 // should cause validation error
7104 gp_ci.pDynamicState = &dyn_state_ci;
7105 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7106 gp_ci.layout = pipeline_layout;
7107 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007108
7109 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007110 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007111
7112 VkPipeline pipeline;
7113 VkPipelineCache pipelineCache;
7114
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007115 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007116 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007117 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007119 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007120
Chia-I Wuf7458c52015-10-26 21:10:41 +08007121 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7122 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7123 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7124 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007125}
7126// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007127// Then run second test where dynamic scissor count doesn't match PSO scissor
7128// count
7129TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7130 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7133 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007134
Tobin Ehlise68360f2015-10-01 11:15:13 -06007135 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007136
7137 if (!m_device->phy().features().multiViewport) {
7138 printf("Device does not support multiple viewports/scissors; skipped.\n");
7139 return;
7140 }
7141
Tobin Ehlise68360f2015-10-01 11:15:13 -06007142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007143
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007144 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007145 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7146 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007147
7148 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007149 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7150 ds_pool_ci.maxSets = 1;
7151 ds_pool_ci.poolSizeCount = 1;
7152 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007153
7154 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007155 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007156 ASSERT_VK_SUCCESS(err);
7157
7158 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007159 dsl_binding.binding = 0;
7160 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7161 dsl_binding.descriptorCount = 1;
7162 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007163
7164 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007165 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7166 ds_layout_ci.bindingCount = 1;
7167 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007168
7169 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007170 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007171 ASSERT_VK_SUCCESS(err);
7172
7173 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007174 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007175 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007176 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007177 alloc_info.descriptorPool = ds_pool;
7178 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007179 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007180 ASSERT_VK_SUCCESS(err);
7181
7182 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007183 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7184 pipeline_layout_ci.setLayoutCount = 1;
7185 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007186
7187 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007188 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007189 ASSERT_VK_SUCCESS(err);
7190
7191 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007192 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7193 vp_state_ci.viewportCount = 1;
7194 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7195 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007196 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007197
7198 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7199 // Set scissor as dynamic to avoid that error
7200 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007201 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7202 dyn_state_ci.dynamicStateCount = 1;
7203 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007204
Cody Northropeb3a6c12015-10-05 14:44:45 -06007205 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007206 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007207
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007208 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7209 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7210 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007211 shaderStages[0] = vs.GetStageCreateInfo();
7212 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007213
Cody Northropf6622dc2015-10-06 10:33:21 -06007214 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7215 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7216 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007217 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007218 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007219 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007220 vi_ci.pVertexAttributeDescriptions = nullptr;
7221
7222 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7223 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7224 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7225
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007226 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007227 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007228 rs_ci.pNext = nullptr;
7229
Mark Youngc89c6312016-03-31 16:03:20 -06007230 VkPipelineColorBlendAttachmentState att = {};
7231 att.blendEnable = VK_FALSE;
7232 att.colorWriteMask = 0xf;
7233
Cody Northropf6622dc2015-10-06 10:33:21 -06007234 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7235 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7236 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007237 cb_ci.attachmentCount = 1;
7238 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007239
Tobin Ehlise68360f2015-10-01 11:15:13 -06007240 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007241 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7242 gp_ci.stageCount = 2;
7243 gp_ci.pStages = shaderStages;
7244 gp_ci.pVertexInputState = &vi_ci;
7245 gp_ci.pInputAssemblyState = &ia_ci;
7246 gp_ci.pViewportState = &vp_state_ci;
7247 gp_ci.pRasterizationState = &rs_ci;
7248 gp_ci.pColorBlendState = &cb_ci;
7249 gp_ci.pDynamicState = &dyn_state_ci;
7250 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7251 gp_ci.layout = pipeline_layout;
7252 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007253
7254 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007255 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007256
7257 VkPipeline pipeline;
7258 VkPipelineCache pipelineCache;
7259
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007260 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007261 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007262 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007263
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007264 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007265
Tobin Ehlisd332f282015-10-02 11:00:56 -06007266 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007267 // First need to successfully create the PSO from above by setting
7268 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007269 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 -07007270
7271 VkViewport vp = {}; // Just need dummy vp to point to
7272 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007273 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007274 ASSERT_VK_SUCCESS(err);
7275 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007276 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007277 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007278 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007279 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007280 Draw(1, 0, 0, 0);
7281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007282 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007283
7284 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7285 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7286 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7287 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007288 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007289}
7290// Create PSO w/o non-zero scissorCount but no scissor data
7291// Then run second test where dynamic viewportCount doesn't match PSO
7292// viewportCount
7293TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7294 VkResult err;
7295
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007296 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 -07007297
7298 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007299
7300 if (!m_device->phy().features().multiViewport) {
7301 printf("Device does not support multiple viewports/scissors; skipped.\n");
7302 return;
7303 }
7304
Karl Schultz6addd812016-02-02 17:17:23 -07007305 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7306
7307 VkDescriptorPoolSize ds_type_count = {};
7308 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7309 ds_type_count.descriptorCount = 1;
7310
7311 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7312 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7313 ds_pool_ci.maxSets = 1;
7314 ds_pool_ci.poolSizeCount = 1;
7315 ds_pool_ci.pPoolSizes = &ds_type_count;
7316
7317 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007318 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007319 ASSERT_VK_SUCCESS(err);
7320
7321 VkDescriptorSetLayoutBinding dsl_binding = {};
7322 dsl_binding.binding = 0;
7323 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7324 dsl_binding.descriptorCount = 1;
7325 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7326
7327 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7328 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7329 ds_layout_ci.bindingCount = 1;
7330 ds_layout_ci.pBindings = &dsl_binding;
7331
7332 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007333 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007334 ASSERT_VK_SUCCESS(err);
7335
7336 VkDescriptorSet descriptorSet;
7337 VkDescriptorSetAllocateInfo alloc_info = {};
7338 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7339 alloc_info.descriptorSetCount = 1;
7340 alloc_info.descriptorPool = ds_pool;
7341 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007342 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007343 ASSERT_VK_SUCCESS(err);
7344
7345 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7346 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7347 pipeline_layout_ci.setLayoutCount = 1;
7348 pipeline_layout_ci.pSetLayouts = &ds_layout;
7349
7350 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007351 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007352 ASSERT_VK_SUCCESS(err);
7353
7354 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7355 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7356 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007357 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007358 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007359 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007360
7361 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7362 // Set scissor as dynamic to avoid that error
7363 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7364 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7365 dyn_state_ci.dynamicStateCount = 1;
7366 dyn_state_ci.pDynamicStates = &vp_state;
7367
7368 VkPipelineShaderStageCreateInfo shaderStages[2];
7369 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007371 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7372 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7373 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007374 shaderStages[0] = vs.GetStageCreateInfo();
7375 shaderStages[1] = fs.GetStageCreateInfo();
7376
7377 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7378 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7379 vi_ci.pNext = nullptr;
7380 vi_ci.vertexBindingDescriptionCount = 0;
7381 vi_ci.pVertexBindingDescriptions = nullptr;
7382 vi_ci.vertexAttributeDescriptionCount = 0;
7383 vi_ci.pVertexAttributeDescriptions = nullptr;
7384
7385 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7386 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7387 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7388
7389 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7390 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7391 rs_ci.pNext = nullptr;
7392
Mark Youngc89c6312016-03-31 16:03:20 -06007393 VkPipelineColorBlendAttachmentState att = {};
7394 att.blendEnable = VK_FALSE;
7395 att.colorWriteMask = 0xf;
7396
Karl Schultz6addd812016-02-02 17:17:23 -07007397 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7398 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7399 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007400 cb_ci.attachmentCount = 1;
7401 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007402
7403 VkGraphicsPipelineCreateInfo gp_ci = {};
7404 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7405 gp_ci.stageCount = 2;
7406 gp_ci.pStages = shaderStages;
7407 gp_ci.pVertexInputState = &vi_ci;
7408 gp_ci.pInputAssemblyState = &ia_ci;
7409 gp_ci.pViewportState = &vp_state_ci;
7410 gp_ci.pRasterizationState = &rs_ci;
7411 gp_ci.pColorBlendState = &cb_ci;
7412 gp_ci.pDynamicState = &dyn_state_ci;
7413 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7414 gp_ci.layout = pipeline_layout;
7415 gp_ci.renderPass = renderPass();
7416
7417 VkPipelineCacheCreateInfo pc_ci = {};
7418 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7419
7420 VkPipeline pipeline;
7421 VkPipelineCache pipelineCache;
7422
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007424 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007425 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007426
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007427 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007428
7429 // Now hit second fail case where we set scissor w/ different count than PSO
7430 // First need to successfully create the PSO from above by setting
7431 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007432 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 -06007433
Tobin Ehlisd332f282015-10-02 11:00:56 -06007434 VkRect2D sc = {}; // Just need dummy vp to point to
7435 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007436 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007437 ASSERT_VK_SUCCESS(err);
7438 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007439 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007440 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007441 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007442 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007443 Draw(1, 0, 0, 0);
7444
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007445 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007446
Chia-I Wuf7458c52015-10-26 21:10:41 +08007447 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7448 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7449 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7450 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007451 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007452}
7453
Mark Young7394fdd2016-03-31 14:56:43 -06007454TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7455 VkResult err;
7456
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007458
7459 ASSERT_NO_FATAL_FAILURE(InitState());
7460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7461
7462 VkDescriptorPoolSize ds_type_count = {};
7463 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7464 ds_type_count.descriptorCount = 1;
7465
7466 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7467 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7468 ds_pool_ci.maxSets = 1;
7469 ds_pool_ci.poolSizeCount = 1;
7470 ds_pool_ci.pPoolSizes = &ds_type_count;
7471
7472 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007473 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007474 ASSERT_VK_SUCCESS(err);
7475
7476 VkDescriptorSetLayoutBinding dsl_binding = {};
7477 dsl_binding.binding = 0;
7478 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7479 dsl_binding.descriptorCount = 1;
7480 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7481
7482 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7483 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7484 ds_layout_ci.bindingCount = 1;
7485 ds_layout_ci.pBindings = &dsl_binding;
7486
7487 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007488 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007489 ASSERT_VK_SUCCESS(err);
7490
7491 VkDescriptorSet descriptorSet;
7492 VkDescriptorSetAllocateInfo alloc_info = {};
7493 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7494 alloc_info.descriptorSetCount = 1;
7495 alloc_info.descriptorPool = ds_pool;
7496 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007497 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007498 ASSERT_VK_SUCCESS(err);
7499
7500 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7501 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7502 pipeline_layout_ci.setLayoutCount = 1;
7503 pipeline_layout_ci.pSetLayouts = &ds_layout;
7504
7505 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007506 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007507 ASSERT_VK_SUCCESS(err);
7508
7509 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7510 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7511 vp_state_ci.scissorCount = 1;
7512 vp_state_ci.pScissors = NULL;
7513 vp_state_ci.viewportCount = 1;
7514 vp_state_ci.pViewports = NULL;
7515
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007516 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007517 // Set scissor as dynamic to avoid that error
7518 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7519 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7520 dyn_state_ci.dynamicStateCount = 2;
7521 dyn_state_ci.pDynamicStates = dynamic_states;
7522
7523 VkPipelineShaderStageCreateInfo shaderStages[2];
7524 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7525
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007526 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7527 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007528 this); // TODO - We shouldn't need a fragment shader
7529 // but add it to be able to run on more devices
7530 shaderStages[0] = vs.GetStageCreateInfo();
7531 shaderStages[1] = fs.GetStageCreateInfo();
7532
7533 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7534 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7535 vi_ci.pNext = nullptr;
7536 vi_ci.vertexBindingDescriptionCount = 0;
7537 vi_ci.pVertexBindingDescriptions = nullptr;
7538 vi_ci.vertexAttributeDescriptionCount = 0;
7539 vi_ci.pVertexAttributeDescriptions = nullptr;
7540
7541 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7542 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7543 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7544
7545 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7546 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7547 rs_ci.pNext = nullptr;
7548
Mark Young47107952016-05-02 15:59:55 -06007549 // Check too low (line width of -1.0f).
7550 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007551
7552 VkPipelineColorBlendAttachmentState att = {};
7553 att.blendEnable = VK_FALSE;
7554 att.colorWriteMask = 0xf;
7555
7556 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7557 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7558 cb_ci.pNext = nullptr;
7559 cb_ci.attachmentCount = 1;
7560 cb_ci.pAttachments = &att;
7561
7562 VkGraphicsPipelineCreateInfo gp_ci = {};
7563 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7564 gp_ci.stageCount = 2;
7565 gp_ci.pStages = shaderStages;
7566 gp_ci.pVertexInputState = &vi_ci;
7567 gp_ci.pInputAssemblyState = &ia_ci;
7568 gp_ci.pViewportState = &vp_state_ci;
7569 gp_ci.pRasterizationState = &rs_ci;
7570 gp_ci.pColorBlendState = &cb_ci;
7571 gp_ci.pDynamicState = &dyn_state_ci;
7572 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7573 gp_ci.layout = pipeline_layout;
7574 gp_ci.renderPass = renderPass();
7575
7576 VkPipelineCacheCreateInfo pc_ci = {};
7577 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7578
7579 VkPipeline pipeline;
7580 VkPipelineCache pipelineCache;
7581
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007582 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007583 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007585
7586 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007587 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007590
7591 // Check too high (line width of 65536.0f).
7592 rs_ci.lineWidth = 65536.0f;
7593
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007594 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007595 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007596 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007597
7598 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007599 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007600
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007602
7603 dyn_state_ci.dynamicStateCount = 3;
7604
7605 rs_ci.lineWidth = 1.0f;
7606
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007607 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007608 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007609 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007610 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007611 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007612
7613 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007614 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007615 m_errorMonitor->VerifyFound();
7616
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007618
7619 // Check too high with dynamic setting.
7620 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7621 m_errorMonitor->VerifyFound();
7622 EndCommandBuffer();
7623
7624 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7625 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7626 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7627 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007628 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007629}
7630
Karl Schultz6addd812016-02-02 17:17:23 -07007631TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007632 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7634 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007635
7636 ASSERT_NO_FATAL_FAILURE(InitState());
7637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007638
Tony Barbourfe3351b2015-07-28 10:17:20 -06007639 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007640 // Don't care about RenderPass handle b/c error should be flagged before
7641 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007642 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007643
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007644 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007645}
7646
Karl Schultz6addd812016-02-02 17:17:23 -07007647TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007648 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7650 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007651
7652 ASSERT_NO_FATAL_FAILURE(InitState());
7653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007654
Tony Barbourfe3351b2015-07-28 10:17:20 -06007655 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007656 // Just create a dummy Renderpass that's non-NULL so we can get to the
7657 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007658 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007659
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007660 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007661}
7662
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007663TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7664 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7665 "the number of renderPass attachments that use loadOp"
7666 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7667
7668 ASSERT_NO_FATAL_FAILURE(InitState());
7669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7670
7671 // Create a renderPass with a single attachment that uses loadOp CLEAR
7672 VkAttachmentReference attach = {};
7673 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7674 VkSubpassDescription subpass = {};
7675 subpass.inputAttachmentCount = 1;
7676 subpass.pInputAttachments = &attach;
7677 VkRenderPassCreateInfo rpci = {};
7678 rpci.subpassCount = 1;
7679 rpci.pSubpasses = &subpass;
7680 rpci.attachmentCount = 1;
7681 VkAttachmentDescription attach_desc = {};
7682 attach_desc.format = VK_FORMAT_UNDEFINED;
7683 // Set loadOp to CLEAR
7684 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7685 rpci.pAttachments = &attach_desc;
7686 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7687 VkRenderPass rp;
7688 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7689
7690 VkCommandBufferInheritanceInfo hinfo = {};
7691 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7692 hinfo.renderPass = VK_NULL_HANDLE;
7693 hinfo.subpass = 0;
7694 hinfo.framebuffer = VK_NULL_HANDLE;
7695 hinfo.occlusionQueryEnable = VK_FALSE;
7696 hinfo.queryFlags = 0;
7697 hinfo.pipelineStatistics = 0;
7698 VkCommandBufferBeginInfo info = {};
7699 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7700 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7701 info.pInheritanceInfo = &hinfo;
7702
7703 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7704 VkRenderPassBeginInfo rp_begin = {};
7705 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7706 rp_begin.pNext = NULL;
7707 rp_begin.renderPass = renderPass();
7708 rp_begin.framebuffer = framebuffer();
7709 rp_begin.clearValueCount = 0; // Should be 1
7710
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7712 "there must be at least 1 entries in "
7713 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007715 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007716
7717 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007718
7719 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007720}
7721
Cody Northrop3bb4d962016-05-09 16:15:57 -06007722TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7723
7724 TEST_DESCRIPTION("End a command buffer with an active render pass");
7725
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7727 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007728
7729 ASSERT_NO_FATAL_FAILURE(InitState());
7730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7731
7732 // The framework's BeginCommandBuffer calls CreateRenderPass
7733 BeginCommandBuffer();
7734
7735 // Call directly into vkEndCommandBuffer instead of the
7736 // the framework's EndCommandBuffer, which inserts a
7737 // vkEndRenderPass
7738 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7739
7740 m_errorMonitor->VerifyFound();
7741
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007742 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7743 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007744}
7745
Karl Schultz6addd812016-02-02 17:17:23 -07007746TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007747 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7749 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007750
7751 ASSERT_NO_FATAL_FAILURE(InitState());
7752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007753
7754 // Renderpass is started here
7755 BeginCommandBuffer();
7756
7757 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007758 vk_testing::Buffer dstBuffer;
7759 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007760
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007761 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007762
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007763 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007764}
7765
Karl Schultz6addd812016-02-02 17:17:23 -07007766TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007767 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7769 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007770
7771 ASSERT_NO_FATAL_FAILURE(InitState());
7772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007773
7774 // Renderpass is started here
7775 BeginCommandBuffer();
7776
7777 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007778 vk_testing::Buffer dstBuffer;
7779 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007780
Karl Schultz6addd812016-02-02 17:17:23 -07007781 VkDeviceSize dstOffset = 0;
7782 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007783 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007785 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007786
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007787 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007788}
7789
Karl Schultz6addd812016-02-02 17:17:23 -07007790TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007791 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7793 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007794
7795 ASSERT_NO_FATAL_FAILURE(InitState());
7796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007797
7798 // Renderpass is started here
7799 BeginCommandBuffer();
7800
Michael Lentine0a369f62016-02-03 16:51:46 -06007801 VkClearColorValue clear_color;
7802 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007803 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7804 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7805 const int32_t tex_width = 32;
7806 const int32_t tex_height = 32;
7807 VkImageCreateInfo image_create_info = {};
7808 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7809 image_create_info.pNext = NULL;
7810 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7811 image_create_info.format = tex_format;
7812 image_create_info.extent.width = tex_width;
7813 image_create_info.extent.height = tex_height;
7814 image_create_info.extent.depth = 1;
7815 image_create_info.mipLevels = 1;
7816 image_create_info.arrayLayers = 1;
7817 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7818 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7819 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007820
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007821 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007822 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007823
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007824 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007825
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007826 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007827
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007828 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007829}
7830
Karl Schultz6addd812016-02-02 17:17:23 -07007831TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007832 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7834 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007835
7836 ASSERT_NO_FATAL_FAILURE(InitState());
7837 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007838
7839 // Renderpass is started here
7840 BeginCommandBuffer();
7841
7842 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007843 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007844 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7845 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7846 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7847 image_create_info.extent.width = 64;
7848 image_create_info.extent.height = 64;
7849 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7850 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007851
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007852 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007853 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007855 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007856
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007857 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7858 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007859
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007860 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007861}
7862
Karl Schultz6addd812016-02-02 17:17:23 -07007863TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007864 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007865 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7868 "must be issued inside an active "
7869 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007870
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007871 ASSERT_NO_FATAL_FAILURE(InitState());
7872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007873
7874 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007875 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007876 ASSERT_VK_SUCCESS(err);
7877
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007878 VkClearAttachment color_attachment;
7879 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7880 color_attachment.clearValue.color.float32[0] = 0;
7881 color_attachment.clearValue.color.float32[1] = 0;
7882 color_attachment.clearValue.color.float32[2] = 0;
7883 color_attachment.clearValue.color.float32[3] = 0;
7884 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007885 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007886 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007887
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007888 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007889}
7890
Chris Forbes3b97e932016-09-07 11:29:24 +12007891TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
7892 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
7893 "called too many times in a renderpass instance");
7894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
7896 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12007897
7898 ASSERT_NO_FATAL_FAILURE(InitState());
7899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7900
7901 BeginCommandBuffer();
7902
7903 // error here.
7904 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
7905 m_errorMonitor->VerifyFound();
7906
7907 EndCommandBuffer();
7908}
7909
Chris Forbes6d624702016-09-07 13:57:05 +12007910TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
7911 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
7912 "called before the final subpass has been reached");
7913
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
7915 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12007916
7917 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007918 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
7919 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12007920
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12007922
7923 VkRenderPass rp;
7924 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
7925 ASSERT_VK_SUCCESS(err);
7926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007927 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12007928
7929 VkFramebuffer fb;
7930 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
7931 ASSERT_VK_SUCCESS(err);
7932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007933 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12007934
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007935 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 +12007936
7937 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
7938
7939 // Error here.
7940 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
7941 m_errorMonitor->VerifyFound();
7942
7943 // Clean up.
7944 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
7945 vkDestroyRenderPass(m_device->device(), rp, nullptr);
7946}
7947
Karl Schultz9e66a292016-04-21 15:57:51 -06007948TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
7949 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7951 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06007952
7953 ASSERT_NO_FATAL_FAILURE(InitState());
7954 BeginCommandBuffer();
7955
7956 VkBufferMemoryBarrier buf_barrier = {};
7957 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
7958 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7959 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7960 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7961 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
7962 buf_barrier.buffer = VK_NULL_HANDLE;
7963 buf_barrier.offset = 0;
7964 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007965 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
7966 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06007967
7968 m_errorMonitor->VerifyFound();
7969}
7970
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007971TEST_F(VkLayerTest, InvalidBarriers) {
7972 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
7973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007975
7976 ASSERT_NO_FATAL_FAILURE(InitState());
7977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7978
7979 VkMemoryBarrier mem_barrier = {};
7980 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
7981 mem_barrier.pNext = NULL;
7982 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7983 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7984 BeginCommandBuffer();
7985 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007986 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007987 &mem_barrier, 0, nullptr, 0, nullptr);
7988 m_errorMonitor->VerifyFound();
7989
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06007991 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007992 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 -06007993 ASSERT_TRUE(image.initialized());
7994 VkImageMemoryBarrier img_barrier = {};
7995 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
7996 img_barrier.pNext = NULL;
7997 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
7998 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
7999 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8000 // New layout can't be UNDEFINED
8001 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8002 img_barrier.image = image.handle();
8003 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8004 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8005 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8006 img_barrier.subresourceRange.baseArrayLayer = 0;
8007 img_barrier.subresourceRange.baseMipLevel = 0;
8008 img_barrier.subresourceRange.layerCount = 1;
8009 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008010 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8011 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008012 m_errorMonitor->VerifyFound();
8013 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8014
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8016 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008017 // baseArrayLayer + layerCount must be <= image's arrayLayers
8018 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008019 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8020 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008021 m_errorMonitor->VerifyFound();
8022 img_barrier.subresourceRange.baseArrayLayer = 0;
8023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008025 // baseMipLevel + levelCount must be <= image's mipLevels
8026 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008027 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8028 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008029 m_errorMonitor->VerifyFound();
8030 img_barrier.subresourceRange.baseMipLevel = 0;
8031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008032 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 -06008033 vk_testing::Buffer buffer;
8034 buffer.init(*m_device, 256);
8035 VkBufferMemoryBarrier buf_barrier = {};
8036 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8037 buf_barrier.pNext = NULL;
8038 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8039 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8040 buf_barrier.buffer = buffer.handle();
8041 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8042 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8043 buf_barrier.offset = 0;
8044 buf_barrier.size = VK_WHOLE_SIZE;
8045 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008046 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8047 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008048 m_errorMonitor->VerifyFound();
8049 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008052 buf_barrier.offset = 257;
8053 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008054 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8055 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008056 m_errorMonitor->VerifyFound();
8057 buf_barrier.offset = 0;
8058
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008060 buf_barrier.size = 257;
8061 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008062 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8063 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008064 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008065
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008066 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008067 m_errorMonitor->SetDesiredFailureMsg(
8068 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8069 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8070 m_errorMonitor->SetDesiredFailureMsg(
8071 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8072 "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 -06008073 VkDepthStencilObj ds_image(m_device);
8074 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8075 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008076 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8077 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008078 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008079 // Use of COLOR aspect on DS image is error
8080 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008081 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8082 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008083 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008084 // Now test depth-only
8085 VkFormatProperties format_props;
8086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008087 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8088 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8090 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8092 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008093 VkDepthStencilObj d_image(m_device);
8094 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8095 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008096 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008097 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008098 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008099 // Use of COLOR aspect on depth image is error
8100 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008101 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8102 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008103 m_errorMonitor->VerifyFound();
8104 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008105 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8106 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008107 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8109 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008110 VkDepthStencilObj s_image(m_device);
8111 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8112 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008113 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008114 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008115 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008116 // Use of COLOR aspect on depth image is error
8117 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008118 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8119 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008120 m_errorMonitor->VerifyFound();
8121 }
8122 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8124 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8126 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008127 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008128 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 -06008129 ASSERT_TRUE(c_image.initialized());
8130 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8131 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8132 img_barrier.image = c_image.handle();
8133 // Set aspect to depth (non-color)
8134 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008135 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8136 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008137 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008138}
8139
Tony Barbour18ba25c2016-09-29 13:42:40 -06008140TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8141 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8142
8143 m_errorMonitor->SetDesiredFailureMsg(
8144 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8145 "must have required access bit");
8146 ASSERT_NO_FATAL_FAILURE(InitState());
8147 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008148 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 -06008149 ASSERT_TRUE(image.initialized());
8150
8151 VkImageMemoryBarrier barrier = {};
8152 VkImageSubresourceRange range;
8153 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8154 barrier.srcAccessMask = 0;
8155 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8156 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8157 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8158 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8159 barrier.image = image.handle();
8160 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8161 range.baseMipLevel = 0;
8162 range.levelCount = 1;
8163 range.baseArrayLayer = 0;
8164 range.layerCount = 1;
8165 barrier.subresourceRange = range;
8166 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8167 cmdbuf.BeginCommandBuffer();
8168 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8169 &barrier);
8170 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8171 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8172 barrier.srcAccessMask = 0;
8173 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8174 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8175 &barrier);
8176
8177 m_errorMonitor->VerifyFound();
8178}
8179
Karl Schultz6addd812016-02-02 17:17:23 -07008180TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008181 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008182 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008183
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008185
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008186 ASSERT_NO_FATAL_FAILURE(InitState());
8187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008188 uint32_t qfi = 0;
8189 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008190 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8191 buffCI.size = 1024;
8192 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8193 buffCI.queueFamilyIndexCount = 1;
8194 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008195
8196 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008197 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008198 ASSERT_VK_SUCCESS(err);
8199
8200 BeginCommandBuffer();
8201 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008202 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8203 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008204 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008205 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008206
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008207 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008208
Chia-I Wuf7458c52015-10-26 21:10:41 +08008209 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008210}
8211
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008212TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8213 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8215 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8216 "of the indices specified when the device was created, via the "
8217 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008218
8219 ASSERT_NO_FATAL_FAILURE(InitState());
8220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8221 VkBufferCreateInfo buffCI = {};
8222 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8223 buffCI.size = 1024;
8224 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8225 buffCI.queueFamilyIndexCount = 1;
8226 // Introduce failure by specifying invalid queue_family_index
8227 uint32_t qfi = 777;
8228 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008229 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008230
8231 VkBuffer ib;
8232 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8233
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008234 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008235 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008236}
8237
Karl Schultz6addd812016-02-02 17:17:23 -07008238TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008239TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008240 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008241
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008242 ASSERT_NO_FATAL_FAILURE(InitState());
8243 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008244
Chris Forbesf29a84f2016-10-06 18:39:28 +13008245 // An empty primary command buffer
8246 VkCommandBufferObj cb(m_device, m_commandPool);
8247 cb.BeginCommandBuffer();
8248 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008249
Chris Forbesf29a84f2016-10-06 18:39:28 +13008250 m_commandBuffer->BeginCommandBuffer();
8251 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8252 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008253
Chris Forbesf29a84f2016-10-06 18:39:28 +13008254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8255 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008256 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008257}
8258
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008259TEST_F(VkLayerTest, DSUsageBitsErrors) {
8260 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8261 "that do not have correct usage bits sets.");
8262 VkResult err;
8263
8264 ASSERT_NO_FATAL_FAILURE(InitState());
8265 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8266 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8267 ds_type_count[i].type = VkDescriptorType(i);
8268 ds_type_count[i].descriptorCount = 1;
8269 }
8270 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8271 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8272 ds_pool_ci.pNext = NULL;
8273 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8274 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8275 ds_pool_ci.pPoolSizes = ds_type_count;
8276
8277 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008279 ASSERT_VK_SUCCESS(err);
8280
8281 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008282 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008283 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8284 dsl_binding[i].binding = 0;
8285 dsl_binding[i].descriptorType = VkDescriptorType(i);
8286 dsl_binding[i].descriptorCount = 1;
8287 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8288 dsl_binding[i].pImmutableSamplers = NULL;
8289 }
8290
8291 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8292 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8293 ds_layout_ci.pNext = NULL;
8294 ds_layout_ci.bindingCount = 1;
8295 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8296 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8297 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008298 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008299 ASSERT_VK_SUCCESS(err);
8300 }
8301 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8302 VkDescriptorSetAllocateInfo alloc_info = {};
8303 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8304 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8305 alloc_info.descriptorPool = ds_pool;
8306 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008307 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008308 ASSERT_VK_SUCCESS(err);
8309
8310 // Create a buffer & bufferView to be used for invalid updates
8311 VkBufferCreateInfo buff_ci = {};
8312 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8313 // This usage is not valid for any descriptor type
8314 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8315 buff_ci.size = 256;
8316 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8317 VkBuffer buffer;
8318 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8319 ASSERT_VK_SUCCESS(err);
8320
8321 VkBufferViewCreateInfo buff_view_ci = {};
8322 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8323 buff_view_ci.buffer = buffer;
8324 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8325 buff_view_ci.range = VK_WHOLE_SIZE;
8326 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008327 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008328 ASSERT_VK_SUCCESS(err);
8329
8330 // Create an image to be used for invalid updates
8331 VkImageCreateInfo image_ci = {};
8332 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8333 image_ci.imageType = VK_IMAGE_TYPE_2D;
8334 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8335 image_ci.extent.width = 64;
8336 image_ci.extent.height = 64;
8337 image_ci.extent.depth = 1;
8338 image_ci.mipLevels = 1;
8339 image_ci.arrayLayers = 1;
8340 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8341 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8342 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8343 // This usage is not valid for any descriptor type
8344 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8345 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8346 VkImage image;
8347 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8348 ASSERT_VK_SUCCESS(err);
8349 // Bind memory to image
8350 VkMemoryRequirements mem_reqs;
8351 VkDeviceMemory image_mem;
8352 bool pass;
8353 VkMemoryAllocateInfo mem_alloc = {};
8354 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8355 mem_alloc.pNext = NULL;
8356 mem_alloc.allocationSize = 0;
8357 mem_alloc.memoryTypeIndex = 0;
8358 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8359 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008360 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008361 ASSERT_TRUE(pass);
8362 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8363 ASSERT_VK_SUCCESS(err);
8364 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8365 ASSERT_VK_SUCCESS(err);
8366 // Now create view for image
8367 VkImageViewCreateInfo image_view_ci = {};
8368 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8369 image_view_ci.image = image;
8370 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8371 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8372 image_view_ci.subresourceRange.layerCount = 1;
8373 image_view_ci.subresourceRange.baseArrayLayer = 0;
8374 image_view_ci.subresourceRange.levelCount = 1;
8375 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8376 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008377 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008378 ASSERT_VK_SUCCESS(err);
8379
8380 VkDescriptorBufferInfo buff_info = {};
8381 buff_info.buffer = buffer;
8382 VkDescriptorImageInfo img_info = {};
8383 img_info.imageView = image_view;
8384 VkWriteDescriptorSet descriptor_write = {};
8385 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8386 descriptor_write.dstBinding = 0;
8387 descriptor_write.descriptorCount = 1;
8388 descriptor_write.pTexelBufferView = &buff_view;
8389 descriptor_write.pBufferInfo = &buff_info;
8390 descriptor_write.pImageInfo = &img_info;
8391
8392 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008393 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8394 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8395 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8396 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8397 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8398 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8399 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8400 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8401 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8402 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8403 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008404 // Start loop at 1 as SAMPLER desc type has no usage bit error
8405 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8406 descriptor_write.descriptorType = VkDescriptorType(i);
8407 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008409
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008410 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008411
8412 m_errorMonitor->VerifyFound();
8413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8414 }
8415 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8416 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008417 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008418 vkDestroyImageView(m_device->device(), image_view, NULL);
8419 vkDestroyBuffer(m_device->device(), buffer, NULL);
8420 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008421 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008422 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8423}
8424
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008425TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008426 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8427 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8428 "1. offset value greater than buffer size\n"
8429 "2. range value of 0\n"
8430 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008431 VkResult err;
8432
8433 ASSERT_NO_FATAL_FAILURE(InitState());
8434 VkDescriptorPoolSize ds_type_count = {};
8435 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8436 ds_type_count.descriptorCount = 1;
8437
8438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8440 ds_pool_ci.pNext = NULL;
8441 ds_pool_ci.maxSets = 1;
8442 ds_pool_ci.poolSizeCount = 1;
8443 ds_pool_ci.pPoolSizes = &ds_type_count;
8444
8445 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008446 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008447 ASSERT_VK_SUCCESS(err);
8448
8449 // Create layout with single uniform buffer descriptor
8450 VkDescriptorSetLayoutBinding dsl_binding = {};
8451 dsl_binding.binding = 0;
8452 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8453 dsl_binding.descriptorCount = 1;
8454 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8455 dsl_binding.pImmutableSamplers = NULL;
8456
8457 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8458 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8459 ds_layout_ci.pNext = NULL;
8460 ds_layout_ci.bindingCount = 1;
8461 ds_layout_ci.pBindings = &dsl_binding;
8462 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008463 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008464 ASSERT_VK_SUCCESS(err);
8465
8466 VkDescriptorSet descriptor_set = {};
8467 VkDescriptorSetAllocateInfo alloc_info = {};
8468 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8469 alloc_info.descriptorSetCount = 1;
8470 alloc_info.descriptorPool = ds_pool;
8471 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008472 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008473 ASSERT_VK_SUCCESS(err);
8474
8475 // Create a buffer to be used for invalid updates
8476 VkBufferCreateInfo buff_ci = {};
8477 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8478 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8479 buff_ci.size = 256;
8480 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8481 VkBuffer buffer;
8482 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8483 ASSERT_VK_SUCCESS(err);
8484 // Have to bind memory to buffer before descriptor update
8485 VkMemoryAllocateInfo mem_alloc = {};
8486 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8487 mem_alloc.pNext = NULL;
8488 mem_alloc.allocationSize = 256;
8489 mem_alloc.memoryTypeIndex = 0;
8490
8491 VkMemoryRequirements mem_reqs;
8492 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008493 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008494 if (!pass) {
8495 vkDestroyBuffer(m_device->device(), buffer, NULL);
8496 return;
8497 }
8498
8499 VkDeviceMemory mem;
8500 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8501 ASSERT_VK_SUCCESS(err);
8502 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8503 ASSERT_VK_SUCCESS(err);
8504
8505 VkDescriptorBufferInfo buff_info = {};
8506 buff_info.buffer = buffer;
8507 // First make offset 1 larger than buffer size
8508 buff_info.offset = 257;
8509 buff_info.range = VK_WHOLE_SIZE;
8510 VkWriteDescriptorSet descriptor_write = {};
8511 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8512 descriptor_write.dstBinding = 0;
8513 descriptor_write.descriptorCount = 1;
8514 descriptor_write.pTexelBufferView = nullptr;
8515 descriptor_write.pBufferInfo = &buff_info;
8516 descriptor_write.pImageInfo = nullptr;
8517
8518 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8519 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008521
8522 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8523
8524 m_errorMonitor->VerifyFound();
8525 // Now cause error due to range of 0
8526 buff_info.offset = 0;
8527 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8529 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008530
8531 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8532
8533 m_errorMonitor->VerifyFound();
8534 // Now cause error due to range exceeding buffer size - offset
8535 buff_info.offset = 128;
8536 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008537 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 -06008538
8539 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8540
8541 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008542 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008543 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8544 vkDestroyBuffer(m_device->device(), buffer, NULL);
8545 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8546 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8547}
8548
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008549TEST_F(VkLayerTest, DSAspectBitsErrors) {
8550 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8551 // are set, but could expand this test to hit more cases.
8552 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8553 "that do not have correct aspect bits sets.");
8554 VkResult err;
8555
8556 ASSERT_NO_FATAL_FAILURE(InitState());
8557 VkDescriptorPoolSize ds_type_count = {};
8558 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8559 ds_type_count.descriptorCount = 1;
8560
8561 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8562 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8563 ds_pool_ci.pNext = NULL;
8564 ds_pool_ci.maxSets = 5;
8565 ds_pool_ci.poolSizeCount = 1;
8566 ds_pool_ci.pPoolSizes = &ds_type_count;
8567
8568 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008569 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008570 ASSERT_VK_SUCCESS(err);
8571
8572 VkDescriptorSetLayoutBinding dsl_binding = {};
8573 dsl_binding.binding = 0;
8574 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8575 dsl_binding.descriptorCount = 1;
8576 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8577 dsl_binding.pImmutableSamplers = NULL;
8578
8579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8581 ds_layout_ci.pNext = NULL;
8582 ds_layout_ci.bindingCount = 1;
8583 ds_layout_ci.pBindings = &dsl_binding;
8584 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008585 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008586 ASSERT_VK_SUCCESS(err);
8587
8588 VkDescriptorSet descriptor_set = {};
8589 VkDescriptorSetAllocateInfo alloc_info = {};
8590 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8591 alloc_info.descriptorSetCount = 1;
8592 alloc_info.descriptorPool = ds_pool;
8593 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008594 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008595 ASSERT_VK_SUCCESS(err);
8596
8597 // Create an image to be used for invalid updates
8598 VkImageCreateInfo image_ci = {};
8599 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8600 image_ci.imageType = VK_IMAGE_TYPE_2D;
8601 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8602 image_ci.extent.width = 64;
8603 image_ci.extent.height = 64;
8604 image_ci.extent.depth = 1;
8605 image_ci.mipLevels = 1;
8606 image_ci.arrayLayers = 1;
8607 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8608 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8609 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8610 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8611 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8612 VkImage image;
8613 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8614 ASSERT_VK_SUCCESS(err);
8615 // Bind memory to image
8616 VkMemoryRequirements mem_reqs;
8617 VkDeviceMemory image_mem;
8618 bool pass;
8619 VkMemoryAllocateInfo mem_alloc = {};
8620 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8621 mem_alloc.pNext = NULL;
8622 mem_alloc.allocationSize = 0;
8623 mem_alloc.memoryTypeIndex = 0;
8624 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8625 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008626 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008627 ASSERT_TRUE(pass);
8628 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8629 ASSERT_VK_SUCCESS(err);
8630 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8631 ASSERT_VK_SUCCESS(err);
8632 // Now create view for image
8633 VkImageViewCreateInfo image_view_ci = {};
8634 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8635 image_view_ci.image = image;
8636 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8637 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8638 image_view_ci.subresourceRange.layerCount = 1;
8639 image_view_ci.subresourceRange.baseArrayLayer = 0;
8640 image_view_ci.subresourceRange.levelCount = 1;
8641 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008642 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008643
8644 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008645 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008646 ASSERT_VK_SUCCESS(err);
8647
8648 VkDescriptorImageInfo img_info = {};
8649 img_info.imageView = image_view;
8650 VkWriteDescriptorSet descriptor_write = {};
8651 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8652 descriptor_write.dstBinding = 0;
8653 descriptor_write.descriptorCount = 1;
8654 descriptor_write.pTexelBufferView = NULL;
8655 descriptor_write.pBufferInfo = NULL;
8656 descriptor_write.pImageInfo = &img_info;
8657 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8658 descriptor_write.dstSet = descriptor_set;
8659 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8660 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008662
8663 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8664
8665 m_errorMonitor->VerifyFound();
8666 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8667 vkDestroyImage(m_device->device(), image, NULL);
8668 vkFreeMemory(m_device->device(), image_mem, NULL);
8669 vkDestroyImageView(m_device->device(), image_view, NULL);
8670 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8671 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8672}
8673
Karl Schultz6addd812016-02-02 17:17:23 -07008674TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008675 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008676 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008677
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8679 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8680 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008681
Tobin Ehlis3b780662015-05-28 12:11:26 -06008682 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008683 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008684 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008685 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8686 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008687
8688 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008689 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8690 ds_pool_ci.pNext = NULL;
8691 ds_pool_ci.maxSets = 1;
8692 ds_pool_ci.poolSizeCount = 1;
8693 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008694
Tobin Ehlis3b780662015-05-28 12:11:26 -06008695 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008697 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008698 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008699 dsl_binding.binding = 0;
8700 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8701 dsl_binding.descriptorCount = 1;
8702 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8703 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008704
Tony Barboureb254902015-07-15 12:50:33 -06008705 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008706 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8707 ds_layout_ci.pNext = NULL;
8708 ds_layout_ci.bindingCount = 1;
8709 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008710
Tobin Ehlis3b780662015-05-28 12:11:26 -06008711 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008712 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008713 ASSERT_VK_SUCCESS(err);
8714
8715 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008716 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008717 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008718 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008719 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, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008722 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008723
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008724 VkSamplerCreateInfo sampler_ci = {};
8725 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8726 sampler_ci.pNext = NULL;
8727 sampler_ci.magFilter = VK_FILTER_NEAREST;
8728 sampler_ci.minFilter = VK_FILTER_NEAREST;
8729 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8730 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8731 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8732 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8733 sampler_ci.mipLodBias = 1.0;
8734 sampler_ci.anisotropyEnable = VK_FALSE;
8735 sampler_ci.maxAnisotropy = 1;
8736 sampler_ci.compareEnable = VK_FALSE;
8737 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8738 sampler_ci.minLod = 1.0;
8739 sampler_ci.maxLod = 1.0;
8740 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8741 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8742 VkSampler sampler;
8743 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8744 ASSERT_VK_SUCCESS(err);
8745
8746 VkDescriptorImageInfo info = {};
8747 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008748
8749 VkWriteDescriptorSet descriptor_write;
8750 memset(&descriptor_write, 0, sizeof(descriptor_write));
8751 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008752 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008753 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008754 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008755 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008756 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008757
8758 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8759
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008760 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008761
Chia-I Wuf7458c52015-10-26 21:10:41 +08008762 vkDestroySampler(m_device->device(), sampler, NULL);
8763 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8764 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008765}
8766
Karl Schultz6addd812016-02-02 17:17:23 -07008767TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008768 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008769 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8772 " binding #0 with 1 total descriptors but update of 1 descriptors "
8773 "starting at binding offset of 0 combined with update array element "
8774 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008775
Tobin Ehlis3b780662015-05-28 12:11:26 -06008776 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008777 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008778 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008779 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8780 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008781
8782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8784 ds_pool_ci.pNext = NULL;
8785 ds_pool_ci.maxSets = 1;
8786 ds_pool_ci.poolSizeCount = 1;
8787 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008788
Tobin Ehlis3b780662015-05-28 12:11:26 -06008789 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008790 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008791 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008792
Tony Barboureb254902015-07-15 12:50:33 -06008793 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008794 dsl_binding.binding = 0;
8795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8796 dsl_binding.descriptorCount = 1;
8797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8798 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008799
8800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008801 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8802 ds_layout_ci.pNext = NULL;
8803 ds_layout_ci.bindingCount = 1;
8804 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008805
Tobin Ehlis3b780662015-05-28 12:11:26 -06008806 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008807 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008808 ASSERT_VK_SUCCESS(err);
8809
8810 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008811 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008812 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008813 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008814 alloc_info.descriptorPool = ds_pool;
8815 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008816 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008817 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008818
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008819 // Correctly update descriptor to avoid "NOT_UPDATED" error
8820 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008821 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008822 buff_info.offset = 0;
8823 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008824
8825 VkWriteDescriptorSet descriptor_write;
8826 memset(&descriptor_write, 0, sizeof(descriptor_write));
8827 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008828 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008829 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008830 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008831 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8832 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008833
8834 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8835
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008836 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008837
Chia-I Wuf7458c52015-10-26 21:10:41 +08008838 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8839 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008840}
8841
Karl Schultz6addd812016-02-02 17:17:23 -07008842TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8843 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8844 // index 2
8845 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008848
Tobin Ehlis3b780662015-05-28 12:11:26 -06008849 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008850 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008851 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008852 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8853 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008854
8855 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008856 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8857 ds_pool_ci.pNext = NULL;
8858 ds_pool_ci.maxSets = 1;
8859 ds_pool_ci.poolSizeCount = 1;
8860 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008861
Tobin Ehlis3b780662015-05-28 12:11:26 -06008862 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008863 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008864 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008865
Tony Barboureb254902015-07-15 12:50:33 -06008866 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008867 dsl_binding.binding = 0;
8868 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8869 dsl_binding.descriptorCount = 1;
8870 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8871 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008872
8873 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008874 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8875 ds_layout_ci.pNext = NULL;
8876 ds_layout_ci.bindingCount = 1;
8877 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008878 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008879 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008880 ASSERT_VK_SUCCESS(err);
8881
8882 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008883 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008884 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008885 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008886 alloc_info.descriptorPool = ds_pool;
8887 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008888 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008889 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008890
Tony Barboureb254902015-07-15 12:50:33 -06008891 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008892 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8893 sampler_ci.pNext = NULL;
8894 sampler_ci.magFilter = VK_FILTER_NEAREST;
8895 sampler_ci.minFilter = VK_FILTER_NEAREST;
8896 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8897 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8898 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8899 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8900 sampler_ci.mipLodBias = 1.0;
8901 sampler_ci.anisotropyEnable = VK_FALSE;
8902 sampler_ci.maxAnisotropy = 1;
8903 sampler_ci.compareEnable = VK_FALSE;
8904 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8905 sampler_ci.minLod = 1.0;
8906 sampler_ci.maxLod = 1.0;
8907 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8908 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06008909
Tobin Ehlis3b780662015-05-28 12:11:26 -06008910 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008911 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008912 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008913
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008914 VkDescriptorImageInfo info = {};
8915 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008916
8917 VkWriteDescriptorSet descriptor_write;
8918 memset(&descriptor_write, 0, sizeof(descriptor_write));
8919 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008920 descriptor_write.dstSet = descriptorSet;
8921 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008922 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008923 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008924 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008925 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008926
8927 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8928
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008929 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008930
Chia-I Wuf7458c52015-10-26 21:10:41 +08008931 vkDestroySampler(m_device->device(), sampler, NULL);
8932 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8933 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008934}
8935
Karl Schultz6addd812016-02-02 17:17:23 -07008936TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
8937 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
8938 // types
8939 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008940
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008941 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 -06008942
Tobin Ehlis3b780662015-05-28 12:11:26 -06008943 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06008944
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008945 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008946 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8947 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008948
8949 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008950 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8951 ds_pool_ci.pNext = NULL;
8952 ds_pool_ci.maxSets = 1;
8953 ds_pool_ci.poolSizeCount = 1;
8954 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008955
Tobin Ehlis3b780662015-05-28 12:11:26 -06008956 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008957 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008958 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008959 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008960 dsl_binding.binding = 0;
8961 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8962 dsl_binding.descriptorCount = 1;
8963 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8964 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008965
Tony Barboureb254902015-07-15 12:50:33 -06008966 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008967 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8968 ds_layout_ci.pNext = NULL;
8969 ds_layout_ci.bindingCount = 1;
8970 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008971
Tobin Ehlis3b780662015-05-28 12:11:26 -06008972 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008973 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008974 ASSERT_VK_SUCCESS(err);
8975
8976 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008977 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008978 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008979 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008980 alloc_info.descriptorPool = ds_pool;
8981 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008982 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008983 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008984
Tony Barboureb254902015-07-15 12:50:33 -06008985 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008986 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8987 sampler_ci.pNext = NULL;
8988 sampler_ci.magFilter = VK_FILTER_NEAREST;
8989 sampler_ci.minFilter = VK_FILTER_NEAREST;
8990 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8991 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8992 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8993 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8994 sampler_ci.mipLodBias = 1.0;
8995 sampler_ci.anisotropyEnable = VK_FALSE;
8996 sampler_ci.maxAnisotropy = 1;
8997 sampler_ci.compareEnable = VK_FALSE;
8998 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8999 sampler_ci.minLod = 1.0;
9000 sampler_ci.maxLod = 1.0;
9001 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9002 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009003 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009004 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009005 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009006
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009007 VkDescriptorImageInfo info = {};
9008 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009009
9010 VkWriteDescriptorSet descriptor_write;
9011 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009012 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009013 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009014 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009015 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009016 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009017 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009018
9019 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9020
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009021 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009022
Chia-I Wuf7458c52015-10-26 21:10:41 +08009023 vkDestroySampler(m_device->device(), sampler, NULL);
9024 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9025 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009026}
9027
Karl Schultz6addd812016-02-02 17:17:23 -07009028TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009029 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009030 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9033 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009034
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009035 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009036 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9037 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009038 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009039 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9040 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009041
9042 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009043 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9044 ds_pool_ci.pNext = NULL;
9045 ds_pool_ci.maxSets = 1;
9046 ds_pool_ci.poolSizeCount = 1;
9047 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009048
9049 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009050 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009051 ASSERT_VK_SUCCESS(err);
9052
9053 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009054 dsl_binding.binding = 0;
9055 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9056 dsl_binding.descriptorCount = 1;
9057 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9058 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009059
9060 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009061 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9062 ds_layout_ci.pNext = NULL;
9063 ds_layout_ci.bindingCount = 1;
9064 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009065 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009067 ASSERT_VK_SUCCESS(err);
9068
9069 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009070 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009071 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009072 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009073 alloc_info.descriptorPool = ds_pool;
9074 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009076 ASSERT_VK_SUCCESS(err);
9077
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009078 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009079
9080 VkDescriptorImageInfo descriptor_info;
9081 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9082 descriptor_info.sampler = sampler;
9083
9084 VkWriteDescriptorSet descriptor_write;
9085 memset(&descriptor_write, 0, sizeof(descriptor_write));
9086 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009087 descriptor_write.dstSet = descriptorSet;
9088 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009089 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009090 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9091 descriptor_write.pImageInfo = &descriptor_info;
9092
9093 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9094
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009095 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009096
Chia-I Wuf7458c52015-10-26 21:10:41 +08009097 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9098 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009099}
9100
Karl Schultz6addd812016-02-02 17:17:23 -07009101TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9102 // Create a single combined Image/Sampler descriptor and send it an invalid
9103 // imageView
9104 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009105
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9107 "image sampler descriptor failed due "
9108 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009109
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009110 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009111 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009112 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9113 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009114
9115 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009116 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9117 ds_pool_ci.pNext = NULL;
9118 ds_pool_ci.maxSets = 1;
9119 ds_pool_ci.poolSizeCount = 1;
9120 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009121
9122 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009123 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009124 ASSERT_VK_SUCCESS(err);
9125
9126 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009127 dsl_binding.binding = 0;
9128 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9129 dsl_binding.descriptorCount = 1;
9130 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9131 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009132
9133 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009134 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9135 ds_layout_ci.pNext = NULL;
9136 ds_layout_ci.bindingCount = 1;
9137 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009138 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009139 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009140 ASSERT_VK_SUCCESS(err);
9141
9142 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009143 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009144 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009145 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009146 alloc_info.descriptorPool = ds_pool;
9147 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009148 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009149 ASSERT_VK_SUCCESS(err);
9150
9151 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009152 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9153 sampler_ci.pNext = NULL;
9154 sampler_ci.magFilter = VK_FILTER_NEAREST;
9155 sampler_ci.minFilter = VK_FILTER_NEAREST;
9156 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9157 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9158 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9159 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9160 sampler_ci.mipLodBias = 1.0;
9161 sampler_ci.anisotropyEnable = VK_FALSE;
9162 sampler_ci.maxAnisotropy = 1;
9163 sampler_ci.compareEnable = VK_FALSE;
9164 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9165 sampler_ci.minLod = 1.0;
9166 sampler_ci.maxLod = 1.0;
9167 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9168 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009169
9170 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009171 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009172 ASSERT_VK_SUCCESS(err);
9173
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009174 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009175
9176 VkDescriptorImageInfo descriptor_info;
9177 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9178 descriptor_info.sampler = sampler;
9179 descriptor_info.imageView = view;
9180
9181 VkWriteDescriptorSet descriptor_write;
9182 memset(&descriptor_write, 0, sizeof(descriptor_write));
9183 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009184 descriptor_write.dstSet = descriptorSet;
9185 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009186 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009187 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9188 descriptor_write.pImageInfo = &descriptor_info;
9189
9190 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9191
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009192 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009193
Chia-I Wuf7458c52015-10-26 21:10:41 +08009194 vkDestroySampler(m_device->device(), sampler, NULL);
9195 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9196 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009197}
9198
Karl Schultz6addd812016-02-02 17:17:23 -07009199TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9200 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9201 // into the other
9202 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9205 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9206 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009207
Tobin Ehlis04356f92015-10-27 16:35:27 -06009208 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009209 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009210 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009211 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9212 ds_type_count[0].descriptorCount = 1;
9213 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9214 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009215
9216 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009217 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9218 ds_pool_ci.pNext = NULL;
9219 ds_pool_ci.maxSets = 1;
9220 ds_pool_ci.poolSizeCount = 2;
9221 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009222
9223 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009224 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009225 ASSERT_VK_SUCCESS(err);
9226 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009227 dsl_binding[0].binding = 0;
9228 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9229 dsl_binding[0].descriptorCount = 1;
9230 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9231 dsl_binding[0].pImmutableSamplers = NULL;
9232 dsl_binding[1].binding = 1;
9233 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9234 dsl_binding[1].descriptorCount = 1;
9235 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9236 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009237
9238 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009239 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9240 ds_layout_ci.pNext = NULL;
9241 ds_layout_ci.bindingCount = 2;
9242 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009243
9244 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009245 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009246 ASSERT_VK_SUCCESS(err);
9247
9248 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009249 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009250 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009251 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009252 alloc_info.descriptorPool = ds_pool;
9253 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009254 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009255 ASSERT_VK_SUCCESS(err);
9256
9257 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009258 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9259 sampler_ci.pNext = NULL;
9260 sampler_ci.magFilter = VK_FILTER_NEAREST;
9261 sampler_ci.minFilter = VK_FILTER_NEAREST;
9262 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9263 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9264 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9265 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9266 sampler_ci.mipLodBias = 1.0;
9267 sampler_ci.anisotropyEnable = VK_FALSE;
9268 sampler_ci.maxAnisotropy = 1;
9269 sampler_ci.compareEnable = VK_FALSE;
9270 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9271 sampler_ci.minLod = 1.0;
9272 sampler_ci.maxLod = 1.0;
9273 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9274 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009275
9276 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009277 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009278 ASSERT_VK_SUCCESS(err);
9279
9280 VkDescriptorImageInfo info = {};
9281 info.sampler = sampler;
9282
9283 VkWriteDescriptorSet descriptor_write;
9284 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9285 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009286 descriptor_write.dstSet = descriptorSet;
9287 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009288 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009289 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9290 descriptor_write.pImageInfo = &info;
9291 // This write update should succeed
9292 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9293 // Now perform a copy update that fails due to type mismatch
9294 VkCopyDescriptorSet copy_ds_update;
9295 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9296 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9297 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009298 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009299 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009300 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009301 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009302 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009304 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009305 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009306 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 -06009307 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9308 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9309 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009310 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009311 copy_ds_update.dstSet = descriptorSet;
9312 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009313 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009314 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9315
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009316 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009317
Tobin Ehlis04356f92015-10-27 16:35:27 -06009318 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9320 "update array offset of 0 and update of "
9321 "5 descriptors oversteps total number "
9322 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009323
Tobin Ehlis04356f92015-10-27 16:35:27 -06009324 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9325 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9326 copy_ds_update.srcSet = descriptorSet;
9327 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009328 copy_ds_update.dstSet = descriptorSet;
9329 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009330 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009331 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9332
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009333 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009334
Chia-I Wuf7458c52015-10-26 21:10:41 +08009335 vkDestroySampler(m_device->device(), sampler, NULL);
9336 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9337 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009338}
9339
Karl Schultz6addd812016-02-02 17:17:23 -07009340TEST_F(VkLayerTest, NumSamplesMismatch) {
9341 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9342 // sampleCount
9343 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009344
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009346
Tobin Ehlis3b780662015-05-28 12:11:26 -06009347 ASSERT_NO_FATAL_FAILURE(InitState());
9348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009349 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009350 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009351 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009352
9353 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009354 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9355 ds_pool_ci.pNext = NULL;
9356 ds_pool_ci.maxSets = 1;
9357 ds_pool_ci.poolSizeCount = 1;
9358 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009359
Tobin Ehlis3b780662015-05-28 12:11:26 -06009360 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009361 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009362 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009363
Tony Barboureb254902015-07-15 12:50:33 -06009364 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009365 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009366 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009367 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009368 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9369 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009370
Tony Barboureb254902015-07-15 12:50:33 -06009371 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9372 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9373 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009374 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009375 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009376
Tobin Ehlis3b780662015-05-28 12:11:26 -06009377 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009378 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009379 ASSERT_VK_SUCCESS(err);
9380
9381 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009382 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009383 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009384 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009385 alloc_info.descriptorPool = ds_pool;
9386 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009387 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009388 ASSERT_VK_SUCCESS(err);
9389
Tony Barboureb254902015-07-15 12:50:33 -06009390 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009391 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009392 pipe_ms_state_ci.pNext = NULL;
9393 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9394 pipe_ms_state_ci.sampleShadingEnable = 0;
9395 pipe_ms_state_ci.minSampleShading = 1.0;
9396 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009397
Tony Barboureb254902015-07-15 12:50:33 -06009398 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009399 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9400 pipeline_layout_ci.pNext = NULL;
9401 pipeline_layout_ci.setLayoutCount = 1;
9402 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009403
9404 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009405 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009406 ASSERT_VK_SUCCESS(err);
9407
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009408 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9409 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9410 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009411 VkPipelineObj pipe(m_device);
9412 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009413 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009414 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009415 pipe.SetMSAA(&pipe_ms_state_ci);
9416 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009417
Tony Barbourfe3351b2015-07-28 10:17:20 -06009418 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009419 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009420
Mark Young29927482016-05-04 14:38:51 -06009421 // Render triangle (the error should trigger on the attempt to draw).
9422 Draw(3, 1, 0, 0);
9423
9424 // Finalize recording of the command buffer
9425 EndCommandBuffer();
9426
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009427 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009428
Chia-I Wuf7458c52015-10-26 21:10:41 +08009429 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9430 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9431 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009432}
Mark Young29927482016-05-04 14:38:51 -06009433
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009434TEST_F(VkLayerTest, RenderPassIncompatible) {
9435 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9436 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009437 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009438 VkResult err;
9439
9440 ASSERT_NO_FATAL_FAILURE(InitState());
9441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9442
9443 VkDescriptorSetLayoutBinding dsl_binding = {};
9444 dsl_binding.binding = 0;
9445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9446 dsl_binding.descriptorCount = 1;
9447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9448 dsl_binding.pImmutableSamplers = NULL;
9449
9450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9452 ds_layout_ci.pNext = NULL;
9453 ds_layout_ci.bindingCount = 1;
9454 ds_layout_ci.pBindings = &dsl_binding;
9455
9456 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009458 ASSERT_VK_SUCCESS(err);
9459
9460 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9461 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9462 pipeline_layout_ci.pNext = NULL;
9463 pipeline_layout_ci.setLayoutCount = 1;
9464 pipeline_layout_ci.pSetLayouts = &ds_layout;
9465
9466 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009467 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009468 ASSERT_VK_SUCCESS(err);
9469
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009470 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9471 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9472 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009473 // Create a renderpass that will be incompatible with default renderpass
9474 VkAttachmentReference attach = {};
9475 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9476 VkAttachmentReference color_att = {};
9477 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9478 VkSubpassDescription subpass = {};
9479 subpass.inputAttachmentCount = 1;
9480 subpass.pInputAttachments = &attach;
9481 subpass.colorAttachmentCount = 1;
9482 subpass.pColorAttachments = &color_att;
9483 VkRenderPassCreateInfo rpci = {};
9484 rpci.subpassCount = 1;
9485 rpci.pSubpasses = &subpass;
9486 rpci.attachmentCount = 1;
9487 VkAttachmentDescription attach_desc = {};
9488 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009489 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9490 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009491 rpci.pAttachments = &attach_desc;
9492 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9493 VkRenderPass rp;
9494 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9495 VkPipelineObj pipe(m_device);
9496 pipe.AddShader(&vs);
9497 pipe.AddShader(&fs);
9498 pipe.AddColorAttachment();
9499 VkViewport view_port = {};
9500 m_viewports.push_back(view_port);
9501 pipe.SetViewport(m_viewports);
9502 VkRect2D rect = {};
9503 m_scissors.push_back(rect);
9504 pipe.SetScissor(m_scissors);
9505 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9506
9507 VkCommandBufferInheritanceInfo cbii = {};
9508 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9509 cbii.renderPass = rp;
9510 cbii.subpass = 0;
9511 VkCommandBufferBeginInfo cbbi = {};
9512 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9513 cbbi.pInheritanceInfo = &cbii;
9514 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9515 VkRenderPassBeginInfo rpbi = {};
9516 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9517 rpbi.framebuffer = m_framebuffer;
9518 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009519 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9520 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009521
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009523 // Render triangle (the error should trigger on the attempt to draw).
9524 Draw(3, 1, 0, 0);
9525
9526 // Finalize recording of the command buffer
9527 EndCommandBuffer();
9528
9529 m_errorMonitor->VerifyFound();
9530
9531 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9532 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9533 vkDestroyRenderPass(m_device->device(), rp, NULL);
9534}
9535
Mark Youngc89c6312016-03-31 16:03:20 -06009536TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9537 // Create Pipeline where the number of blend attachments doesn't match the
9538 // number of color attachments. In this case, we don't add any color
9539 // blend attachments even though we have a color attachment.
9540 VkResult err;
9541
9542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009543 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009544
9545 ASSERT_NO_FATAL_FAILURE(InitState());
9546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9547 VkDescriptorPoolSize ds_type_count = {};
9548 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9549 ds_type_count.descriptorCount = 1;
9550
9551 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9552 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9553 ds_pool_ci.pNext = NULL;
9554 ds_pool_ci.maxSets = 1;
9555 ds_pool_ci.poolSizeCount = 1;
9556 ds_pool_ci.pPoolSizes = &ds_type_count;
9557
9558 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009559 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009560 ASSERT_VK_SUCCESS(err);
9561
9562 VkDescriptorSetLayoutBinding dsl_binding = {};
9563 dsl_binding.binding = 0;
9564 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9565 dsl_binding.descriptorCount = 1;
9566 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9567 dsl_binding.pImmutableSamplers = NULL;
9568
9569 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9570 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9571 ds_layout_ci.pNext = NULL;
9572 ds_layout_ci.bindingCount = 1;
9573 ds_layout_ci.pBindings = &dsl_binding;
9574
9575 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009576 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009577 ASSERT_VK_SUCCESS(err);
9578
9579 VkDescriptorSet descriptorSet;
9580 VkDescriptorSetAllocateInfo alloc_info = {};
9581 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9582 alloc_info.descriptorSetCount = 1;
9583 alloc_info.descriptorPool = ds_pool;
9584 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009585 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009586 ASSERT_VK_SUCCESS(err);
9587
9588 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009589 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009590 pipe_ms_state_ci.pNext = NULL;
9591 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9592 pipe_ms_state_ci.sampleShadingEnable = 0;
9593 pipe_ms_state_ci.minSampleShading = 1.0;
9594 pipe_ms_state_ci.pSampleMask = NULL;
9595
9596 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9597 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9598 pipeline_layout_ci.pNext = NULL;
9599 pipeline_layout_ci.setLayoutCount = 1;
9600 pipeline_layout_ci.pSetLayouts = &ds_layout;
9601
9602 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009604 ASSERT_VK_SUCCESS(err);
9605
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009606 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9607 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9608 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009609 VkPipelineObj pipe(m_device);
9610 pipe.AddShader(&vs);
9611 pipe.AddShader(&fs);
9612 pipe.SetMSAA(&pipe_ms_state_ci);
9613 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9614
9615 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009616 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009617
Mark Young29927482016-05-04 14:38:51 -06009618 // Render triangle (the error should trigger on the attempt to draw).
9619 Draw(3, 1, 0, 0);
9620
9621 // Finalize recording of the command buffer
9622 EndCommandBuffer();
9623
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009624 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009625
9626 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9627 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9628 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9629}
Mark Young29927482016-05-04 14:38:51 -06009630
Mark Muellerd4914412016-06-13 17:52:06 -06009631TEST_F(VkLayerTest, MissingClearAttachment) {
9632 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9633 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009634 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009636 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009637
9638 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9639 m_errorMonitor->VerifyFound();
9640}
9641
Karl Schultz6addd812016-02-02 17:17:23 -07009642TEST_F(VkLayerTest, ClearCmdNoDraw) {
9643 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9644 // to issuing a Draw
9645 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009646
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009648 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009649
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009650 ASSERT_NO_FATAL_FAILURE(InitState());
9651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009652
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009653 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009654 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9655 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009656
9657 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009658 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9659 ds_pool_ci.pNext = NULL;
9660 ds_pool_ci.maxSets = 1;
9661 ds_pool_ci.poolSizeCount = 1;
9662 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009663
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009664 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009665 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009666 ASSERT_VK_SUCCESS(err);
9667
Tony Barboureb254902015-07-15 12:50:33 -06009668 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009669 dsl_binding.binding = 0;
9670 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9671 dsl_binding.descriptorCount = 1;
9672 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9673 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009674
Tony Barboureb254902015-07-15 12:50:33 -06009675 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009676 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9677 ds_layout_ci.pNext = NULL;
9678 ds_layout_ci.bindingCount = 1;
9679 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009680
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009681 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009682 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009683 ASSERT_VK_SUCCESS(err);
9684
9685 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009686 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009687 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009688 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009689 alloc_info.descriptorPool = ds_pool;
9690 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009691 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009692 ASSERT_VK_SUCCESS(err);
9693
Tony Barboureb254902015-07-15 12:50:33 -06009694 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009695 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009696 pipe_ms_state_ci.pNext = NULL;
9697 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9698 pipe_ms_state_ci.sampleShadingEnable = 0;
9699 pipe_ms_state_ci.minSampleShading = 1.0;
9700 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009701
Tony Barboureb254902015-07-15 12:50:33 -06009702 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009703 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9704 pipeline_layout_ci.pNext = NULL;
9705 pipeline_layout_ci.setLayoutCount = 1;
9706 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009707
9708 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009709 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009710 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009712 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009713 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009714 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009715 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009716
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009717 VkPipelineObj pipe(m_device);
9718 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009719 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009720 pipe.SetMSAA(&pipe_ms_state_ci);
9721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009722
9723 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009724
Karl Schultz6addd812016-02-02 17:17:23 -07009725 // Main thing we care about for this test is that the VkImage obj we're
9726 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009727 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009728 VkClearAttachment color_attachment;
9729 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9730 color_attachment.clearValue.color.float32[0] = 1.0;
9731 color_attachment.clearValue.color.float32[1] = 1.0;
9732 color_attachment.clearValue.color.float32[2] = 1.0;
9733 color_attachment.clearValue.color.float32[3] = 1.0;
9734 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009735 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009736
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009737 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009738
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009739 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009740
Chia-I Wuf7458c52015-10-26 21:10:41 +08009741 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9742 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9743 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009744}
9745
Karl Schultz6addd812016-02-02 17:17:23 -07009746TEST_F(VkLayerTest, VtxBufferBadIndex) {
9747 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9750 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009751
Tobin Ehlis502480b2015-06-24 15:53:07 -06009752 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009753 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009755
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009756 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009757 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9758 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009759
9760 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009761 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9762 ds_pool_ci.pNext = NULL;
9763 ds_pool_ci.maxSets = 1;
9764 ds_pool_ci.poolSizeCount = 1;
9765 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009766
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009767 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009768 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009769 ASSERT_VK_SUCCESS(err);
9770
Tony Barboureb254902015-07-15 12:50:33 -06009771 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009772 dsl_binding.binding = 0;
9773 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9774 dsl_binding.descriptorCount = 1;
9775 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9776 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009777
Tony Barboureb254902015-07-15 12:50:33 -06009778 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009779 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9780 ds_layout_ci.pNext = NULL;
9781 ds_layout_ci.bindingCount = 1;
9782 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009783
Tobin Ehlis502480b2015-06-24 15:53:07 -06009784 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009785 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009786 ASSERT_VK_SUCCESS(err);
9787
9788 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009789 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009790 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009791 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009792 alloc_info.descriptorPool = ds_pool;
9793 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009794 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009795 ASSERT_VK_SUCCESS(err);
9796
Tony Barboureb254902015-07-15 12:50:33 -06009797 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009798 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009799 pipe_ms_state_ci.pNext = NULL;
9800 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9801 pipe_ms_state_ci.sampleShadingEnable = 0;
9802 pipe_ms_state_ci.minSampleShading = 1.0;
9803 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009804
Tony Barboureb254902015-07-15 12:50:33 -06009805 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009806 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9807 pipeline_layout_ci.pNext = NULL;
9808 pipeline_layout_ci.setLayoutCount = 1;
9809 pipeline_layout_ci.pSetLayouts = &ds_layout;
9810 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009811
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009812 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009813 ASSERT_VK_SUCCESS(err);
9814
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009815 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9816 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9817 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009818 VkPipelineObj pipe(m_device);
9819 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009820 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009821 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009822 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009823 pipe.SetViewport(m_viewports);
9824 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009825 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009826
9827 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009828 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009829 // Don't care about actual data, just need to get to draw to flag error
9830 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009831 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009832 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009833 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009834
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009835 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009836
Chia-I Wuf7458c52015-10-26 21:10:41 +08009837 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9838 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9839 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009840}
Mark Muellerdfe37552016-07-07 14:47:42 -06009841
Mark Mueller2ee294f2016-08-04 12:59:48 -06009842TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9843 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9844 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009845 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009847 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9848 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009850 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9851 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009852
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009853 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009856 // The following test fails with recent NVidia drivers.
9857 // By the time core_validation is reached, the NVidia
9858 // driver has sanitized the invalid condition and core_validation
9859 // is not introduced to the failure condition. This is not the case
9860 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009861 // uint32_t count = static_cast<uint32_t>(~0);
9862 // VkPhysicalDevice physical_device;
9863 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9864 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009865
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009867 float queue_priority = 0.0;
9868
9869 VkDeviceQueueCreateInfo queue_create_info = {};
9870 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9871 queue_create_info.queueCount = 1;
9872 queue_create_info.pQueuePriorities = &queue_priority;
9873 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9874
9875 VkPhysicalDeviceFeatures features = m_device->phy().features();
9876 VkDevice testDevice;
9877 VkDeviceCreateInfo device_create_info = {};
9878 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9879 device_create_info.queueCreateInfoCount = 1;
9880 device_create_info.pQueueCreateInfos = &queue_create_info;
9881 device_create_info.pEnabledFeatures = &features;
9882 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9883 m_errorMonitor->VerifyFound();
9884
9885 queue_create_info.queueFamilyIndex = 1;
9886
9887 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
9888 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
9889 for (unsigned i = 0; i < feature_count; i++) {
9890 if (VK_FALSE == feature_array[i]) {
9891 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009893 device_create_info.pEnabledFeatures = &features;
9894 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9895 m_errorMonitor->VerifyFound();
9896 break;
9897 }
9898 }
9899}
9900
9901TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
9902 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
9903 "End a command buffer with a query still in progress.");
9904
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009905 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
9906 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
9907 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009909 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009910
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009912
9913 ASSERT_NO_FATAL_FAILURE(InitState());
9914
9915 VkEvent event;
9916 VkEventCreateInfo event_create_info{};
9917 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9918 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9919
Mark Mueller2ee294f2016-08-04 12:59:48 -06009920 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009921 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009922
9923 BeginCommandBuffer();
9924
9925 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009926 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 -06009927 ASSERT_TRUE(image.initialized());
9928 VkImageMemoryBarrier img_barrier = {};
9929 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9930 img_barrier.pNext = NULL;
9931 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9932 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9933 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9934 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9935 img_barrier.image = image.handle();
9936 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -06009937
9938 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
9939 // that layer validation catches the case when it is not.
9940 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -06009941 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9942 img_barrier.subresourceRange.baseArrayLayer = 0;
9943 img_barrier.subresourceRange.baseMipLevel = 0;
9944 img_barrier.subresourceRange.layerCount = 1;
9945 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009946 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
9947 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009948 m_errorMonitor->VerifyFound();
9949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009951
9952 VkQueryPool query_pool;
9953 VkQueryPoolCreateInfo query_pool_create_info = {};
9954 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
9955 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
9956 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009957 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009959 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009960 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
9961
9962 vkEndCommandBuffer(m_commandBuffer->handle());
9963 m_errorMonitor->VerifyFound();
9964
9965 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
9966 vkDestroyEvent(m_device->device(), event, nullptr);
9967}
9968
Mark Muellerdfe37552016-07-07 14:47:42 -06009969TEST_F(VkLayerTest, VertexBufferInvalid) {
9970 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
9971 "delete a buffer twice, use an invalid offset for each "
9972 "buffer type, and attempt to bind a null buffer");
9973
9974 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
9975 "using deleted buffer ";
9976 const char *double_destroy_message = "Cannot free buffer 0x";
9977 const char *invalid_offset_message = "vkBindBufferMemory(): "
9978 "memoryOffset is 0x";
9979 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
9980 "storage memoryOffset "
9981 "is 0x";
9982 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
9983 "texel memoryOffset "
9984 "is 0x";
9985 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
9986 "uniform memoryOffset "
9987 "is 0x";
9988 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
9989 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -06009990 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -06009991
9992 ASSERT_NO_FATAL_FAILURE(InitState());
9993 ASSERT_NO_FATAL_FAILURE(InitViewport());
9994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9995
9996 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009997 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -06009998 pipe_ms_state_ci.pNext = NULL;
9999 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10000 pipe_ms_state_ci.sampleShadingEnable = 0;
10001 pipe_ms_state_ci.minSampleShading = 1.0;
10002 pipe_ms_state_ci.pSampleMask = nullptr;
10003
10004 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10005 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10006 VkPipelineLayout pipeline_layout;
10007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010008 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010009 ASSERT_VK_SUCCESS(err);
10010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010011 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10012 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010013 VkPipelineObj pipe(m_device);
10014 pipe.AddShader(&vs);
10015 pipe.AddShader(&fs);
10016 pipe.AddColorAttachment();
10017 pipe.SetMSAA(&pipe_ms_state_ci);
10018 pipe.SetViewport(m_viewports);
10019 pipe.SetScissor(m_scissors);
10020 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10021
10022 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010023 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010024
10025 {
10026 // Create and bind a vertex buffer in a reduced scope, which will cause
10027 // it to be deleted upon leaving this scope
10028 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010029 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010030 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10031 draw_verticies.AddVertexInputToPipe(pipe);
10032 }
10033
10034 Draw(1, 0, 0, 0);
10035
10036 EndCommandBuffer();
10037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010039 QueueCommandBuffer(false);
10040 m_errorMonitor->VerifyFound();
10041
10042 {
10043 // Create and bind a vertex buffer in a reduced scope, and delete it
10044 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010045 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010047 buffer_test.TestDoubleDestroy();
10048 }
10049 m_errorMonitor->VerifyFound();
10050
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010051 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010052 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10054 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10055 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010056 m_errorMonitor->VerifyFound();
10057 }
10058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010059 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10060 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010061 // Create and bind a memory buffer with an invalid offset again,
10062 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10064 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10065 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010066 m_errorMonitor->VerifyFound();
10067 }
10068
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010069 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010070 // Create and bind a memory buffer with an invalid offset again, but
10071 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10073 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10074 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010075 m_errorMonitor->VerifyFound();
10076 }
10077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010078 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010079 // Create and bind a memory buffer with an invalid offset again, but
10080 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10082 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10083 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010084 m_errorMonitor->VerifyFound();
10085 }
10086
10087 {
10088 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10090 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10091 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010092 m_errorMonitor->VerifyFound();
10093 }
10094
10095 {
10096 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10098 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10099 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010100 }
10101 m_errorMonitor->VerifyFound();
10102
10103 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10104}
10105
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010106// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10107TEST_F(VkLayerTest, InvalidImageLayout) {
10108 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010109 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10110 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010111 // 3 in ValidateCmdBufImageLayouts
10112 // * -1 Attempt to submit cmd buf w/ deleted image
10113 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10114 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10116 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010117
10118 ASSERT_NO_FATAL_FAILURE(InitState());
10119 // Create src & dst images to use for copy operations
10120 VkImage src_image;
10121 VkImage dst_image;
10122
10123 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10124 const int32_t tex_width = 32;
10125 const int32_t tex_height = 32;
10126
10127 VkImageCreateInfo image_create_info = {};
10128 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10129 image_create_info.pNext = NULL;
10130 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10131 image_create_info.format = tex_format;
10132 image_create_info.extent.width = tex_width;
10133 image_create_info.extent.height = tex_height;
10134 image_create_info.extent.depth = 1;
10135 image_create_info.mipLevels = 1;
10136 image_create_info.arrayLayers = 4;
10137 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10138 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10139 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10140 image_create_info.flags = 0;
10141
10142 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10143 ASSERT_VK_SUCCESS(err);
10144 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10145 ASSERT_VK_SUCCESS(err);
10146
10147 BeginCommandBuffer();
10148 VkImageCopy copyRegion;
10149 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10150 copyRegion.srcSubresource.mipLevel = 0;
10151 copyRegion.srcSubresource.baseArrayLayer = 0;
10152 copyRegion.srcSubresource.layerCount = 1;
10153 copyRegion.srcOffset.x = 0;
10154 copyRegion.srcOffset.y = 0;
10155 copyRegion.srcOffset.z = 0;
10156 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10157 copyRegion.dstSubresource.mipLevel = 0;
10158 copyRegion.dstSubresource.baseArrayLayer = 0;
10159 copyRegion.dstSubresource.layerCount = 1;
10160 copyRegion.dstOffset.x = 0;
10161 copyRegion.dstOffset.y = 0;
10162 copyRegion.dstOffset.z = 0;
10163 copyRegion.extent.width = 1;
10164 copyRegion.extent.height = 1;
10165 copyRegion.extent.depth = 1;
10166 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10167 m_errorMonitor->VerifyFound();
10168 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10170 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10171 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010172 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10173 m_errorMonitor->VerifyFound();
10174 // Final src error is due to bad layout type
10175 m_errorMonitor->SetDesiredFailureMsg(
10176 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10177 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10178 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10179 m_errorMonitor->VerifyFound();
10180 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10182 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010183 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10184 m_errorMonitor->VerifyFound();
10185 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10187 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10188 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010189 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10190 m_errorMonitor->VerifyFound();
10191 m_errorMonitor->SetDesiredFailureMsg(
10192 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10193 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10194 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10195 m_errorMonitor->VerifyFound();
10196 // Now cause error due to bad image layout transition in PipelineBarrier
10197 VkImageMemoryBarrier image_barrier[1] = {};
10198 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10199 image_barrier[0].image = src_image;
10200 image_barrier[0].subresourceRange.layerCount = 2;
10201 image_barrier[0].subresourceRange.levelCount = 2;
10202 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10204 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10205 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10206 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10207 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010208 m_errorMonitor->VerifyFound();
10209
10210 // Finally some layout errors at RenderPass create time
10211 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10212 VkAttachmentReference attach = {};
10213 // perf warning for GENERAL layout w/ non-DS input attachment
10214 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10215 VkSubpassDescription subpass = {};
10216 subpass.inputAttachmentCount = 1;
10217 subpass.pInputAttachments = &attach;
10218 VkRenderPassCreateInfo rpci = {};
10219 rpci.subpassCount = 1;
10220 rpci.pSubpasses = &subpass;
10221 rpci.attachmentCount = 1;
10222 VkAttachmentDescription attach_desc = {};
10223 attach_desc.format = VK_FORMAT_UNDEFINED;
10224 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010225 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010226 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10228 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010229 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10230 m_errorMonitor->VerifyFound();
10231 // error w/ non-general layout
10232 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10233
10234 m_errorMonitor->SetDesiredFailureMsg(
10235 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10236 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10237 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10238 m_errorMonitor->VerifyFound();
10239 subpass.inputAttachmentCount = 0;
10240 subpass.colorAttachmentCount = 1;
10241 subpass.pColorAttachments = &attach;
10242 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10243 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10245 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010246 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10247 m_errorMonitor->VerifyFound();
10248 // error w/ non-color opt or GENERAL layout for color attachment
10249 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10250 m_errorMonitor->SetDesiredFailureMsg(
10251 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10252 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10253 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10254 m_errorMonitor->VerifyFound();
10255 subpass.colorAttachmentCount = 0;
10256 subpass.pDepthStencilAttachment = &attach;
10257 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10258 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10260 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010261 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10262 m_errorMonitor->VerifyFound();
10263 // error w/ non-ds opt or GENERAL layout for color attachment
10264 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10266 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10267 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010268 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10269 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010270 // For this error we need a valid renderpass so create default one
10271 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10272 attach.attachment = 0;
10273 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10274 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10275 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10276 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10277 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10278 // Can't do a CLEAR load on READ_ONLY initialLayout
10279 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10280 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10281 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10283 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10284 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010285 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10286 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010287
10288 vkDestroyImage(m_device->device(), src_image, NULL);
10289 vkDestroyImage(m_device->device(), dst_image, NULL);
10290}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010291
Tobin Ehlise0936662016-10-11 08:10:51 -060010292TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10293 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10294 VkResult err;
10295
10296 ASSERT_NO_FATAL_FAILURE(InitState());
10297
10298 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10299 VkImageTiling tiling;
10300 VkFormatProperties format_properties;
10301 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10302 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10303 tiling = VK_IMAGE_TILING_LINEAR;
10304 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10305 tiling = VK_IMAGE_TILING_OPTIMAL;
10306 } else {
10307 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10308 "skipped.\n");
10309 return;
10310 }
10311
10312 VkDescriptorPoolSize ds_type = {};
10313 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10314 ds_type.descriptorCount = 1;
10315
10316 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10317 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10318 ds_pool_ci.maxSets = 1;
10319 ds_pool_ci.poolSizeCount = 1;
10320 ds_pool_ci.pPoolSizes = &ds_type;
10321 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10322
10323 VkDescriptorPool ds_pool;
10324 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10325 ASSERT_VK_SUCCESS(err);
10326
10327 VkDescriptorSetLayoutBinding dsl_binding = {};
10328 dsl_binding.binding = 0;
10329 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10330 dsl_binding.descriptorCount = 1;
10331 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10332 dsl_binding.pImmutableSamplers = NULL;
10333
10334 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10335 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10336 ds_layout_ci.pNext = NULL;
10337 ds_layout_ci.bindingCount = 1;
10338 ds_layout_ci.pBindings = &dsl_binding;
10339
10340 VkDescriptorSetLayout ds_layout;
10341 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10342 ASSERT_VK_SUCCESS(err);
10343
10344 VkDescriptorSetAllocateInfo alloc_info = {};
10345 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10346 alloc_info.descriptorSetCount = 1;
10347 alloc_info.descriptorPool = ds_pool;
10348 alloc_info.pSetLayouts = &ds_layout;
10349 VkDescriptorSet descriptor_set;
10350 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10351 ASSERT_VK_SUCCESS(err);
10352
10353 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10354 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10355 pipeline_layout_ci.pNext = NULL;
10356 pipeline_layout_ci.setLayoutCount = 1;
10357 pipeline_layout_ci.pSetLayouts = &ds_layout;
10358 VkPipelineLayout pipeline_layout;
10359 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10360 ASSERT_VK_SUCCESS(err);
10361
10362 VkImageObj image(m_device);
10363 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10364 ASSERT_TRUE(image.initialized());
10365 VkImageView view = image.targetView(tex_format);
10366
10367 VkDescriptorImageInfo image_info = {};
10368 image_info.imageView = view;
10369 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10370
10371 VkWriteDescriptorSet descriptor_write = {};
10372 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10373 descriptor_write.dstSet = descriptor_set;
10374 descriptor_write.dstBinding = 0;
10375 descriptor_write.descriptorCount = 1;
10376 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10377 descriptor_write.pImageInfo = &image_info;
10378
10379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10380 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10381 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10382 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10383 m_errorMonitor->VerifyFound();
10384
10385 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10386 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10387 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10388 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10389}
10390
Mark Mueller93b938f2016-08-18 10:27:40 -060010391TEST_F(VkLayerTest, SimultaneousUse) {
10392 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10393 "in primary and secondary command buffers.");
10394
10395 ASSERT_NO_FATAL_FAILURE(InitState());
10396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10397
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010398 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010399 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10400 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010401
10402 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010403 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010404 command_buffer_allocate_info.commandPool = m_commandPool;
10405 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10406 command_buffer_allocate_info.commandBufferCount = 1;
10407
10408 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010409 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010410 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10411 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010412 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010413 command_buffer_inheritance_info.renderPass = m_renderPass;
10414 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10415 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010416 command_buffer_begin_info.flags =
10417 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010418 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10419
10420 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010421 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10422 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010423 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010424 vkEndCommandBuffer(secondary_command_buffer);
10425
Mark Mueller93b938f2016-08-18 10:27:40 -060010426 VkSubmitInfo submit_info = {};
10427 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10428 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010429 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010430 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010431
Mark Mueller4042b652016-09-05 22:52:21 -060010432 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010433 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10435 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010436 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010437 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10438 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010439
10440 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010441 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10442
Mark Mueller4042b652016-09-05 22:52:21 -060010443 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010444 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010445 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10448 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010449 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010450 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10451 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010452}
10453
Mark Mueller917f6bc2016-08-30 10:57:19 -060010454TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10455 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10456 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010457 "Delete objects that are inuse. Call VkQueueSubmit "
10458 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010459
10460 ASSERT_NO_FATAL_FAILURE(InitState());
10461 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010463 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10464 const char *cannot_delete_event_message = "Cannot delete event 0x";
10465 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10466 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010467
10468 BeginCommandBuffer();
10469
10470 VkEvent event;
10471 VkEventCreateInfo event_create_info = {};
10472 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10473 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010474 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010475
Mark Muellerc8d441e2016-08-23 17:36:00 -060010476 EndCommandBuffer();
10477 vkDestroyEvent(m_device->device(), event, nullptr);
10478
10479 VkSubmitInfo submit_info = {};
10480 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10481 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010482 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010484 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10485 m_errorMonitor->VerifyFound();
10486
10487 m_errorMonitor->SetDesiredFailureMsg(0, "");
10488 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10489
10490 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10491
Mark Mueller917f6bc2016-08-30 10:57:19 -060010492 VkSemaphoreCreateInfo semaphore_create_info = {};
10493 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10494 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010495 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010496 VkFenceCreateInfo fence_create_info = {};
10497 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10498 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010499 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010500
10501 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010502 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010503 descriptor_pool_type_count.descriptorCount = 1;
10504
10505 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10506 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10507 descriptor_pool_create_info.maxSets = 1;
10508 descriptor_pool_create_info.poolSizeCount = 1;
10509 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010510 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010511
10512 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010513 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010514
10515 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010516 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010517 descriptorset_layout_binding.descriptorCount = 1;
10518 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10519
10520 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010521 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010522 descriptorset_layout_create_info.bindingCount = 1;
10523 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10524
10525 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010526 ASSERT_VK_SUCCESS(
10527 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010528
10529 VkDescriptorSet descriptorset;
10530 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010531 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010532 descriptorset_allocate_info.descriptorSetCount = 1;
10533 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10534 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010535 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010536
Mark Mueller4042b652016-09-05 22:52:21 -060010537 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10538
10539 VkDescriptorBufferInfo buffer_info = {};
10540 buffer_info.buffer = buffer_test.GetBuffer();
10541 buffer_info.offset = 0;
10542 buffer_info.range = 1024;
10543
10544 VkWriteDescriptorSet write_descriptor_set = {};
10545 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10546 write_descriptor_set.dstSet = descriptorset;
10547 write_descriptor_set.descriptorCount = 1;
10548 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10549 write_descriptor_set.pBufferInfo = &buffer_info;
10550
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010551 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010552
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010553 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10554 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010555
10556 VkPipelineObj pipe(m_device);
10557 pipe.AddColorAttachment();
10558 pipe.AddShader(&vs);
10559 pipe.AddShader(&fs);
10560
10561 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010562 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010563 pipeline_layout_create_info.setLayoutCount = 1;
10564 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10565
10566 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010567 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010568
10569 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10570
Mark Muellerc8d441e2016-08-23 17:36:00 -060010571 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010572 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010573
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010574 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10575 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10576 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010577
Mark Muellerc8d441e2016-08-23 17:36:00 -060010578 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010579
Mark Mueller917f6bc2016-08-30 10:57:19 -060010580 submit_info.signalSemaphoreCount = 1;
10581 submit_info.pSignalSemaphores = &semaphore;
10582 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010583
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010585 vkDestroyEvent(m_device->device(), event, nullptr);
10586 m_errorMonitor->VerifyFound();
10587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010589 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10590 m_errorMonitor->VerifyFound();
10591
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010593 vkDestroyFence(m_device->device(), fence, nullptr);
10594 m_errorMonitor->VerifyFound();
10595
Tobin Ehlis122207b2016-09-01 08:50:06 -070010596 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010597 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10598 vkDestroyFence(m_device->device(), fence, nullptr);
10599 vkDestroyEvent(m_device->device(), event, nullptr);
10600 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010601 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010602 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10603}
10604
Tobin Ehlis2adda372016-09-01 08:51:06 -070010605TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10606 TEST_DESCRIPTION("Delete in-use query pool.");
10607
10608 ASSERT_NO_FATAL_FAILURE(InitState());
10609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10610
10611 VkQueryPool query_pool;
10612 VkQueryPoolCreateInfo query_pool_ci{};
10613 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10614 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10615 query_pool_ci.queryCount = 1;
10616 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10617 BeginCommandBuffer();
10618 // Reset query pool to create binding with cmd buffer
10619 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10620
10621 EndCommandBuffer();
10622
10623 VkSubmitInfo submit_info = {};
10624 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10625 submit_info.commandBufferCount = 1;
10626 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10627 // Submit cmd buffer and then destroy query pool while in-flight
10628 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010631 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10632 m_errorMonitor->VerifyFound();
10633
10634 vkQueueWaitIdle(m_device->m_queue);
10635 // Now that cmd buffer done we can safely destroy query_pool
10636 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10637}
10638
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010639TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10640 TEST_DESCRIPTION("Delete in-use pipeline.");
10641
10642 ASSERT_NO_FATAL_FAILURE(InitState());
10643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10644
10645 // Empty pipeline layout used for binding PSO
10646 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10647 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10648 pipeline_layout_ci.setLayoutCount = 0;
10649 pipeline_layout_ci.pSetLayouts = NULL;
10650
10651 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010652 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010653 ASSERT_VK_SUCCESS(err);
10654
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010656 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010657 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10658 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010659 // Store pipeline handle so we can actually delete it before test finishes
10660 VkPipeline delete_this_pipeline;
10661 { // Scope pipeline so it will be auto-deleted
10662 VkPipelineObj pipe(m_device);
10663 pipe.AddShader(&vs);
10664 pipe.AddShader(&fs);
10665 pipe.AddColorAttachment();
10666 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10667 delete_this_pipeline = pipe.handle();
10668
10669 BeginCommandBuffer();
10670 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010671 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010672
10673 EndCommandBuffer();
10674
10675 VkSubmitInfo submit_info = {};
10676 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10677 submit_info.commandBufferCount = 1;
10678 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10679 // Submit cmd buffer and then pipeline destroyed while in-flight
10680 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10681 } // Pipeline deletion triggered here
10682 m_errorMonitor->VerifyFound();
10683 // Make sure queue finished and then actually delete pipeline
10684 vkQueueWaitIdle(m_device->m_queue);
10685 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10686 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10687}
10688
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010689TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10690 TEST_DESCRIPTION("Delete in-use imageView.");
10691
10692 ASSERT_NO_FATAL_FAILURE(InitState());
10693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10694
10695 VkDescriptorPoolSize ds_type_count;
10696 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10697 ds_type_count.descriptorCount = 1;
10698
10699 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10700 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10701 ds_pool_ci.maxSets = 1;
10702 ds_pool_ci.poolSizeCount = 1;
10703 ds_pool_ci.pPoolSizes = &ds_type_count;
10704
10705 VkDescriptorPool ds_pool;
10706 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10707 ASSERT_VK_SUCCESS(err);
10708
10709 VkSamplerCreateInfo sampler_ci = {};
10710 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10711 sampler_ci.pNext = NULL;
10712 sampler_ci.magFilter = VK_FILTER_NEAREST;
10713 sampler_ci.minFilter = VK_FILTER_NEAREST;
10714 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10715 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10716 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10717 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10718 sampler_ci.mipLodBias = 1.0;
10719 sampler_ci.anisotropyEnable = VK_FALSE;
10720 sampler_ci.maxAnisotropy = 1;
10721 sampler_ci.compareEnable = VK_FALSE;
10722 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10723 sampler_ci.minLod = 1.0;
10724 sampler_ci.maxLod = 1.0;
10725 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10726 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10727 VkSampler sampler;
10728
10729 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10730 ASSERT_VK_SUCCESS(err);
10731
10732 VkDescriptorSetLayoutBinding layout_binding;
10733 layout_binding.binding = 0;
10734 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10735 layout_binding.descriptorCount = 1;
10736 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10737 layout_binding.pImmutableSamplers = NULL;
10738
10739 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10740 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10741 ds_layout_ci.bindingCount = 1;
10742 ds_layout_ci.pBindings = &layout_binding;
10743 VkDescriptorSetLayout ds_layout;
10744 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10745 ASSERT_VK_SUCCESS(err);
10746
10747 VkDescriptorSetAllocateInfo alloc_info = {};
10748 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10749 alloc_info.descriptorSetCount = 1;
10750 alloc_info.descriptorPool = ds_pool;
10751 alloc_info.pSetLayouts = &ds_layout;
10752 VkDescriptorSet descriptor_set;
10753 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10754 ASSERT_VK_SUCCESS(err);
10755
10756 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10757 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10758 pipeline_layout_ci.pNext = NULL;
10759 pipeline_layout_ci.setLayoutCount = 1;
10760 pipeline_layout_ci.pSetLayouts = &ds_layout;
10761
10762 VkPipelineLayout pipeline_layout;
10763 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10764 ASSERT_VK_SUCCESS(err);
10765
10766 VkImageObj image(m_device);
10767 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10768 ASSERT_TRUE(image.initialized());
10769
10770 VkImageView view;
10771 VkImageViewCreateInfo ivci = {};
10772 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10773 ivci.image = image.handle();
10774 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10775 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10776 ivci.subresourceRange.layerCount = 1;
10777 ivci.subresourceRange.baseMipLevel = 0;
10778 ivci.subresourceRange.levelCount = 1;
10779 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10780
10781 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10782 ASSERT_VK_SUCCESS(err);
10783
10784 VkDescriptorImageInfo image_info{};
10785 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10786 image_info.imageView = view;
10787 image_info.sampler = sampler;
10788
10789 VkWriteDescriptorSet descriptor_write = {};
10790 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10791 descriptor_write.dstSet = descriptor_set;
10792 descriptor_write.dstBinding = 0;
10793 descriptor_write.descriptorCount = 1;
10794 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10795 descriptor_write.pImageInfo = &image_info;
10796
10797 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10798
10799 // Create PSO to use the sampler
10800 char const *vsSource = "#version 450\n"
10801 "\n"
10802 "out gl_PerVertex { \n"
10803 " vec4 gl_Position;\n"
10804 "};\n"
10805 "void main(){\n"
10806 " gl_Position = vec4(1);\n"
10807 "}\n";
10808 char const *fsSource = "#version 450\n"
10809 "\n"
10810 "layout(set=0, binding=0) uniform sampler2D s;\n"
10811 "layout(location=0) out vec4 x;\n"
10812 "void main(){\n"
10813 " x = texture(s, vec2(1));\n"
10814 "}\n";
10815 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10816 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10817 VkPipelineObj pipe(m_device);
10818 pipe.AddShader(&vs);
10819 pipe.AddShader(&fs);
10820 pipe.AddColorAttachment();
10821 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10822
10823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10824
10825 BeginCommandBuffer();
10826 // Bind pipeline to cmd buffer
10827 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10828 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10829 &descriptor_set, 0, nullptr);
10830 Draw(1, 0, 0, 0);
10831 EndCommandBuffer();
10832 // Submit cmd buffer then destroy sampler
10833 VkSubmitInfo submit_info = {};
10834 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10835 submit_info.commandBufferCount = 1;
10836 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10837 // Submit cmd buffer and then destroy imageView while in-flight
10838 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10839
10840 vkDestroyImageView(m_device->device(), view, nullptr);
10841 m_errorMonitor->VerifyFound();
10842 vkQueueWaitIdle(m_device->m_queue);
10843 // Now we can actually destroy imageView
10844 vkDestroyImageView(m_device->device(), view, NULL);
10845 vkDestroySampler(m_device->device(), sampler, nullptr);
10846 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10847 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10848 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10849}
10850
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010851TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10852 TEST_DESCRIPTION("Delete in-use bufferView.");
10853
10854 ASSERT_NO_FATAL_FAILURE(InitState());
10855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10856
10857 VkDescriptorPoolSize ds_type_count;
10858 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10859 ds_type_count.descriptorCount = 1;
10860
10861 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10862 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10863 ds_pool_ci.maxSets = 1;
10864 ds_pool_ci.poolSizeCount = 1;
10865 ds_pool_ci.pPoolSizes = &ds_type_count;
10866
10867 VkDescriptorPool ds_pool;
10868 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10869 ASSERT_VK_SUCCESS(err);
10870
10871 VkDescriptorSetLayoutBinding layout_binding;
10872 layout_binding.binding = 0;
10873 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10874 layout_binding.descriptorCount = 1;
10875 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10876 layout_binding.pImmutableSamplers = NULL;
10877
10878 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10879 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10880 ds_layout_ci.bindingCount = 1;
10881 ds_layout_ci.pBindings = &layout_binding;
10882 VkDescriptorSetLayout ds_layout;
10883 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10884 ASSERT_VK_SUCCESS(err);
10885
10886 VkDescriptorSetAllocateInfo alloc_info = {};
10887 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10888 alloc_info.descriptorSetCount = 1;
10889 alloc_info.descriptorPool = ds_pool;
10890 alloc_info.pSetLayouts = &ds_layout;
10891 VkDescriptorSet descriptor_set;
10892 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10893 ASSERT_VK_SUCCESS(err);
10894
10895 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10896 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10897 pipeline_layout_ci.pNext = NULL;
10898 pipeline_layout_ci.setLayoutCount = 1;
10899 pipeline_layout_ci.pSetLayouts = &ds_layout;
10900
10901 VkPipelineLayout pipeline_layout;
10902 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10903 ASSERT_VK_SUCCESS(err);
10904
10905 VkBuffer buffer;
10906 uint32_t queue_family_index = 0;
10907 VkBufferCreateInfo buffer_create_info = {};
10908 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10909 buffer_create_info.size = 1024;
10910 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10911 buffer_create_info.queueFamilyIndexCount = 1;
10912 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
10913
10914 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
10915 ASSERT_VK_SUCCESS(err);
10916
10917 VkMemoryRequirements memory_reqs;
10918 VkDeviceMemory buffer_memory;
10919
10920 VkMemoryAllocateInfo memory_info = {};
10921 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10922 memory_info.allocationSize = 0;
10923 memory_info.memoryTypeIndex = 0;
10924
10925 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
10926 memory_info.allocationSize = memory_reqs.size;
10927 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
10928 ASSERT_TRUE(pass);
10929
10930 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
10931 ASSERT_VK_SUCCESS(err);
10932 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
10933 ASSERT_VK_SUCCESS(err);
10934
10935 VkBufferView view;
10936 VkBufferViewCreateInfo bvci = {};
10937 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10938 bvci.buffer = buffer;
10939 bvci.format = VK_FORMAT_R8_UNORM;
10940 bvci.range = VK_WHOLE_SIZE;
10941
10942 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
10943 ASSERT_VK_SUCCESS(err);
10944
10945 VkWriteDescriptorSet descriptor_write = {};
10946 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10947 descriptor_write.dstSet = descriptor_set;
10948 descriptor_write.dstBinding = 0;
10949 descriptor_write.descriptorCount = 1;
10950 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10951 descriptor_write.pTexelBufferView = &view;
10952
10953 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10954
10955 char const *vsSource = "#version 450\n"
10956 "\n"
10957 "out gl_PerVertex { \n"
10958 " vec4 gl_Position;\n"
10959 "};\n"
10960 "void main(){\n"
10961 " gl_Position = vec4(1);\n"
10962 "}\n";
10963 char const *fsSource = "#version 450\n"
10964 "\n"
10965 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
10966 "layout(location=0) out vec4 x;\n"
10967 "void main(){\n"
10968 " x = imageLoad(s, 0);\n"
10969 "}\n";
10970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10972 VkPipelineObj pipe(m_device);
10973 pipe.AddShader(&vs);
10974 pipe.AddShader(&fs);
10975 pipe.AddColorAttachment();
10976 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10977
10978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
10979
10980 BeginCommandBuffer();
10981 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10982 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10983 VkRect2D scissor = {{0, 0}, {16, 16}};
10984 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10985 // Bind pipeline to cmd buffer
10986 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10987 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10988 &descriptor_set, 0, nullptr);
10989 Draw(1, 0, 0, 0);
10990 EndCommandBuffer();
10991
10992 VkSubmitInfo submit_info = {};
10993 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10994 submit_info.commandBufferCount = 1;
10995 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10996 // Submit cmd buffer and then destroy bufferView while in-flight
10997 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10998
10999 vkDestroyBufferView(m_device->device(), view, nullptr);
11000 m_errorMonitor->VerifyFound();
11001 vkQueueWaitIdle(m_device->m_queue);
11002 // Now we can actually destroy bufferView
11003 vkDestroyBufferView(m_device->device(), view, NULL);
11004 vkDestroyBuffer(m_device->device(), buffer, NULL);
11005 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11006 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11007 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11008 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11009}
11010
Tobin Ehlis209532e2016-09-07 13:52:18 -060011011TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11012 TEST_DESCRIPTION("Delete in-use sampler.");
11013
11014 ASSERT_NO_FATAL_FAILURE(InitState());
11015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11016
11017 VkDescriptorPoolSize ds_type_count;
11018 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11019 ds_type_count.descriptorCount = 1;
11020
11021 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11022 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11023 ds_pool_ci.maxSets = 1;
11024 ds_pool_ci.poolSizeCount = 1;
11025 ds_pool_ci.pPoolSizes = &ds_type_count;
11026
11027 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011028 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011029 ASSERT_VK_SUCCESS(err);
11030
11031 VkSamplerCreateInfo sampler_ci = {};
11032 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11033 sampler_ci.pNext = NULL;
11034 sampler_ci.magFilter = VK_FILTER_NEAREST;
11035 sampler_ci.minFilter = VK_FILTER_NEAREST;
11036 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11037 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11038 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11039 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11040 sampler_ci.mipLodBias = 1.0;
11041 sampler_ci.anisotropyEnable = VK_FALSE;
11042 sampler_ci.maxAnisotropy = 1;
11043 sampler_ci.compareEnable = VK_FALSE;
11044 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11045 sampler_ci.minLod = 1.0;
11046 sampler_ci.maxLod = 1.0;
11047 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11048 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11049 VkSampler sampler;
11050
11051 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11052 ASSERT_VK_SUCCESS(err);
11053
11054 VkDescriptorSetLayoutBinding layout_binding;
11055 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011056 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011057 layout_binding.descriptorCount = 1;
11058 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11059 layout_binding.pImmutableSamplers = NULL;
11060
11061 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11062 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11063 ds_layout_ci.bindingCount = 1;
11064 ds_layout_ci.pBindings = &layout_binding;
11065 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011066 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011067 ASSERT_VK_SUCCESS(err);
11068
11069 VkDescriptorSetAllocateInfo alloc_info = {};
11070 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11071 alloc_info.descriptorSetCount = 1;
11072 alloc_info.descriptorPool = ds_pool;
11073 alloc_info.pSetLayouts = &ds_layout;
11074 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011075 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011076 ASSERT_VK_SUCCESS(err);
11077
11078 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11079 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11080 pipeline_layout_ci.pNext = NULL;
11081 pipeline_layout_ci.setLayoutCount = 1;
11082 pipeline_layout_ci.pSetLayouts = &ds_layout;
11083
11084 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011085 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011086 ASSERT_VK_SUCCESS(err);
11087
11088 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011089 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 -060011090 ASSERT_TRUE(image.initialized());
11091
11092 VkImageView view;
11093 VkImageViewCreateInfo ivci = {};
11094 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11095 ivci.image = image.handle();
11096 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11097 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11098 ivci.subresourceRange.layerCount = 1;
11099 ivci.subresourceRange.baseMipLevel = 0;
11100 ivci.subresourceRange.levelCount = 1;
11101 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11102
11103 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11104 ASSERT_VK_SUCCESS(err);
11105
11106 VkDescriptorImageInfo image_info{};
11107 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11108 image_info.imageView = view;
11109 image_info.sampler = sampler;
11110
11111 VkWriteDescriptorSet descriptor_write = {};
11112 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11113 descriptor_write.dstSet = descriptor_set;
11114 descriptor_write.dstBinding = 0;
11115 descriptor_write.descriptorCount = 1;
11116 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11117 descriptor_write.pImageInfo = &image_info;
11118
11119 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11120
11121 // Create PSO to use the sampler
11122 char const *vsSource = "#version 450\n"
11123 "\n"
11124 "out gl_PerVertex { \n"
11125 " vec4 gl_Position;\n"
11126 "};\n"
11127 "void main(){\n"
11128 " gl_Position = vec4(1);\n"
11129 "}\n";
11130 char const *fsSource = "#version 450\n"
11131 "\n"
11132 "layout(set=0, binding=0) uniform sampler2D s;\n"
11133 "layout(location=0) out vec4 x;\n"
11134 "void main(){\n"
11135 " x = texture(s, vec2(1));\n"
11136 "}\n";
11137 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11138 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11139 VkPipelineObj pipe(m_device);
11140 pipe.AddShader(&vs);
11141 pipe.AddShader(&fs);
11142 pipe.AddColorAttachment();
11143 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11144
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011146
11147 BeginCommandBuffer();
11148 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011149 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11150 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11151 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011152 Draw(1, 0, 0, 0);
11153 EndCommandBuffer();
11154 // Submit cmd buffer then destroy sampler
11155 VkSubmitInfo submit_info = {};
11156 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11157 submit_info.commandBufferCount = 1;
11158 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11159 // Submit cmd buffer and then destroy sampler while in-flight
11160 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11161
11162 vkDestroySampler(m_device->device(), sampler, nullptr);
11163 m_errorMonitor->VerifyFound();
11164 vkQueueWaitIdle(m_device->m_queue);
11165 // Now we can actually destroy sampler
11166 vkDestroySampler(m_device->device(), sampler, nullptr);
11167 vkDestroyImageView(m_device->device(), view, NULL);
11168 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11169 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11170 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11171}
11172
Mark Mueller1cd9f412016-08-25 13:23:52 -060011173TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011174 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011175 "signaled but not waited on by the queue. Wait on a "
11176 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011177
11178 ASSERT_NO_FATAL_FAILURE(InitState());
11179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011181 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11182 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11183 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011184
11185 BeginCommandBuffer();
11186 EndCommandBuffer();
11187
11188 VkSemaphoreCreateInfo semaphore_create_info = {};
11189 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11190 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011191 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011192 VkSubmitInfo submit_info = {};
11193 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11194 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011195 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011196 submit_info.signalSemaphoreCount = 1;
11197 submit_info.pSignalSemaphores = &semaphore;
11198 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11199 m_errorMonitor->SetDesiredFailureMsg(0, "");
11200 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11201 BeginCommandBuffer();
11202 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011204 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11205 m_errorMonitor->VerifyFound();
11206
Mark Mueller1cd9f412016-08-25 13:23:52 -060011207 VkFenceCreateInfo fence_create_info = {};
11208 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11209 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011210 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011213 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11214 m_errorMonitor->VerifyFound();
11215
Mark Mueller4042b652016-09-05 22:52:21 -060011216 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011217 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011218 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11219}
11220
Tobin Ehlis4af23302016-07-19 10:50:30 -060011221TEST_F(VkLayerTest, FramebufferIncompatible) {
11222 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11223 "that does not match the framebuffer for the active "
11224 "renderpass.");
11225 ASSERT_NO_FATAL_FAILURE(InitState());
11226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11227
11228 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011229 VkAttachmentDescription attachment = {0,
11230 VK_FORMAT_B8G8R8A8_UNORM,
11231 VK_SAMPLE_COUNT_1_BIT,
11232 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11233 VK_ATTACHMENT_STORE_OP_STORE,
11234 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11235 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11236 VK_IMAGE_LAYOUT_UNDEFINED,
11237 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011241 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011243 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011244
11245 VkRenderPass rp;
11246 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11247 ASSERT_VK_SUCCESS(err);
11248
11249 // A compatible framebuffer.
11250 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011251 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 -060011252 ASSERT_TRUE(image.initialized());
11253
11254 VkImageViewCreateInfo ivci = {
11255 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11256 nullptr,
11257 0,
11258 image.handle(),
11259 VK_IMAGE_VIEW_TYPE_2D,
11260 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011261 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11262 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011263 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11264 };
11265 VkImageView view;
11266 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11267 ASSERT_VK_SUCCESS(err);
11268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011269 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011270 VkFramebuffer fb;
11271 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11272 ASSERT_VK_SUCCESS(err);
11273
11274 VkCommandBufferAllocateInfo cbai = {};
11275 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11276 cbai.commandPool = m_commandPool;
11277 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11278 cbai.commandBufferCount = 1;
11279
11280 VkCommandBuffer sec_cb;
11281 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11282 ASSERT_VK_SUCCESS(err);
11283 VkCommandBufferBeginInfo cbbi = {};
11284 VkCommandBufferInheritanceInfo cbii = {};
11285 cbii.renderPass = renderPass();
11286 cbii.framebuffer = fb;
11287 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11288 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011289 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 -060011290 cbbi.pInheritanceInfo = &cbii;
11291 vkBeginCommandBuffer(sec_cb, &cbbi);
11292 vkEndCommandBuffer(sec_cb);
11293
Chris Forbes3400bc52016-09-13 18:10:34 +120011294 VkCommandBufferBeginInfo cbbi2 = {
11295 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11296 0, nullptr
11297 };
11298 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11299 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011302 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011303 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11304 m_errorMonitor->VerifyFound();
11305 // Cleanup
11306 vkDestroyImageView(m_device->device(), view, NULL);
11307 vkDestroyRenderPass(m_device->device(), rp, NULL);
11308 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11309}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011310
11311TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11312 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11313 "invalid value. If logicOp is not available, attempt to "
11314 "use it and verify that we see the correct error.");
11315 ASSERT_NO_FATAL_FAILURE(InitState());
11316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11317
11318 auto features = m_device->phy().features();
11319 // Set the expected error depending on whether or not logicOp available
11320 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11322 "enabled, logicOpEnable must be "
11323 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011324 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011326 }
11327 // Create a pipeline using logicOp
11328 VkResult err;
11329
11330 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11331 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11332
11333 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011334 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011335 ASSERT_VK_SUCCESS(err);
11336
11337 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11338 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11339 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011340 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011341 vp_state_ci.pViewports = &vp;
11342 vp_state_ci.scissorCount = 1;
11343 VkRect2D scissors = {}; // Dummy scissors to point to
11344 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011345
11346 VkPipelineShaderStageCreateInfo shaderStages[2];
11347 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011349 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11350 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011351 shaderStages[0] = vs.GetStageCreateInfo();
11352 shaderStages[1] = fs.GetStageCreateInfo();
11353
11354 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11355 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11356
11357 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11358 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11359 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11360
11361 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11362 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011363 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011364
11365 VkPipelineColorBlendAttachmentState att = {};
11366 att.blendEnable = VK_FALSE;
11367 att.colorWriteMask = 0xf;
11368
11369 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11370 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11371 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11372 cb_ci.logicOpEnable = VK_TRUE;
11373 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11374 cb_ci.attachmentCount = 1;
11375 cb_ci.pAttachments = &att;
11376
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011377 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11378 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11379 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11380
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011381 VkGraphicsPipelineCreateInfo gp_ci = {};
11382 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11383 gp_ci.stageCount = 2;
11384 gp_ci.pStages = shaderStages;
11385 gp_ci.pVertexInputState = &vi_ci;
11386 gp_ci.pInputAssemblyState = &ia_ci;
11387 gp_ci.pViewportState = &vp_state_ci;
11388 gp_ci.pRasterizationState = &rs_ci;
11389 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011390 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011391 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11392 gp_ci.layout = pipeline_layout;
11393 gp_ci.renderPass = renderPass();
11394
11395 VkPipelineCacheCreateInfo pc_ci = {};
11396 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11397
11398 VkPipeline pipeline;
11399 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011400 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011401 ASSERT_VK_SUCCESS(err);
11402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011403 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011404 m_errorMonitor->VerifyFound();
11405 if (VK_SUCCESS == err) {
11406 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11407 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011408 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11409 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11410}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011411#endif // DRAW_STATE_TESTS
11412
Tobin Ehlis0788f522015-05-26 16:11:58 -060011413#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011414#if GTEST_IS_THREADSAFE
11415struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011416 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011417 VkEvent event;
11418 bool bailout;
11419};
11420
Karl Schultz6addd812016-02-02 17:17:23 -070011421extern "C" void *AddToCommandBuffer(void *arg) {
11422 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011423
Mike Stroyana6d14942016-07-13 15:10:05 -060011424 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011425 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011426 if (data->bailout) {
11427 break;
11428 }
11429 }
11430 return NULL;
11431}
11432
Karl Schultz6addd812016-02-02 17:17:23 -070011433TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011434 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011437
Mike Stroyanaccf7692015-05-12 16:00:45 -060011438 ASSERT_NO_FATAL_FAILURE(InitState());
11439 ASSERT_NO_FATAL_FAILURE(InitViewport());
11440 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11441
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011442 // Calls AllocateCommandBuffers
11443 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011444
11445 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011446 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011447
11448 VkEventCreateInfo event_info;
11449 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011450 VkResult err;
11451
11452 memset(&event_info, 0, sizeof(event_info));
11453 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11454
Chia-I Wuf7458c52015-10-26 21:10:41 +080011455 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011456 ASSERT_VK_SUCCESS(err);
11457
Mike Stroyanaccf7692015-05-12 16:00:45 -060011458 err = vkResetEvent(device(), event);
11459 ASSERT_VK_SUCCESS(err);
11460
11461 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011462 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011463 data.event = event;
11464 data.bailout = false;
11465 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011466
11467 // First do some correct operations using multiple threads.
11468 // Add many entries to command buffer from another thread.
11469 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11470 // Make non-conflicting calls from this thread at the same time.
11471 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011472 uint32_t count;
11473 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011474 }
11475 test_platform_thread_join(thread, NULL);
11476
11477 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011478 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011479 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011480 // Add many entries to command buffer from this thread at the same time.
11481 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011482
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011483 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011484 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011485
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011486 m_errorMonitor->SetBailout(NULL);
11487
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011488 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011489
Chia-I Wuf7458c52015-10-26 21:10:41 +080011490 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011491}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011492#endif // GTEST_IS_THREADSAFE
11493#endif // THREADING_TESTS
11494
Chris Forbes9f7ff632015-05-25 11:13:08 +120011495#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011496TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011497 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11498 "with an impossible code size");
11499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011501
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011502 ASSERT_NO_FATAL_FAILURE(InitState());
11503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11504
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011505 VkShaderModule module;
11506 VkShaderModuleCreateInfo moduleCreateInfo;
11507 struct icd_spv_header spv;
11508
11509 spv.magic = ICD_SPV_MAGIC;
11510 spv.version = ICD_SPV_VERSION;
11511 spv.gen_magic = 0;
11512
11513 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11514 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011515 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011516 moduleCreateInfo.codeSize = 4;
11517 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011518 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011519
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011520 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011521}
11522
Karl Schultz6addd812016-02-02 17:17:23 -070011523TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011524 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11525 "with a bad magic number");
11526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011528
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011529 ASSERT_NO_FATAL_FAILURE(InitState());
11530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11531
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011532 VkShaderModule module;
11533 VkShaderModuleCreateInfo moduleCreateInfo;
11534 struct icd_spv_header spv;
11535
11536 spv.magic = ~ICD_SPV_MAGIC;
11537 spv.version = ICD_SPV_VERSION;
11538 spv.gen_magic = 0;
11539
11540 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11541 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011542 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011543 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11544 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011545 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011546
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011547 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011548}
11549
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011550#if 0
11551// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011552TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011554 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011555
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011556 ASSERT_NO_FATAL_FAILURE(InitState());
11557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11558
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011559 VkShaderModule module;
11560 VkShaderModuleCreateInfo moduleCreateInfo;
11561 struct icd_spv_header spv;
11562
11563 spv.magic = ICD_SPV_MAGIC;
11564 spv.version = ~ICD_SPV_VERSION;
11565 spv.gen_magic = 0;
11566
11567 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11568 moduleCreateInfo.pNext = NULL;
11569
Karl Schultz6addd812016-02-02 17:17:23 -070011570 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011571 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11572 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011573 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011574
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011575 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011576}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011577#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011578
Karl Schultz6addd812016-02-02 17:17:23 -070011579TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011580 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11581 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011583
Chris Forbes9f7ff632015-05-25 11:13:08 +120011584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011586
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011587 char const *vsSource = "#version 450\n"
11588 "\n"
11589 "layout(location=0) out float x;\n"
11590 "out gl_PerVertex {\n"
11591 " vec4 gl_Position;\n"
11592 "};\n"
11593 "void main(){\n"
11594 " gl_Position = vec4(1);\n"
11595 " x = 0;\n"
11596 "}\n";
11597 char const *fsSource = "#version 450\n"
11598 "\n"
11599 "layout(location=0) out vec4 color;\n"
11600 "void main(){\n"
11601 " color = vec4(1);\n"
11602 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011603
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011604 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11605 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011606
11607 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011608 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011609 pipe.AddShader(&vs);
11610 pipe.AddShader(&fs);
11611
Chris Forbes9f7ff632015-05-25 11:13:08 +120011612 VkDescriptorSetObj descriptorSet(m_device);
11613 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011614 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011615
Tony Barbour5781e8f2015-08-04 16:23:11 -060011616 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011617
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011618 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011619}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011620
Mark Mueller098c9cb2016-09-08 09:01:57 -060011621TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11622 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11623
11624 ASSERT_NO_FATAL_FAILURE(InitState());
11625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11626
11627 const char *bad_specialization_message =
11628 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11629
11630 char const *vsSource =
11631 "#version 450\n"
11632 "\n"
11633 "out gl_PerVertex {\n"
11634 " vec4 gl_Position;\n"
11635 "};\n"
11636 "void main(){\n"
11637 " gl_Position = vec4(1);\n"
11638 "}\n";
11639
11640 char const *fsSource =
11641 "#version 450\n"
11642 "\n"
11643 "layout (constant_id = 0) const float r = 0.0f;\n"
11644 "layout(location = 0) out vec4 uFragColor;\n"
11645 "void main(){\n"
11646 " uFragColor = vec4(r,1,0,1);\n"
11647 "}\n";
11648
11649 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11650 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11651
11652 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11653 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11654
11655 VkPipelineLayout pipeline_layout;
11656 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11657
11658 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11659 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11660 vp_state_create_info.viewportCount = 1;
11661 VkViewport viewport = {};
11662 vp_state_create_info.pViewports = &viewport;
11663 vp_state_create_info.scissorCount = 1;
11664 VkRect2D scissors = {};
11665 vp_state_create_info.pScissors = &scissors;
11666
11667 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11668
11669 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11670 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11671 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11672 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11673
11674 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11675 vs.GetStageCreateInfo(),
11676 fs.GetStageCreateInfo()
11677 };
11678
11679 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11680 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11681
11682 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11683 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11684 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11685
11686 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11687 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11688 rasterization_state_create_info.pNext = nullptr;
11689 rasterization_state_create_info.lineWidth = 1.0f;
11690 rasterization_state_create_info.rasterizerDiscardEnable = true;
11691
11692 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11693 color_blend_attachment_state.blendEnable = VK_FALSE;
11694 color_blend_attachment_state.colorWriteMask = 0xf;
11695
11696 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11697 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11698 color_blend_state_create_info.attachmentCount = 1;
11699 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11700
11701 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11702 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11703 graphicspipe_create_info.stageCount = 2;
11704 graphicspipe_create_info.pStages = shader_stage_create_info;
11705 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11706 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11707 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11708 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11709 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11710 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11711 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11712 graphicspipe_create_info.layout = pipeline_layout;
11713 graphicspipe_create_info.renderPass = renderPass();
11714
11715 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11716 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11717
11718 VkPipelineCache pipelineCache;
11719 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11720
11721 // This structure maps constant ids to data locations.
11722 const VkSpecializationMapEntry entry =
11723 // id, offset, size
11724 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11725
11726 uint32_t data = 1;
11727
11728 // Set up the info describing spec map and data
11729 const VkSpecializationInfo specialization_info = {
11730 1,
11731 &entry,
11732 1 * sizeof(float),
11733 &data,
11734 };
11735 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11736
11737 VkPipeline pipeline;
11738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11739 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11740 m_errorMonitor->VerifyFound();
11741
11742 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11743 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11744}
11745
11746TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11747 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11748
11749 ASSERT_NO_FATAL_FAILURE(InitState());
11750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11751
11752 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11753
11754 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11755 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11756 descriptor_pool_type_count[0].descriptorCount = 1;
11757 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11758 descriptor_pool_type_count[1].descriptorCount = 1;
11759
11760 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11761 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11762 descriptor_pool_create_info.maxSets = 1;
11763 descriptor_pool_create_info.poolSizeCount = 2;
11764 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11765 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11766
11767 VkDescriptorPool descriptorset_pool;
11768 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11769
11770 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11771 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11772 descriptorset_layout_binding.descriptorCount = 1;
11773 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11774
11775 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11776 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11777 descriptorset_layout_create_info.bindingCount = 1;
11778 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11779
11780 VkDescriptorSetLayout descriptorset_layout;
11781 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11782
11783 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11784 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11785 descriptorset_allocate_info.descriptorSetCount = 1;
11786 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11787 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11788 VkDescriptorSet descriptorset;
11789 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11790
11791 // Challenge core_validation with a non uniform buffer type.
11792 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11793
Mark Mueller098c9cb2016-09-08 09:01:57 -060011794 char const *vsSource =
11795 "#version 450\n"
11796 "\n"
11797 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11798 " mat4 mvp;\n"
11799 "} ubuf;\n"
11800 "out gl_PerVertex {\n"
11801 " vec4 gl_Position;\n"
11802 "};\n"
11803 "void main(){\n"
11804 " gl_Position = ubuf.mvp * vec4(1);\n"
11805 "}\n";
11806
11807 char const *fsSource =
11808 "#version 450\n"
11809 "\n"
11810 "layout(location = 0) out vec4 uFragColor;\n"
11811 "void main(){\n"
11812 " uFragColor = vec4(0,1,0,1);\n"
11813 "}\n";
11814
11815 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11816 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11817
11818 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11819 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11820 pipeline_layout_create_info.setLayoutCount = 1;
11821 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11822
11823 VkPipelineLayout pipeline_layout;
11824 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11825
11826 VkPipelineObj pipe(m_device);
11827 pipe.AddColorAttachment();
11828 pipe.AddShader(&vs);
11829 pipe.AddShader(&fs);
11830
11831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11832 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11833 m_errorMonitor->VerifyFound();
11834
11835 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11836 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11837 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11838}
11839
11840TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11841 TEST_DESCRIPTION(
11842 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11843
11844 ASSERT_NO_FATAL_FAILURE(InitState());
11845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11846
11847 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11848
11849 VkDescriptorPoolSize descriptor_pool_type_count = {};
11850 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11851 descriptor_pool_type_count.descriptorCount = 1;
11852
11853 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11854 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11855 descriptor_pool_create_info.maxSets = 1;
11856 descriptor_pool_create_info.poolSizeCount = 1;
11857 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11858 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11859
11860 VkDescriptorPool descriptorset_pool;
11861 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11862
11863 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11864 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11865 descriptorset_layout_binding.descriptorCount = 1;
11866 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11867 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11868
11869 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11870 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11871 descriptorset_layout_create_info.bindingCount = 1;
11872 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11873
11874 VkDescriptorSetLayout descriptorset_layout;
11875 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11876 nullptr, &descriptorset_layout));
11877
11878 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11879 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11880 descriptorset_allocate_info.descriptorSetCount = 1;
11881 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11882 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11883 VkDescriptorSet descriptorset;
11884 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11885
11886 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11887
Mark Mueller098c9cb2016-09-08 09:01:57 -060011888 char const *vsSource =
11889 "#version 450\n"
11890 "\n"
11891 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11892 " mat4 mvp;\n"
11893 "} ubuf;\n"
11894 "out gl_PerVertex {\n"
11895 " vec4 gl_Position;\n"
11896 "};\n"
11897 "void main(){\n"
11898 " gl_Position = ubuf.mvp * vec4(1);\n"
11899 "}\n";
11900
11901 char const *fsSource =
11902 "#version 450\n"
11903 "\n"
11904 "layout(location = 0) out vec4 uFragColor;\n"
11905 "void main(){\n"
11906 " uFragColor = vec4(0,1,0,1);\n"
11907 "}\n";
11908
11909 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11910 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11911
11912 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11913 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11914 pipeline_layout_create_info.setLayoutCount = 1;
11915 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11916
11917 VkPipelineLayout pipeline_layout;
11918 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11919
11920 VkPipelineObj pipe(m_device);
11921 pipe.AddColorAttachment();
11922 pipe.AddShader(&vs);
11923 pipe.AddShader(&fs);
11924
11925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
11926 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11927 m_errorMonitor->VerifyFound();
11928
11929 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11930 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11931 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11932}
11933
11934TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
11935 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
11936 "accessible from the current shader stage.");
11937
11938 ASSERT_NO_FATAL_FAILURE(InitState());
11939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11940
11941 const char *push_constant_not_accessible_message =
11942 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
11943
11944 char const *vsSource =
11945 "#version 450\n"
11946 "\n"
11947 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
11948 "out gl_PerVertex {\n"
11949 " vec4 gl_Position;\n"
11950 "};\n"
11951 "void main(){\n"
11952 " gl_Position = vec4(consts.x);\n"
11953 "}\n";
11954
11955 char const *fsSource =
11956 "#version 450\n"
11957 "\n"
11958 "layout(location = 0) out vec4 uFragColor;\n"
11959 "void main(){\n"
11960 " uFragColor = vec4(0,1,0,1);\n"
11961 "}\n";
11962
11963 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11964 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11965
11966 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11967 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11968
11969 // Set up a push constant range
11970 VkPushConstantRange push_constant_ranges = {};
11971 // Set to the wrong stage to challenge core_validation
11972 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11973 push_constant_ranges.size = 4;
11974
11975 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
11976 pipeline_layout_create_info.pushConstantRangeCount = 1;
11977
11978 VkPipelineLayout pipeline_layout;
11979 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11980
11981 VkPipelineObj pipe(m_device);
11982 pipe.AddColorAttachment();
11983 pipe.AddShader(&vs);
11984 pipe.AddShader(&fs);
11985
11986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
11987 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11988 m_errorMonitor->VerifyFound();
11989
11990 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11991}
11992
11993TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
11994 TEST_DESCRIPTION(
11995 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
11996
11997 ASSERT_NO_FATAL_FAILURE(InitState());
11998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11999
12000 const char *feature_not_enabled_message =
12001 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12002
12003 // Some awkward steps are required to test with custom device features.
12004 std::vector<const char *> device_extension_names;
12005 auto features = m_device->phy().features();
12006 // Disable support for 64 bit floats
12007 features.shaderFloat64 = false;
12008 // The sacrificial device object
12009 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12010
12011 char const *vsSource = "#version 450\n"
12012 "\n"
12013 "out gl_PerVertex {\n"
12014 " vec4 gl_Position;\n"
12015 "};\n"
12016 "void main(){\n"
12017 " gl_Position = vec4(1);\n"
12018 "}\n";
12019 char const *fsSource = "#version 450\n"
12020 "\n"
12021 "layout(location=0) out vec4 color;\n"
12022 "void main(){\n"
12023 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12024 " color = vec4(green);\n"
12025 "}\n";
12026
12027 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12028 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12029
12030 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012031
12032 VkPipelineObj pipe(&test_device);
12033 pipe.AddColorAttachment();
12034 pipe.AddShader(&vs);
12035 pipe.AddShader(&fs);
12036
12037 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12038 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12039 VkPipelineLayout pipeline_layout;
12040 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12041
12042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12043 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12044 m_errorMonitor->VerifyFound();
12045
12046 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12047}
12048
12049TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12050 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12051
12052 ASSERT_NO_FATAL_FAILURE(InitState());
12053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12054
12055 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12056
12057 char const *vsSource = "#version 450\n"
12058 "\n"
12059 "out gl_PerVertex {\n"
12060 " vec4 gl_Position;\n"
12061 "};\n"
12062 "layout(xfb_buffer = 1) out;"
12063 "void main(){\n"
12064 " gl_Position = vec4(1);\n"
12065 "}\n";
12066 char const *fsSource = "#version 450\n"
12067 "\n"
12068 "layout(location=0) out vec4 color;\n"
12069 "void main(){\n"
12070 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12071 " color = vec4(green);\n"
12072 "}\n";
12073
12074 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12075 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12076
12077 VkPipelineObj pipe(m_device);
12078 pipe.AddColorAttachment();
12079 pipe.AddShader(&vs);
12080 pipe.AddShader(&fs);
12081
12082 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12083 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12084 VkPipelineLayout pipeline_layout;
12085 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12086
12087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12088 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12089 m_errorMonitor->VerifyFound();
12090
12091 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12092}
12093
Karl Schultz6addd812016-02-02 17:17:23 -070012094TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012095 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12096 "which is not present in the outputs of the previous stage");
12097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012099
Chris Forbes59cb88d2015-05-25 11:13:13 +120012100 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012103 char const *vsSource = "#version 450\n"
12104 "\n"
12105 "out gl_PerVertex {\n"
12106 " vec4 gl_Position;\n"
12107 "};\n"
12108 "void main(){\n"
12109 " gl_Position = vec4(1);\n"
12110 "}\n";
12111 char const *fsSource = "#version 450\n"
12112 "\n"
12113 "layout(location=0) in float x;\n"
12114 "layout(location=0) out vec4 color;\n"
12115 "void main(){\n"
12116 " color = vec4(x);\n"
12117 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012118
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012119 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12120 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012121
12122 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012123 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012124 pipe.AddShader(&vs);
12125 pipe.AddShader(&fs);
12126
Chris Forbes59cb88d2015-05-25 11:13:13 +120012127 VkDescriptorSetObj descriptorSet(m_device);
12128 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012129 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012130
Tony Barbour5781e8f2015-08-04 16:23:11 -060012131 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012132
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012133 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012134}
12135
Karl Schultz6addd812016-02-02 17:17:23 -070012136TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012137 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12138 "within an interace block, which is not present in the outputs "
12139 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012141
12142 ASSERT_NO_FATAL_FAILURE(InitState());
12143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12144
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012145 char const *vsSource = "#version 450\n"
12146 "\n"
12147 "out gl_PerVertex {\n"
12148 " vec4 gl_Position;\n"
12149 "};\n"
12150 "void main(){\n"
12151 " gl_Position = vec4(1);\n"
12152 "}\n";
12153 char const *fsSource = "#version 450\n"
12154 "\n"
12155 "in block { layout(location=0) float x; } ins;\n"
12156 "layout(location=0) out vec4 color;\n"
12157 "void main(){\n"
12158 " color = vec4(ins.x);\n"
12159 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012160
12161 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12162 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12163
12164 VkPipelineObj pipe(m_device);
12165 pipe.AddColorAttachment();
12166 pipe.AddShader(&vs);
12167 pipe.AddShader(&fs);
12168
12169 VkDescriptorSetObj descriptorSet(m_device);
12170 descriptorSet.AppendDummy();
12171 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12172
12173 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12174
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012175 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012176}
12177
Karl Schultz6addd812016-02-02 17:17:23 -070012178TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012179 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012180 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12182 "output arr[2] of float32' vs 'ptr to "
12183 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012184
12185 ASSERT_NO_FATAL_FAILURE(InitState());
12186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12187
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012188 char const *vsSource = "#version 450\n"
12189 "\n"
12190 "layout(location=0) out float x[2];\n"
12191 "out gl_PerVertex {\n"
12192 " vec4 gl_Position;\n"
12193 "};\n"
12194 "void main(){\n"
12195 " x[0] = 0; x[1] = 0;\n"
12196 " gl_Position = vec4(1);\n"
12197 "}\n";
12198 char const *fsSource = "#version 450\n"
12199 "\n"
12200 "layout(location=0) in float x[3];\n"
12201 "layout(location=0) out vec4 color;\n"
12202 "void main(){\n"
12203 " color = vec4(x[0] + x[1] + x[2]);\n"
12204 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012205
12206 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12207 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12208
12209 VkPipelineObj pipe(m_device);
12210 pipe.AddColorAttachment();
12211 pipe.AddShader(&vs);
12212 pipe.AddShader(&fs);
12213
12214 VkDescriptorSetObj descriptorSet(m_device);
12215 descriptorSet.AppendDummy();
12216 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12217
12218 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12219
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012220 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012221}
12222
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012223
Karl Schultz6addd812016-02-02 17:17:23 -070012224TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012225 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012226 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012228
Chris Forbesb56af562015-05-25 11:13:17 +120012229 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012232 char const *vsSource = "#version 450\n"
12233 "\n"
12234 "layout(location=0) out int x;\n"
12235 "out gl_PerVertex {\n"
12236 " vec4 gl_Position;\n"
12237 "};\n"
12238 "void main(){\n"
12239 " x = 0;\n"
12240 " gl_Position = vec4(1);\n"
12241 "}\n";
12242 char const *fsSource = "#version 450\n"
12243 "\n"
12244 "layout(location=0) in float x;\n" /* VS writes int */
12245 "layout(location=0) out vec4 color;\n"
12246 "void main(){\n"
12247 " color = vec4(x);\n"
12248 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012249
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012250 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12251 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012252
12253 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012254 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012255 pipe.AddShader(&vs);
12256 pipe.AddShader(&fs);
12257
Chris Forbesb56af562015-05-25 11:13:17 +120012258 VkDescriptorSetObj descriptorSet(m_device);
12259 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012260 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012261
Tony Barbour5781e8f2015-08-04 16:23:11 -060012262 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012263
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012264 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012265}
12266
Karl Schultz6addd812016-02-02 17:17:23 -070012267TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012268 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012269 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012270 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012272
12273 ASSERT_NO_FATAL_FAILURE(InitState());
12274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012276 char const *vsSource = "#version 450\n"
12277 "\n"
12278 "out block { layout(location=0) int x; } outs;\n"
12279 "out gl_PerVertex {\n"
12280 " vec4 gl_Position;\n"
12281 "};\n"
12282 "void main(){\n"
12283 " outs.x = 0;\n"
12284 " gl_Position = vec4(1);\n"
12285 "}\n";
12286 char const *fsSource = "#version 450\n"
12287 "\n"
12288 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12289 "layout(location=0) out vec4 color;\n"
12290 "void main(){\n"
12291 " color = vec4(ins.x);\n"
12292 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012293
12294 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12295 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12296
12297 VkPipelineObj pipe(m_device);
12298 pipe.AddColorAttachment();
12299 pipe.AddShader(&vs);
12300 pipe.AddShader(&fs);
12301
12302 VkDescriptorSetObj descriptorSet(m_device);
12303 descriptorSet.AppendDummy();
12304 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12305
12306 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12307
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012308 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012309}
12310
12311TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012312 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012313 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012314 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012315 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 +130012316
12317 ASSERT_NO_FATAL_FAILURE(InitState());
12318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012320 char const *vsSource = "#version 450\n"
12321 "\n"
12322 "out block { layout(location=1) float x; } outs;\n"
12323 "out gl_PerVertex {\n"
12324 " vec4 gl_Position;\n"
12325 "};\n"
12326 "void main(){\n"
12327 " outs.x = 0;\n"
12328 " gl_Position = vec4(1);\n"
12329 "}\n";
12330 char const *fsSource = "#version 450\n"
12331 "\n"
12332 "in block { layout(location=0) float x; } ins;\n"
12333 "layout(location=0) out vec4 color;\n"
12334 "void main(){\n"
12335 " color = vec4(ins.x);\n"
12336 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012337
12338 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12339 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12340
12341 VkPipelineObj pipe(m_device);
12342 pipe.AddColorAttachment();
12343 pipe.AddShader(&vs);
12344 pipe.AddShader(&fs);
12345
12346 VkDescriptorSetObj descriptorSet(m_device);
12347 descriptorSet.AppendDummy();
12348 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12349
12350 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12351
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012352 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012353}
12354
12355TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012356 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012357 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012358 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012359 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 +130012360
12361 ASSERT_NO_FATAL_FAILURE(InitState());
12362 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012364 char const *vsSource = "#version 450\n"
12365 "\n"
12366 "out block { layout(location=0, component=0) float x; } outs;\n"
12367 "out gl_PerVertex {\n"
12368 " vec4 gl_Position;\n"
12369 "};\n"
12370 "void main(){\n"
12371 " outs.x = 0;\n"
12372 " gl_Position = vec4(1);\n"
12373 "}\n";
12374 char const *fsSource = "#version 450\n"
12375 "\n"
12376 "in block { layout(location=0, component=1) float x; } ins;\n"
12377 "layout(location=0) out vec4 color;\n"
12378 "void main(){\n"
12379 " color = vec4(ins.x);\n"
12380 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012381
12382 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12383 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12384
12385 VkPipelineObj pipe(m_device);
12386 pipe.AddColorAttachment();
12387 pipe.AddShader(&vs);
12388 pipe.AddShader(&fs);
12389
12390 VkDescriptorSetObj descriptorSet(m_device);
12391 descriptorSet.AppendDummy();
12392 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12393
12394 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12395
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012396 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012397}
12398
Karl Schultz6addd812016-02-02 17:17:23 -070012399TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012400 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12401 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012403
Chris Forbesde136e02015-05-25 11:13:28 +120012404 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012406
12407 VkVertexInputBindingDescription input_binding;
12408 memset(&input_binding, 0, sizeof(input_binding));
12409
12410 VkVertexInputAttributeDescription input_attrib;
12411 memset(&input_attrib, 0, sizeof(input_attrib));
12412 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012414 char const *vsSource = "#version 450\n"
12415 "\n"
12416 "out gl_PerVertex {\n"
12417 " vec4 gl_Position;\n"
12418 "};\n"
12419 "void main(){\n"
12420 " gl_Position = vec4(1);\n"
12421 "}\n";
12422 char const *fsSource = "#version 450\n"
12423 "\n"
12424 "layout(location=0) out vec4 color;\n"
12425 "void main(){\n"
12426 " color = vec4(1);\n"
12427 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012428
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012429 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12430 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012431
12432 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012433 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012434 pipe.AddShader(&vs);
12435 pipe.AddShader(&fs);
12436
12437 pipe.AddVertexInputBindings(&input_binding, 1);
12438 pipe.AddVertexInputAttribs(&input_attrib, 1);
12439
Chris Forbesde136e02015-05-25 11:13:28 +120012440 VkDescriptorSetObj descriptorSet(m_device);
12441 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012442 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012443
Tony Barbour5781e8f2015-08-04 16:23:11 -060012444 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012445
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012446 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012447}
12448
Karl Schultz6addd812016-02-02 17:17:23 -070012449TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012450 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12451 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012453
12454 ASSERT_NO_FATAL_FAILURE(InitState());
12455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12456
12457 VkVertexInputBindingDescription input_binding;
12458 memset(&input_binding, 0, sizeof(input_binding));
12459
12460 VkVertexInputAttributeDescription input_attrib;
12461 memset(&input_attrib, 0, sizeof(input_attrib));
12462 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012464 char const *vsSource = "#version 450\n"
12465 "\n"
12466 "layout(location=1) in float x;\n"
12467 "out gl_PerVertex {\n"
12468 " vec4 gl_Position;\n"
12469 "};\n"
12470 "void main(){\n"
12471 " gl_Position = vec4(x);\n"
12472 "}\n";
12473 char const *fsSource = "#version 450\n"
12474 "\n"
12475 "layout(location=0) out vec4 color;\n"
12476 "void main(){\n"
12477 " color = vec4(1);\n"
12478 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012479
12480 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12481 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12482
12483 VkPipelineObj pipe(m_device);
12484 pipe.AddColorAttachment();
12485 pipe.AddShader(&vs);
12486 pipe.AddShader(&fs);
12487
12488 pipe.AddVertexInputBindings(&input_binding, 1);
12489 pipe.AddVertexInputAttribs(&input_attrib, 1);
12490
12491 VkDescriptorSetObj descriptorSet(m_device);
12492 descriptorSet.AppendDummy();
12493 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12494
12495 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12496
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012497 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012498}
12499
Karl Schultz6addd812016-02-02 17:17:23 -070012500TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012501 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012502 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012503 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 -060012504
Chris Forbes62e8e502015-05-25 11:13:29 +120012505 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012508 char const *vsSource = "#version 450\n"
12509 "\n"
12510 "layout(location=0) in vec4 x;\n" /* not provided */
12511 "out gl_PerVertex {\n"
12512 " vec4 gl_Position;\n"
12513 "};\n"
12514 "void main(){\n"
12515 " gl_Position = x;\n"
12516 "}\n";
12517 char const *fsSource = "#version 450\n"
12518 "\n"
12519 "layout(location=0) out vec4 color;\n"
12520 "void main(){\n"
12521 " color = vec4(1);\n"
12522 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012523
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012524 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12525 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012526
12527 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012528 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012529 pipe.AddShader(&vs);
12530 pipe.AddShader(&fs);
12531
Chris Forbes62e8e502015-05-25 11:13:29 +120012532 VkDescriptorSetObj descriptorSet(m_device);
12533 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012534 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012535
Tony Barbour5781e8f2015-08-04 16:23:11 -060012536 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012537
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012538 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012539}
12540
Karl Schultz6addd812016-02-02 17:17:23 -070012541TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012542 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12543 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012544 "vertex shader input that consumes it");
12545 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 -060012546
Chris Forbesc97d98e2015-05-25 11:13:31 +120012547 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012549
12550 VkVertexInputBindingDescription input_binding;
12551 memset(&input_binding, 0, sizeof(input_binding));
12552
12553 VkVertexInputAttributeDescription input_attrib;
12554 memset(&input_attrib, 0, sizeof(input_attrib));
12555 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12556
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012557 char const *vsSource = "#version 450\n"
12558 "\n"
12559 "layout(location=0) in int x;\n" /* attrib provided float */
12560 "out gl_PerVertex {\n"
12561 " vec4 gl_Position;\n"
12562 "};\n"
12563 "void main(){\n"
12564 " gl_Position = vec4(x);\n"
12565 "}\n";
12566 char const *fsSource = "#version 450\n"
12567 "\n"
12568 "layout(location=0) out vec4 color;\n"
12569 "void main(){\n"
12570 " color = vec4(1);\n"
12571 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012572
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012573 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12574 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012575
12576 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012577 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012578 pipe.AddShader(&vs);
12579 pipe.AddShader(&fs);
12580
12581 pipe.AddVertexInputBindings(&input_binding, 1);
12582 pipe.AddVertexInputAttribs(&input_attrib, 1);
12583
Chris Forbesc97d98e2015-05-25 11:13:31 +120012584 VkDescriptorSetObj descriptorSet(m_device);
12585 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012586 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012587
Tony Barbour5781e8f2015-08-04 16:23:11 -060012588 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012589
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012590 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012591}
12592
Chris Forbesc68b43c2016-04-06 11:18:47 +120012593TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012594 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12595 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12597 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012598
12599 ASSERT_NO_FATAL_FAILURE(InitState());
12600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12601
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012602 char const *vsSource = "#version 450\n"
12603 "\n"
12604 "out gl_PerVertex {\n"
12605 " vec4 gl_Position;\n"
12606 "};\n"
12607 "void main(){\n"
12608 " gl_Position = vec4(1);\n"
12609 "}\n";
12610 char const *fsSource = "#version 450\n"
12611 "\n"
12612 "layout(location=0) out vec4 color;\n"
12613 "void main(){\n"
12614 " color = vec4(1);\n"
12615 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012616
12617 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12618 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12619
12620 VkPipelineObj pipe(m_device);
12621 pipe.AddColorAttachment();
12622 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012623 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012624 pipe.AddShader(&fs);
12625
12626 VkDescriptorSetObj descriptorSet(m_device);
12627 descriptorSet.AppendDummy();
12628 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12629
12630 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12631
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012632 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012633}
12634
Chris Forbes82ff92a2016-09-09 10:50:24 +120012635TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12637 "No entrypoint found named `foo`");
12638
12639 ASSERT_NO_FATAL_FAILURE(InitState());
12640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12641
12642 char const *vsSource = "#version 450\n"
12643 "out gl_PerVertex {\n"
12644 " vec4 gl_Position;\n"
12645 "};\n"
12646 "void main(){\n"
12647 " gl_Position = vec4(0);\n"
12648 "}\n";
12649 char const *fsSource = "#version 450\n"
12650 "\n"
12651 "layout(location=0) out vec4 color;\n"
12652 "void main(){\n"
12653 " color = vec4(1);\n"
12654 "}\n";
12655
12656 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12657 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12658
12659 VkPipelineObj pipe(m_device);
12660 pipe.AddColorAttachment();
12661 pipe.AddShader(&vs);
12662 pipe.AddShader(&fs);
12663
12664 VkDescriptorSetObj descriptorSet(m_device);
12665 descriptorSet.AppendDummy();
12666 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12667
12668 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12669
12670 m_errorMonitor->VerifyFound();
12671}
12672
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012673TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12674 m_errorMonitor->SetDesiredFailureMsg(
12675 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12676 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12677 "uses a depth/stencil attachment");
12678
12679 ASSERT_NO_FATAL_FAILURE(InitState());
12680 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12681
12682 char const *vsSource = "#version 450\n"
12683 "void main(){ gl_Position = vec4(0); }\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";
12690
12691 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12692 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12693
12694 VkPipelineObj pipe(m_device);
12695 pipe.AddColorAttachment();
12696 pipe.AddShader(&vs);
12697 pipe.AddShader(&fs);
12698
12699 VkDescriptorSetObj descriptorSet(m_device);
12700 descriptorSet.AppendDummy();
12701 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12702
12703 VkAttachmentDescription attachments[] = {
12704 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12705 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12706 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12707 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12708 },
12709 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12710 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12711 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12712 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12713 },
12714 };
12715 VkAttachmentReference refs[] = {
12716 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12717 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12718 };
12719 VkSubpassDescription subpass = {
12720 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12721 1, &refs[0], nullptr, &refs[1],
12722 0, nullptr
12723 };
12724 VkRenderPassCreateInfo rpci = {
12725 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12726 0, 2, attachments, 1, &subpass, 0, nullptr
12727 };
12728 VkRenderPass rp;
12729 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12730 ASSERT_VK_SUCCESS(err);
12731
12732 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12733
12734 m_errorMonitor->VerifyFound();
12735
12736 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12737}
12738
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012739TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012740 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12741 "the TCS without the patch decoration, but consumed in the TES "
12742 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12744 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012745
12746 ASSERT_NO_FATAL_FAILURE(InitState());
12747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12748
Chris Forbesc1e852d2016-04-04 19:26:42 +120012749 if (!m_device->phy().features().tessellationShader) {
12750 printf("Device does not support tessellation shaders; skipped.\n");
12751 return;
12752 }
12753
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012754 char const *vsSource = "#version 450\n"
12755 "void main(){}\n";
12756 char const *tcsSource = "#version 450\n"
12757 "layout(location=0) out int x[];\n"
12758 "layout(vertices=3) out;\n"
12759 "void main(){\n"
12760 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12761 " gl_TessLevelInner[0] = 1;\n"
12762 " x[gl_InvocationID] = gl_InvocationID;\n"
12763 "}\n";
12764 char const *tesSource = "#version 450\n"
12765 "layout(triangles, equal_spacing, cw) in;\n"
12766 "layout(location=0) patch in int x;\n"
12767 "out gl_PerVertex { vec4 gl_Position; };\n"
12768 "void main(){\n"
12769 " gl_Position.xyz = gl_TessCoord;\n"
12770 " gl_Position.w = x;\n"
12771 "}\n";
12772 char const *fsSource = "#version 450\n"
12773 "layout(location=0) out vec4 color;\n"
12774 "void main(){\n"
12775 " color = vec4(1);\n"
12776 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012777
12778 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12779 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12780 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12781 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12782
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012783 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12784 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012785
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012786 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012787
12788 VkPipelineObj pipe(m_device);
12789 pipe.SetInputAssembly(&iasci);
12790 pipe.SetTessellation(&tsci);
12791 pipe.AddColorAttachment();
12792 pipe.AddShader(&vs);
12793 pipe.AddShader(&tcs);
12794 pipe.AddShader(&tes);
12795 pipe.AddShader(&fs);
12796
12797 VkDescriptorSetObj descriptorSet(m_device);
12798 descriptorSet.AppendDummy();
12799 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12800
12801 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12802
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012803 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012804}
12805
Karl Schultz6addd812016-02-02 17:17:23 -070012806TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012807 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12808 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12810 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012811
Chris Forbes280ba2c2015-06-12 11:16:41 +120012812 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012814
12815 /* Two binding descriptions for binding 0 */
12816 VkVertexInputBindingDescription input_bindings[2];
12817 memset(input_bindings, 0, sizeof(input_bindings));
12818
12819 VkVertexInputAttributeDescription input_attrib;
12820 memset(&input_attrib, 0, sizeof(input_attrib));
12821 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12822
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012823 char const *vsSource = "#version 450\n"
12824 "\n"
12825 "layout(location=0) in float x;\n" /* attrib provided float */
12826 "out gl_PerVertex {\n"
12827 " vec4 gl_Position;\n"
12828 "};\n"
12829 "void main(){\n"
12830 " gl_Position = vec4(x);\n"
12831 "}\n";
12832 char const *fsSource = "#version 450\n"
12833 "\n"
12834 "layout(location=0) out vec4 color;\n"
12835 "void main(){\n"
12836 " color = vec4(1);\n"
12837 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012838
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012839 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12840 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012841
12842 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012843 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012844 pipe.AddShader(&vs);
12845 pipe.AddShader(&fs);
12846
12847 pipe.AddVertexInputBindings(input_bindings, 2);
12848 pipe.AddVertexInputAttribs(&input_attrib, 1);
12849
Chris Forbes280ba2c2015-06-12 11:16:41 +120012850 VkDescriptorSetObj descriptorSet(m_device);
12851 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012852 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012853
Tony Barbour5781e8f2015-08-04 16:23:11 -060012854 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012855
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012856 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012857}
Chris Forbes8f68b562015-05-25 11:13:32 +120012858
Karl Schultz6addd812016-02-02 17:17:23 -070012859TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012860 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012861 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012863
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012864 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012866 char const *vsSource = "#version 450\n"
12867 "\n"
12868 "out gl_PerVertex {\n"
12869 " vec4 gl_Position;\n"
12870 "};\n"
12871 "void main(){\n"
12872 " gl_Position = vec4(1);\n"
12873 "}\n";
12874 char const *fsSource = "#version 450\n"
12875 "\n"
12876 "void main(){\n"
12877 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012878
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012879 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12880 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012881
12882 VkPipelineObj pipe(m_device);
12883 pipe.AddShader(&vs);
12884 pipe.AddShader(&fs);
12885
Chia-I Wu08accc62015-07-07 11:50:03 +080012886 /* set up CB 0, not written */
12887 pipe.AddColorAttachment();
12888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012889
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012890 VkDescriptorSetObj descriptorSet(m_device);
12891 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012892 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012893
Tony Barbour5781e8f2015-08-04 16:23:11 -060012894 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012895
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012896 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012897}
12898
Karl Schultz6addd812016-02-02 17:17:23 -070012899TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012900 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120012901 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012903 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012904
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012905 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012907 char const *vsSource = "#version 450\n"
12908 "\n"
12909 "out gl_PerVertex {\n"
12910 " vec4 gl_Position;\n"
12911 "};\n"
12912 "void main(){\n"
12913 " gl_Position = vec4(1);\n"
12914 "}\n";
12915 char const *fsSource = "#version 450\n"
12916 "\n"
12917 "layout(location=0) out vec4 x;\n"
12918 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
12919 "void main(){\n"
12920 " x = vec4(1);\n"
12921 " y = vec4(1);\n"
12922 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012923
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012924 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12925 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012926
12927 VkPipelineObj pipe(m_device);
12928 pipe.AddShader(&vs);
12929 pipe.AddShader(&fs);
12930
Chia-I Wu08accc62015-07-07 11:50:03 +080012931 /* set up CB 0, not written */
12932 pipe.AddColorAttachment();
12933 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012934 /* FS writes CB 1, but we don't configure it */
12935
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012936 VkDescriptorSetObj descriptorSet(m_device);
12937 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012938 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012939
Tony Barbour5781e8f2015-08-04 16:23:11 -060012940 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012941
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012942 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120012943}
12944
Karl Schultz6addd812016-02-02 17:17:23 -070012945TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012946 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012947 "type of an fragment shader output variable, and the format of the corresponding attachment");
12948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012949
Chris Forbesa36d69e2015-05-25 11:13:44 +120012950 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012952 char const *vsSource = "#version 450\n"
12953 "\n"
12954 "out gl_PerVertex {\n"
12955 " vec4 gl_Position;\n"
12956 "};\n"
12957 "void main(){\n"
12958 " gl_Position = vec4(1);\n"
12959 "}\n";
12960 char const *fsSource = "#version 450\n"
12961 "\n"
12962 "layout(location=0) out ivec4 x;\n" /* not UNORM */
12963 "void main(){\n"
12964 " x = ivec4(1);\n"
12965 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120012966
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012967 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12968 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012969
12970 VkPipelineObj pipe(m_device);
12971 pipe.AddShader(&vs);
12972 pipe.AddShader(&fs);
12973
Chia-I Wu08accc62015-07-07 11:50:03 +080012974 /* set up CB 0; type is UNORM by default */
12975 pipe.AddColorAttachment();
12976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012977
Chris Forbesa36d69e2015-05-25 11:13:44 +120012978 VkDescriptorSetObj descriptorSet(m_device);
12979 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012980 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120012981
Tony Barbour5781e8f2015-08-04 16:23:11 -060012982 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120012983
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012984 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120012985}
Chris Forbes7b1b8932015-06-05 14:43:36 +120012986
Karl Schultz6addd812016-02-02 17:17:23 -070012987TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012988 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
12989 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012991
Chris Forbes556c76c2015-08-14 12:04:59 +120012992 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120012993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012994 char const *vsSource = "#version 450\n"
12995 "\n"
12996 "out gl_PerVertex {\n"
12997 " vec4 gl_Position;\n"
12998 "};\n"
12999 "void main(){\n"
13000 " gl_Position = vec4(1);\n"
13001 "}\n";
13002 char const *fsSource = "#version 450\n"
13003 "\n"
13004 "layout(location=0) out vec4 x;\n"
13005 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13006 "void main(){\n"
13007 " x = vec4(bar.y);\n"
13008 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013009
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013010 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13011 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013012
Chris Forbes556c76c2015-08-14 12:04:59 +120013013 VkPipelineObj pipe(m_device);
13014 pipe.AddShader(&vs);
13015 pipe.AddShader(&fs);
13016
13017 /* set up CB 0; type is UNORM by default */
13018 pipe.AddColorAttachment();
13019 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13020
13021 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013022 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013023
13024 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13025
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013026 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013027}
13028
Chris Forbes5c59e902016-02-26 16:56:09 +130013029TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013030 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13031 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013033
13034 ASSERT_NO_FATAL_FAILURE(InitState());
13035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013036 char const *vsSource = "#version 450\n"
13037 "\n"
13038 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13039 "out gl_PerVertex {\n"
13040 " vec4 gl_Position;\n"
13041 "};\n"
13042 "void main(){\n"
13043 " gl_Position = vec4(consts.x);\n"
13044 "}\n";
13045 char const *fsSource = "#version 450\n"
13046 "\n"
13047 "layout(location=0) out vec4 x;\n"
13048 "void main(){\n"
13049 " x = vec4(1);\n"
13050 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013051
13052 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13053 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13054
13055 VkPipelineObj pipe(m_device);
13056 pipe.AddShader(&vs);
13057 pipe.AddShader(&fs);
13058
13059 /* set up CB 0; type is UNORM by default */
13060 pipe.AddColorAttachment();
13061 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13062
13063 VkDescriptorSetObj descriptorSet(m_device);
13064 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13065
13066 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13067
13068 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013069 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013070}
13071
Chris Forbes3fb17902016-08-22 14:57:55 +120013072TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13073 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13074 "which is not included in the subpass description");
13075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13076 "consumes input attachment index 0 but not provided in subpass");
13077
13078 ASSERT_NO_FATAL_FAILURE(InitState());
13079
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013080 char const *vsSource = "#version 450\n"
13081 "\n"
13082 "out gl_PerVertex {\n"
13083 " vec4 gl_Position;\n"
13084 "};\n"
13085 "void main(){\n"
13086 " gl_Position = vec4(1);\n"
13087 "}\n";
13088 char const *fsSource = "#version 450\n"
13089 "\n"
13090 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13091 "layout(location=0) out vec4 color;\n"
13092 "void main() {\n"
13093 " color = subpassLoad(x);\n"
13094 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013095
13096 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13097 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13098
13099 VkPipelineObj pipe(m_device);
13100 pipe.AddShader(&vs);
13101 pipe.AddShader(&fs);
13102 pipe.AddColorAttachment();
13103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013105 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13106 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013107 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013108 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013109 ASSERT_VK_SUCCESS(err);
13110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013111 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013112 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013113 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013114 ASSERT_VK_SUCCESS(err);
13115
13116 // error here.
13117 pipe.CreateVKPipeline(pl, renderPass());
13118
13119 m_errorMonitor->VerifyFound();
13120
13121 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13122 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13123}
13124
Chris Forbes5a9a0472016-08-22 16:02:09 +120013125TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13126 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13127 "with a format having a different fundamental type");
13128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13129 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13130
13131 ASSERT_NO_FATAL_FAILURE(InitState());
13132
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013133 char const *vsSource = "#version 450\n"
13134 "\n"
13135 "out gl_PerVertex {\n"
13136 " vec4 gl_Position;\n"
13137 "};\n"
13138 "void main(){\n"
13139 " gl_Position = vec4(1);\n"
13140 "}\n";
13141 char const *fsSource = "#version 450\n"
13142 "\n"
13143 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13144 "layout(location=0) out vec4 color;\n"
13145 "void main() {\n"
13146 " color = subpassLoad(x);\n"
13147 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013148
13149 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13150 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13151
13152 VkPipelineObj pipe(m_device);
13153 pipe.AddShader(&vs);
13154 pipe.AddShader(&fs);
13155 pipe.AddColorAttachment();
13156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013158 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13159 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013160 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013161 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013162 ASSERT_VK_SUCCESS(err);
13163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013164 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013165 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013166 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013167 ASSERT_VK_SUCCESS(err);
13168
13169 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013170 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13171 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13172 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13173 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13174 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 +120013175 };
13176 VkAttachmentReference color = {
13177 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13178 };
13179 VkAttachmentReference input = {
13180 1, VK_IMAGE_LAYOUT_GENERAL,
13181 };
13182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013183 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013185 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013186 VkRenderPass rp;
13187 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13188 ASSERT_VK_SUCCESS(err);
13189
13190 // error here.
13191 pipe.CreateVKPipeline(pl, rp);
13192
13193 m_errorMonitor->VerifyFound();
13194
13195 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13196 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13197 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13198}
13199
Chris Forbes541f7b02016-08-22 15:30:27 +120013200TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13201 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13202 "which is not included in the subpass description -- array case");
13203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13204 "consumes input attachment index 1 but not provided in subpass");
13205
13206 ASSERT_NO_FATAL_FAILURE(InitState());
13207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013208 char const *vsSource = "#version 450\n"
13209 "\n"
13210 "out gl_PerVertex {\n"
13211 " vec4 gl_Position;\n"
13212 "};\n"
13213 "void main(){\n"
13214 " gl_Position = vec4(1);\n"
13215 "}\n";
13216 char const *fsSource = "#version 450\n"
13217 "\n"
13218 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13219 "layout(location=0) out vec4 color;\n"
13220 "void main() {\n"
13221 " color = subpassLoad(xs[1]);\n"
13222 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013223
13224 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13225 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13226
13227 VkPipelineObj pipe(m_device);
13228 pipe.AddShader(&vs);
13229 pipe.AddShader(&fs);
13230 pipe.AddColorAttachment();
13231 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013233 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13234 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013235 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013236 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013237 ASSERT_VK_SUCCESS(err);
13238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013239 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013240 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013241 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013242 ASSERT_VK_SUCCESS(err);
13243
13244 // error here.
13245 pipe.CreateVKPipeline(pl, renderPass());
13246
13247 m_errorMonitor->VerifyFound();
13248
13249 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13250 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13251}
13252
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013253TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013254 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13255 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013257
13258 ASSERT_NO_FATAL_FAILURE(InitState());
13259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013260 char const *csSource = "#version 450\n"
13261 "\n"
13262 "layout(local_size_x=1) in;\n"
13263 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13264 "void main(){\n"
13265 " x = vec4(1);\n"
13266 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013267
13268 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13269
13270 VkDescriptorSetObj descriptorSet(m_device);
13271 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013273 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13274 nullptr,
13275 0,
13276 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13277 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13278 descriptorSet.GetPipelineLayout(),
13279 VK_NULL_HANDLE,
13280 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013281
13282 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013283 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013284
13285 m_errorMonitor->VerifyFound();
13286
13287 if (err == VK_SUCCESS) {
13288 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13289 }
13290}
13291
Chris Forbes22a9b092016-07-19 14:34:05 +120013292TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013293 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13294 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13296 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013297
13298 ASSERT_NO_FATAL_FAILURE(InitState());
13299
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013300 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13301 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013302 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013303 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013304 ASSERT_VK_SUCCESS(err);
13305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013306 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013307 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013308 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013309 ASSERT_VK_SUCCESS(err);
13310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013311 char const *csSource = "#version 450\n"
13312 "\n"
13313 "layout(local_size_x=1) in;\n"
13314 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13315 "void main() {\n"
13316 " x.x = 1.0f;\n"
13317 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013318 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013320 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13321 nullptr,
13322 0,
13323 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13324 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13325 pl,
13326 VK_NULL_HANDLE,
13327 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013328
13329 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013330 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013331
13332 m_errorMonitor->VerifyFound();
13333
13334 if (err == VK_SUCCESS) {
13335 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13336 }
13337
13338 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13339 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13340}
13341
Chris Forbes50020592016-07-27 13:52:41 +120013342TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13343 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13344 "does not match the dimensionality declared in the shader");
13345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013346 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 +120013347
13348 ASSERT_NO_FATAL_FAILURE(InitState());
13349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013351 char const *vsSource = "#version 450\n"
13352 "\n"
13353 "out gl_PerVertex { vec4 gl_Position; };\n"
13354 "void main() { gl_Position = vec4(0); }\n";
13355 char const *fsSource = "#version 450\n"
13356 "\n"
13357 "layout(set=0, binding=0) uniform sampler3D s;\n"
13358 "layout(location=0) out vec4 color;\n"
13359 "void main() {\n"
13360 " color = texture(s, vec3(0));\n"
13361 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013362 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13363 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13364
13365 VkPipelineObj pipe(m_device);
13366 pipe.AddShader(&vs);
13367 pipe.AddShader(&fs);
13368 pipe.AddColorAttachment();
13369
13370 VkTextureObj texture(m_device, nullptr);
13371 VkSamplerObj sampler(m_device);
13372
13373 VkDescriptorSetObj descriptorSet(m_device);
13374 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13375 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13376
13377 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13378 ASSERT_VK_SUCCESS(err);
13379
13380 BeginCommandBuffer();
13381
13382 m_commandBuffer->BindPipeline(pipe);
13383 m_commandBuffer->BindDescriptorSet(descriptorSet);
13384
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013385 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013386 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013387 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013388 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13389
13390 // error produced here.
13391 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13392
13393 m_errorMonitor->VerifyFound();
13394
13395 EndCommandBuffer();
13396}
13397
Chris Forbes5533bfc2016-07-27 14:12:34 +120013398TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13399 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13400 "are consumed via singlesample images types in the shader, or vice versa.");
13401
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013403
13404 ASSERT_NO_FATAL_FAILURE(InitState());
13405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13406
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013407 char const *vsSource = "#version 450\n"
13408 "\n"
13409 "out gl_PerVertex { vec4 gl_Position; };\n"
13410 "void main() { gl_Position = vec4(0); }\n";
13411 char const *fsSource = "#version 450\n"
13412 "\n"
13413 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13414 "layout(location=0) out vec4 color;\n"
13415 "void main() {\n"
13416 " color = texelFetch(s, ivec2(0), 0);\n"
13417 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013418 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13419 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13420
13421 VkPipelineObj pipe(m_device);
13422 pipe.AddShader(&vs);
13423 pipe.AddShader(&fs);
13424 pipe.AddColorAttachment();
13425
13426 VkTextureObj texture(m_device, nullptr);
13427 VkSamplerObj sampler(m_device);
13428
13429 VkDescriptorSetObj descriptorSet(m_device);
13430 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13431 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13432
13433 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13434 ASSERT_VK_SUCCESS(err);
13435
13436 BeginCommandBuffer();
13437
13438 m_commandBuffer->BindPipeline(pipe);
13439 m_commandBuffer->BindDescriptorSet(descriptorSet);
13440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013441 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013442 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013443 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013444 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13445
13446 // error produced here.
13447 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13448
13449 m_errorMonitor->VerifyFound();
13450
13451 EndCommandBuffer();
13452}
13453
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013454#endif // SHADER_CHECKER_TESTS
13455
13456#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013457TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013459
13460 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013461
13462 // Create an image
13463 VkImage image;
13464
Karl Schultz6addd812016-02-02 17:17:23 -070013465 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13466 const int32_t tex_width = 32;
13467 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013468
13469 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013470 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13471 image_create_info.pNext = NULL;
13472 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13473 image_create_info.format = tex_format;
13474 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013475 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013476 image_create_info.extent.depth = 1;
13477 image_create_info.mipLevels = 1;
13478 image_create_info.arrayLayers = 1;
13479 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13480 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13481 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13482 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013483
13484 // Introduce error by sending down a bogus width extent
13485 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013486 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013487
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013488 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013489}
13490
Mark Youngc48c4c12016-04-11 14:26:49 -060013491TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13493 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013494
13495 ASSERT_NO_FATAL_FAILURE(InitState());
13496
13497 // Create an image
13498 VkImage image;
13499
13500 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13501 const int32_t tex_width = 32;
13502 const int32_t tex_height = 32;
13503
13504 VkImageCreateInfo image_create_info = {};
13505 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13506 image_create_info.pNext = NULL;
13507 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13508 image_create_info.format = tex_format;
13509 image_create_info.extent.width = tex_width;
13510 image_create_info.extent.height = tex_height;
13511 image_create_info.extent.depth = 1;
13512 image_create_info.mipLevels = 1;
13513 image_create_info.arrayLayers = 1;
13514 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13515 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13516 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13517 image_create_info.flags = 0;
13518
13519 // Introduce error by sending down a bogus width extent
13520 image_create_info.extent.width = 0;
13521 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13522
13523 m_errorMonitor->VerifyFound();
13524}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013525#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013526
Tobin Ehliscde08892015-09-22 10:11:37 -060013527#if IMAGE_TESTS
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013528TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13529 TEST_DESCRIPTION("Create a render pass with an attachment description "
13530 "format set to VK_FORMAT_UNDEFINED");
13531
13532 ASSERT_NO_FATAL_FAILURE(InitState());
13533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013536
13537 VkAttachmentReference color_attach = {};
13538 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13539 color_attach.attachment = 0;
13540 VkSubpassDescription subpass = {};
13541 subpass.colorAttachmentCount = 1;
13542 subpass.pColorAttachments = &color_attach;
13543
13544 VkRenderPassCreateInfo rpci = {};
13545 rpci.subpassCount = 1;
13546 rpci.pSubpasses = &subpass;
13547 rpci.attachmentCount = 1;
13548 VkAttachmentDescription attach_desc = {};
13549 attach_desc.format = VK_FORMAT_UNDEFINED;
13550 rpci.pAttachments = &attach_desc;
13551 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13552 VkRenderPass rp;
13553 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13554
13555 m_errorMonitor->VerifyFound();
13556
13557 if (result == VK_SUCCESS) {
13558 vkDestroyRenderPass(m_device->device(), rp, NULL);
13559 }
13560}
13561
Karl Schultz6addd812016-02-02 17:17:23 -070013562TEST_F(VkLayerTest, InvalidImageView) {
13563 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013564
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013566
Tobin Ehliscde08892015-09-22 10:11:37 -060013567 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013568
Mike Stroyana3082432015-09-25 13:39:21 -060013569 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013570 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013571
Karl Schultz6addd812016-02-02 17:17:23 -070013572 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13573 const int32_t tex_width = 32;
13574 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013575
13576 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013577 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13578 image_create_info.pNext = NULL;
13579 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13580 image_create_info.format = tex_format;
13581 image_create_info.extent.width = tex_width;
13582 image_create_info.extent.height = tex_height;
13583 image_create_info.extent.depth = 1;
13584 image_create_info.mipLevels = 1;
13585 image_create_info.arrayLayers = 1;
13586 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13587 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13588 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13589 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013590
Chia-I Wuf7458c52015-10-26 21:10:41 +080013591 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013592 ASSERT_VK_SUCCESS(err);
13593
13594 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013595 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13596 image_view_create_info.image = image;
13597 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13598 image_view_create_info.format = tex_format;
13599 image_view_create_info.subresourceRange.layerCount = 1;
13600 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13601 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013602 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013603
13604 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013605 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013606
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013607 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013608 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013609}
Mike Stroyana3082432015-09-25 13:39:21 -060013610
Mark Youngd339ba32016-05-30 13:28:35 -060013611TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13612 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013614 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013615
13616 ASSERT_NO_FATAL_FAILURE(InitState());
13617
13618 // Create an image and try to create a view with no memory backing the image
13619 VkImage image;
13620
13621 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13622 const int32_t tex_width = 32;
13623 const int32_t tex_height = 32;
13624
13625 VkImageCreateInfo image_create_info = {};
13626 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13627 image_create_info.pNext = NULL;
13628 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13629 image_create_info.format = tex_format;
13630 image_create_info.extent.width = tex_width;
13631 image_create_info.extent.height = tex_height;
13632 image_create_info.extent.depth = 1;
13633 image_create_info.mipLevels = 1;
13634 image_create_info.arrayLayers = 1;
13635 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13636 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13637 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13638 image_create_info.flags = 0;
13639
13640 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13641 ASSERT_VK_SUCCESS(err);
13642
13643 VkImageViewCreateInfo image_view_create_info = {};
13644 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13645 image_view_create_info.image = image;
13646 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13647 image_view_create_info.format = tex_format;
13648 image_view_create_info.subresourceRange.layerCount = 1;
13649 image_view_create_info.subresourceRange.baseMipLevel = 0;
13650 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013651 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013652
13653 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013654 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013655
13656 m_errorMonitor->VerifyFound();
13657 vkDestroyImage(m_device->device(), image, NULL);
13658 // If last error is success, it still created the view, so delete it.
13659 if (err == VK_SUCCESS) {
13660 vkDestroyImageView(m_device->device(), view, NULL);
13661 }
Mark Youngd339ba32016-05-30 13:28:35 -060013662}
13663
Karl Schultz6addd812016-02-02 17:17:23 -070013664TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013665 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013667 "formats must have ONLY the "
13668 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13670 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013671
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013672 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013673
Karl Schultz6addd812016-02-02 17:17:23 -070013674 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013675 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013676 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013677 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013678
13679 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013680 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013681 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013682 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13683 image_view_create_info.format = tex_format;
13684 image_view_create_info.subresourceRange.baseMipLevel = 0;
13685 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013686 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013687 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013688 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013689
13690 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013691 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013692
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013693 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013694}
13695
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013696TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013697 VkResult err;
13698 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13701 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013702
Mike Stroyana3082432015-09-25 13:39:21 -060013703 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013704
13705 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013706 VkImage srcImage;
13707 VkImage dstImage;
13708 VkDeviceMemory srcMem;
13709 VkDeviceMemory destMem;
13710 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013711
13712 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013713 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13714 image_create_info.pNext = NULL;
13715 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13716 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13717 image_create_info.extent.width = 32;
13718 image_create_info.extent.height = 32;
13719 image_create_info.extent.depth = 1;
13720 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013721 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013722 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13723 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13724 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13725 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013726
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013727 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013728 ASSERT_VK_SUCCESS(err);
13729
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013730 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013731 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013732 ASSERT_VK_SUCCESS(err);
13733
13734 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013735 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013736 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13737 memAlloc.pNext = NULL;
13738 memAlloc.allocationSize = 0;
13739 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013740
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013741 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013742 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013743 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013744 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013745 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013746 ASSERT_VK_SUCCESS(err);
13747
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013748 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013749 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013750 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013751 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013752 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013753 ASSERT_VK_SUCCESS(err);
13754
13755 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13756 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013757 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013758 ASSERT_VK_SUCCESS(err);
13759
13760 BeginCommandBuffer();
13761 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013762 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013763 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013764 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013765 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013766 copyRegion.srcOffset.x = 0;
13767 copyRegion.srcOffset.y = 0;
13768 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013769 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013770 copyRegion.dstSubresource.mipLevel = 0;
13771 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013772 // Introduce failure by forcing the dst layerCount to differ from src
13773 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013774 copyRegion.dstOffset.x = 0;
13775 copyRegion.dstOffset.y = 0;
13776 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013777 copyRegion.extent.width = 1;
13778 copyRegion.extent.height = 1;
13779 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013780 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013781 EndCommandBuffer();
13782
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013783 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013784
Chia-I Wuf7458c52015-10-26 21:10:41 +080013785 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013786 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013787 vkFreeMemory(m_device->device(), srcMem, NULL);
13788 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013789}
13790
Tony Barbourd6673642016-05-05 14:46:39 -060013791TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13792
13793 TEST_DESCRIPTION("Creating images with unsuported formats ");
13794
13795 ASSERT_NO_FATAL_FAILURE(InitState());
13796 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13797 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013798 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 -060013799 VK_IMAGE_TILING_OPTIMAL, 0);
13800 ASSERT_TRUE(image.initialized());
13801
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013802 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13803 VkImageCreateInfo image_create_info;
13804 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13805 image_create_info.pNext = NULL;
13806 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13807 image_create_info.format = VK_FORMAT_UNDEFINED;
13808 image_create_info.extent.width = 32;
13809 image_create_info.extent.height = 32;
13810 image_create_info.extent.depth = 1;
13811 image_create_info.mipLevels = 1;
13812 image_create_info.arrayLayers = 1;
13813 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13814 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13815 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13816 image_create_info.flags = 0;
13817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13819 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013820
13821 VkImage localImage;
13822 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13823 m_errorMonitor->VerifyFound();
13824
Tony Barbourd6673642016-05-05 14:46:39 -060013825 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013826 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013827 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13828 VkFormat format = static_cast<VkFormat>(f);
13829 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013830 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013831 unsupported = format;
13832 break;
13833 }
13834 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013835
Tony Barbourd6673642016-05-05 14:46:39 -060013836 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013837 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013839
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013840 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013841 m_errorMonitor->VerifyFound();
13842 }
13843}
13844
13845TEST_F(VkLayerTest, ImageLayerViewTests) {
13846 VkResult ret;
13847 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13848
13849 ASSERT_NO_FATAL_FAILURE(InitState());
13850
13851 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013852 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 -060013853 VK_IMAGE_TILING_OPTIMAL, 0);
13854 ASSERT_TRUE(image.initialized());
13855
13856 VkImageView imgView;
13857 VkImageViewCreateInfo imgViewInfo = {};
13858 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13859 imgViewInfo.image = image.handle();
13860 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13861 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13862 imgViewInfo.subresourceRange.layerCount = 1;
13863 imgViewInfo.subresourceRange.baseMipLevel = 0;
13864 imgViewInfo.subresourceRange.levelCount = 1;
13865 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13866
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013868 // View can't have baseMipLevel >= image's mipLevels - Expect
13869 // VIEW_CREATE_ERROR
13870 imgViewInfo.subresourceRange.baseMipLevel = 1;
13871 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13872 m_errorMonitor->VerifyFound();
13873 imgViewInfo.subresourceRange.baseMipLevel = 0;
13874
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013876 // View can't have baseArrayLayer >= image's arraySize - Expect
13877 // VIEW_CREATE_ERROR
13878 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13879 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13880 m_errorMonitor->VerifyFound();
13881 imgViewInfo.subresourceRange.baseArrayLayer = 0;
13882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13884 "pCreateInfo->subresourceRange."
13885 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013886 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
13887 imgViewInfo.subresourceRange.levelCount = 0;
13888 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13889 m_errorMonitor->VerifyFound();
13890 imgViewInfo.subresourceRange.levelCount = 1;
13891
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13893 "pCreateInfo->subresourceRange."
13894 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013895 m_errorMonitor->SetDesiredFailureMsg(
13896 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13897 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060013898 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
13899 imgViewInfo.subresourceRange.layerCount = 0;
13900 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13901 m_errorMonitor->VerifyFound();
13902 imgViewInfo.subresourceRange.layerCount = 1;
13903
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13906 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13907 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013908 // Can't use depth format for view into color image - Expect INVALID_FORMAT
13909 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
13910 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13911 m_errorMonitor->VerifyFound();
13912 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
13915 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
13916 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060013917 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
13918 // VIEW_CREATE_ERROR
13919 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
13920 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13921 m_errorMonitor->VerifyFound();
13922 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13923
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
13925 "differing formats but they must be "
13926 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013927 // TODO: Update framework to easily passing mutable flag into ImageObj init
13928 // For now just allowing image for this one test to not have memory bound
13929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13930 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060013931 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
13932 // VIEW_CREATE_ERROR
13933 VkImageCreateInfo mutImgInfo = image.create_info();
13934 VkImage mutImage;
13935 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013936 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060013937 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
13938 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
13939 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
13940 ASSERT_VK_SUCCESS(ret);
13941 imgViewInfo.image = mutImage;
13942 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13943 m_errorMonitor->VerifyFound();
13944 imgViewInfo.image = image.handle();
13945 vkDestroyImage(m_device->handle(), mutImage, NULL);
13946}
13947
13948TEST_F(VkLayerTest, MiscImageLayerTests) {
13949
13950 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
13951
13952 ASSERT_NO_FATAL_FAILURE(InitState());
13953
13954 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013955 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 -060013956 VK_IMAGE_TILING_OPTIMAL, 0);
13957 ASSERT_TRUE(image.initialized());
13958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060013960 vk_testing::Buffer buffer;
13961 VkMemoryPropertyFlags reqs = 0;
13962 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
13963 VkBufferImageCopy region = {};
13964 region.bufferRowLength = 128;
13965 region.bufferImageHeight = 128;
13966 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13967 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
13968 region.imageSubresource.layerCount = 0;
13969 region.imageExtent.height = 4;
13970 region.imageExtent.width = 4;
13971 region.imageExtent.depth = 1;
13972 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013973 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13974 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060013975 m_errorMonitor->VerifyFound();
13976 region.imageSubresource.layerCount = 1;
13977
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013978 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
13979 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
13980 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
13982 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13983 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013984 m_errorMonitor->VerifyFound();
13985
13986 // BufferOffset must be a multiple of 4
13987 // Introduce failure by setting bufferOffset to a value not divisible by 4
13988 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
13990 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
13991 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060013992 m_errorMonitor->VerifyFound();
13993
13994 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
13995 region.bufferOffset = 0;
13996 region.imageExtent.height = 128;
13997 region.imageExtent.width = 128;
13998 // Introduce failure by setting bufferRowLength > 0 but less than width
13999 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14001 "must be zero or greater-than-or-equal-to imageExtent.width");
14002 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14003 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014004 m_errorMonitor->VerifyFound();
14005
14006 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14007 region.bufferRowLength = 128;
14008 // Introduce failure by setting bufferRowHeight > 0 but less than height
14009 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14011 "must be zero or greater-than-or-equal-to imageExtent.height");
14012 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14013 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014014 m_errorMonitor->VerifyFound();
14015
14016 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14018 "specify only COLOR or DEPTH or "
14019 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014020 // Expect MISMATCHED_IMAGE_ASPECT
14021 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014022 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14023 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014024 m_errorMonitor->VerifyFound();
14025 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14026
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14028 "If the format of srcImage is a depth, stencil, depth stencil or "
14029 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014030 // Expect INVALID_FILTER
14031 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014032 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 -060014033 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014034 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 -060014035 VkImageBlit blitRegion = {};
14036 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14037 blitRegion.srcSubresource.baseArrayLayer = 0;
14038 blitRegion.srcSubresource.layerCount = 1;
14039 blitRegion.srcSubresource.mipLevel = 0;
14040 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14041 blitRegion.dstSubresource.baseArrayLayer = 0;
14042 blitRegion.dstSubresource.layerCount = 1;
14043 blitRegion.dstSubresource.mipLevel = 0;
14044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014045 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14046 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014047 m_errorMonitor->VerifyFound();
14048
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014049 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14051 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14052 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014053 m_errorMonitor->VerifyFound();
14054
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014056 VkImageMemoryBarrier img_barrier;
14057 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14058 img_barrier.pNext = NULL;
14059 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14060 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14061 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14062 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14063 img_barrier.image = image.handle();
14064 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14065 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14066 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14067 img_barrier.subresourceRange.baseArrayLayer = 0;
14068 img_barrier.subresourceRange.baseMipLevel = 0;
14069 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14070 img_barrier.subresourceRange.layerCount = 0;
14071 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014072 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14073 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014074 m_errorMonitor->VerifyFound();
14075 img_barrier.subresourceRange.layerCount = 1;
14076}
14077
14078TEST_F(VkLayerTest, ImageFormatLimits) {
14079
14080 TEST_DESCRIPTION("Exceed the limits of image format ");
14081
Cody Northropc31a84f2016-08-22 10:41:47 -060014082 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014084 VkImageCreateInfo image_create_info = {};
14085 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14086 image_create_info.pNext = NULL;
14087 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14088 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14089 image_create_info.extent.width = 32;
14090 image_create_info.extent.height = 32;
14091 image_create_info.extent.depth = 1;
14092 image_create_info.mipLevels = 1;
14093 image_create_info.arrayLayers = 1;
14094 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14095 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14096 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14097 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14098 image_create_info.flags = 0;
14099
14100 VkImage nullImg;
14101 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014102 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14103 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014104 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14105 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14106 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14107 m_errorMonitor->VerifyFound();
14108 image_create_info.extent.depth = 1;
14109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014111 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14112 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14113 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14114 m_errorMonitor->VerifyFound();
14115 image_create_info.mipLevels = 1;
14116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014118 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14119 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14120 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14121 m_errorMonitor->VerifyFound();
14122 image_create_info.arrayLayers = 1;
14123
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014125 int samples = imgFmtProps.sampleCounts >> 1;
14126 image_create_info.samples = (VkSampleCountFlagBits)samples;
14127 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14128 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14129 m_errorMonitor->VerifyFound();
14130 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14133 "VK_IMAGE_LAYOUT_UNDEFINED or "
14134 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014135 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14136 // Expect INVALID_LAYOUT
14137 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14138 m_errorMonitor->VerifyFound();
14139 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14140}
14141
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014142TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14143
14144 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014146
14147 ASSERT_NO_FATAL_FAILURE(InitState());
14148
14149 VkImageObj src_image(m_device);
14150 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14151 VkImageObj dst_image(m_device);
14152 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14153
14154 BeginCommandBuffer();
14155 VkImageCopy copy_region;
14156 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14157 copy_region.srcSubresource.mipLevel = 0;
14158 copy_region.srcSubresource.baseArrayLayer = 0;
14159 copy_region.srcSubresource.layerCount = 0;
14160 copy_region.srcOffset.x = 0;
14161 copy_region.srcOffset.y = 0;
14162 copy_region.srcOffset.z = 0;
14163 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14164 copy_region.dstSubresource.mipLevel = 0;
14165 copy_region.dstSubresource.baseArrayLayer = 0;
14166 copy_region.dstSubresource.layerCount = 0;
14167 copy_region.dstOffset.x = 0;
14168 copy_region.dstOffset.y = 0;
14169 copy_region.dstOffset.z = 0;
14170 copy_region.extent.width = 64;
14171 copy_region.extent.height = 64;
14172 copy_region.extent.depth = 1;
14173 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14174 &copy_region);
14175 EndCommandBuffer();
14176
14177 m_errorMonitor->VerifyFound();
14178}
14179
14180TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14181
14182 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014184
14185 ASSERT_NO_FATAL_FAILURE(InitState());
14186
14187 VkImageObj src_image(m_device);
14188 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14189 VkImageObj dst_image(m_device);
14190 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14191
14192 BeginCommandBuffer();
14193 VkImageCopy copy_region;
14194 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14195 copy_region.srcSubresource.mipLevel = 0;
14196 copy_region.srcSubresource.baseArrayLayer = 0;
14197 copy_region.srcSubresource.layerCount = 0;
14198 copy_region.srcOffset.x = 0;
14199 copy_region.srcOffset.y = 0;
14200 copy_region.srcOffset.z = 0;
14201 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14202 copy_region.dstSubresource.mipLevel = 0;
14203 copy_region.dstSubresource.baseArrayLayer = 0;
14204 copy_region.dstSubresource.layerCount = 0;
14205 copy_region.dstOffset.x = 0;
14206 copy_region.dstOffset.y = 0;
14207 copy_region.dstOffset.z = 0;
14208 copy_region.extent.width = 64;
14209 copy_region.extent.height = 64;
14210 copy_region.extent.depth = 1;
14211 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14212 &copy_region);
14213 EndCommandBuffer();
14214
14215 m_errorMonitor->VerifyFound();
14216}
14217
Karl Schultz6addd812016-02-02 17:17:23 -070014218TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014219 VkResult err;
14220 bool pass;
14221
14222 // Create color images with different format sizes and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14224 "vkCmdCopyImage called with unmatched source and dest image format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014225
14226 ASSERT_NO_FATAL_FAILURE(InitState());
14227
14228 // Create two images of different types and try to copy between them
14229 VkImage srcImage;
14230 VkImage dstImage;
14231 VkDeviceMemory srcMem;
14232 VkDeviceMemory destMem;
14233 VkMemoryRequirements memReqs;
14234
14235 VkImageCreateInfo image_create_info = {};
14236 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14237 image_create_info.pNext = NULL;
14238 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14239 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14240 image_create_info.extent.width = 32;
14241 image_create_info.extent.height = 32;
14242 image_create_info.extent.depth = 1;
14243 image_create_info.mipLevels = 1;
14244 image_create_info.arrayLayers = 1;
14245 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14246 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14247 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14248 image_create_info.flags = 0;
14249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014250 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014251 ASSERT_VK_SUCCESS(err);
14252
14253 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14254 // Introduce failure by creating second image with a different-sized format.
14255 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14256
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014257 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014258 ASSERT_VK_SUCCESS(err);
14259
14260 // Allocate memory
14261 VkMemoryAllocateInfo memAlloc = {};
14262 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14263 memAlloc.pNext = NULL;
14264 memAlloc.allocationSize = 0;
14265 memAlloc.memoryTypeIndex = 0;
14266
14267 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14268 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014269 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014270 ASSERT_TRUE(pass);
14271 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14272 ASSERT_VK_SUCCESS(err);
14273
14274 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14275 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014276 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014277 ASSERT_TRUE(pass);
14278 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14279 ASSERT_VK_SUCCESS(err);
14280
14281 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14282 ASSERT_VK_SUCCESS(err);
14283 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14284 ASSERT_VK_SUCCESS(err);
14285
14286 BeginCommandBuffer();
14287 VkImageCopy copyRegion;
14288 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14289 copyRegion.srcSubresource.mipLevel = 0;
14290 copyRegion.srcSubresource.baseArrayLayer = 0;
14291 copyRegion.srcSubresource.layerCount = 0;
14292 copyRegion.srcOffset.x = 0;
14293 copyRegion.srcOffset.y = 0;
14294 copyRegion.srcOffset.z = 0;
14295 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14296 copyRegion.dstSubresource.mipLevel = 0;
14297 copyRegion.dstSubresource.baseArrayLayer = 0;
14298 copyRegion.dstSubresource.layerCount = 0;
14299 copyRegion.dstOffset.x = 0;
14300 copyRegion.dstOffset.y = 0;
14301 copyRegion.dstOffset.z = 0;
14302 copyRegion.extent.width = 1;
14303 copyRegion.extent.height = 1;
14304 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014305 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014306 EndCommandBuffer();
14307
14308 m_errorMonitor->VerifyFound();
14309
14310 vkDestroyImage(m_device->device(), srcImage, NULL);
14311 vkDestroyImage(m_device->device(), dstImage, NULL);
14312 vkFreeMemory(m_device->device(), srcMem, NULL);
14313 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014314}
14315
Karl Schultz6addd812016-02-02 17:17:23 -070014316TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14317 VkResult err;
14318 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014319
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014320 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14322 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014323
Mike Stroyana3082432015-09-25 13:39:21 -060014324 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014325
14326 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014327 VkImage srcImage;
14328 VkImage dstImage;
14329 VkDeviceMemory srcMem;
14330 VkDeviceMemory destMem;
14331 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014332
14333 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014334 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14335 image_create_info.pNext = NULL;
14336 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14337 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14338 image_create_info.extent.width = 32;
14339 image_create_info.extent.height = 32;
14340 image_create_info.extent.depth = 1;
14341 image_create_info.mipLevels = 1;
14342 image_create_info.arrayLayers = 1;
14343 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14344 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14346 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014348 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014349 ASSERT_VK_SUCCESS(err);
14350
Karl Schultzbdb75952016-04-19 11:36:49 -060014351 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14352
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014353 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014354 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014355 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014356 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014357
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014358 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014359 ASSERT_VK_SUCCESS(err);
14360
14361 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014362 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014363 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14364 memAlloc.pNext = NULL;
14365 memAlloc.allocationSize = 0;
14366 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014367
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014368 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014369 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014370 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014371 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014372 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014373 ASSERT_VK_SUCCESS(err);
14374
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014375 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014376 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014377 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014378 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014379 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014380 ASSERT_VK_SUCCESS(err);
14381
14382 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14383 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014384 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014385 ASSERT_VK_SUCCESS(err);
14386
14387 BeginCommandBuffer();
14388 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014389 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014390 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014391 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014392 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014393 copyRegion.srcOffset.x = 0;
14394 copyRegion.srcOffset.y = 0;
14395 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014396 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014397 copyRegion.dstSubresource.mipLevel = 0;
14398 copyRegion.dstSubresource.baseArrayLayer = 0;
14399 copyRegion.dstSubresource.layerCount = 0;
14400 copyRegion.dstOffset.x = 0;
14401 copyRegion.dstOffset.y = 0;
14402 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014403 copyRegion.extent.width = 1;
14404 copyRegion.extent.height = 1;
14405 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014406 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014407 EndCommandBuffer();
14408
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014409 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014410
Chia-I Wuf7458c52015-10-26 21:10:41 +080014411 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014412 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014413 vkFreeMemory(m_device->device(), srcMem, NULL);
14414 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014415}
14416
Karl Schultz6addd812016-02-02 17:17:23 -070014417TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
14418 VkResult err;
14419 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14422 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014423
Mike Stroyana3082432015-09-25 13:39:21 -060014424 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014425
14426 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014427 VkImage srcImage;
14428 VkImage dstImage;
14429 VkDeviceMemory srcMem;
14430 VkDeviceMemory destMem;
14431 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014432
14433 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014434 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14435 image_create_info.pNext = NULL;
14436 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14437 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14438 image_create_info.extent.width = 32;
14439 image_create_info.extent.height = 1;
14440 image_create_info.extent.depth = 1;
14441 image_create_info.mipLevels = 1;
14442 image_create_info.arrayLayers = 1;
14443 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14444 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14446 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014448 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014449 ASSERT_VK_SUCCESS(err);
14450
Karl Schultz6addd812016-02-02 17:17:23 -070014451 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014452
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014453 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014454 ASSERT_VK_SUCCESS(err);
14455
14456 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014457 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014458 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14459 memAlloc.pNext = NULL;
14460 memAlloc.allocationSize = 0;
14461 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014462
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014463 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014464 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014465 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014466 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014467 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014468 ASSERT_VK_SUCCESS(err);
14469
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014470 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014471 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014472 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014473 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014474 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014475 ASSERT_VK_SUCCESS(err);
14476
14477 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14478 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014479 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014480 ASSERT_VK_SUCCESS(err);
14481
14482 BeginCommandBuffer();
14483 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014484 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14485 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014486 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014487 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014488 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014489 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014490 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014491 resolveRegion.srcOffset.x = 0;
14492 resolveRegion.srcOffset.y = 0;
14493 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014494 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014495 resolveRegion.dstSubresource.mipLevel = 0;
14496 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014497 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014498 resolveRegion.dstOffset.x = 0;
14499 resolveRegion.dstOffset.y = 0;
14500 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014501 resolveRegion.extent.width = 1;
14502 resolveRegion.extent.height = 1;
14503 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014504 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014505 EndCommandBuffer();
14506
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014507 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014508
Chia-I Wuf7458c52015-10-26 21:10:41 +080014509 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014510 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014511 vkFreeMemory(m_device->device(), srcMem, NULL);
14512 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014513}
14514
Karl Schultz6addd812016-02-02 17:17:23 -070014515TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14516 VkResult err;
14517 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14520 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014521
Mike Stroyana3082432015-09-25 13:39:21 -060014522 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014523
Chris Forbesa7530692016-05-08 12:35:39 +120014524 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014525 VkImage srcImage;
14526 VkImage dstImage;
14527 VkDeviceMemory srcMem;
14528 VkDeviceMemory destMem;
14529 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014530
14531 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014532 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14533 image_create_info.pNext = NULL;
14534 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14535 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14536 image_create_info.extent.width = 32;
14537 image_create_info.extent.height = 1;
14538 image_create_info.extent.depth = 1;
14539 image_create_info.mipLevels = 1;
14540 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014541 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014542 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14543 // Note: Some implementations expect color attachment usage for any
14544 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014545 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014546 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014548 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014549 ASSERT_VK_SUCCESS(err);
14550
Karl Schultz6addd812016-02-02 17:17:23 -070014551 // Note: Some implementations expect color attachment usage for any
14552 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014553 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014554
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014555 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014556 ASSERT_VK_SUCCESS(err);
14557
14558 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014559 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014560 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14561 memAlloc.pNext = NULL;
14562 memAlloc.allocationSize = 0;
14563 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014564
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014565 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014566 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014567 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014568 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014569 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014570 ASSERT_VK_SUCCESS(err);
14571
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014572 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014573 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014574 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014575 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014576 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014577 ASSERT_VK_SUCCESS(err);
14578
14579 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14580 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014581 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014582 ASSERT_VK_SUCCESS(err);
14583
14584 BeginCommandBuffer();
14585 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014586 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14587 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014588 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014589 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014590 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014591 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014592 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014593 resolveRegion.srcOffset.x = 0;
14594 resolveRegion.srcOffset.y = 0;
14595 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014596 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014597 resolveRegion.dstSubresource.mipLevel = 0;
14598 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014599 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014600 resolveRegion.dstOffset.x = 0;
14601 resolveRegion.dstOffset.y = 0;
14602 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014603 resolveRegion.extent.width = 1;
14604 resolveRegion.extent.height = 1;
14605 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014606 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014607 EndCommandBuffer();
14608
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014609 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014610
Chia-I Wuf7458c52015-10-26 21:10:41 +080014611 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014612 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014613 vkFreeMemory(m_device->device(), srcMem, NULL);
14614 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014615}
14616
Karl Schultz6addd812016-02-02 17:17:23 -070014617TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14618 VkResult err;
14619 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014620
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14622 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014623
Mike Stroyana3082432015-09-25 13:39:21 -060014624 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014625
14626 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014627 VkImage srcImage;
14628 VkImage dstImage;
14629 VkDeviceMemory srcMem;
14630 VkDeviceMemory destMem;
14631 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014632
14633 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014634 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14635 image_create_info.pNext = NULL;
14636 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14637 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14638 image_create_info.extent.width = 32;
14639 image_create_info.extent.height = 1;
14640 image_create_info.extent.depth = 1;
14641 image_create_info.mipLevels = 1;
14642 image_create_info.arrayLayers = 1;
14643 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14644 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14645 // Note: Some implementations expect color attachment usage for any
14646 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014647 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014648 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014649
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014650 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014651 ASSERT_VK_SUCCESS(err);
14652
Karl Schultz6addd812016-02-02 17:17:23 -070014653 // Set format to something other than source image
14654 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14655 // Note: Some implementations expect color attachment usage for any
14656 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014657 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014658 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014660 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014661 ASSERT_VK_SUCCESS(err);
14662
14663 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014664 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014665 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14666 memAlloc.pNext = NULL;
14667 memAlloc.allocationSize = 0;
14668 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014669
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014670 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014671 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014672 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014673 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014674 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014675 ASSERT_VK_SUCCESS(err);
14676
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014677 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014678 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014679 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014680 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014681 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014682 ASSERT_VK_SUCCESS(err);
14683
14684 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14685 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014686 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014687 ASSERT_VK_SUCCESS(err);
14688
14689 BeginCommandBuffer();
14690 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014691 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14692 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014693 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014694 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014695 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014696 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014697 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014698 resolveRegion.srcOffset.x = 0;
14699 resolveRegion.srcOffset.y = 0;
14700 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014701 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014702 resolveRegion.dstSubresource.mipLevel = 0;
14703 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014704 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014705 resolveRegion.dstOffset.x = 0;
14706 resolveRegion.dstOffset.y = 0;
14707 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014708 resolveRegion.extent.width = 1;
14709 resolveRegion.extent.height = 1;
14710 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014711 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014712 EndCommandBuffer();
14713
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014714 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014715
Chia-I Wuf7458c52015-10-26 21:10:41 +080014716 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014717 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014718 vkFreeMemory(m_device->device(), srcMem, NULL);
14719 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014720}
14721
Karl Schultz6addd812016-02-02 17:17:23 -070014722TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14723 VkResult err;
14724 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014725
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14727 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014728
Mike Stroyana3082432015-09-25 13:39:21 -060014729 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014730
14731 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014732 VkImage srcImage;
14733 VkImage dstImage;
14734 VkDeviceMemory srcMem;
14735 VkDeviceMemory destMem;
14736 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014737
14738 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014739 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14740 image_create_info.pNext = NULL;
14741 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14742 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14743 image_create_info.extent.width = 32;
14744 image_create_info.extent.height = 1;
14745 image_create_info.extent.depth = 1;
14746 image_create_info.mipLevels = 1;
14747 image_create_info.arrayLayers = 1;
14748 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14749 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14750 // Note: Some implementations expect color attachment usage for any
14751 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014752 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014753 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014755 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014756 ASSERT_VK_SUCCESS(err);
14757
Karl Schultz6addd812016-02-02 17:17:23 -070014758 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14759 // Note: Some implementations expect color attachment usage for any
14760 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014761 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014762 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014763
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014764 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014765 ASSERT_VK_SUCCESS(err);
14766
14767 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014768 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014769 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14770 memAlloc.pNext = NULL;
14771 memAlloc.allocationSize = 0;
14772 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014773
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014774 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014775 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014776 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014777 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014778 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014779 ASSERT_VK_SUCCESS(err);
14780
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014781 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014782 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014783 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014784 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014785 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014786 ASSERT_VK_SUCCESS(err);
14787
14788 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14789 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014790 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014791 ASSERT_VK_SUCCESS(err);
14792
14793 BeginCommandBuffer();
14794 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014795 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14796 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014797 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014798 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014799 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014800 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014801 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014802 resolveRegion.srcOffset.x = 0;
14803 resolveRegion.srcOffset.y = 0;
14804 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014805 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014806 resolveRegion.dstSubresource.mipLevel = 0;
14807 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014808 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014809 resolveRegion.dstOffset.x = 0;
14810 resolveRegion.dstOffset.y = 0;
14811 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014812 resolveRegion.extent.width = 1;
14813 resolveRegion.extent.height = 1;
14814 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014815 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014816 EndCommandBuffer();
14817
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014818 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014819
Chia-I Wuf7458c52015-10-26 21:10:41 +080014820 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014821 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014822 vkFreeMemory(m_device->device(), srcMem, NULL);
14823 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014824}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014825
Karl Schultz6addd812016-02-02 17:17:23 -070014826TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014827 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014828 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14829 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014830 // The image format check comes 2nd in validation so we trigger it first,
14831 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014832 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14835 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014836
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014837 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014838
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014839 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014840 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14841 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014842
14843 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014844 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14845 ds_pool_ci.pNext = NULL;
14846 ds_pool_ci.maxSets = 1;
14847 ds_pool_ci.poolSizeCount = 1;
14848 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014849
14850 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014851 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014852 ASSERT_VK_SUCCESS(err);
14853
14854 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014855 dsl_binding.binding = 0;
14856 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14857 dsl_binding.descriptorCount = 1;
14858 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14859 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014860
14861 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014862 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14863 ds_layout_ci.pNext = NULL;
14864 ds_layout_ci.bindingCount = 1;
14865 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014866 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014867 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014868 ASSERT_VK_SUCCESS(err);
14869
14870 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014871 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014872 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014873 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014874 alloc_info.descriptorPool = ds_pool;
14875 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014876 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014877 ASSERT_VK_SUCCESS(err);
14878
Karl Schultz6addd812016-02-02 17:17:23 -070014879 VkImage image_bad;
14880 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014881 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060014882 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014883 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070014884 const int32_t tex_width = 32;
14885 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014886
14887 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014888 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14889 image_create_info.pNext = NULL;
14890 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14891 image_create_info.format = tex_format_bad;
14892 image_create_info.extent.width = tex_width;
14893 image_create_info.extent.height = tex_height;
14894 image_create_info.extent.depth = 1;
14895 image_create_info.mipLevels = 1;
14896 image_create_info.arrayLayers = 1;
14897 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14898 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014899 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014900 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014901
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014902 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014903 ASSERT_VK_SUCCESS(err);
14904 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014905 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14906 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014907 ASSERT_VK_SUCCESS(err);
14908
14909 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014910 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14911 image_view_create_info.image = image_bad;
14912 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14913 image_view_create_info.format = tex_format_bad;
14914 image_view_create_info.subresourceRange.baseArrayLayer = 0;
14915 image_view_create_info.subresourceRange.baseMipLevel = 0;
14916 image_view_create_info.subresourceRange.layerCount = 1;
14917 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014918 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014919
14920 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014921 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014922
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014923 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014924
Chia-I Wuf7458c52015-10-26 21:10:41 +080014925 vkDestroyImage(m_device->device(), image_bad, NULL);
14926 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
14928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014929}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014930
14931TEST_F(VkLayerTest, ClearImageErrors) {
14932 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
14933 "ClearDepthStencilImage with a color image.");
14934
14935 ASSERT_NO_FATAL_FAILURE(InitState());
14936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14937
14938 // Renderpass is started here so end it as Clear cmds can't be in renderpass
14939 BeginCommandBuffer();
14940 m_commandBuffer->EndRenderPass();
14941
14942 // Color image
14943 VkClearColorValue clear_color;
14944 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
14945 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
14946 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
14947 const int32_t img_width = 32;
14948 const int32_t img_height = 32;
14949 VkImageCreateInfo image_create_info = {};
14950 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14951 image_create_info.pNext = NULL;
14952 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14953 image_create_info.format = color_format;
14954 image_create_info.extent.width = img_width;
14955 image_create_info.extent.height = img_height;
14956 image_create_info.extent.depth = 1;
14957 image_create_info.mipLevels = 1;
14958 image_create_info.arrayLayers = 1;
14959 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14960 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14961 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14962
14963 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014964 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014966 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014967
14968 // Depth/Stencil image
14969 VkClearDepthStencilValue clear_value = {0};
14970 reqs = 0; // don't need HOST_VISIBLE DS image
14971 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
14972 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
14973 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
14974 ds_image_create_info.extent.width = 64;
14975 ds_image_create_info.extent.height = 64;
14976 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14977 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
14978
14979 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014980 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014982 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 -060014983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014985
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014986 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060014987 &color_range);
14988
14989 m_errorMonitor->VerifyFound();
14990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
14992 "image created without "
14993 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060014994
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014995 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060014996 &color_range);
14997
14998 m_errorMonitor->VerifyFound();
14999
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015000 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15002 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015004 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15005 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015006
15007 m_errorMonitor->VerifyFound();
15008}
Tobin Ehliscde08892015-09-22 10:11:37 -060015009#endif // IMAGE_TESTS
15010
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015011
15012// WSI Enabled Tests
15013//
15014TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15015
15016#if defined(VK_USE_PLATFORM_XCB_KHR)
15017 VkSurfaceKHR surface = VK_NULL_HANDLE;
15018
15019 VkResult err;
15020 bool pass;
15021 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15022 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15023 // uint32_t swapchain_image_count = 0;
15024 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15025 // uint32_t image_index = 0;
15026 // VkPresentInfoKHR present_info = {};
15027
15028 ASSERT_NO_FATAL_FAILURE(InitState());
15029
15030 // Use the create function from one of the VK_KHR_*_surface extension in
15031 // order to create a surface, testing all known errors in the process,
15032 // before successfully creating a surface:
15033 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15035 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15036 pass = (err != VK_SUCCESS);
15037 ASSERT_TRUE(pass);
15038 m_errorMonitor->VerifyFound();
15039
15040 // Next, try to create a surface with the wrong
15041 // VkXcbSurfaceCreateInfoKHR::sType:
15042 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15043 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15045 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15046 pass = (err != VK_SUCCESS);
15047 ASSERT_TRUE(pass);
15048 m_errorMonitor->VerifyFound();
15049
15050 // Create a native window, and then correctly create a surface:
15051 xcb_connection_t *connection;
15052 xcb_screen_t *screen;
15053 xcb_window_t xcb_window;
15054 xcb_intern_atom_reply_t *atom_wm_delete_window;
15055
15056 const xcb_setup_t *setup;
15057 xcb_screen_iterator_t iter;
15058 int scr;
15059 uint32_t value_mask, value_list[32];
15060 int width = 1;
15061 int height = 1;
15062
15063 connection = xcb_connect(NULL, &scr);
15064 ASSERT_TRUE(connection != NULL);
15065 setup = xcb_get_setup(connection);
15066 iter = xcb_setup_roots_iterator(setup);
15067 while (scr-- > 0)
15068 xcb_screen_next(&iter);
15069 screen = iter.data;
15070
15071 xcb_window = xcb_generate_id(connection);
15072
15073 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15074 value_list[0] = screen->black_pixel;
15075 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15076
15077 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15078 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15079
15080 /* Magic code that will send notification when window is destroyed */
15081 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15082 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15083
15084 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15085 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15086 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15087 free(reply);
15088
15089 xcb_map_window(connection, xcb_window);
15090
15091 // Force the x/y coordinates to 100,100 results are identical in consecutive
15092 // runs
15093 const uint32_t coords[] = { 100, 100 };
15094 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15095
15096 // Finally, try to correctly create a surface:
15097 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15098 xcb_create_info.pNext = NULL;
15099 xcb_create_info.flags = 0;
15100 xcb_create_info.connection = connection;
15101 xcb_create_info.window = xcb_window;
15102 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15103 pass = (err == VK_SUCCESS);
15104 ASSERT_TRUE(pass);
15105
15106 // Check if surface supports presentation:
15107
15108 // 1st, do so without having queried the queue families:
15109 VkBool32 supported = false;
15110 // TODO: Get the following error to come out:
15111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15112 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15113 "function");
15114 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15115 pass = (err != VK_SUCCESS);
15116 // ASSERT_TRUE(pass);
15117 // m_errorMonitor->VerifyFound();
15118
15119 // Next, query a queue family index that's too large:
15120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15121 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15122 pass = (err != VK_SUCCESS);
15123 ASSERT_TRUE(pass);
15124 m_errorMonitor->VerifyFound();
15125
15126 // Finally, do so correctly:
15127 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15128 // SUPPORTED
15129 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15130 pass = (err == VK_SUCCESS);
15131 ASSERT_TRUE(pass);
15132
15133 // Before proceeding, try to create a swapchain without having called
15134 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15135 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15136 swapchain_create_info.pNext = NULL;
15137 swapchain_create_info.flags = 0;
15138 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15139 swapchain_create_info.surface = surface;
15140 swapchain_create_info.imageArrayLayers = 1;
15141 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15142 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15144 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15145 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15146 pass = (err != VK_SUCCESS);
15147 ASSERT_TRUE(pass);
15148 m_errorMonitor->VerifyFound();
15149
15150 // Get the surface capabilities:
15151 VkSurfaceCapabilitiesKHR surface_capabilities;
15152
15153 // Do so correctly (only error logged by this entrypoint is if the
15154 // extension isn't enabled):
15155 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15156 pass = (err == VK_SUCCESS);
15157 ASSERT_TRUE(pass);
15158
15159 // Get the surface formats:
15160 uint32_t surface_format_count;
15161
15162 // First, try without a pointer to surface_format_count:
15163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15164 "specified as NULL");
15165 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15166 pass = (err == VK_SUCCESS);
15167 ASSERT_TRUE(pass);
15168 m_errorMonitor->VerifyFound();
15169
15170 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15171 // correctly done a 1st try (to get the count):
15172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15173 surface_format_count = 0;
15174 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15175 pass = (err == VK_SUCCESS);
15176 ASSERT_TRUE(pass);
15177 m_errorMonitor->VerifyFound();
15178
15179 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15180 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15181 pass = (err == VK_SUCCESS);
15182 ASSERT_TRUE(pass);
15183
15184 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15185 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15186
15187 // Next, do a 2nd try with surface_format_count being set too high:
15188 surface_format_count += 5;
15189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15190 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15191 pass = (err == VK_SUCCESS);
15192 ASSERT_TRUE(pass);
15193 m_errorMonitor->VerifyFound();
15194
15195 // Finally, do a correct 1st and 2nd try:
15196 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15197 pass = (err == VK_SUCCESS);
15198 ASSERT_TRUE(pass);
15199 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15200 pass = (err == VK_SUCCESS);
15201 ASSERT_TRUE(pass);
15202
15203 // Get the surface present modes:
15204 uint32_t surface_present_mode_count;
15205
15206 // First, try without a pointer to surface_format_count:
15207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15208 "specified as NULL");
15209
15210 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15211 pass = (err == VK_SUCCESS);
15212 ASSERT_TRUE(pass);
15213 m_errorMonitor->VerifyFound();
15214
15215 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15216 // correctly done a 1st try (to get the count):
15217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15218 surface_present_mode_count = 0;
15219 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15220 (VkPresentModeKHR *)&surface_present_mode_count);
15221 pass = (err == VK_SUCCESS);
15222 ASSERT_TRUE(pass);
15223 m_errorMonitor->VerifyFound();
15224
15225 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15226 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15227 pass = (err == VK_SUCCESS);
15228 ASSERT_TRUE(pass);
15229
15230 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15231 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15232
15233 // Next, do a 2nd try with surface_format_count being set too high:
15234 surface_present_mode_count += 5;
15235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15236 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15237 pass = (err == VK_SUCCESS);
15238 ASSERT_TRUE(pass);
15239 m_errorMonitor->VerifyFound();
15240
15241 // Finally, do a correct 1st and 2nd try:
15242 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15243 pass = (err == VK_SUCCESS);
15244 ASSERT_TRUE(pass);
15245 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15246 pass = (err == VK_SUCCESS);
15247 ASSERT_TRUE(pass);
15248
15249 // Create a swapchain:
15250
15251 // First, try without a pointer to swapchain_create_info:
15252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15253 "specified as NULL");
15254
15255 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15256 pass = (err != VK_SUCCESS);
15257 ASSERT_TRUE(pass);
15258 m_errorMonitor->VerifyFound();
15259
15260 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15261 // sType:
15262 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15264
15265 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15266 pass = (err != VK_SUCCESS);
15267 ASSERT_TRUE(pass);
15268 m_errorMonitor->VerifyFound();
15269
15270 // Next, call with a NULL swapchain pointer:
15271 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15272 swapchain_create_info.pNext = NULL;
15273 swapchain_create_info.flags = 0;
15274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15275 "specified as NULL");
15276
15277 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15278 pass = (err != VK_SUCCESS);
15279 ASSERT_TRUE(pass);
15280 m_errorMonitor->VerifyFound();
15281
15282 // TODO: Enhance swapchain layer so that
15283 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15284
15285 // Next, call with a queue family index that's too large:
15286 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15287 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15288 swapchain_create_info.queueFamilyIndexCount = 2;
15289 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15291 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15292 pass = (err != VK_SUCCESS);
15293 ASSERT_TRUE(pass);
15294 m_errorMonitor->VerifyFound();
15295
15296 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15297 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15298 swapchain_create_info.queueFamilyIndexCount = 1;
15299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15300 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15301 "pCreateInfo->pQueueFamilyIndices).");
15302 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15303 pass = (err != VK_SUCCESS);
15304 ASSERT_TRUE(pass);
15305 m_errorMonitor->VerifyFound();
15306
15307 // Next, call with an invalid imageSharingMode:
15308 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15309 swapchain_create_info.queueFamilyIndexCount = 1;
15310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15311 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15312 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15313 pass = (err != VK_SUCCESS);
15314 ASSERT_TRUE(pass);
15315 m_errorMonitor->VerifyFound();
15316 // Fix for the future:
15317 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15318 // SUPPORTED
15319 swapchain_create_info.queueFamilyIndexCount = 0;
15320 queueFamilyIndex[0] = 0;
15321 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15322
15323 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15324 // Get the images from a swapchain:
15325 // Acquire an image from a swapchain:
15326 // Present an image to a swapchain:
15327 // Destroy the swapchain:
15328
15329 // TODOs:
15330 //
15331 // - Try destroying the device without first destroying the swapchain
15332 //
15333 // - Try destroying the device without first destroying the surface
15334 //
15335 // - Try destroying the surface without first destroying the swapchain
15336
15337 // Destroy the surface:
15338 vkDestroySurfaceKHR(instance(), surface, NULL);
15339
15340 // Tear down the window:
15341 xcb_destroy_window(connection, xcb_window);
15342 xcb_disconnect(connection);
15343
15344#else // VK_USE_PLATFORM_XCB_KHR
15345 return;
15346#endif // VK_USE_PLATFORM_XCB_KHR
15347}
15348
15349//
15350// POSITIVE VALIDATION TESTS
15351//
15352// These tests do not expect to encounter ANY validation errors pass only if this is true
15353
Tobin Ehlise0006882016-11-03 10:14:28 -060015354TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15355 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15356 "by a transition in the primary.");
15357 VkResult err;
15358 m_errorMonitor->ExpectSuccess();
15359 ASSERT_NO_FATAL_FAILURE(InitState());
15360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15361 // Allocate a secondary and primary cmd buffer
15362 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15363 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15364 command_buffer_allocate_info.commandPool = m_commandPool;
15365 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15366 command_buffer_allocate_info.commandBufferCount = 1;
15367
15368 VkCommandBuffer secondary_command_buffer;
15369 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15370 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15371 VkCommandBuffer primary_command_buffer;
15372 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15373 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15374 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15375 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15376 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15377 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15378 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15379
15380 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15381 ASSERT_VK_SUCCESS(err);
15382 VkImageObj image(m_device);
15383 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15384 ASSERT_TRUE(image.initialized());
15385 VkImageMemoryBarrier img_barrier = {};
15386 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15387 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15388 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15389 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15390 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15391 img_barrier.image = image.handle();
15392 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15393 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15394 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15395 img_barrier.subresourceRange.baseArrayLayer = 0;
15396 img_barrier.subresourceRange.baseMipLevel = 0;
15397 img_barrier.subresourceRange.layerCount = 1;
15398 img_barrier.subresourceRange.levelCount = 1;
15399 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15400 0, nullptr, 1, &img_barrier);
15401 err = vkEndCommandBuffer(secondary_command_buffer);
15402 ASSERT_VK_SUCCESS(err);
15403
15404 // Now update primary cmd buffer to execute secondary and transitions image
15405 command_buffer_begin_info.pInheritanceInfo = nullptr;
15406 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15407 ASSERT_VK_SUCCESS(err);
15408 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15409 VkImageMemoryBarrier img_barrier2 = {};
15410 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15411 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15412 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15413 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15414 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15415 img_barrier2.image = image.handle();
15416 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15417 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15418 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15419 img_barrier2.subresourceRange.baseArrayLayer = 0;
15420 img_barrier2.subresourceRange.baseMipLevel = 0;
15421 img_barrier2.subresourceRange.layerCount = 1;
15422 img_barrier2.subresourceRange.levelCount = 1;
15423 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15424 nullptr, 1, &img_barrier2);
15425 err = vkEndCommandBuffer(primary_command_buffer);
15426 ASSERT_VK_SUCCESS(err);
15427 VkSubmitInfo submit_info = {};
15428 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15429 submit_info.commandBufferCount = 1;
15430 submit_info.pCommandBuffers = &primary_command_buffer;
15431 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15432 ASSERT_VK_SUCCESS(err);
15433 m_errorMonitor->VerifyNotFound();
15434 err = vkDeviceWaitIdle(m_device->device());
15435 ASSERT_VK_SUCCESS(err);
15436 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15437 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15438}
15439
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015440// This is a positive test. No failures are expected.
15441TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15442 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15443 "is ignoring VkWriteDescriptorSet members that are not "
15444 "related to the descriptor type specified by "
15445 "VkWriteDescriptorSet::descriptorType. Correct "
15446 "validation behavior will result in the test running to "
15447 "completion without validation errors.");
15448
15449 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15450
15451 ASSERT_NO_FATAL_FAILURE(InitState());
15452
15453 // Image Case
15454 {
15455 m_errorMonitor->ExpectSuccess();
15456
15457 VkImage image;
15458 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15459 const int32_t tex_width = 32;
15460 const int32_t tex_height = 32;
15461 VkImageCreateInfo image_create_info = {};
15462 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15463 image_create_info.pNext = NULL;
15464 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15465 image_create_info.format = tex_format;
15466 image_create_info.extent.width = tex_width;
15467 image_create_info.extent.height = tex_height;
15468 image_create_info.extent.depth = 1;
15469 image_create_info.mipLevels = 1;
15470 image_create_info.arrayLayers = 1;
15471 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15472 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15473 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15474 image_create_info.flags = 0;
15475 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15476 ASSERT_VK_SUCCESS(err);
15477
15478 VkMemoryRequirements memory_reqs;
15479 VkDeviceMemory image_memory;
15480 bool pass;
15481 VkMemoryAllocateInfo memory_info = {};
15482 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15483 memory_info.pNext = NULL;
15484 memory_info.allocationSize = 0;
15485 memory_info.memoryTypeIndex = 0;
15486 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15487 memory_info.allocationSize = memory_reqs.size;
15488 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15489 ASSERT_TRUE(pass);
15490 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15491 ASSERT_VK_SUCCESS(err);
15492 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15493 ASSERT_VK_SUCCESS(err);
15494
15495 VkImageViewCreateInfo image_view_create_info = {};
15496 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15497 image_view_create_info.image = image;
15498 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15499 image_view_create_info.format = tex_format;
15500 image_view_create_info.subresourceRange.layerCount = 1;
15501 image_view_create_info.subresourceRange.baseMipLevel = 0;
15502 image_view_create_info.subresourceRange.levelCount = 1;
15503 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15504
15505 VkImageView view;
15506 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15507 ASSERT_VK_SUCCESS(err);
15508
15509 VkDescriptorPoolSize ds_type_count = {};
15510 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15511 ds_type_count.descriptorCount = 1;
15512
15513 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15514 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15515 ds_pool_ci.pNext = NULL;
15516 ds_pool_ci.maxSets = 1;
15517 ds_pool_ci.poolSizeCount = 1;
15518 ds_pool_ci.pPoolSizes = &ds_type_count;
15519
15520 VkDescriptorPool ds_pool;
15521 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15522 ASSERT_VK_SUCCESS(err);
15523
15524 VkDescriptorSetLayoutBinding dsl_binding = {};
15525 dsl_binding.binding = 0;
15526 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15527 dsl_binding.descriptorCount = 1;
15528 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15529 dsl_binding.pImmutableSamplers = NULL;
15530
15531 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15532 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15533 ds_layout_ci.pNext = NULL;
15534 ds_layout_ci.bindingCount = 1;
15535 ds_layout_ci.pBindings = &dsl_binding;
15536 VkDescriptorSetLayout ds_layout;
15537 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15538 ASSERT_VK_SUCCESS(err);
15539
15540 VkDescriptorSet descriptor_set;
15541 VkDescriptorSetAllocateInfo alloc_info = {};
15542 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15543 alloc_info.descriptorSetCount = 1;
15544 alloc_info.descriptorPool = ds_pool;
15545 alloc_info.pSetLayouts = &ds_layout;
15546 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15547 ASSERT_VK_SUCCESS(err);
15548
15549 VkDescriptorImageInfo image_info = {};
15550 image_info.imageView = view;
15551 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15552
15553 VkWriteDescriptorSet descriptor_write;
15554 memset(&descriptor_write, 0, sizeof(descriptor_write));
15555 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15556 descriptor_write.dstSet = descriptor_set;
15557 descriptor_write.dstBinding = 0;
15558 descriptor_write.descriptorCount = 1;
15559 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15560 descriptor_write.pImageInfo = &image_info;
15561
15562 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15563 // be
15564 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15565 // This will most likely produce a crash if the parameter_validation
15566 // layer
15567 // does not correctly ignore pBufferInfo.
15568 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15569 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15570
15571 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15572
15573 m_errorMonitor->VerifyNotFound();
15574
15575 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15576 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15577 vkDestroyImageView(m_device->device(), view, NULL);
15578 vkDestroyImage(m_device->device(), image, NULL);
15579 vkFreeMemory(m_device->device(), image_memory, NULL);
15580 }
15581
15582 // Buffer Case
15583 {
15584 m_errorMonitor->ExpectSuccess();
15585
15586 VkBuffer buffer;
15587 uint32_t queue_family_index = 0;
15588 VkBufferCreateInfo buffer_create_info = {};
15589 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15590 buffer_create_info.size = 1024;
15591 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15592 buffer_create_info.queueFamilyIndexCount = 1;
15593 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15594
15595 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15596 ASSERT_VK_SUCCESS(err);
15597
15598 VkMemoryRequirements memory_reqs;
15599 VkDeviceMemory buffer_memory;
15600 bool pass;
15601 VkMemoryAllocateInfo memory_info = {};
15602 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15603 memory_info.pNext = NULL;
15604 memory_info.allocationSize = 0;
15605 memory_info.memoryTypeIndex = 0;
15606
15607 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15608 memory_info.allocationSize = memory_reqs.size;
15609 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15610 ASSERT_TRUE(pass);
15611
15612 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15613 ASSERT_VK_SUCCESS(err);
15614 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15615 ASSERT_VK_SUCCESS(err);
15616
15617 VkDescriptorPoolSize ds_type_count = {};
15618 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15619 ds_type_count.descriptorCount = 1;
15620
15621 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15622 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15623 ds_pool_ci.pNext = NULL;
15624 ds_pool_ci.maxSets = 1;
15625 ds_pool_ci.poolSizeCount = 1;
15626 ds_pool_ci.pPoolSizes = &ds_type_count;
15627
15628 VkDescriptorPool ds_pool;
15629 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15630 ASSERT_VK_SUCCESS(err);
15631
15632 VkDescriptorSetLayoutBinding dsl_binding = {};
15633 dsl_binding.binding = 0;
15634 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15635 dsl_binding.descriptorCount = 1;
15636 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15637 dsl_binding.pImmutableSamplers = NULL;
15638
15639 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15640 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15641 ds_layout_ci.pNext = NULL;
15642 ds_layout_ci.bindingCount = 1;
15643 ds_layout_ci.pBindings = &dsl_binding;
15644 VkDescriptorSetLayout ds_layout;
15645 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15646 ASSERT_VK_SUCCESS(err);
15647
15648 VkDescriptorSet descriptor_set;
15649 VkDescriptorSetAllocateInfo alloc_info = {};
15650 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15651 alloc_info.descriptorSetCount = 1;
15652 alloc_info.descriptorPool = ds_pool;
15653 alloc_info.pSetLayouts = &ds_layout;
15654 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15655 ASSERT_VK_SUCCESS(err);
15656
15657 VkDescriptorBufferInfo buffer_info = {};
15658 buffer_info.buffer = buffer;
15659 buffer_info.offset = 0;
15660 buffer_info.range = 1024;
15661
15662 VkWriteDescriptorSet descriptor_write;
15663 memset(&descriptor_write, 0, sizeof(descriptor_write));
15664 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15665 descriptor_write.dstSet = descriptor_set;
15666 descriptor_write.dstBinding = 0;
15667 descriptor_write.descriptorCount = 1;
15668 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15669 descriptor_write.pBufferInfo = &buffer_info;
15670
15671 // Set pImageInfo and pTexelBufferView to invalid values, which should
15672 // be
15673 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15674 // This will most likely produce a crash if the parameter_validation
15675 // layer
15676 // does not correctly ignore pImageInfo.
15677 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15678 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15679
15680 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15681
15682 m_errorMonitor->VerifyNotFound();
15683
15684 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15686 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15687 vkDestroyBuffer(m_device->device(), buffer, NULL);
15688 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15689 }
15690
15691 // Texel Buffer Case
15692 {
15693 m_errorMonitor->ExpectSuccess();
15694
15695 VkBuffer buffer;
15696 uint32_t queue_family_index = 0;
15697 VkBufferCreateInfo buffer_create_info = {};
15698 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15699 buffer_create_info.size = 1024;
15700 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15701 buffer_create_info.queueFamilyIndexCount = 1;
15702 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15703
15704 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15705 ASSERT_VK_SUCCESS(err);
15706
15707 VkMemoryRequirements memory_reqs;
15708 VkDeviceMemory buffer_memory;
15709 bool pass;
15710 VkMemoryAllocateInfo memory_info = {};
15711 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15712 memory_info.pNext = NULL;
15713 memory_info.allocationSize = 0;
15714 memory_info.memoryTypeIndex = 0;
15715
15716 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15717 memory_info.allocationSize = memory_reqs.size;
15718 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15719 ASSERT_TRUE(pass);
15720
15721 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15722 ASSERT_VK_SUCCESS(err);
15723 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15724 ASSERT_VK_SUCCESS(err);
15725
15726 VkBufferViewCreateInfo buff_view_ci = {};
15727 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15728 buff_view_ci.buffer = buffer;
15729 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15730 buff_view_ci.range = VK_WHOLE_SIZE;
15731 VkBufferView buffer_view;
15732 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15733
15734 VkDescriptorPoolSize ds_type_count = {};
15735 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15736 ds_type_count.descriptorCount = 1;
15737
15738 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15739 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15740 ds_pool_ci.pNext = NULL;
15741 ds_pool_ci.maxSets = 1;
15742 ds_pool_ci.poolSizeCount = 1;
15743 ds_pool_ci.pPoolSizes = &ds_type_count;
15744
15745 VkDescriptorPool ds_pool;
15746 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15747 ASSERT_VK_SUCCESS(err);
15748
15749 VkDescriptorSetLayoutBinding dsl_binding = {};
15750 dsl_binding.binding = 0;
15751 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15752 dsl_binding.descriptorCount = 1;
15753 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15754 dsl_binding.pImmutableSamplers = NULL;
15755
15756 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15757 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15758 ds_layout_ci.pNext = NULL;
15759 ds_layout_ci.bindingCount = 1;
15760 ds_layout_ci.pBindings = &dsl_binding;
15761 VkDescriptorSetLayout ds_layout;
15762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15763 ASSERT_VK_SUCCESS(err);
15764
15765 VkDescriptorSet descriptor_set;
15766 VkDescriptorSetAllocateInfo alloc_info = {};
15767 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15768 alloc_info.descriptorSetCount = 1;
15769 alloc_info.descriptorPool = ds_pool;
15770 alloc_info.pSetLayouts = &ds_layout;
15771 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15772 ASSERT_VK_SUCCESS(err);
15773
15774 VkWriteDescriptorSet descriptor_write;
15775 memset(&descriptor_write, 0, sizeof(descriptor_write));
15776 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15777 descriptor_write.dstSet = descriptor_set;
15778 descriptor_write.dstBinding = 0;
15779 descriptor_write.descriptorCount = 1;
15780 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15781 descriptor_write.pTexelBufferView = &buffer_view;
15782
15783 // Set pImageInfo and pBufferInfo to invalid values, which should be
15784 // ignored for descriptorType ==
15785 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15786 // This will most likely produce a crash if the parameter_validation
15787 // layer
15788 // does not correctly ignore pImageInfo and pBufferInfo.
15789 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15790 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15791
15792 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15793
15794 m_errorMonitor->VerifyNotFound();
15795
15796 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15797 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15798 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15799 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15800 vkDestroyBuffer(m_device->device(), buffer, NULL);
15801 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15802 }
15803}
15804
Tobin Ehlisf7428442016-10-25 07:58:24 -060015805TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15806 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15807
15808 ASSERT_NO_FATAL_FAILURE(InitState());
15809 // Create layout where two binding #s are "1"
15810 static const uint32_t NUM_BINDINGS = 3;
15811 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15812 dsl_binding[0].binding = 1;
15813 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15814 dsl_binding[0].descriptorCount = 1;
15815 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15816 dsl_binding[0].pImmutableSamplers = NULL;
15817 dsl_binding[1].binding = 0;
15818 dsl_binding[1].descriptorCount = 1;
15819 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15820 dsl_binding[1].descriptorCount = 1;
15821 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15822 dsl_binding[1].pImmutableSamplers = NULL;
15823 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15824 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15825 dsl_binding[2].descriptorCount = 1;
15826 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15827 dsl_binding[2].pImmutableSamplers = NULL;
15828
15829 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15830 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15831 ds_layout_ci.pNext = NULL;
15832 ds_layout_ci.bindingCount = NUM_BINDINGS;
15833 ds_layout_ci.pBindings = dsl_binding;
15834 VkDescriptorSetLayout ds_layout;
15835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15836 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15837 m_errorMonitor->VerifyFound();
15838}
15839
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015840TEST_F(VkLayerTest, ViewportBoundsChecking) {
15841 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
15842
15843 ASSERT_NO_FATAL_FAILURE(InitState());
15844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15845
15846 char const *vsSource = "#version 450\n"
15847 "void main() { gl_Position = vec4(1); }\n";
15848 char const *fsSource = "#version 450\n"
15849 "layout(location=0) out vec4 color;\n"
15850 "void main() { color = vec4(1); }\n";
15851
15852 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15853 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15854
15855 VkPipelineObj pipe(m_device);
15856 pipe.AddShader(&vs);
15857 pipe.AddShader(&fs);
15858 pipe.AddColorAttachment();
15859
15860 VkDescriptorSetObj descriptorSet(m_device);
15861 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15862 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15863 ASSERT_VK_SUCCESS(err);
15864
15865 BeginCommandBuffer();
15866 m_commandBuffer->BindPipeline(pipe);
15867
15868 VkViewport viewport = {0, 0, 16, 16, 0, 1};
15869 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15870
15871 {
15872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15873 VkRect2D scissor = {{-1, 0}, {16, 16}};
15874 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15875 m_errorMonitor->VerifyFound();
15876 }
15877
15878 {
15879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15880 VkRect2D scissor = {{0, -2}, {16, 16}};
15881 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15882 m_errorMonitor->VerifyFound();
15883 }
15884
15885 {
15886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
15887 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
15888 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15889 m_errorMonitor->VerifyFound();
15890 }
15891
15892 {
15893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
15894 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
15895 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15896 m_errorMonitor->VerifyFound();
15897 }
15898
15899 EndCommandBuffer();
15900}
15901
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015902// This is a positive test. No failures are expected.
15903TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
15904 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
15905 VkResult err;
15906
15907 ASSERT_NO_FATAL_FAILURE(InitState());
15908 m_errorMonitor->ExpectSuccess();
15909 VkDescriptorPoolSize ds_type_count = {};
15910 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15911 ds_type_count.descriptorCount = 2;
15912
15913 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15914 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15915 ds_pool_ci.pNext = NULL;
15916 ds_pool_ci.maxSets = 1;
15917 ds_pool_ci.poolSizeCount = 1;
15918 ds_pool_ci.pPoolSizes = &ds_type_count;
15919
15920 VkDescriptorPool ds_pool;
15921 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15922 ASSERT_VK_SUCCESS(err);
15923
15924 // Create layout with two uniform buffer descriptors w/ empty binding between them
15925 static const uint32_t NUM_BINDINGS = 3;
15926 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15927 dsl_binding[0].binding = 0;
15928 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15929 dsl_binding[0].descriptorCount = 1;
15930 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
15931 dsl_binding[0].pImmutableSamplers = NULL;
15932 dsl_binding[1].binding = 1;
15933 dsl_binding[1].descriptorCount = 0; // empty binding
15934 dsl_binding[2].binding = 2;
15935 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15936 dsl_binding[2].descriptorCount = 1;
15937 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
15938 dsl_binding[2].pImmutableSamplers = NULL;
15939
15940 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15941 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15942 ds_layout_ci.pNext = NULL;
15943 ds_layout_ci.bindingCount = NUM_BINDINGS;
15944 ds_layout_ci.pBindings = dsl_binding;
15945 VkDescriptorSetLayout ds_layout;
15946 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15947 ASSERT_VK_SUCCESS(err);
15948
15949 VkDescriptorSet descriptor_set = {};
15950 VkDescriptorSetAllocateInfo alloc_info = {};
15951 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15952 alloc_info.descriptorSetCount = 1;
15953 alloc_info.descriptorPool = ds_pool;
15954 alloc_info.pSetLayouts = &ds_layout;
15955 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15956 ASSERT_VK_SUCCESS(err);
15957
15958 // Create a buffer to be used for update
15959 VkBufferCreateInfo buff_ci = {};
15960 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15961 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15962 buff_ci.size = 256;
15963 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
15964 VkBuffer buffer;
15965 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
15966 ASSERT_VK_SUCCESS(err);
15967 // Have to bind memory to buffer before descriptor update
15968 VkMemoryAllocateInfo mem_alloc = {};
15969 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15970 mem_alloc.pNext = NULL;
15971 mem_alloc.allocationSize = 512; // one allocation for both buffers
15972 mem_alloc.memoryTypeIndex = 0;
15973
15974 VkMemoryRequirements mem_reqs;
15975 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
15976 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
15977 if (!pass) {
15978 vkDestroyBuffer(m_device->device(), buffer, NULL);
15979 return;
15980 }
15981
15982 VkDeviceMemory mem;
15983 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
15984 ASSERT_VK_SUCCESS(err);
15985 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
15986 ASSERT_VK_SUCCESS(err);
15987
15988 // Only update the descriptor at binding 2
15989 VkDescriptorBufferInfo buff_info = {};
15990 buff_info.buffer = buffer;
15991 buff_info.offset = 0;
15992 buff_info.range = VK_WHOLE_SIZE;
15993 VkWriteDescriptorSet descriptor_write = {};
15994 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15995 descriptor_write.dstBinding = 2;
15996 descriptor_write.descriptorCount = 1;
15997 descriptor_write.pTexelBufferView = nullptr;
15998 descriptor_write.pBufferInfo = &buff_info;
15999 descriptor_write.pImageInfo = nullptr;
16000 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16001 descriptor_write.dstSet = descriptor_set;
16002
16003 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16004
16005 m_errorMonitor->VerifyNotFound();
16006 // Cleanup
16007 vkFreeMemory(m_device->device(), mem, NULL);
16008 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16009 vkDestroyBuffer(m_device->device(), buffer, NULL);
16010 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16011}
16012
16013// This is a positive test. No failures are expected.
16014TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16015 VkResult err;
16016 bool pass;
16017
16018 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16019 "the buffer, create an image, and bind the same memory to "
16020 "it");
16021
16022 m_errorMonitor->ExpectSuccess();
16023
16024 ASSERT_NO_FATAL_FAILURE(InitState());
16025
16026 VkBuffer buffer;
16027 VkImage image;
16028 VkDeviceMemory mem;
16029 VkMemoryRequirements mem_reqs;
16030
16031 VkBufferCreateInfo buf_info = {};
16032 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16033 buf_info.pNext = NULL;
16034 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16035 buf_info.size = 256;
16036 buf_info.queueFamilyIndexCount = 0;
16037 buf_info.pQueueFamilyIndices = NULL;
16038 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16039 buf_info.flags = 0;
16040 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16041 ASSERT_VK_SUCCESS(err);
16042
16043 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16044
16045 VkMemoryAllocateInfo alloc_info = {};
16046 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16047 alloc_info.pNext = NULL;
16048 alloc_info.memoryTypeIndex = 0;
16049
16050 // Ensure memory is big enough for both bindings
16051 alloc_info.allocationSize = 0x10000;
16052
16053 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16054 if (!pass) {
16055 vkDestroyBuffer(m_device->device(), buffer, NULL);
16056 return;
16057 }
16058
16059 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16060 ASSERT_VK_SUCCESS(err);
16061
16062 uint8_t *pData;
16063 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16064 ASSERT_VK_SUCCESS(err);
16065
16066 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16067
16068 vkUnmapMemory(m_device->device(), mem);
16069
16070 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16071 ASSERT_VK_SUCCESS(err);
16072
16073 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16074 // memory. In fact, it was never used by the GPU.
16075 // Just be be sure, wait for idle.
16076 vkDestroyBuffer(m_device->device(), buffer, NULL);
16077 vkDeviceWaitIdle(m_device->device());
16078
16079 VkImageCreateInfo image_create_info = {};
16080 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16081 image_create_info.pNext = NULL;
16082 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16083 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16084 image_create_info.extent.width = 64;
16085 image_create_info.extent.height = 64;
16086 image_create_info.extent.depth = 1;
16087 image_create_info.mipLevels = 1;
16088 image_create_info.arrayLayers = 1;
16089 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16090 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16091 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16092 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16093 image_create_info.queueFamilyIndexCount = 0;
16094 image_create_info.pQueueFamilyIndices = NULL;
16095 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16096 image_create_info.flags = 0;
16097
16098 VkMemoryAllocateInfo mem_alloc = {};
16099 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16100 mem_alloc.pNext = NULL;
16101 mem_alloc.allocationSize = 0;
16102 mem_alloc.memoryTypeIndex = 0;
16103
16104 /* Create a mappable image. It will be the texture if linear images are ok
16105 * to be textures or it will be the staging image if they are not.
16106 */
16107 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16108 ASSERT_VK_SUCCESS(err);
16109
16110 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16111
16112 mem_alloc.allocationSize = mem_reqs.size;
16113
16114 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16115 if (!pass) {
16116 vkDestroyImage(m_device->device(), image, NULL);
16117 return;
16118 }
16119
16120 // VALIDATION FAILURE:
16121 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16122 ASSERT_VK_SUCCESS(err);
16123
16124 m_errorMonitor->VerifyNotFound();
16125
16126 vkFreeMemory(m_device->device(), mem, NULL);
16127 vkDestroyBuffer(m_device->device(), buffer, NULL);
16128 vkDestroyImage(m_device->device(), image, NULL);
16129}
16130
16131TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16132
16133 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16134 "mapping while using VK_WHOLE_SIZE does not cause access "
16135 "violations");
16136 VkResult err;
16137 uint8_t *pData;
16138 ASSERT_NO_FATAL_FAILURE(InitState());
16139
16140 VkDeviceMemory mem;
16141 VkMemoryRequirements mem_reqs;
16142 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16143 VkMemoryAllocateInfo alloc_info = {};
16144 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16145 alloc_info.pNext = NULL;
16146 alloc_info.memoryTypeIndex = 0;
16147
16148 static const VkDeviceSize allocation_size = 0x1000;
16149 alloc_info.allocationSize = allocation_size;
16150
16151 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16152 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16153 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16154 if (!pass) {
16155 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16156 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16157 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16158 if (!pass) {
16159 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16160 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16161 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16162 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16163 if (!pass) {
16164 return;
16165 }
16166 }
16167 }
16168
16169 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16170 ASSERT_VK_SUCCESS(err);
16171
16172 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16173 // mapped range
16174 m_errorMonitor->ExpectSuccess();
16175 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16176 ASSERT_VK_SUCCESS(err);
16177 VkMappedMemoryRange mmr = {};
16178 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16179 mmr.memory = mem;
16180 mmr.offset = 0;
16181 mmr.size = VK_WHOLE_SIZE;
16182 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16183 ASSERT_VK_SUCCESS(err);
16184 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16185 ASSERT_VK_SUCCESS(err);
16186 m_errorMonitor->VerifyNotFound();
16187 vkUnmapMemory(m_device->device(), mem);
16188
16189 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16190 // mapped range
16191 m_errorMonitor->ExpectSuccess();
16192 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16193 ASSERT_VK_SUCCESS(err);
16194 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16195 mmr.memory = mem;
16196 mmr.offset = 13;
16197 mmr.size = VK_WHOLE_SIZE;
16198 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16199 ASSERT_VK_SUCCESS(err);
16200 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16201 ASSERT_VK_SUCCESS(err);
16202 m_errorMonitor->VerifyNotFound();
16203 vkUnmapMemory(m_device->device(), mem);
16204
16205 // Map with prime offset and size
16206 // Flush/Invalidate subrange of mapped area with prime offset and size
16207 m_errorMonitor->ExpectSuccess();
16208 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16209 ASSERT_VK_SUCCESS(err);
16210 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16211 mmr.memory = mem;
16212 mmr.offset = allocation_size - 107;
16213 mmr.size = 61;
16214 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16215 ASSERT_VK_SUCCESS(err);
16216 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16217 ASSERT_VK_SUCCESS(err);
16218 m_errorMonitor->VerifyNotFound();
16219 vkUnmapMemory(m_device->device(), mem);
16220
16221 // Map without offset and flush WHOLE_SIZE with two separate offsets
16222 m_errorMonitor->ExpectSuccess();
16223 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16224 ASSERT_VK_SUCCESS(err);
16225 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16226 mmr.memory = mem;
16227 mmr.offset = allocation_size - 100;
16228 mmr.size = VK_WHOLE_SIZE;
16229 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16230 ASSERT_VK_SUCCESS(err);
16231 mmr.offset = allocation_size - 200;
16232 mmr.size = VK_WHOLE_SIZE;
16233 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16234 ASSERT_VK_SUCCESS(err);
16235 m_errorMonitor->VerifyNotFound();
16236 vkUnmapMemory(m_device->device(), mem);
16237
16238 vkFreeMemory(m_device->device(), mem, NULL);
16239}
16240
16241// This is a positive test. We used to expect error in this case but spec now allows it
16242TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16243 m_errorMonitor->ExpectSuccess();
16244 vk_testing::Fence testFence;
16245 VkFenceCreateInfo fenceInfo = {};
16246 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16247 fenceInfo.pNext = NULL;
16248
16249 ASSERT_NO_FATAL_FAILURE(InitState());
16250 testFence.init(*m_device, fenceInfo);
16251 VkFence fences[1] = { testFence.handle() };
16252 VkResult result = vkResetFences(m_device->device(), 1, fences);
16253 ASSERT_VK_SUCCESS(result);
16254
16255 m_errorMonitor->VerifyNotFound();
16256}
16257
16258TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16259 m_errorMonitor->ExpectSuccess();
16260
16261 ASSERT_NO_FATAL_FAILURE(InitState());
16262 VkResult err;
16263
16264 // Record (empty!) command buffer that can be submitted multiple times
16265 // simultaneously.
16266 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16267 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16268 m_commandBuffer->BeginCommandBuffer(&cbbi);
16269 m_commandBuffer->EndCommandBuffer();
16270
16271 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16272 VkFence fence;
16273 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16274 ASSERT_VK_SUCCESS(err);
16275
16276 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16277 VkSemaphore s1, s2;
16278 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16279 ASSERT_VK_SUCCESS(err);
16280 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16281 ASSERT_VK_SUCCESS(err);
16282
16283 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16284 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16285 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16286 ASSERT_VK_SUCCESS(err);
16287
16288 // Submit CB again, signaling s2.
16289 si.pSignalSemaphores = &s2;
16290 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16291 ASSERT_VK_SUCCESS(err);
16292
16293 // Wait for fence.
16294 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16295 ASSERT_VK_SUCCESS(err);
16296
16297 // CB is still in flight from second submission, but semaphore s1 is no
16298 // longer in flight. delete it.
16299 vkDestroySemaphore(m_device->device(), s1, nullptr);
16300
16301 m_errorMonitor->VerifyNotFound();
16302
16303 // Force device idle and clean up remaining objects
16304 vkDeviceWaitIdle(m_device->device());
16305 vkDestroySemaphore(m_device->device(), s2, nullptr);
16306 vkDestroyFence(m_device->device(), fence, nullptr);
16307}
16308
16309TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16310 m_errorMonitor->ExpectSuccess();
16311
16312 ASSERT_NO_FATAL_FAILURE(InitState());
16313 VkResult err;
16314
16315 // A fence created signaled
16316 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16317 VkFence f1;
16318 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16319 ASSERT_VK_SUCCESS(err);
16320
16321 // A fence created not
16322 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16323 VkFence f2;
16324 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16325 ASSERT_VK_SUCCESS(err);
16326
16327 // Submit the unsignaled fence
16328 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16329 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16330
16331 // Wait on both fences, with signaled first.
16332 VkFence fences[] = { f1, f2 };
16333 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16334
16335 // Should have both retired!
16336 vkDestroyFence(m_device->device(), f1, nullptr);
16337 vkDestroyFence(m_device->device(), f2, nullptr);
16338
16339 m_errorMonitor->VerifyNotFound();
16340}
16341
16342TEST_F(VkPositiveLayerTest, ValidUsage) {
16343 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16344 "doesn't generate validation errors");
16345
16346 ASSERT_NO_FATAL_FAILURE(InitState());
16347
16348 m_errorMonitor->ExpectSuccess();
16349 // Verify that we can create a view with usage INPUT_ATTACHMENT
16350 VkImageObj image(m_device);
16351 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16352 ASSERT_TRUE(image.initialized());
16353 VkImageView imageView;
16354 VkImageViewCreateInfo ivci = {};
16355 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16356 ivci.image = image.handle();
16357 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16358 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16359 ivci.subresourceRange.layerCount = 1;
16360 ivci.subresourceRange.baseMipLevel = 0;
16361 ivci.subresourceRange.levelCount = 1;
16362 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16363
16364 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16365 m_errorMonitor->VerifyNotFound();
16366 vkDestroyImageView(m_device->device(), imageView, NULL);
16367}
16368
16369// This is a positive test. No failures are expected.
16370TEST_F(VkPositiveLayerTest, BindSparse) {
16371 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16372 "and then free the memory");
16373
16374 ASSERT_NO_FATAL_FAILURE(InitState());
16375
16376 auto index = m_device->graphics_queue_node_index_;
16377 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16378 return;
16379
16380 m_errorMonitor->ExpectSuccess();
16381
16382 VkImage image;
16383 VkImageCreateInfo image_create_info = {};
16384 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16385 image_create_info.pNext = NULL;
16386 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16387 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16388 image_create_info.extent.width = 64;
16389 image_create_info.extent.height = 64;
16390 image_create_info.extent.depth = 1;
16391 image_create_info.mipLevels = 1;
16392 image_create_info.arrayLayers = 1;
16393 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16394 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16395 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16396 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16397 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16398 ASSERT_VK_SUCCESS(err);
16399
16400 VkMemoryRequirements memory_reqs;
16401 VkDeviceMemory memory_one, memory_two;
16402 bool pass;
16403 VkMemoryAllocateInfo memory_info = {};
16404 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16405 memory_info.pNext = NULL;
16406 memory_info.allocationSize = 0;
16407 memory_info.memoryTypeIndex = 0;
16408 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16409 // Find an image big enough to allow sparse mapping of 2 memory regions
16410 // Increase the image size until it is at least twice the
16411 // size of the required alignment, to ensure we can bind both
16412 // allocated memory blocks to the image on aligned offsets.
16413 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16414 vkDestroyImage(m_device->device(), image, nullptr);
16415 image_create_info.extent.width *= 2;
16416 image_create_info.extent.height *= 2;
16417 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16418 ASSERT_VK_SUCCESS(err);
16419 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16420 }
16421 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16422 // at the end of the first
16423 memory_info.allocationSize = memory_reqs.alignment;
16424 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16425 ASSERT_TRUE(pass);
16426 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16427 ASSERT_VK_SUCCESS(err);
16428 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16429 ASSERT_VK_SUCCESS(err);
16430 VkSparseMemoryBind binds[2];
16431 binds[0].flags = 0;
16432 binds[0].memory = memory_one;
16433 binds[0].memoryOffset = 0;
16434 binds[0].resourceOffset = 0;
16435 binds[0].size = memory_info.allocationSize;
16436 binds[1].flags = 0;
16437 binds[1].memory = memory_two;
16438 binds[1].memoryOffset = 0;
16439 binds[1].resourceOffset = memory_info.allocationSize;
16440 binds[1].size = memory_info.allocationSize;
16441
16442 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16443 opaqueBindInfo.image = image;
16444 opaqueBindInfo.bindCount = 2;
16445 opaqueBindInfo.pBinds = binds;
16446
16447 VkFence fence = VK_NULL_HANDLE;
16448 VkBindSparseInfo bindSparseInfo = {};
16449 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16450 bindSparseInfo.imageOpaqueBindCount = 1;
16451 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16452
16453 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16454 vkQueueWaitIdle(m_device->m_queue);
16455 vkDestroyImage(m_device->device(), image, NULL);
16456 vkFreeMemory(m_device->device(), memory_one, NULL);
16457 vkFreeMemory(m_device->device(), memory_two, NULL);
16458 m_errorMonitor->VerifyNotFound();
16459}
16460
16461TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16462 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16463 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16464 "the command buffer has prior knowledge of that "
16465 "attachment's layout.");
16466
16467 m_errorMonitor->ExpectSuccess();
16468
16469 ASSERT_NO_FATAL_FAILURE(InitState());
16470
16471 // A renderpass with one color attachment.
16472 VkAttachmentDescription attachment = { 0,
16473 VK_FORMAT_R8G8B8A8_UNORM,
16474 VK_SAMPLE_COUNT_1_BIT,
16475 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16476 VK_ATTACHMENT_STORE_OP_STORE,
16477 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16478 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16479 VK_IMAGE_LAYOUT_UNDEFINED,
16480 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16481
16482 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16483
16484 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16485
16486 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16487
16488 VkRenderPass rp;
16489 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16490 ASSERT_VK_SUCCESS(err);
16491
16492 // A compatible framebuffer.
16493 VkImageObj image(m_device);
16494 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16495 ASSERT_TRUE(image.initialized());
16496
16497 VkImageViewCreateInfo ivci = {
16498 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16499 nullptr,
16500 0,
16501 image.handle(),
16502 VK_IMAGE_VIEW_TYPE_2D,
16503 VK_FORMAT_R8G8B8A8_UNORM,
16504 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16505 VK_COMPONENT_SWIZZLE_IDENTITY },
16506 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16507 };
16508 VkImageView view;
16509 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16510 ASSERT_VK_SUCCESS(err);
16511
16512 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16513 VkFramebuffer fb;
16514 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16515 ASSERT_VK_SUCCESS(err);
16516
16517 // Record a single command buffer which uses this renderpass twice. The
16518 // bug is triggered at the beginning of the second renderpass, when the
16519 // command buffer already has a layout recorded for the attachment.
16520 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16521 BeginCommandBuffer();
16522 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16523 vkCmdEndRenderPass(m_commandBuffer->handle());
16524 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16525
16526 m_errorMonitor->VerifyNotFound();
16527
16528 vkCmdEndRenderPass(m_commandBuffer->handle());
16529 EndCommandBuffer();
16530
16531 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16532 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16533 vkDestroyImageView(m_device->device(), view, nullptr);
16534}
16535
16536TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16537 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16538 "command buffer, bind them together, then destroy "
16539 "command pool and framebuffer and verify there are no "
16540 "errors.");
16541
16542 m_errorMonitor->ExpectSuccess();
16543
16544 ASSERT_NO_FATAL_FAILURE(InitState());
16545
16546 // A renderpass with one color attachment.
16547 VkAttachmentDescription attachment = { 0,
16548 VK_FORMAT_R8G8B8A8_UNORM,
16549 VK_SAMPLE_COUNT_1_BIT,
16550 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16551 VK_ATTACHMENT_STORE_OP_STORE,
16552 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16553 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16554 VK_IMAGE_LAYOUT_UNDEFINED,
16555 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16556
16557 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16558
16559 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16560
16561 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16562
16563 VkRenderPass rp;
16564 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16565 ASSERT_VK_SUCCESS(err);
16566
16567 // A compatible framebuffer.
16568 VkImageObj image(m_device);
16569 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16570 ASSERT_TRUE(image.initialized());
16571
16572 VkImageViewCreateInfo ivci = {
16573 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16574 nullptr,
16575 0,
16576 image.handle(),
16577 VK_IMAGE_VIEW_TYPE_2D,
16578 VK_FORMAT_R8G8B8A8_UNORM,
16579 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16580 VK_COMPONENT_SWIZZLE_IDENTITY },
16581 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16582 };
16583 VkImageView view;
16584 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16585 ASSERT_VK_SUCCESS(err);
16586
16587 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16588 VkFramebuffer fb;
16589 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16590 ASSERT_VK_SUCCESS(err);
16591
16592 // Explicitly create a command buffer to bind the FB to so that we can then
16593 // destroy the command pool in order to implicitly free command buffer
16594 VkCommandPool command_pool;
16595 VkCommandPoolCreateInfo pool_create_info{};
16596 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16597 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16598 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16599 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16600
16601 VkCommandBuffer command_buffer;
16602 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16603 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16604 command_buffer_allocate_info.commandPool = command_pool;
16605 command_buffer_allocate_info.commandBufferCount = 1;
16606 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16607 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16608
16609 // Begin our cmd buffer with renderpass using our framebuffer
16610 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16611 VkCommandBufferBeginInfo begin_info{};
16612 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16613 vkBeginCommandBuffer(command_buffer, &begin_info);
16614
16615 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16616 vkCmdEndRenderPass(command_buffer);
16617 vkEndCommandBuffer(command_buffer);
16618 vkDestroyImageView(m_device->device(), view, nullptr);
16619 // Destroy command pool to implicitly free command buffer
16620 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16621 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16622 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16623 m_errorMonitor->VerifyNotFound();
16624}
16625
16626TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16627 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16628 "transitions for the first subpass");
16629
16630 m_errorMonitor->ExpectSuccess();
16631
16632 ASSERT_NO_FATAL_FAILURE(InitState());
16633
16634 // A renderpass with one color attachment.
16635 VkAttachmentDescription attachment = { 0,
16636 VK_FORMAT_R8G8B8A8_UNORM,
16637 VK_SAMPLE_COUNT_1_BIT,
16638 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16639 VK_ATTACHMENT_STORE_OP_STORE,
16640 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16641 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16642 VK_IMAGE_LAYOUT_UNDEFINED,
16643 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16644
16645 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16646
16647 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16648
16649 VkSubpassDependency dep = { 0,
16650 0,
16651 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16652 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16653 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16654 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16655 VK_DEPENDENCY_BY_REGION_BIT };
16656
16657 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16658
16659 VkResult err;
16660 VkRenderPass rp;
16661 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16662 ASSERT_VK_SUCCESS(err);
16663
16664 // A compatible framebuffer.
16665 VkImageObj image(m_device);
16666 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16667 ASSERT_TRUE(image.initialized());
16668
16669 VkImageViewCreateInfo ivci = {
16670 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16671 nullptr,
16672 0,
16673 image.handle(),
16674 VK_IMAGE_VIEW_TYPE_2D,
16675 VK_FORMAT_R8G8B8A8_UNORM,
16676 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16677 VK_COMPONENT_SWIZZLE_IDENTITY },
16678 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16679 };
16680 VkImageView view;
16681 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16682 ASSERT_VK_SUCCESS(err);
16683
16684 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16685 VkFramebuffer fb;
16686 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16687 ASSERT_VK_SUCCESS(err);
16688
16689 // Record a single command buffer which issues a pipeline barrier w/
16690 // image memory barrier for the attachment. This detects the previously
16691 // missing tracking of the subpass layout by throwing a validation error
16692 // if it doesn't occur.
16693 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16694 BeginCommandBuffer();
16695 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16696
16697 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
16698 nullptr,
16699 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16700 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16701 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16702 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16703 VK_QUEUE_FAMILY_IGNORED,
16704 VK_QUEUE_FAMILY_IGNORED,
16705 image.handle(),
16706 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
16707 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16708 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16709 &imb);
16710
16711 vkCmdEndRenderPass(m_commandBuffer->handle());
16712 m_errorMonitor->VerifyNotFound();
16713 EndCommandBuffer();
16714
16715 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16716 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16717 vkDestroyImageView(m_device->device(), view, nullptr);
16718}
16719
16720TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
16721 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
16722 "is used as a depth/stencil framebuffer attachment, the "
16723 "aspectMask is ignored and both depth and stencil image "
16724 "subresources are used.");
16725
16726 VkFormatProperties format_properties;
16727 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
16728 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
16729 return;
16730 }
16731
16732 m_errorMonitor->ExpectSuccess();
16733
16734 ASSERT_NO_FATAL_FAILURE(InitState());
16735
16736 VkAttachmentDescription attachment = { 0,
16737 VK_FORMAT_D32_SFLOAT_S8_UINT,
16738 VK_SAMPLE_COUNT_1_BIT,
16739 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16740 VK_ATTACHMENT_STORE_OP_STORE,
16741 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16742 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16743 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
16744 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16745
16746 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16747
16748 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
16749
16750 VkSubpassDependency dep = { 0,
16751 0,
16752 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16753 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16754 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16755 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16756 VK_DEPENDENCY_BY_REGION_BIT};
16757
16758 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16759
16760 VkResult err;
16761 VkRenderPass rp;
16762 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16763 ASSERT_VK_SUCCESS(err);
16764
16765 VkImageObj image(m_device);
16766 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
16767 0x26, // usage
16768 VK_IMAGE_TILING_OPTIMAL, 0);
16769 ASSERT_TRUE(image.initialized());
16770 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
16771
16772 VkImageViewCreateInfo ivci = {
16773 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16774 nullptr,
16775 0,
16776 image.handle(),
16777 VK_IMAGE_VIEW_TYPE_2D,
16778 VK_FORMAT_D32_SFLOAT_S8_UINT,
16779 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
16780 { 0x2, 0, 1, 0, 1 },
16781 };
16782 VkImageView view;
16783 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16784 ASSERT_VK_SUCCESS(err);
16785
16786 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16787 VkFramebuffer fb;
16788 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16789 ASSERT_VK_SUCCESS(err);
16790
16791 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16792 BeginCommandBuffer();
16793 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16794
16795 VkImageMemoryBarrier imb = {};
16796 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16797 imb.pNext = nullptr;
16798 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16799 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16800 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16801 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16802 imb.srcQueueFamilyIndex = 0;
16803 imb.dstQueueFamilyIndex = 0;
16804 imb.image = image.handle();
16805 imb.subresourceRange.aspectMask = 0x6;
16806 imb.subresourceRange.baseMipLevel = 0;
16807 imb.subresourceRange.levelCount = 0x1;
16808 imb.subresourceRange.baseArrayLayer = 0;
16809 imb.subresourceRange.layerCount = 0x1;
16810
16811 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16812 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16813 &imb);
16814
16815 vkCmdEndRenderPass(m_commandBuffer->handle());
16816 EndCommandBuffer();
16817 QueueCommandBuffer(false);
16818 m_errorMonitor->VerifyNotFound();
16819
16820 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16821 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16822 vkDestroyImageView(m_device->device(), view, nullptr);
16823}
16824
16825TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
16826 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
16827 "errors, when an attachment reference is "
16828 "VK_ATTACHMENT_UNUSED");
16829
16830 m_errorMonitor->ExpectSuccess();
16831
16832 ASSERT_NO_FATAL_FAILURE(InitState());
16833
16834 // A renderpass with no attachments
16835 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16836
16837 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16838
16839 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
16840
16841 VkRenderPass rp;
16842 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16843 ASSERT_VK_SUCCESS(err);
16844
16845 // A compatible framebuffer.
16846 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
16847 VkFramebuffer fb;
16848 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16849 ASSERT_VK_SUCCESS(err);
16850
16851 // Record a command buffer which just begins and ends the renderpass. The
16852 // bug manifests in BeginRenderPass.
16853 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16854 BeginCommandBuffer();
16855 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16856 vkCmdEndRenderPass(m_commandBuffer->handle());
16857 m_errorMonitor->VerifyNotFound();
16858 EndCommandBuffer();
16859
16860 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16861 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16862}
16863
16864// This is a positive test. No errors are expected.
16865TEST_F(VkPositiveLayerTest, StencilLoadOp) {
16866 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
16867 "CLEAR. stencil[Load|Store]Op used to be ignored.");
16868 VkResult result = VK_SUCCESS;
16869 VkImageFormatProperties formatProps;
16870 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
16871 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
16872 &formatProps);
16873 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
16874 return;
16875 }
16876
16877 ASSERT_NO_FATAL_FAILURE(InitState());
16878 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
16879 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
16880 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
16881 VkAttachmentDescription att = {};
16882 VkAttachmentReference ref = {};
16883 att.format = depth_stencil_fmt;
16884 att.samples = VK_SAMPLE_COUNT_1_BIT;
16885 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
16886 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
16887 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
16888 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
16889 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16890 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16891
16892 VkClearValue clear;
16893 clear.depthStencil.depth = 1.0;
16894 clear.depthStencil.stencil = 0;
16895 ref.attachment = 0;
16896 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16897
16898 VkSubpassDescription subpass = {};
16899 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
16900 subpass.flags = 0;
16901 subpass.inputAttachmentCount = 0;
16902 subpass.pInputAttachments = NULL;
16903 subpass.colorAttachmentCount = 0;
16904 subpass.pColorAttachments = NULL;
16905 subpass.pResolveAttachments = NULL;
16906 subpass.pDepthStencilAttachment = &ref;
16907 subpass.preserveAttachmentCount = 0;
16908 subpass.pPreserveAttachments = NULL;
16909
16910 VkRenderPass rp;
16911 VkRenderPassCreateInfo rp_info = {};
16912 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16913 rp_info.attachmentCount = 1;
16914 rp_info.pAttachments = &att;
16915 rp_info.subpassCount = 1;
16916 rp_info.pSubpasses = &subpass;
16917 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
16918 ASSERT_VK_SUCCESS(result);
16919
16920 VkImageView *depthView = m_depthStencil->BindInfo();
16921 VkFramebufferCreateInfo fb_info = {};
16922 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
16923 fb_info.pNext = NULL;
16924 fb_info.renderPass = rp;
16925 fb_info.attachmentCount = 1;
16926 fb_info.pAttachments = depthView;
16927 fb_info.width = 100;
16928 fb_info.height = 100;
16929 fb_info.layers = 1;
16930 VkFramebuffer fb;
16931 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
16932 ASSERT_VK_SUCCESS(result);
16933
16934 VkRenderPassBeginInfo rpbinfo = {};
16935 rpbinfo.clearValueCount = 1;
16936 rpbinfo.pClearValues = &clear;
16937 rpbinfo.pNext = NULL;
16938 rpbinfo.renderPass = rp;
16939 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
16940 rpbinfo.renderArea.extent.width = 100;
16941 rpbinfo.renderArea.extent.height = 100;
16942 rpbinfo.renderArea.offset.x = 0;
16943 rpbinfo.renderArea.offset.y = 0;
16944 rpbinfo.framebuffer = fb;
16945
16946 VkFence fence = {};
16947 VkFenceCreateInfo fence_ci = {};
16948 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16949 fence_ci.pNext = nullptr;
16950 fence_ci.flags = 0;
16951 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
16952 ASSERT_VK_SUCCESS(result);
16953
16954 m_commandBuffer->BeginCommandBuffer();
16955 m_commandBuffer->BeginRenderPass(rpbinfo);
16956 m_commandBuffer->EndRenderPass();
16957 m_commandBuffer->EndCommandBuffer();
16958 m_commandBuffer->QueueCommandBuffer(fence);
16959
16960 VkImageObj destImage(m_device);
16961 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16962 VK_IMAGE_TILING_OPTIMAL, 0);
16963 VkImageMemoryBarrier barrier = {};
16964 VkImageSubresourceRange range;
16965 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16966 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16967 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
16968 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16969 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
16970 barrier.image = m_depthStencil->handle();
16971 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16972 range.baseMipLevel = 0;
16973 range.levelCount = 1;
16974 range.baseArrayLayer = 0;
16975 range.layerCount = 1;
16976 barrier.subresourceRange = range;
16977 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16978 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
16979 cmdbuf.BeginCommandBuffer();
16980 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
16981 &barrier);
16982 barrier.srcAccessMask = 0;
16983 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16984 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
16985 barrier.image = destImage.handle();
16986 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16987 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
16988 &barrier);
16989 VkImageCopy cregion;
16990 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16991 cregion.srcSubresource.mipLevel = 0;
16992 cregion.srcSubresource.baseArrayLayer = 0;
16993 cregion.srcSubresource.layerCount = 1;
16994 cregion.srcOffset.x = 0;
16995 cregion.srcOffset.y = 0;
16996 cregion.srcOffset.z = 0;
16997 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16998 cregion.dstSubresource.mipLevel = 0;
16999 cregion.dstSubresource.baseArrayLayer = 0;
17000 cregion.dstSubresource.layerCount = 1;
17001 cregion.dstOffset.x = 0;
17002 cregion.dstOffset.y = 0;
17003 cregion.dstOffset.z = 0;
17004 cregion.extent.width = 100;
17005 cregion.extent.height = 100;
17006 cregion.extent.depth = 1;
17007 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17008 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17009 cmdbuf.EndCommandBuffer();
17010
17011 VkSubmitInfo submit_info;
17012 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17013 submit_info.pNext = NULL;
17014 submit_info.waitSemaphoreCount = 0;
17015 submit_info.pWaitSemaphores = NULL;
17016 submit_info.pWaitDstStageMask = NULL;
17017 submit_info.commandBufferCount = 1;
17018 submit_info.pCommandBuffers = &cmdbuf.handle();
17019 submit_info.signalSemaphoreCount = 0;
17020 submit_info.pSignalSemaphores = NULL;
17021
17022 m_errorMonitor->ExpectSuccess();
17023 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17024 m_errorMonitor->VerifyNotFound();
17025
17026 vkQueueWaitIdle(m_device->m_queue);
17027 vkDestroyFence(m_device->device(), fence, nullptr);
17028 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17029 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17030}
17031
17032// This is a positive test. No errors should be generated.
17033TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17034 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17035
17036 m_errorMonitor->ExpectSuccess();
17037 ASSERT_NO_FATAL_FAILURE(InitState());
17038
17039 VkEvent event;
17040 VkEventCreateInfo event_create_info{};
17041 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17042 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17043
17044 VkCommandPool command_pool;
17045 VkCommandPoolCreateInfo pool_create_info{};
17046 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17047 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17048 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17049 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17050
17051 VkCommandBuffer command_buffer;
17052 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17053 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17054 command_buffer_allocate_info.commandPool = command_pool;
17055 command_buffer_allocate_info.commandBufferCount = 1;
17056 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17057 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17058
17059 VkQueue queue = VK_NULL_HANDLE;
17060 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17061
17062 {
17063 VkCommandBufferBeginInfo begin_info{};
17064 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17065 vkBeginCommandBuffer(command_buffer, &begin_info);
17066
17067 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17068 nullptr, 0, nullptr);
17069 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17070 vkEndCommandBuffer(command_buffer);
17071 }
17072 {
17073 VkSubmitInfo submit_info{};
17074 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17075 submit_info.commandBufferCount = 1;
17076 submit_info.pCommandBuffers = &command_buffer;
17077 submit_info.signalSemaphoreCount = 0;
17078 submit_info.pSignalSemaphores = nullptr;
17079 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17080 }
17081 { vkSetEvent(m_device->device(), event); }
17082
17083 vkQueueWaitIdle(queue);
17084
17085 vkDestroyEvent(m_device->device(), event, nullptr);
17086 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17087 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17088
17089 m_errorMonitor->VerifyNotFound();
17090}
17091// This is a positive test. No errors should be generated.
17092TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17093 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17094
17095 ASSERT_NO_FATAL_FAILURE(InitState());
17096 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17097 return;
17098
17099 m_errorMonitor->ExpectSuccess();
17100
17101 VkQueryPool query_pool;
17102 VkQueryPoolCreateInfo query_pool_create_info{};
17103 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17104 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17105 query_pool_create_info.queryCount = 1;
17106 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17107
17108 VkCommandPool command_pool;
17109 VkCommandPoolCreateInfo pool_create_info{};
17110 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17111 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17112 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17113 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17114
17115 VkCommandBuffer command_buffer;
17116 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17117 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17118 command_buffer_allocate_info.commandPool = command_pool;
17119 command_buffer_allocate_info.commandBufferCount = 1;
17120 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17121 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17122
17123 VkCommandBuffer secondary_command_buffer;
17124 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17125 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17126
17127 VkQueue queue = VK_NULL_HANDLE;
17128 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17129
17130 uint32_t qfi = 0;
17131 VkBufferCreateInfo buff_create_info = {};
17132 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17133 buff_create_info.size = 1024;
17134 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17135 buff_create_info.queueFamilyIndexCount = 1;
17136 buff_create_info.pQueueFamilyIndices = &qfi;
17137
17138 VkResult err;
17139 VkBuffer buffer;
17140 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17141 ASSERT_VK_SUCCESS(err);
17142 VkMemoryAllocateInfo mem_alloc = {};
17143 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17144 mem_alloc.pNext = NULL;
17145 mem_alloc.allocationSize = 1024;
17146 mem_alloc.memoryTypeIndex = 0;
17147
17148 VkMemoryRequirements memReqs;
17149 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17150 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17151 if (!pass) {
17152 vkDestroyBuffer(m_device->device(), buffer, NULL);
17153 return;
17154 }
17155
17156 VkDeviceMemory mem;
17157 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17158 ASSERT_VK_SUCCESS(err);
17159 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17160 ASSERT_VK_SUCCESS(err);
17161
17162 VkCommandBufferInheritanceInfo hinfo = {};
17163 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17164 hinfo.renderPass = VK_NULL_HANDLE;
17165 hinfo.subpass = 0;
17166 hinfo.framebuffer = VK_NULL_HANDLE;
17167 hinfo.occlusionQueryEnable = VK_FALSE;
17168 hinfo.queryFlags = 0;
17169 hinfo.pipelineStatistics = 0;
17170
17171 {
17172 VkCommandBufferBeginInfo begin_info{};
17173 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17174 begin_info.pInheritanceInfo = &hinfo;
17175 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17176
17177 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17178 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17179
17180 vkEndCommandBuffer(secondary_command_buffer);
17181
17182 begin_info.pInheritanceInfo = nullptr;
17183 vkBeginCommandBuffer(command_buffer, &begin_info);
17184
17185 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17186 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17187
17188 vkEndCommandBuffer(command_buffer);
17189 }
17190 {
17191 VkSubmitInfo submit_info{};
17192 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17193 submit_info.commandBufferCount = 1;
17194 submit_info.pCommandBuffers = &command_buffer;
17195 submit_info.signalSemaphoreCount = 0;
17196 submit_info.pSignalSemaphores = nullptr;
17197 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17198 }
17199
17200 vkQueueWaitIdle(queue);
17201
17202 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17203 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17204 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17205 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17206 vkDestroyBuffer(m_device->device(), buffer, NULL);
17207 vkFreeMemory(m_device->device(), mem, NULL);
17208
17209 m_errorMonitor->VerifyNotFound();
17210}
17211
17212// This is a positive test. No errors should be generated.
17213TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17214 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17215
17216 ASSERT_NO_FATAL_FAILURE(InitState());
17217 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17218 return;
17219
17220 m_errorMonitor->ExpectSuccess();
17221
17222 VkQueryPool query_pool;
17223 VkQueryPoolCreateInfo query_pool_create_info{};
17224 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17225 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17226 query_pool_create_info.queryCount = 1;
17227 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17228
17229 VkCommandPool command_pool;
17230 VkCommandPoolCreateInfo pool_create_info{};
17231 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17232 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17233 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17234 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17235
17236 VkCommandBuffer command_buffer[2];
17237 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17238 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17239 command_buffer_allocate_info.commandPool = command_pool;
17240 command_buffer_allocate_info.commandBufferCount = 2;
17241 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17242 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17243
17244 VkQueue queue = VK_NULL_HANDLE;
17245 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17246
17247 uint32_t qfi = 0;
17248 VkBufferCreateInfo buff_create_info = {};
17249 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17250 buff_create_info.size = 1024;
17251 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17252 buff_create_info.queueFamilyIndexCount = 1;
17253 buff_create_info.pQueueFamilyIndices = &qfi;
17254
17255 VkResult err;
17256 VkBuffer buffer;
17257 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17258 ASSERT_VK_SUCCESS(err);
17259 VkMemoryAllocateInfo mem_alloc = {};
17260 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17261 mem_alloc.pNext = NULL;
17262 mem_alloc.allocationSize = 1024;
17263 mem_alloc.memoryTypeIndex = 0;
17264
17265 VkMemoryRequirements memReqs;
17266 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17267 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17268 if (!pass) {
17269 vkDestroyBuffer(m_device->device(), buffer, NULL);
17270 return;
17271 }
17272
17273 VkDeviceMemory mem;
17274 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17275 ASSERT_VK_SUCCESS(err);
17276 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17277 ASSERT_VK_SUCCESS(err);
17278
17279 {
17280 VkCommandBufferBeginInfo begin_info{};
17281 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17282 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17283
17284 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17285 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17286
17287 vkEndCommandBuffer(command_buffer[0]);
17288
17289 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17290
17291 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17292
17293 vkEndCommandBuffer(command_buffer[1]);
17294 }
17295 {
17296 VkSubmitInfo submit_info{};
17297 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17298 submit_info.commandBufferCount = 2;
17299 submit_info.pCommandBuffers = command_buffer;
17300 submit_info.signalSemaphoreCount = 0;
17301 submit_info.pSignalSemaphores = nullptr;
17302 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17303 }
17304
17305 vkQueueWaitIdle(queue);
17306
17307 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17308 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17309 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17310 vkDestroyBuffer(m_device->device(), buffer, NULL);
17311 vkFreeMemory(m_device->device(), mem, NULL);
17312
17313 m_errorMonitor->VerifyNotFound();
17314}
17315
17316TEST_F(VkPositiveLayerTest, ResetEventThenSet) {
17317 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17318
17319 m_errorMonitor->ExpectSuccess();
17320
17321 ASSERT_NO_FATAL_FAILURE(InitState());
17322 VkEvent event;
17323 VkEventCreateInfo event_create_info{};
17324 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17325 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17326
17327 VkCommandPool command_pool;
17328 VkCommandPoolCreateInfo pool_create_info{};
17329 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17330 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17331 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17332 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17333
17334 VkCommandBuffer command_buffer;
17335 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17336 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17337 command_buffer_allocate_info.commandPool = command_pool;
17338 command_buffer_allocate_info.commandBufferCount = 1;
17339 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17340 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17341
17342 VkQueue queue = VK_NULL_HANDLE;
17343 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17344
17345 {
17346 VkCommandBufferBeginInfo begin_info{};
17347 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17348 vkBeginCommandBuffer(command_buffer, &begin_info);
17349
17350 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
17351 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
17352 nullptr, 0, nullptr, 0, nullptr);
17353 vkEndCommandBuffer(command_buffer);
17354 }
17355 {
17356 VkSubmitInfo submit_info{};
17357 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17358 submit_info.commandBufferCount = 1;
17359 submit_info.pCommandBuffers = &command_buffer;
17360 submit_info.signalSemaphoreCount = 0;
17361 submit_info.pSignalSemaphores = nullptr;
17362 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17363 }
17364 {
17365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17366 "command buffer.");
17367 vkSetEvent(m_device->device(), event);
17368 m_errorMonitor->VerifyFound();
17369 }
17370
17371 vkQueueWaitIdle(queue);
17372
17373 vkDestroyEvent(m_device->device(), event, nullptr);
17374 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17375 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17376}
17377
17378// This is a positive test. No errors should be generated.
17379TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17380 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17381 "run through a Submit & WaitForFences cycle 3 times. This "
17382 "previously revealed a bug so running this positive test "
17383 "to prevent a regression.");
17384 m_errorMonitor->ExpectSuccess();
17385
17386 ASSERT_NO_FATAL_FAILURE(InitState());
17387 VkQueue queue = VK_NULL_HANDLE;
17388 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17389
17390 static const uint32_t NUM_OBJECTS = 2;
17391 static const uint32_t NUM_FRAMES = 3;
17392 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17393 VkFence fences[NUM_OBJECTS] = {};
17394
17395 VkCommandPool cmd_pool;
17396 VkCommandPoolCreateInfo cmd_pool_ci = {};
17397 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17398 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17399 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17400 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17401 ASSERT_VK_SUCCESS(err);
17402
17403 VkCommandBufferAllocateInfo cmd_buf_info = {};
17404 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17405 cmd_buf_info.commandPool = cmd_pool;
17406 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17407 cmd_buf_info.commandBufferCount = 1;
17408
17409 VkFenceCreateInfo fence_ci = {};
17410 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17411 fence_ci.pNext = nullptr;
17412 fence_ci.flags = 0;
17413
17414 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17415 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17416 ASSERT_VK_SUCCESS(err);
17417 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17418 ASSERT_VK_SUCCESS(err);
17419 }
17420
17421 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17422 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17423 // Create empty cmd buffer
17424 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17425 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17426
17427 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17428 ASSERT_VK_SUCCESS(err);
17429 err = vkEndCommandBuffer(cmd_buffers[obj]);
17430 ASSERT_VK_SUCCESS(err);
17431
17432 VkSubmitInfo submit_info = {};
17433 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17434 submit_info.commandBufferCount = 1;
17435 submit_info.pCommandBuffers = &cmd_buffers[obj];
17436 // Submit cmd buffer and wait for fence
17437 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17438 ASSERT_VK_SUCCESS(err);
17439 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17440 ASSERT_VK_SUCCESS(err);
17441 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17442 ASSERT_VK_SUCCESS(err);
17443 }
17444 }
17445 m_errorMonitor->VerifyNotFound();
17446 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17447 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17448 vkDestroyFence(m_device->device(), fences[i], nullptr);
17449 }
17450}
17451// This is a positive test. No errors should be generated.
17452TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17453
17454 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17455 "submitted on separate queues followed by a QueueWaitIdle.");
17456
17457 ASSERT_NO_FATAL_FAILURE(InitState());
17458 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17459 return;
17460
17461 m_errorMonitor->ExpectSuccess();
17462
17463 VkSemaphore semaphore;
17464 VkSemaphoreCreateInfo semaphore_create_info{};
17465 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17466 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17467
17468 VkCommandPool command_pool;
17469 VkCommandPoolCreateInfo pool_create_info{};
17470 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17471 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17472 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17473 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17474
17475 VkCommandBuffer command_buffer[2];
17476 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17477 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17478 command_buffer_allocate_info.commandPool = command_pool;
17479 command_buffer_allocate_info.commandBufferCount = 2;
17480 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17481 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17482
17483 VkQueue queue = VK_NULL_HANDLE;
17484 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17485
17486 {
17487 VkCommandBufferBeginInfo begin_info{};
17488 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17489 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17490
17491 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17492 nullptr, 0, nullptr, 0, nullptr);
17493
17494 VkViewport viewport{};
17495 viewport.maxDepth = 1.0f;
17496 viewport.minDepth = 0.0f;
17497 viewport.width = 512;
17498 viewport.height = 512;
17499 viewport.x = 0;
17500 viewport.y = 0;
17501 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17502 vkEndCommandBuffer(command_buffer[0]);
17503 }
17504 {
17505 VkCommandBufferBeginInfo begin_info{};
17506 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17507 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17508
17509 VkViewport viewport{};
17510 viewport.maxDepth = 1.0f;
17511 viewport.minDepth = 0.0f;
17512 viewport.width = 512;
17513 viewport.height = 512;
17514 viewport.x = 0;
17515 viewport.y = 0;
17516 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17517 vkEndCommandBuffer(command_buffer[1]);
17518 }
17519 {
17520 VkSubmitInfo submit_info{};
17521 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17522 submit_info.commandBufferCount = 1;
17523 submit_info.pCommandBuffers = &command_buffer[0];
17524 submit_info.signalSemaphoreCount = 1;
17525 submit_info.pSignalSemaphores = &semaphore;
17526 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17527 }
17528 {
17529 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17530 VkSubmitInfo submit_info{};
17531 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17532 submit_info.commandBufferCount = 1;
17533 submit_info.pCommandBuffers = &command_buffer[1];
17534 submit_info.waitSemaphoreCount = 1;
17535 submit_info.pWaitSemaphores = &semaphore;
17536 submit_info.pWaitDstStageMask = flags;
17537 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17538 }
17539
17540 vkQueueWaitIdle(m_device->m_queue);
17541
17542 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17543 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17544 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17545
17546 m_errorMonitor->VerifyNotFound();
17547}
17548
17549// This is a positive test. No errors should be generated.
17550TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17551
17552 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17553 "submitted on separate queues, the second having a fence"
17554 "followed by a QueueWaitIdle.");
17555
17556 ASSERT_NO_FATAL_FAILURE(InitState());
17557 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17558 return;
17559
17560 m_errorMonitor->ExpectSuccess();
17561
17562 VkFence fence;
17563 VkFenceCreateInfo fence_create_info{};
17564 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17565 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17566
17567 VkSemaphore semaphore;
17568 VkSemaphoreCreateInfo semaphore_create_info{};
17569 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17570 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17571
17572 VkCommandPool command_pool;
17573 VkCommandPoolCreateInfo pool_create_info{};
17574 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17575 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17576 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17577 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17578
17579 VkCommandBuffer command_buffer[2];
17580 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17581 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17582 command_buffer_allocate_info.commandPool = command_pool;
17583 command_buffer_allocate_info.commandBufferCount = 2;
17584 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17585 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17586
17587 VkQueue queue = VK_NULL_HANDLE;
17588 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17589
17590 {
17591 VkCommandBufferBeginInfo begin_info{};
17592 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17593 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17594
17595 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17596 nullptr, 0, nullptr, 0, nullptr);
17597
17598 VkViewport viewport{};
17599 viewport.maxDepth = 1.0f;
17600 viewport.minDepth = 0.0f;
17601 viewport.width = 512;
17602 viewport.height = 512;
17603 viewport.x = 0;
17604 viewport.y = 0;
17605 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17606 vkEndCommandBuffer(command_buffer[0]);
17607 }
17608 {
17609 VkCommandBufferBeginInfo begin_info{};
17610 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17611 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17612
17613 VkViewport viewport{};
17614 viewport.maxDepth = 1.0f;
17615 viewport.minDepth = 0.0f;
17616 viewport.width = 512;
17617 viewport.height = 512;
17618 viewport.x = 0;
17619 viewport.y = 0;
17620 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17621 vkEndCommandBuffer(command_buffer[1]);
17622 }
17623 {
17624 VkSubmitInfo submit_info{};
17625 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17626 submit_info.commandBufferCount = 1;
17627 submit_info.pCommandBuffers = &command_buffer[0];
17628 submit_info.signalSemaphoreCount = 1;
17629 submit_info.pSignalSemaphores = &semaphore;
17630 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17631 }
17632 {
17633 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17634 VkSubmitInfo submit_info{};
17635 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17636 submit_info.commandBufferCount = 1;
17637 submit_info.pCommandBuffers = &command_buffer[1];
17638 submit_info.waitSemaphoreCount = 1;
17639 submit_info.pWaitSemaphores = &semaphore;
17640 submit_info.pWaitDstStageMask = flags;
17641 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17642 }
17643
17644 vkQueueWaitIdle(m_device->m_queue);
17645
17646 vkDestroyFence(m_device->device(), fence, nullptr);
17647 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17648 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17649 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17650
17651 m_errorMonitor->VerifyNotFound();
17652}
17653
17654// This is a positive test. No errors should be generated.
17655TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17656
17657 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17658 "submitted on separate queues, the second having a fence"
17659 "followed by two consecutive WaitForFences calls on the same fence.");
17660
17661 ASSERT_NO_FATAL_FAILURE(InitState());
17662 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17663 return;
17664
17665 m_errorMonitor->ExpectSuccess();
17666
17667 VkFence fence;
17668 VkFenceCreateInfo fence_create_info{};
17669 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17670 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17671
17672 VkSemaphore semaphore;
17673 VkSemaphoreCreateInfo semaphore_create_info{};
17674 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17675 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17676
17677 VkCommandPool command_pool;
17678 VkCommandPoolCreateInfo pool_create_info{};
17679 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17680 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17681 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17682 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17683
17684 VkCommandBuffer command_buffer[2];
17685 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17686 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17687 command_buffer_allocate_info.commandPool = command_pool;
17688 command_buffer_allocate_info.commandBufferCount = 2;
17689 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17690 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17691
17692 VkQueue queue = VK_NULL_HANDLE;
17693 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17694
17695 {
17696 VkCommandBufferBeginInfo begin_info{};
17697 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17698 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17699
17700 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17701 nullptr, 0, nullptr, 0, nullptr);
17702
17703 VkViewport viewport{};
17704 viewport.maxDepth = 1.0f;
17705 viewport.minDepth = 0.0f;
17706 viewport.width = 512;
17707 viewport.height = 512;
17708 viewport.x = 0;
17709 viewport.y = 0;
17710 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17711 vkEndCommandBuffer(command_buffer[0]);
17712 }
17713 {
17714 VkCommandBufferBeginInfo begin_info{};
17715 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17716 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17717
17718 VkViewport viewport{};
17719 viewport.maxDepth = 1.0f;
17720 viewport.minDepth = 0.0f;
17721 viewport.width = 512;
17722 viewport.height = 512;
17723 viewport.x = 0;
17724 viewport.y = 0;
17725 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17726 vkEndCommandBuffer(command_buffer[1]);
17727 }
17728 {
17729 VkSubmitInfo submit_info{};
17730 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17731 submit_info.commandBufferCount = 1;
17732 submit_info.pCommandBuffers = &command_buffer[0];
17733 submit_info.signalSemaphoreCount = 1;
17734 submit_info.pSignalSemaphores = &semaphore;
17735 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17736 }
17737 {
17738 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17739 VkSubmitInfo submit_info{};
17740 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17741 submit_info.commandBufferCount = 1;
17742 submit_info.pCommandBuffers = &command_buffer[1];
17743 submit_info.waitSemaphoreCount = 1;
17744 submit_info.pWaitSemaphores = &semaphore;
17745 submit_info.pWaitDstStageMask = flags;
17746 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17747 }
17748
17749 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17750 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17751
17752 vkDestroyFence(m_device->device(), fence, nullptr);
17753 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17754 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17755 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17756
17757 m_errorMonitor->VerifyNotFound();
17758}
17759
17760TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
17761
17762 ASSERT_NO_FATAL_FAILURE(InitState());
17763 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
17764 printf("Test requires two queues, skipping\n");
17765 return;
17766 }
17767
17768 VkResult err;
17769
17770 m_errorMonitor->ExpectSuccess();
17771
17772 VkQueue q0 = m_device->m_queue;
17773 VkQueue q1 = nullptr;
17774 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
17775 ASSERT_NE(q1, nullptr);
17776
17777 // An (empty) command buffer. We must have work in the first submission --
17778 // the layer treats unfenced work differently from fenced work.
17779 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
17780 VkCommandPool pool;
17781 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
17782 ASSERT_VK_SUCCESS(err);
17783 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
17784 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
17785 VkCommandBuffer cb;
17786 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
17787 ASSERT_VK_SUCCESS(err);
17788 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
17789 err = vkBeginCommandBuffer(cb, &cbbi);
17790 ASSERT_VK_SUCCESS(err);
17791 err = vkEndCommandBuffer(cb);
17792 ASSERT_VK_SUCCESS(err);
17793
17794 // A semaphore
17795 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17796 VkSemaphore s;
17797 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
17798 ASSERT_VK_SUCCESS(err);
17799
17800 // First submission, to q0
17801 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
17802
17803 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
17804 ASSERT_VK_SUCCESS(err);
17805
17806 // Second submission, to q1, waiting on s
17807 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
17808 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
17809
17810 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
17811 ASSERT_VK_SUCCESS(err);
17812
17813 // Wait for q0 idle
17814 err = vkQueueWaitIdle(q0);
17815 ASSERT_VK_SUCCESS(err);
17816
17817 // Command buffer should have been completed (it was on q0); reset the pool.
17818 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
17819
17820 m_errorMonitor->VerifyNotFound();
17821
17822 // Force device completely idle and clean up resources
17823 vkDeviceWaitIdle(m_device->device());
17824 vkDestroyCommandPool(m_device->device(), pool, nullptr);
17825 vkDestroySemaphore(m_device->device(), s, nullptr);
17826}
17827
17828// This is a positive test. No errors should be generated.
17829TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
17830
17831 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17832 "submitted on separate queues, the second having a fence, "
17833 "followed by a WaitForFences call.");
17834
17835 ASSERT_NO_FATAL_FAILURE(InitState());
17836 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17837 return;
17838
17839 m_errorMonitor->ExpectSuccess();
17840
17841 ASSERT_NO_FATAL_FAILURE(InitState());
17842 VkFence fence;
17843 VkFenceCreateInfo fence_create_info{};
17844 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17845 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17846
17847 VkSemaphore semaphore;
17848 VkSemaphoreCreateInfo semaphore_create_info{};
17849 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17850 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17851
17852 VkCommandPool command_pool;
17853 VkCommandPoolCreateInfo pool_create_info{};
17854 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17855 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17856 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17857 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17858
17859 VkCommandBuffer command_buffer[2];
17860 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17861 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17862 command_buffer_allocate_info.commandPool = command_pool;
17863 command_buffer_allocate_info.commandBufferCount = 2;
17864 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17865 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17866
17867 VkQueue queue = VK_NULL_HANDLE;
17868 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17869
17870 {
17871 VkCommandBufferBeginInfo begin_info{};
17872 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17873 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17874
17875 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17876 nullptr, 0, nullptr, 0, nullptr);
17877
17878 VkViewport viewport{};
17879 viewport.maxDepth = 1.0f;
17880 viewport.minDepth = 0.0f;
17881 viewport.width = 512;
17882 viewport.height = 512;
17883 viewport.x = 0;
17884 viewport.y = 0;
17885 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17886 vkEndCommandBuffer(command_buffer[0]);
17887 }
17888 {
17889 VkCommandBufferBeginInfo begin_info{};
17890 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17891 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17892
17893 VkViewport viewport{};
17894 viewport.maxDepth = 1.0f;
17895 viewport.minDepth = 0.0f;
17896 viewport.width = 512;
17897 viewport.height = 512;
17898 viewport.x = 0;
17899 viewport.y = 0;
17900 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17901 vkEndCommandBuffer(command_buffer[1]);
17902 }
17903 {
17904 VkSubmitInfo submit_info{};
17905 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17906 submit_info.commandBufferCount = 1;
17907 submit_info.pCommandBuffers = &command_buffer[0];
17908 submit_info.signalSemaphoreCount = 1;
17909 submit_info.pSignalSemaphores = &semaphore;
17910 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17911 }
17912 {
17913 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17914 VkSubmitInfo submit_info{};
17915 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17916 submit_info.commandBufferCount = 1;
17917 submit_info.pCommandBuffers = &command_buffer[1];
17918 submit_info.waitSemaphoreCount = 1;
17919 submit_info.pWaitSemaphores = &semaphore;
17920 submit_info.pWaitDstStageMask = flags;
17921 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17922 }
17923
17924 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17925
17926 vkDestroyFence(m_device->device(), fence, nullptr);
17927 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17928 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17929 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17930
17931 m_errorMonitor->VerifyNotFound();
17932}
17933
17934// This is a positive test. No errors should be generated.
17935TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
17936
17937 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17938 "on the same queue, sharing a signal/wait semaphore, the "
17939 "second having a fence, "
17940 "followed by a WaitForFences call.");
17941
17942 m_errorMonitor->ExpectSuccess();
17943
17944 ASSERT_NO_FATAL_FAILURE(InitState());
17945 VkFence fence;
17946 VkFenceCreateInfo fence_create_info{};
17947 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17948 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17949
17950 VkSemaphore semaphore;
17951 VkSemaphoreCreateInfo semaphore_create_info{};
17952 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17953 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17954
17955 VkCommandPool command_pool;
17956 VkCommandPoolCreateInfo pool_create_info{};
17957 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17958 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17959 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17960 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17961
17962 VkCommandBuffer command_buffer[2];
17963 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17964 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17965 command_buffer_allocate_info.commandPool = command_pool;
17966 command_buffer_allocate_info.commandBufferCount = 2;
17967 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17968 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17969
17970 {
17971 VkCommandBufferBeginInfo begin_info{};
17972 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17973 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17974
17975 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17976 nullptr, 0, nullptr, 0, nullptr);
17977
17978 VkViewport viewport{};
17979 viewport.maxDepth = 1.0f;
17980 viewport.minDepth = 0.0f;
17981 viewport.width = 512;
17982 viewport.height = 512;
17983 viewport.x = 0;
17984 viewport.y = 0;
17985 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17986 vkEndCommandBuffer(command_buffer[0]);
17987 }
17988 {
17989 VkCommandBufferBeginInfo begin_info{};
17990 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17991 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17992
17993 VkViewport viewport{};
17994 viewport.maxDepth = 1.0f;
17995 viewport.minDepth = 0.0f;
17996 viewport.width = 512;
17997 viewport.height = 512;
17998 viewport.x = 0;
17999 viewport.y = 0;
18000 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18001 vkEndCommandBuffer(command_buffer[1]);
18002 }
18003 {
18004 VkSubmitInfo submit_info{};
18005 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18006 submit_info.commandBufferCount = 1;
18007 submit_info.pCommandBuffers = &command_buffer[0];
18008 submit_info.signalSemaphoreCount = 1;
18009 submit_info.pSignalSemaphores = &semaphore;
18010 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18011 }
18012 {
18013 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18014 VkSubmitInfo submit_info{};
18015 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18016 submit_info.commandBufferCount = 1;
18017 submit_info.pCommandBuffers = &command_buffer[1];
18018 submit_info.waitSemaphoreCount = 1;
18019 submit_info.pWaitSemaphores = &semaphore;
18020 submit_info.pWaitDstStageMask = flags;
18021 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18022 }
18023
18024 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18025
18026 vkDestroyFence(m_device->device(), fence, nullptr);
18027 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18028 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18029 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18030
18031 m_errorMonitor->VerifyNotFound();
18032}
18033
18034// This is a positive test. No errors should be generated.
18035TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18036
18037 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18038 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18039 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18040
18041 m_errorMonitor->ExpectSuccess();
18042
18043 ASSERT_NO_FATAL_FAILURE(InitState());
18044 VkFence fence;
18045 VkFenceCreateInfo fence_create_info{};
18046 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18047 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18048
18049 VkCommandPool command_pool;
18050 VkCommandPoolCreateInfo pool_create_info{};
18051 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18052 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18053 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18054 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18055
18056 VkCommandBuffer command_buffer[2];
18057 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18058 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18059 command_buffer_allocate_info.commandPool = command_pool;
18060 command_buffer_allocate_info.commandBufferCount = 2;
18061 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18062 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18063
18064 {
18065 VkCommandBufferBeginInfo begin_info{};
18066 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18067 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18068
18069 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18070 nullptr, 0, nullptr, 0, nullptr);
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[0], 0, 1, &viewport);
18080 vkEndCommandBuffer(command_buffer[0]);
18081 }
18082 {
18083 VkCommandBufferBeginInfo begin_info{};
18084 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18085 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18086
18087 VkViewport viewport{};
18088 viewport.maxDepth = 1.0f;
18089 viewport.minDepth = 0.0f;
18090 viewport.width = 512;
18091 viewport.height = 512;
18092 viewport.x = 0;
18093 viewport.y = 0;
18094 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18095 vkEndCommandBuffer(command_buffer[1]);
18096 }
18097 {
18098 VkSubmitInfo submit_info{};
18099 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18100 submit_info.commandBufferCount = 1;
18101 submit_info.pCommandBuffers = &command_buffer[0];
18102 submit_info.signalSemaphoreCount = 0;
18103 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18104 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18105 }
18106 {
18107 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18108 VkSubmitInfo submit_info{};
18109 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18110 submit_info.commandBufferCount = 1;
18111 submit_info.pCommandBuffers = &command_buffer[1];
18112 submit_info.waitSemaphoreCount = 0;
18113 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18114 submit_info.pWaitDstStageMask = flags;
18115 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18116 }
18117
18118 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18119
18120 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18121 ASSERT_VK_SUCCESS(err);
18122
18123 vkDestroyFence(m_device->device(), fence, nullptr);
18124 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18125 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18126
18127 m_errorMonitor->VerifyNotFound();
18128}
18129
18130// This is a positive test. No errors should be generated.
18131TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18132
18133 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18134 "on the same queue, the second having a fence, followed "
18135 "by a WaitForFences call.");
18136
18137 m_errorMonitor->ExpectSuccess();
18138
18139 ASSERT_NO_FATAL_FAILURE(InitState());
18140 VkFence fence;
18141 VkFenceCreateInfo fence_create_info{};
18142 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18143 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18144
18145 VkCommandPool command_pool;
18146 VkCommandPoolCreateInfo pool_create_info{};
18147 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18148 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18149 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18150 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18151
18152 VkCommandBuffer command_buffer[2];
18153 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18154 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18155 command_buffer_allocate_info.commandPool = command_pool;
18156 command_buffer_allocate_info.commandBufferCount = 2;
18157 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18158 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18159
18160 {
18161 VkCommandBufferBeginInfo begin_info{};
18162 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18163 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18164
18165 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18166 nullptr, 0, nullptr, 0, nullptr);
18167
18168 VkViewport viewport{};
18169 viewport.maxDepth = 1.0f;
18170 viewport.minDepth = 0.0f;
18171 viewport.width = 512;
18172 viewport.height = 512;
18173 viewport.x = 0;
18174 viewport.y = 0;
18175 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18176 vkEndCommandBuffer(command_buffer[0]);
18177 }
18178 {
18179 VkCommandBufferBeginInfo begin_info{};
18180 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18181 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18182
18183 VkViewport viewport{};
18184 viewport.maxDepth = 1.0f;
18185 viewport.minDepth = 0.0f;
18186 viewport.width = 512;
18187 viewport.height = 512;
18188 viewport.x = 0;
18189 viewport.y = 0;
18190 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18191 vkEndCommandBuffer(command_buffer[1]);
18192 }
18193 {
18194 VkSubmitInfo submit_info{};
18195 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18196 submit_info.commandBufferCount = 1;
18197 submit_info.pCommandBuffers = &command_buffer[0];
18198 submit_info.signalSemaphoreCount = 0;
18199 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18200 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18201 }
18202 {
18203 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18204 VkSubmitInfo submit_info{};
18205 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18206 submit_info.commandBufferCount = 1;
18207 submit_info.pCommandBuffers = &command_buffer[1];
18208 submit_info.waitSemaphoreCount = 0;
18209 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18210 submit_info.pWaitDstStageMask = flags;
18211 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18212 }
18213
18214 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18215
18216 vkDestroyFence(m_device->device(), fence, nullptr);
18217 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18218 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18219
18220 m_errorMonitor->VerifyNotFound();
18221}
18222
18223// This is a positive test. No errors should be generated.
18224TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18225
18226 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18227 "QueueSubmit call followed by a WaitForFences call.");
18228 ASSERT_NO_FATAL_FAILURE(InitState());
18229
18230 m_errorMonitor->ExpectSuccess();
18231
18232 VkFence fence;
18233 VkFenceCreateInfo fence_create_info{};
18234 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18235 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18236
18237 VkSemaphore semaphore;
18238 VkSemaphoreCreateInfo semaphore_create_info{};
18239 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18240 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18241
18242 VkCommandPool command_pool;
18243 VkCommandPoolCreateInfo pool_create_info{};
18244 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18245 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18246 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18247 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18248
18249 VkCommandBuffer command_buffer[2];
18250 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18251 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18252 command_buffer_allocate_info.commandPool = command_pool;
18253 command_buffer_allocate_info.commandBufferCount = 2;
18254 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18255 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18256
18257 {
18258 VkCommandBufferBeginInfo begin_info{};
18259 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18260 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18261
18262 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18263 nullptr, 0, nullptr, 0, nullptr);
18264
18265 VkViewport viewport{};
18266 viewport.maxDepth = 1.0f;
18267 viewport.minDepth = 0.0f;
18268 viewport.width = 512;
18269 viewport.height = 512;
18270 viewport.x = 0;
18271 viewport.y = 0;
18272 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18273 vkEndCommandBuffer(command_buffer[0]);
18274 }
18275 {
18276 VkCommandBufferBeginInfo begin_info{};
18277 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18278 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18279
18280 VkViewport viewport{};
18281 viewport.maxDepth = 1.0f;
18282 viewport.minDepth = 0.0f;
18283 viewport.width = 512;
18284 viewport.height = 512;
18285 viewport.x = 0;
18286 viewport.y = 0;
18287 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18288 vkEndCommandBuffer(command_buffer[1]);
18289 }
18290 {
18291 VkSubmitInfo submit_info[2];
18292 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18293
18294 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18295 submit_info[0].pNext = NULL;
18296 submit_info[0].commandBufferCount = 1;
18297 submit_info[0].pCommandBuffers = &command_buffer[0];
18298 submit_info[0].signalSemaphoreCount = 1;
18299 submit_info[0].pSignalSemaphores = &semaphore;
18300 submit_info[0].waitSemaphoreCount = 0;
18301 submit_info[0].pWaitSemaphores = NULL;
18302 submit_info[0].pWaitDstStageMask = 0;
18303
18304 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18305 submit_info[1].pNext = NULL;
18306 submit_info[1].commandBufferCount = 1;
18307 submit_info[1].pCommandBuffers = &command_buffer[1];
18308 submit_info[1].waitSemaphoreCount = 1;
18309 submit_info[1].pWaitSemaphores = &semaphore;
18310 submit_info[1].pWaitDstStageMask = flags;
18311 submit_info[1].signalSemaphoreCount = 0;
18312 submit_info[1].pSignalSemaphores = NULL;
18313 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18314 }
18315
18316 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18317
18318 vkDestroyFence(m_device->device(), fence, nullptr);
18319 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18320 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18321 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18322
18323 m_errorMonitor->VerifyNotFound();
18324}
18325
18326TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18327 m_errorMonitor->ExpectSuccess();
18328
18329 ASSERT_NO_FATAL_FAILURE(InitState());
18330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18331
18332 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18333 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18334
18335 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18336 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18337 m_errorMonitor->VerifyNotFound();
18338 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18339 m_errorMonitor->VerifyNotFound();
18340 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18341 m_errorMonitor->VerifyNotFound();
18342
18343 m_commandBuffer->EndCommandBuffer();
18344 m_errorMonitor->VerifyNotFound();
18345}
18346
18347TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18348 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18349 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18350 "has a valid layout, and a second subpass then uses a "
18351 "valid *READ_ONLY* layout.");
18352 m_errorMonitor->ExpectSuccess();
18353 ASSERT_NO_FATAL_FAILURE(InitState());
18354
18355 VkAttachmentReference attach[2] = {};
18356 attach[0].attachment = 0;
18357 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18358 attach[1].attachment = 0;
18359 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18360 VkSubpassDescription subpasses[2] = {};
18361 // First subpass clears DS attach on load
18362 subpasses[0].pDepthStencilAttachment = &attach[0];
18363 // 2nd subpass reads in DS as input attachment
18364 subpasses[1].inputAttachmentCount = 1;
18365 subpasses[1].pInputAttachments = &attach[1];
18366 VkAttachmentDescription attach_desc = {};
18367 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18368 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18369 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18370 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18371 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18372 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18373 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18374 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18375 VkRenderPassCreateInfo rpci = {};
18376 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18377 rpci.attachmentCount = 1;
18378 rpci.pAttachments = &attach_desc;
18379 rpci.subpassCount = 2;
18380 rpci.pSubpasses = subpasses;
18381
18382 // Now create RenderPass and verify no errors
18383 VkRenderPass rp;
18384 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18385 m_errorMonitor->VerifyNotFound();
18386
18387 vkDestroyRenderPass(m_device->device(), rp, NULL);
18388}
18389
18390TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18391 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18392 "as vertex attributes");
18393 m_errorMonitor->ExpectSuccess();
18394
18395 ASSERT_NO_FATAL_FAILURE(InitState());
18396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18397
18398 VkVertexInputBindingDescription input_binding;
18399 memset(&input_binding, 0, sizeof(input_binding));
18400
18401 VkVertexInputAttributeDescription input_attribs[2];
18402 memset(input_attribs, 0, sizeof(input_attribs));
18403
18404 for (int i = 0; i < 2; i++) {
18405 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18406 input_attribs[i].location = i;
18407 }
18408
18409 char const *vsSource = "#version 450\n"
18410 "\n"
18411 "layout(location=0) in mat2x4 x;\n"
18412 "out gl_PerVertex {\n"
18413 " vec4 gl_Position;\n"
18414 "};\n"
18415 "void main(){\n"
18416 " gl_Position = x[0] + x[1];\n"
18417 "}\n";
18418 char const *fsSource = "#version 450\n"
18419 "\n"
18420 "layout(location=0) out vec4 color;\n"
18421 "void main(){\n"
18422 " color = vec4(1);\n"
18423 "}\n";
18424
18425 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18426 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18427
18428 VkPipelineObj pipe(m_device);
18429 pipe.AddColorAttachment();
18430 pipe.AddShader(&vs);
18431 pipe.AddShader(&fs);
18432
18433 pipe.AddVertexInputBindings(&input_binding, 1);
18434 pipe.AddVertexInputAttribs(input_attribs, 2);
18435
18436 VkDescriptorSetObj descriptorSet(m_device);
18437 descriptorSet.AppendDummy();
18438 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18439
18440 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18441
18442 /* expect success */
18443 m_errorMonitor->VerifyNotFound();
18444}
18445
18446TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18447 m_errorMonitor->ExpectSuccess();
18448
18449 ASSERT_NO_FATAL_FAILURE(InitState());
18450 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18451
18452 VkVertexInputBindingDescription input_binding;
18453 memset(&input_binding, 0, sizeof(input_binding));
18454
18455 VkVertexInputAttributeDescription input_attribs[2];
18456 memset(input_attribs, 0, sizeof(input_attribs));
18457
18458 for (int i = 0; i < 2; i++) {
18459 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18460 input_attribs[i].location = i;
18461 }
18462
18463 char const *vsSource = "#version 450\n"
18464 "\n"
18465 "layout(location=0) in vec4 x[2];\n"
18466 "out gl_PerVertex {\n"
18467 " vec4 gl_Position;\n"
18468 "};\n"
18469 "void main(){\n"
18470 " gl_Position = x[0] + x[1];\n"
18471 "}\n";
18472 char const *fsSource = "#version 450\n"
18473 "\n"
18474 "layout(location=0) out vec4 color;\n"
18475 "void main(){\n"
18476 " color = vec4(1);\n"
18477 "}\n";
18478
18479 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18480 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18481
18482 VkPipelineObj pipe(m_device);
18483 pipe.AddColorAttachment();
18484 pipe.AddShader(&vs);
18485 pipe.AddShader(&fs);
18486
18487 pipe.AddVertexInputBindings(&input_binding, 1);
18488 pipe.AddVertexInputAttribs(input_attribs, 2);
18489
18490 VkDescriptorSetObj descriptorSet(m_device);
18491 descriptorSet.AppendDummy();
18492 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18493
18494 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18495
18496 m_errorMonitor->VerifyNotFound();
18497}
18498
18499TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18500 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18501 "through multiple vertex shader inputs, each consuming a different "
18502 "subset of the components.");
18503 m_errorMonitor->ExpectSuccess();
18504
18505 ASSERT_NO_FATAL_FAILURE(InitState());
18506 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18507
18508 VkVertexInputBindingDescription input_binding;
18509 memset(&input_binding, 0, sizeof(input_binding));
18510
18511 VkVertexInputAttributeDescription input_attribs[3];
18512 memset(input_attribs, 0, sizeof(input_attribs));
18513
18514 for (int i = 0; i < 3; i++) {
18515 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18516 input_attribs[i].location = i;
18517 }
18518
18519 char const *vsSource = "#version 450\n"
18520 "\n"
18521 "layout(location=0) in vec4 x;\n"
18522 "layout(location=1) in vec3 y1;\n"
18523 "layout(location=1, component=3) in float y2;\n"
18524 "layout(location=2) in vec4 z;\n"
18525 "out gl_PerVertex {\n"
18526 " vec4 gl_Position;\n"
18527 "};\n"
18528 "void main(){\n"
18529 " gl_Position = x + vec4(y1, y2) + z;\n"
18530 "}\n";
18531 char const *fsSource = "#version 450\n"
18532 "\n"
18533 "layout(location=0) out vec4 color;\n"
18534 "void main(){\n"
18535 " color = vec4(1);\n"
18536 "}\n";
18537
18538 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18539 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18540
18541 VkPipelineObj pipe(m_device);
18542 pipe.AddColorAttachment();
18543 pipe.AddShader(&vs);
18544 pipe.AddShader(&fs);
18545
18546 pipe.AddVertexInputBindings(&input_binding, 1);
18547 pipe.AddVertexInputAttribs(input_attribs, 3);
18548
18549 VkDescriptorSetObj descriptorSet(m_device);
18550 descriptorSet.AppendDummy();
18551 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18552
18553 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18554
18555 m_errorMonitor->VerifyNotFound();
18556}
18557
18558TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18559 m_errorMonitor->ExpectSuccess();
18560
18561 ASSERT_NO_FATAL_FAILURE(InitState());
18562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18563
18564 char const *vsSource = "#version 450\n"
18565 "out gl_PerVertex {\n"
18566 " vec4 gl_Position;\n"
18567 "};\n"
18568 "void main(){\n"
18569 " gl_Position = vec4(0);\n"
18570 "}\n";
18571 char const *fsSource = "#version 450\n"
18572 "\n"
18573 "layout(location=0) out vec4 color;\n"
18574 "void main(){\n"
18575 " color = vec4(1);\n"
18576 "}\n";
18577
18578 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18579 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18580
18581 VkPipelineObj pipe(m_device);
18582 pipe.AddColorAttachment();
18583 pipe.AddShader(&vs);
18584 pipe.AddShader(&fs);
18585
18586 VkDescriptorSetObj descriptorSet(m_device);
18587 descriptorSet.AppendDummy();
18588 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18589
18590 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18591
18592 m_errorMonitor->VerifyNotFound();
18593}
18594
18595TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18596 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18597 "set out in 14.1.3: fundamental type must match, and producer side must "
18598 "have at least as many components");
18599 m_errorMonitor->ExpectSuccess();
18600
18601 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18602
18603 ASSERT_NO_FATAL_FAILURE(InitState());
18604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18605
18606 char const *vsSource = "#version 450\n"
18607 "out gl_PerVertex {\n"
18608 " vec4 gl_Position;\n"
18609 "};\n"
18610 "layout(location=0) out vec3 x;\n"
18611 "layout(location=1) out ivec3 y;\n"
18612 "layout(location=2) out vec3 z;\n"
18613 "void main(){\n"
18614 " gl_Position = vec4(0);\n"
18615 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18616 "}\n";
18617 char const *fsSource = "#version 450\n"
18618 "\n"
18619 "layout(location=0) out vec4 color;\n"
18620 "layout(location=0) in float x;\n"
18621 "layout(location=1) flat in int y;\n"
18622 "layout(location=2) in vec2 z;\n"
18623 "void main(){\n"
18624 " color = vec4(1 + x + y + z.x);\n"
18625 "}\n";
18626
18627 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18628 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18629
18630 VkPipelineObj pipe(m_device);
18631 pipe.AddColorAttachment();
18632 pipe.AddShader(&vs);
18633 pipe.AddShader(&fs);
18634
18635 VkDescriptorSetObj descriptorSet(m_device);
18636 descriptorSet.AppendDummy();
18637 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18638
18639 VkResult err = VK_SUCCESS;
18640 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18641 ASSERT_VK_SUCCESS(err);
18642
18643 m_errorMonitor->VerifyNotFound();
18644}
18645
18646TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18647 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18648 "passed between the TCS and TES stages");
18649 m_errorMonitor->ExpectSuccess();
18650
18651 ASSERT_NO_FATAL_FAILURE(InitState());
18652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18653
18654 if (!m_device->phy().features().tessellationShader) {
18655 printf("Device does not support tessellation shaders; skipped.\n");
18656 return;
18657 }
18658
18659 char const *vsSource = "#version 450\n"
18660 "void main(){}\n";
18661 char const *tcsSource = "#version 450\n"
18662 "layout(location=0) out int x[];\n"
18663 "layout(vertices=3) out;\n"
18664 "void main(){\n"
18665 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18666 " gl_TessLevelInner[0] = 1;\n"
18667 " x[gl_InvocationID] = gl_InvocationID;\n"
18668 "}\n";
18669 char const *tesSource = "#version 450\n"
18670 "layout(triangles, equal_spacing, cw) in;\n"
18671 "layout(location=0) in int x[];\n"
18672 "out gl_PerVertex { vec4 gl_Position; };\n"
18673 "void main(){\n"
18674 " gl_Position.xyz = gl_TessCoord;\n"
18675 " gl_Position.w = x[0] + x[1] + x[2];\n"
18676 "}\n";
18677 char const *fsSource = "#version 450\n"
18678 "layout(location=0) out vec4 color;\n"
18679 "void main(){\n"
18680 " color = vec4(1);\n"
18681 "}\n";
18682
18683 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18684 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
18685 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
18686 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18687
18688 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
18689 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
18690
18691 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
18692
18693 VkPipelineObj pipe(m_device);
18694 pipe.SetInputAssembly(&iasci);
18695 pipe.SetTessellation(&tsci);
18696 pipe.AddColorAttachment();
18697 pipe.AddShader(&vs);
18698 pipe.AddShader(&tcs);
18699 pipe.AddShader(&tes);
18700 pipe.AddShader(&fs);
18701
18702 VkDescriptorSetObj descriptorSet(m_device);
18703 descriptorSet.AppendDummy();
18704 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18705
18706 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18707
18708 m_errorMonitor->VerifyNotFound();
18709}
18710
18711TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
18712 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
18713 "interface block passed into the geometry shader. This "
18714 "is interesting because the 'extra' array level is not "
18715 "present on the member type, but on the block instance.");
18716 m_errorMonitor->ExpectSuccess();
18717
18718 ASSERT_NO_FATAL_FAILURE(InitState());
18719 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18720
18721 if (!m_device->phy().features().geometryShader) {
18722 printf("Device does not support geometry shaders; skipped.\n");
18723 return;
18724 }
18725
18726 char const *vsSource = "#version 450\n"
18727 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
18728 "void main(){\n"
18729 " vs_out.x = vec4(1);\n"
18730 "}\n";
18731 char const *gsSource = "#version 450\n"
18732 "layout(triangles) in;\n"
18733 "layout(triangle_strip, max_vertices=3) out;\n"
18734 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
18735 "out gl_PerVertex { vec4 gl_Position; };\n"
18736 "void main() {\n"
18737 " gl_Position = gs_in[0].x;\n"
18738 " EmitVertex();\n"
18739 "}\n";
18740 char const *fsSource = "#version 450\n"
18741 "layout(location=0) out vec4 color;\n"
18742 "void main(){\n"
18743 " color = vec4(1);\n"
18744 "}\n";
18745
18746 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18747 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
18748 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18749
18750 VkPipelineObj pipe(m_device);
18751 pipe.AddColorAttachment();
18752 pipe.AddShader(&vs);
18753 pipe.AddShader(&gs);
18754 pipe.AddShader(&fs);
18755
18756 VkDescriptorSetObj descriptorSet(m_device);
18757 descriptorSet.AppendDummy();
18758 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18759
18760 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18761
18762 m_errorMonitor->VerifyNotFound();
18763}
18764
18765TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
18766 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
18767 "attributes. This is interesting because they consume multiple "
18768 "locations.");
18769 m_errorMonitor->ExpectSuccess();
18770
18771 ASSERT_NO_FATAL_FAILURE(InitState());
18772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18773
18774 if (!m_device->phy().features().shaderFloat64) {
18775 printf("Device does not support 64bit vertex attributes; skipped.\n");
18776 return;
18777 }
18778
18779 VkVertexInputBindingDescription input_bindings[1];
18780 memset(input_bindings, 0, sizeof(input_bindings));
18781
18782 VkVertexInputAttributeDescription input_attribs[4];
18783 memset(input_attribs, 0, sizeof(input_attribs));
18784 input_attribs[0].location = 0;
18785 input_attribs[0].offset = 0;
18786 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18787 input_attribs[1].location = 2;
18788 input_attribs[1].offset = 32;
18789 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18790 input_attribs[2].location = 4;
18791 input_attribs[2].offset = 64;
18792 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18793 input_attribs[3].location = 6;
18794 input_attribs[3].offset = 96;
18795 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18796
18797 char const *vsSource = "#version 450\n"
18798 "\n"
18799 "layout(location=0) in dmat4 x;\n"
18800 "out gl_PerVertex {\n"
18801 " vec4 gl_Position;\n"
18802 "};\n"
18803 "void main(){\n"
18804 " gl_Position = vec4(x[0][0]);\n"
18805 "}\n";
18806 char const *fsSource = "#version 450\n"
18807 "\n"
18808 "layout(location=0) out vec4 color;\n"
18809 "void main(){\n"
18810 " color = vec4(1);\n"
18811 "}\n";
18812
18813 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18814 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18815
18816 VkPipelineObj pipe(m_device);
18817 pipe.AddColorAttachment();
18818 pipe.AddShader(&vs);
18819 pipe.AddShader(&fs);
18820
18821 pipe.AddVertexInputBindings(input_bindings, 1);
18822 pipe.AddVertexInputAttribs(input_attribs, 4);
18823
18824 VkDescriptorSetObj descriptorSet(m_device);
18825 descriptorSet.AppendDummy();
18826 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18827
18828 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18829
18830 m_errorMonitor->VerifyNotFound();
18831}
18832
18833TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
18834 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
18835 m_errorMonitor->ExpectSuccess();
18836
18837 ASSERT_NO_FATAL_FAILURE(InitState());
18838
18839 char const *vsSource = "#version 450\n"
18840 "\n"
18841 "out gl_PerVertex {\n"
18842 " vec4 gl_Position;\n"
18843 "};\n"
18844 "void main(){\n"
18845 " gl_Position = vec4(1);\n"
18846 "}\n";
18847 char const *fsSource = "#version 450\n"
18848 "\n"
18849 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
18850 "layout(location=0) out vec4 color;\n"
18851 "void main() {\n"
18852 " color = subpassLoad(x);\n"
18853 "}\n";
18854
18855 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18857
18858 VkPipelineObj pipe(m_device);
18859 pipe.AddShader(&vs);
18860 pipe.AddShader(&fs);
18861 pipe.AddColorAttachment();
18862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18863
18864 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
18865 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
18866 VkDescriptorSetLayout dsl;
18867 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18868 ASSERT_VK_SUCCESS(err);
18869
18870 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18871 VkPipelineLayout pl;
18872 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18873 ASSERT_VK_SUCCESS(err);
18874
18875 VkAttachmentDescription descs[2] = {
18876 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18877 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18878 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
18879 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18880 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
18881 };
18882 VkAttachmentReference color = {
18883 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18884 };
18885 VkAttachmentReference input = {
18886 1, VK_IMAGE_LAYOUT_GENERAL,
18887 };
18888
18889 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
18890
18891 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
18892 VkRenderPass rp;
18893 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18894 ASSERT_VK_SUCCESS(err);
18895
18896 // should be OK. would go wrong here if it's going to...
18897 pipe.CreateVKPipeline(pl, rp);
18898
18899 m_errorMonitor->VerifyNotFound();
18900
18901 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18902 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18903 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
18904}
18905
18906TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
18907 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
18908 "descriptor-backed resource which is not provided, but the shader does not "
18909 "statically use it. This is interesting because it requires compute pipelines "
18910 "to have a proper descriptor use walk, which they didn't for some time.");
18911 m_errorMonitor->ExpectSuccess();
18912
18913 ASSERT_NO_FATAL_FAILURE(InitState());
18914
18915 char const *csSource = "#version 450\n"
18916 "\n"
18917 "layout(local_size_x=1) in;\n"
18918 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
18919 "void main(){\n"
18920 " // x is not used.\n"
18921 "}\n";
18922
18923 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18924
18925 VkDescriptorSetObj descriptorSet(m_device);
18926 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18927
18928 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18929 nullptr,
18930 0,
18931 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18932 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18933 descriptorSet.GetPipelineLayout(),
18934 VK_NULL_HANDLE,
18935 -1 };
18936
18937 VkPipeline pipe;
18938 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18939
18940 m_errorMonitor->VerifyNotFound();
18941
18942 if (err == VK_SUCCESS) {
18943 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18944 }
18945}
18946
18947TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
18948 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
18949 "sampler portion of a combined image + sampler");
18950 m_errorMonitor->ExpectSuccess();
18951
18952 ASSERT_NO_FATAL_FAILURE(InitState());
18953
18954 VkDescriptorSetLayoutBinding bindings[] = {
18955 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18956 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18957 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
18958 };
18959 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
18960 VkDescriptorSetLayout dsl;
18961 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18962 ASSERT_VK_SUCCESS(err);
18963
18964 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18965 VkPipelineLayout pl;
18966 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18967 ASSERT_VK_SUCCESS(err);
18968
18969 char const *csSource = "#version 450\n"
18970 "\n"
18971 "layout(local_size_x=1) in;\n"
18972 "layout(set=0, binding=0) uniform sampler s;\n"
18973 "layout(set=0, binding=1) uniform texture2D t;\n"
18974 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
18975 "void main() {\n"
18976 " x = texture(sampler2D(t, s), vec2(0));\n"
18977 "}\n";
18978 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
18979
18980 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
18981 nullptr,
18982 0,
18983 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
18984 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
18985 pl,
18986 VK_NULL_HANDLE,
18987 -1 };
18988
18989 VkPipeline pipe;
18990 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
18991
18992 m_errorMonitor->VerifyNotFound();
18993
18994 if (err == VK_SUCCESS) {
18995 vkDestroyPipeline(m_device->device(), pipe, nullptr);
18996 }
18997
18998 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
18999 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19000}
19001
19002TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19003 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19004 "image portion of a combined image + sampler");
19005 m_errorMonitor->ExpectSuccess();
19006
19007 ASSERT_NO_FATAL_FAILURE(InitState());
19008
19009 VkDescriptorSetLayoutBinding bindings[] = {
19010 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19011 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19012 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19013 };
19014 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19015 VkDescriptorSetLayout dsl;
19016 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19017 ASSERT_VK_SUCCESS(err);
19018
19019 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19020 VkPipelineLayout pl;
19021 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19022 ASSERT_VK_SUCCESS(err);
19023
19024 char const *csSource = "#version 450\n"
19025 "\n"
19026 "layout(local_size_x=1) in;\n"
19027 "layout(set=0, binding=0) uniform texture2D t;\n"
19028 "layout(set=0, binding=1) uniform sampler s;\n"
19029 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19030 "void main() {\n"
19031 " x = texture(sampler2D(t, s), vec2(0));\n"
19032 "}\n";
19033 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19034
19035 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19036 nullptr,
19037 0,
19038 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19039 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19040 pl,
19041 VK_NULL_HANDLE,
19042 -1 };
19043
19044 VkPipeline pipe;
19045 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19046
19047 m_errorMonitor->VerifyNotFound();
19048
19049 if (err == VK_SUCCESS) {
19050 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19051 }
19052
19053 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19054 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19055}
19056
19057TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19058 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19059 "both the sampler and the image of a combined image+sampler "
19060 "but via separate variables");
19061 m_errorMonitor->ExpectSuccess();
19062
19063 ASSERT_NO_FATAL_FAILURE(InitState());
19064
19065 VkDescriptorSetLayoutBinding bindings[] = {
19066 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19067 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19068 };
19069 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19070 VkDescriptorSetLayout dsl;
19071 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19072 ASSERT_VK_SUCCESS(err);
19073
19074 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19075 VkPipelineLayout pl;
19076 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19077 ASSERT_VK_SUCCESS(err);
19078
19079 char const *csSource = "#version 450\n"
19080 "\n"
19081 "layout(local_size_x=1) in;\n"
19082 "layout(set=0, binding=0) uniform texture2D t;\n"
19083 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19084 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19085 "void main() {\n"
19086 " x = texture(sampler2D(t, s), vec2(0));\n"
19087 "}\n";
19088 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19089
19090 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19091 nullptr,
19092 0,
19093 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19094 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19095 pl,
19096 VK_NULL_HANDLE,
19097 -1 };
19098
19099 VkPipeline pipe;
19100 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19101
19102 m_errorMonitor->VerifyNotFound();
19103
19104 if (err == VK_SUCCESS) {
19105 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19106 }
19107
19108 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19109 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19110}
19111
19112TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19113 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19114
19115 ASSERT_NO_FATAL_FAILURE(InitState());
19116
19117 // Positive test to check parameter_validation and unique_objects support
19118 // for NV_dedicated_allocation
19119 uint32_t extension_count = 0;
19120 bool supports_nv_dedicated_allocation = false;
19121 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19122 ASSERT_VK_SUCCESS(err);
19123
19124 if (extension_count > 0) {
19125 std::vector<VkExtensionProperties> available_extensions(extension_count);
19126
19127 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19128 ASSERT_VK_SUCCESS(err);
19129
19130 for (const auto &extension_props : available_extensions) {
19131 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19132 supports_nv_dedicated_allocation = true;
19133 }
19134 }
19135 }
19136
19137 if (supports_nv_dedicated_allocation) {
19138 m_errorMonitor->ExpectSuccess();
19139
19140 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19141 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19142 dedicated_buffer_create_info.pNext = nullptr;
19143 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19144
19145 uint32_t queue_family_index = 0;
19146 VkBufferCreateInfo buffer_create_info = {};
19147 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19148 buffer_create_info.pNext = &dedicated_buffer_create_info;
19149 buffer_create_info.size = 1024;
19150 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19151 buffer_create_info.queueFamilyIndexCount = 1;
19152 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19153
19154 VkBuffer buffer;
19155 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19156 ASSERT_VK_SUCCESS(err);
19157
19158 VkMemoryRequirements memory_reqs;
19159 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19160
19161 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19162 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19163 dedicated_memory_info.pNext = nullptr;
19164 dedicated_memory_info.buffer = buffer;
19165 dedicated_memory_info.image = VK_NULL_HANDLE;
19166
19167 VkMemoryAllocateInfo memory_info = {};
19168 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19169 memory_info.pNext = &dedicated_memory_info;
19170 memory_info.allocationSize = memory_reqs.size;
19171
19172 bool pass;
19173 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19174 ASSERT_TRUE(pass);
19175
19176 VkDeviceMemory buffer_memory;
19177 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19178 ASSERT_VK_SUCCESS(err);
19179
19180 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19181 ASSERT_VK_SUCCESS(err);
19182
19183 vkDestroyBuffer(m_device->device(), buffer, NULL);
19184 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19185
19186 m_errorMonitor->VerifyNotFound();
19187 }
19188}
19189
19190TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19191 VkResult err;
19192
19193 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19194
19195 ASSERT_NO_FATAL_FAILURE(InitState());
19196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19197
19198 std::vector<const char *> device_extension_names;
19199 auto features = m_device->phy().features();
19200 // Artificially disable support for non-solid fill modes
19201 features.fillModeNonSolid = false;
19202 // The sacrificial device object
19203 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19204
19205 VkRenderpassObj render_pass(&test_device);
19206
19207 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19208 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19209 pipeline_layout_ci.setLayoutCount = 0;
19210 pipeline_layout_ci.pSetLayouts = NULL;
19211
19212 VkPipelineLayout pipeline_layout;
19213 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19214 ASSERT_VK_SUCCESS(err);
19215
19216 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19217 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19218 rs_ci.pNext = nullptr;
19219 rs_ci.lineWidth = 1.0f;
19220 rs_ci.rasterizerDiscardEnable = true;
19221
19222 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19223 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19224
19225 // Set polygonMode=FILL. No error is expected
19226 m_errorMonitor->ExpectSuccess();
19227 {
19228 VkPipelineObj pipe(&test_device);
19229 pipe.AddShader(&vs);
19230 pipe.AddShader(&fs);
19231 pipe.AddColorAttachment();
19232 // Set polygonMode to a good value
19233 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19234 pipe.SetRasterization(&rs_ci);
19235 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19236 }
19237 m_errorMonitor->VerifyNotFound();
19238
19239 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19240}
19241
19242TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19243 VkResult err;
19244 ASSERT_NO_FATAL_FAILURE(InitState());
19245 ASSERT_NO_FATAL_FAILURE(InitViewport());
19246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19247
19248 VkPipelineLayout pipeline_layout;
19249 VkPushConstantRange pc_range = {};
19250 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19251 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19252 pipeline_layout_ci.pushConstantRangeCount = 1;
19253 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19254
19255 //
19256 // Check for invalid push constant ranges in pipeline layouts.
19257 //
19258 struct PipelineLayoutTestCase {
19259 VkPushConstantRange const range;
19260 char const *msg;
19261 };
19262
19263 // Check for overlapping ranges
19264 const uint32_t ranges_per_test = 5;
19265 struct OverlappingRangeTestCase {
19266 VkPushConstantRange const ranges[ranges_per_test];
19267 char const *msg;
19268 };
19269
19270 // Run some positive tests to make sure overlap checking in the layer is OK
19271 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19272 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19273 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19274 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19275 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19276 "" },
19277 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19278 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19279 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19280 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19281 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19282 "" } } };
19283 for (const auto &iter : overlapping_range_tests_pos) {
19284 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19285 m_errorMonitor->ExpectSuccess();
19286 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19287 m_errorMonitor->VerifyNotFound();
19288 if (VK_SUCCESS == err) {
19289 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19290 }
19291 }
19292
19293 //
19294 // CmdPushConstants tests
19295 //
19296 const uint8_t dummy_values[100] = {};
19297
19298 BeginCommandBuffer();
19299
19300 // positive overlapping range tests with cmd
19301 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19302 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19303 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19304 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19305 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19306 } };
19307
19308 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19309 const VkPushConstantRange pc_range4[] = {
19310 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19311 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19312 };
19313
19314 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19315 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19316 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19317 ASSERT_VK_SUCCESS(err);
19318 for (const auto &iter : cmd_overlap_tests_pos) {
19319 m_errorMonitor->ExpectSuccess();
19320 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19321 iter.range.size, dummy_values);
19322 m_errorMonitor->VerifyNotFound();
19323 }
19324 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19325
19326 EndCommandBuffer();
19327}
19328
19329
19330
19331
19332
19333
19334
19335#if 0 // A few devices have issues with this test so disabling for now
19336TEST_F(VkPositiveLayerTest, LongFenceChain)
19337{
19338 m_errorMonitor->ExpectSuccess();
19339
19340 ASSERT_NO_FATAL_FAILURE(InitState());
19341 VkResult err;
19342
19343 std::vector<VkFence> fences;
19344
19345 const int chainLength = 32768;
19346
19347 for (int i = 0; i < chainLength; i++) {
19348 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19349 VkFence fence;
19350 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19351 ASSERT_VK_SUCCESS(err);
19352
19353 fences.push_back(fence);
19354
19355 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19356 0, nullptr, 0, nullptr };
19357 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19358 ASSERT_VK_SUCCESS(err);
19359
19360 }
19361
19362 // BOOM, stack overflow.
19363 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19364
19365 for (auto fence : fences)
19366 vkDestroyFence(m_device->device(), fence, nullptr);
19367
19368 m_errorMonitor->VerifyNotFound();
19369}
19370#endif
19371
19372
Cody Northrop1242dfd2016-07-13 17:24:59 -060019373#if defined(ANDROID) && defined(VALIDATION_APK)
19374static bool initialized = false;
19375static bool active = false;
19376
19377// Convert Intents to argv
19378// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019379std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019380 std::vector<std::string> args;
19381 JavaVM &vm = *app.activity->vm;
19382 JNIEnv *p_env;
19383 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19384 return args;
19385
19386 JNIEnv &env = *p_env;
19387 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019388 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019389 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019390 jmethodID get_string_extra_method =
19391 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019392 jvalue get_string_extra_args;
19393 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019394 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019395
19396 std::string args_str;
19397 if (extra_str) {
19398 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19399 args_str = extra_utf;
19400 env.ReleaseStringUTFChars(extra_str, extra_utf);
19401 env.DeleteLocalRef(extra_str);
19402 }
19403
19404 env.DeleteLocalRef(get_string_extra_args.l);
19405 env.DeleteLocalRef(intent);
19406 vm.DetachCurrentThread();
19407
19408 // split args_str
19409 std::stringstream ss(args_str);
19410 std::string arg;
19411 while (std::getline(ss, arg, ' ')) {
19412 if (!arg.empty())
19413 args.push_back(arg);
19414 }
19415
19416 return args;
19417}
19418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019419static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019421static void processCommand(struct android_app *app, int32_t cmd) {
19422 switch (cmd) {
19423 case APP_CMD_INIT_WINDOW: {
19424 if (app->window) {
19425 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019426 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019427 break;
19428 }
19429 case APP_CMD_GAINED_FOCUS: {
19430 active = true;
19431 break;
19432 }
19433 case APP_CMD_LOST_FOCUS: {
19434 active = false;
19435 break;
19436 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019437 }
19438}
19439
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019440void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019441 app_dummy();
19442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019443 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019444
19445 int vulkanSupport = InitVulkan();
19446 if (vulkanSupport == 0) {
19447 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19448 return;
19449 }
19450
19451 app->onAppCmd = processCommand;
19452 app->onInputEvent = processInput;
19453
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019454 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019455 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019456 struct android_poll_source *source;
19457 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019458 if (source) {
19459 source->process(app, source);
19460 }
19461
19462 if (app->destroyRequested != 0) {
19463 VkTestFramework::Finish();
19464 return;
19465 }
19466 }
19467
19468 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019469 // Use the following key to send arguments to gtest, i.e.
19470 // --es args "--gtest_filter=-VkLayerTest.foo"
19471 const char key[] = "args";
19472 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019474 std::string filter = "";
19475 if (args.size() > 0) {
19476 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19477 filter += args[0];
19478 } else {
19479 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19480 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019481
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019482 int argc = 2;
19483 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19484 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019486 // Route output to files until we can override the gtest output
19487 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19488 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019490 ::testing::InitGoogleTest(&argc, argv);
19491 VkTestFramework::InitArgs(&argc, argv);
19492 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019493
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019494 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019496 if (result != 0) {
19497 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19498 } else {
19499 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19500 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019502 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019503
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019504 fclose(stdout);
19505 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019506
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019507 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019509 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019510 }
19511 }
19512}
19513#endif
19514
Tony Barbour300a6082015-04-07 13:44:53 -060019515int main(int argc, char **argv) {
19516 int result;
19517
Cody Northrop8e54a402016-03-08 22:25:52 -070019518#ifdef ANDROID
19519 int vulkanSupport = InitVulkan();
19520 if (vulkanSupport == 0)
19521 return 1;
19522#endif
19523
Tony Barbour300a6082015-04-07 13:44:53 -060019524 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019525 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019526
19527 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19528
19529 result = RUN_ALL_TESTS();
19530
Tony Barbour6918cd52015-04-09 12:58:51 -060019531 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019532 return result;
19533}