blob: 97a80080d99ab8fe0ce1b1154055039a106f1a8a [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
59 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600112// Call SetDesiredFailureMsg with: a string to be compared against all
113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
118// Call DesiredMsgFound to determine if the desired failure message
119// was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600120class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700121 public:
122 ErrorMonitor() {
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600123 test_platform_thread_create_mutex(&m_mutex);
124 test_platform_thread_lock_mutex(&m_mutex);
Chris Forbes17756132016-09-16 14:36:39 +1200125 m_msgFlags = VK_DEBUG_REPORT_ERROR_BIT_EXT;
Karl Schultz6addd812016-02-02 17:17:23 -0700126 m_bailout = NULL;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600127 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dustin Graves48458142016-04-29 16:11:55 -0600130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); }
131
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600132 // ErrorMonitor will look for an error message containing the specified string
Karl Schultz6addd812016-02-02 17:17:23 -0700133 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600134 // Also discard all collected messages to this point
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600135 test_platform_thread_lock_mutex(&m_mutex);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600136 m_failure_message_strings.clear();
137 // If we are looking for a matching string, ignore any IDs
138 m_desired_message_ids.clear();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600139 m_otherMsgs.clear();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600140 m_desired_message_strings.insert(msgString);
Karl Schultz6addd812016-02-02 17:17:23 -0700141 m_msgFound = VK_FALSE;
142 m_msgFlags = msgFlags;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600143 test_platform_thread_unlock_mutex(&m_mutex);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600146 // ErrorMonitor will look for a message ID matching the specified one
147 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
148 // Also discard all collected messages to this point
149 test_platform_thread_lock_mutex(&m_mutex);
150 m_failure_message_strings.clear();
151 // If we are looking for IDs don't look for strings
152 m_desired_message_strings.clear();
153 m_otherMsgs.clear();
154 m_desired_message_ids.insert(msg_id);
155 m_msgFound = VK_FALSE;
156 m_msgFlags = msgFlags;
157 test_platform_thread_unlock_mutex(&m_mutex);
158 }
159
160 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600161 VkBool32 result = VK_FALSE;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600162 test_platform_thread_lock_mutex(&m_mutex);
Mike Stroyanaccf7692015-05-12 16:00:45 -0600163 if (m_bailout != NULL) {
164 *m_bailout = true;
165 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600166 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600167 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600168
169 for (auto desired_msg : m_desired_message_strings) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600170 if (desired_msg.length() == 0) {
171 // An empty desired_msg string "" indicates a positive test - not expecting an error.
172 // Return true to avoid calling layers/driver with this error.
173 // And don't erase the "" string, so it remains if another error is found.
174 result = VK_TRUE;
175 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600176 found_expected = true;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600177 m_failure_message_strings.insert(errorString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600178 m_msgFound = VK_TRUE;
179 result = VK_TRUE;
180 // We only want one match for each expected error so remove from set here
181 // Since we're about the break the loop it's ok to remove from set we're iterating over
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600182 m_desired_message_strings.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186 for (auto desired_id : m_desired_message_ids) {
187 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
188 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
189 // Return true to avoid calling layers/driver with this error.
190 result = VK_TRUE;
191 } else if (desired_id == message_code) {
192 // Double-check that the string matches the error enum
193 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
194 found_expected = true;
195 result = VK_TRUE;
196 m_msgFound = VK_TRUE;
197 m_desired_message_ids.erase(desired_id);
198 break;
199 } else {
200 // Treat this message as a regular unexpected error, but print a warning jic
201 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
202 errorString.c_str(), desired_id, validation_error_map[desired_id]);
203 }
204 }
205 }
206
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600207 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200208 printf("Unexpected: %s\n", msgString);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600209 m_otherMsgs.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600210 }
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600211 test_platform_thread_unlock_mutex(&m_mutex);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600212 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600213 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600214
Karl Schultz6addd812016-02-02 17:17:23 -0700215 vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600216
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600217 VkDebugReportFlagsEXT GetMessageFlags(void) { return m_msgFlags; }
218
Karl Schultz6addd812016-02-02 17:17:23 -0700219 VkBool32 DesiredMsgFound(void) { return m_msgFound; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220
Karl Schultz6addd812016-02-02 17:17:23 -0700221 void SetBailout(bool *bailout) { m_bailout = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600222
Karl Schultz6addd812016-02-02 17:17:23 -0700223 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600225 if (otherMsgs.size()) {
226 cout << "Other error messages logged for this test were:" << endl;
227 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
228 cout << " " << *iter << endl;
229 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600230 }
231 }
232
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600233 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200234
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
236 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
237 m_msgFlags = message_flag_mask;
238 // Match ANY message matching specified type
239 SetDesiredFailureMsg(message_flag_mask, "");
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200240 }
241
242 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600243 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244 if (!DesiredMsgFound()) {
245 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600246 for (auto desired_msg : m_desired_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600247 FAIL() << "Did not receive expected error '" << desired_msg << "'";
248 }
Tony Barbour59b42282016-11-03 13:31:28 -0600249 for (auto desired_id : m_desired_message_ids) {
250 FAIL() << "Did not receive expected error '" << desired_id << "'";
251 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200252 }
253 }
254
255 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 // ExpectSuccess() configured us to match anything. Any error is a failure.
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200257 if (DesiredMsgFound()) {
258 DumpFailureMsgs();
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600259 for (auto msg : m_failure_message_strings) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600260 FAIL() << "Expected to succeed but got error: " << msg;
261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
263 }
264
Karl Schultz6addd812016-02-02 17:17:23 -0700265 private:
266 VkFlags m_msgFlags;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600267 std::unordered_set<uint32_t>m_desired_message_ids;
268 std::unordered_set<string> m_desired_message_strings;
269 std::unordered_set<string> m_failure_message_strings;
Karl Schultz6addd812016-02-02 17:17:23 -0700270 vector<string> m_otherMsgs;
Mike Stroyan4268d1f2015-07-13 14:45:35 -0600271 test_platform_thread_mutex m_mutex;
Karl Schultz6addd812016-02-02 17:17:23 -0700272 bool *m_bailout;
273 VkBool32 m_msgFound;
Tony Barbour300a6082015-04-07 13:44:53 -0600274};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500275
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600276static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
277 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
278 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
280 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600281 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600282 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600283 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600284}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500285
Karl Schultz6addd812016-02-02 17:17:23 -0700286class VkLayerTest : public VkRenderFramework {
287 public:
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800288 VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer);
289 VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
291 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700292 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600293 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
294 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700295 }
Tony Barbour300a6082015-04-07 13:44:53 -0600296
Tony Barbourfe3351b2015-07-28 10:17:20 -0600297 /* Convenience functions that use built-in command buffer */
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298 VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_commandBuffer); }
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800299 VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
301 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700302 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
308 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
309 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700310 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
311 }
312 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
313 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
314 }
315
316 protected:
317 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600318 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600319
320 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600321 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600322 std::vector<const char *> instance_extension_names;
323 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600324
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600326 /*
327 * Since CreateDbgMsgCallback is an instance level extension call
328 * any extension / layer that utilizes that feature also needs
329 * to be enabled at create instance time.
330 */
Karl Schultz6addd812016-02-02 17:17:23 -0700331 // Use Threading layer first to protect others from
332 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700333 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600334 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800335 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700336 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800337 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600338 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700339 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600340
Ian Elliott2c1daf52016-05-12 09:41:46 -0600341 if (m_enableWSI) {
342 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
343 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
344#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
345#if defined(VK_USE_PLATFORM_ANDROID_KHR)
346 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
347#endif // VK_USE_PLATFORM_ANDROID_KHR
348#if defined(VK_USE_PLATFORM_MIR_KHR)
349 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
350#endif // VK_USE_PLATFORM_MIR_KHR
351#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
352 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
353#endif // VK_USE_PLATFORM_WAYLAND_KHR
354#if defined(VK_USE_PLATFORM_WIN32_KHR)
355 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
356#endif // VK_USE_PLATFORM_WIN32_KHR
357#endif // NEED_TO_TEST_THIS_ON_PLATFORM
358#if defined(VK_USE_PLATFORM_XCB_KHR)
359 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
360#elif defined(VK_USE_PLATFORM_XLIB_KHR)
361 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
362#endif // VK_USE_PLATFORM_XLIB_KHR
363 }
364
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600365 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600366 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800367 this->app_info.pApplicationName = "layer_tests";
368 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600369 this->app_info.pEngineName = "unittest";
370 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600371 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600372
Tony Barbour15524c32015-04-29 17:34:29 -0600373 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600375 }
376
377 virtual void TearDown() {
378 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600379 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600380 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600381 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600382
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600384};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500385
Karl Schultz6addd812016-02-02 17:17:23 -0700386VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600387 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600388
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 result = commandBuffer.BeginCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600390
391 /*
392 * For render test all drawing happens in a single render pass
393 * on a single command buffer.
394 */
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200395 if (VK_SUCCESS == result && renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800396 commandBuffer.BeginRenderPass(renderPassBeginInfo());
Tony Barbour300a6082015-04-07 13:44:53 -0600397 }
398
399 return result;
400}
401
Karl Schultz6addd812016-02-02 17:17:23 -0700402VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) {
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600403 VkResult result;
Tony Barbour300a6082015-04-07 13:44:53 -0600404
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200405 if (renderPass()) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800406 commandBuffer.EndRenderPass();
Chris Forbes76a5eeb2015-06-16 14:05:59 +1200407 }
Tony Barbour300a6082015-04-07 13:44:53 -0600408
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 result = commandBuffer.EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -0600410
411 return result;
412}
413
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600414void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500415 // Create identity matrix
416 int i;
417 struct vktriangle_vs_uniform data;
418
419 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700420 glm::mat4 View = glm::mat4(1.0f);
421 glm::mat4 Model = glm::mat4(1.0f);
422 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700424 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425
426 memcpy(&data.mvp, &MVP[0][0], matrixSize);
427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430 };
431
Karl Schultz6addd812016-02-02 17:17:23 -0700432 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 data.position[i][0] = tri_data[i].posX;
434 data.position[i][1] = tri_data[i].posY;
435 data.position[i][2] = tri_data[i].posZ;
436 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700437 data.color[i][0] = tri_data[i].r;
438 data.color[i][1] = tri_data[i].g;
439 data.color[i][2] = tri_data[i].b;
440 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500441 }
442
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 ASSERT_NO_FATAL_FAILURE(InitViewport());
444
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200445 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
446 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Karl Schultz6addd812016-02-02 17:17:23 -0700448 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600449 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500450
451 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800452 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 pipelineobj.AddShader(&vs);
454 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600455 if (failMask & BsoFailLineWidth) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600458 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
460 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 }
462 if (failMask & BsoFailDepthBias) {
463 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600464 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600465 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600466 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600467 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600468 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 }
Karl Schultz6addd812016-02-02 17:17:23 -0700470 // Viewport and scissors must stay in synch or other errors will occur than
471 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600472 if (failMask & BsoFailViewport) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
474 }
475 if (failMask & BsoFailScissor) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
477 }
478 if (failMask & BsoFailBlend) {
479 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 VkPipelineColorBlendAttachmentState att_state = {};
481 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
482 att_state.blendEnable = VK_TRUE;
483 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600484 }
485 if (failMask & BsoFailDepthBounds) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
487 }
488 if (failMask & BsoFailStencilReadMask) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
490 }
491 if (failMask & BsoFailStencilWriteMask) {
492 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
493 }
494 if (failMask & BsoFailStencilReference) {
495 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
496 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500497
498 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500500
501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourfe3351b2015-07-28 10:17:20 -0600502 ASSERT_VK_SUCCESS(BeginCommandBuffer());
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Tony Barbourfe3351b2015-07-28 10:17:20 -0600504 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505
506 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600507 if (failMask & BsoFailIndexBuffer) {
508 // Use DrawIndexed w/o an index buffer bound
509 DrawIndexed(3, 1, 0, 0, 0);
510 } else {
511 Draw(3, 1, 0, 0);
512 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513
Mark Muellerd4914412016-06-13 17:52:06 -0600514 if (failMask & BsoFailCmdClearAttachments) {
515 VkClearAttachment color_attachment = {};
516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
517 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
518 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
519
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600520 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600521 }
522
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 // finalize recording of the command buffer
Tony Barbourfe3351b2015-07-28 10:17:20 -0600524 EndCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525
Tony Barbourfe3351b2015-07-28 10:17:20 -0600526 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500527}
528
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600529void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
530 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600532 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500533 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600534 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500535 }
536
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800537 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700538 // Make sure depthWriteEnable is set so that Depth fail test will work
539 // correctly
540 // Make sure stencilTestEnable is set so that Stencil fail test will work
541 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600542 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800543 stencil.failOp = VK_STENCIL_OP_KEEP;
544 stencil.passOp = VK_STENCIL_OP_KEEP;
545 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
546 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600547
548 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
549 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.pNext = NULL;
551 ds_ci.depthTestEnable = VK_FALSE;
552 ds_ci.depthWriteEnable = VK_TRUE;
553 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
554 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600555 if (failMask & BsoFailDepthBounds) {
556 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600557 ds_ci.maxDepthBounds = 0.0f;
558 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600559 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600560 ds_ci.stencilTestEnable = VK_TRUE;
561 ds_ci.front = stencil;
562 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600563
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600564 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600565 pipelineobj.SetViewport(m_viewports);
566 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800567 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600568 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600569 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800570 commandBuffer->BindPipeline(pipelineobj);
571 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500572}
573
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600574class VkPositiveLayerTest : public VkLayerTest {
575 public:
576 protected:
577};
578
Ian Elliott2c1daf52016-05-12 09:41:46 -0600579class VkWsiEnabledLayerTest : public VkLayerTest {
580 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600581 protected:
582 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600583};
584
Mark Muellerdfe37552016-07-07 14:47:42 -0600585class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600587 enum eTestEnFlags {
588 eDoubleDelete,
589 eInvalidDeviceOffset,
590 eInvalidMemoryOffset,
591 eBindNullBuffer,
592 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600593 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 };
595
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600597
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
599 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 return true;
601 }
602 VkDeviceSize offset_limit = 0;
603 if (eInvalidMemoryOffset == aTestFlag) {
604 VkBuffer vulkanBuffer;
605 VkBufferCreateInfo buffer_create_info = {};
606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
607 buffer_create_info.size = 32;
608 buffer_create_info.usage = aBufferUsage;
609
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600611 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600613 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
615 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600616 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
617 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600618 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600620 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 }
623 if (eOffsetAlignment < offset_limit) {
624 return true;
625 }
626 return false;
627 }
628
629 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
631 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 if (eBindNullBuffer == aTestFlag) {
634 VulkanMemory = 0;
635 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
636 } else {
637 VkBufferCreateInfo buffer_create_info = {};
638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
639 buffer_create_info.size = 32;
640 buffer_create_info.usage = aBufferUsage;
641
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643
644 CreateCurrent = true;
645
646 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600647 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600648
649 VkMemoryAllocateInfo memory_allocate_info = {};
650 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
651 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
653 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600654 if (!pass) {
655 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
656 return;
657 }
658
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600659 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600660 AllocateCurrent = true;
661 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
663 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 BoundCurrent = true;
665
666 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
667 }
668 }
669
670 ~VkBufferTest() {
671 if (CreateCurrent) {
672 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
673 }
674 if (AllocateCurrent) {
675 if (InvalidDeleteEn) {
676 union {
677 VkDeviceMemory device_memory;
678 unsigned long long index_access;
679 } bad_index;
680
681 bad_index.device_memory = VulkanMemory;
682 bad_index.index_access++;
683
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600684 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600685 }
686 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
687 }
688 }
689
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600690 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600691
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600693
694 void TestDoubleDestroy() {
695 // Destroy the buffer but leave the flag set, which will cause
696 // the buffer to be destroyed again in the destructor.
697 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600701 bool AllocateCurrent;
702 bool BoundCurrent;
703 bool CreateCurrent;
704 bool InvalidDeleteEn;
705
706 VkBuffer VulkanBuffer;
707 VkDevice VulkanDevice;
708 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709};
710
711class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 public:
713 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600714 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600715 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
718 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 BindIdGenerator++; // NB: This can wrap w/misuse
720
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600721 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
722 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
725 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
726 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
727 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
728 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729
730 unsigned i = 0;
731 do {
732 VertexInputAttributeDescription[i].binding = BindId;
733 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
735 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (AttributeCount < i);
738
739 i = 0;
740 do {
741 VertexInputBindingDescription[i].binding = BindId;
742 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 i++;
745 } while (BindingCount < i);
746 }
747
748 ~VkVerticesObj() {
749 if (VertexInputAttributeDescription) {
750 delete[] VertexInputAttributeDescription;
751 }
752 if (VertexInputBindingDescription) {
753 delete[] VertexInputBindingDescription;
754 }
755 }
756
757 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
759 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 return true;
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 VkDeviceSize *offsetList;
765 unsigned offsetCount;
766
767 if (aOffsetCount) {
768 offsetList = aOffsetList;
769 offsetCount = aOffsetCount;
770 } else {
771 offsetList = new VkDeviceSize[1]();
772 offsetCount = 1;
773 }
774
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600775 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 BoundCurrent = true;
777
778 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600779 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600780 }
781 }
782
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600783 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600784 static uint32_t BindIdGenerator;
785
786 bool BoundCurrent;
787 unsigned AttributeCount;
788 unsigned BindingCount;
789 uint32_t BindId;
790
791 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
792 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
793 VkVertexInputBindingDescription *VertexInputBindingDescription;
794 VkConstantBufferObj VulkanMemoryBuffer;
795};
796
797uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500798// ********************************************************************************************************************
799// ********************************************************************************************************************
800// ********************************************************************************************************************
801// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600802#if PARAMETER_VALIDATION_TESTS
803TEST_F(VkLayerTest, RequiredParameter) {
804 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
805 "pointer, array, and array count parameters");
806
807 ASSERT_NO_FATAL_FAILURE(InitState());
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600810 // Specify NULL for a pointer to a handle
811 // Expected to trigger an error with
812 // parameter_validation::validate_required_pointer
813 vkGetPhysicalDeviceFeatures(gpu(), NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
817 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600818 // Specify NULL for pointer to array count
819 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600820 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify 0 for a required array count
825 // Expected to trigger an error with parameter_validation::validate_array
826 VkViewport view_port = {};
827 m_commandBuffer->SetViewport(0, 0, &view_port);
828 m_errorMonitor->VerifyFound();
829
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for a required array
832 // Expected to trigger an error with parameter_validation::validate_array
833 m_commandBuffer->SetViewport(0, 1, NULL);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify VK_NULL_HANDLE for a required handle
838 // Expected to trigger an error with
839 // parameter_validation::validate_required_handle
840 vkUnmapMemory(device(), VK_NULL_HANDLE);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
844 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845 // Specify VK_NULL_HANDLE for a required handle array entry
846 // Expected to trigger an error with
847 // parameter_validation::validate_required_handle_array
848 VkFence fence = VK_NULL_HANDLE;
849 vkResetFences(device(), 1, &fence);
850 m_errorMonitor->VerifyFound();
851
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600853 // Specify NULL for a required struct pointer
854 // Expected to trigger an error with
855 // parameter_validation::validate_struct_type
856 VkDeviceMemory memory = VK_NULL_HANDLE;
857 vkAllocateMemory(device(), NULL, NULL, &memory);
858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required VkFlags parameter
862 // Expected to trigger an error with parameter_validation::validate_flags
863 m_commandBuffer->SetStencilReference(0, 0);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600867 // Specify 0 for a required VkFlags array entry
868 // Expected to trigger an error with
869 // parameter_validation::validate_flags_array
870 VkSemaphore semaphore = VK_NULL_HANDLE;
871 VkPipelineStageFlags stageFlags = 0;
872 VkSubmitInfo submitInfo = {};
873 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
874 submitInfo.waitSemaphoreCount = 1;
875 submitInfo.pWaitSemaphores = &semaphore;
876 submitInfo.pWaitDstStageMask = &stageFlags;
877 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600880
Dustin Gravesfce74c02016-05-10 11:42:58 -0600881TEST_F(VkLayerTest, ReservedParameter) {
882 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
883
884 ASSERT_NO_FATAL_FAILURE(InitState());
885
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600887 // Specify 0 for a reserved VkFlags parameter
888 // Expected to trigger an error with
889 // parameter_validation::validate_reserved_flags
890 VkEvent event_handle = VK_NULL_HANDLE;
891 VkEventCreateInfo event_info = {};
892 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
893 event_info.flags = 1;
894 vkCreateEvent(device(), &event_info, NULL, &event_handle);
895 m_errorMonitor->VerifyFound();
896}
897
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600898TEST_F(VkLayerTest, InvalidStructSType) {
899 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
900 "structure's sType field");
901
902 ASSERT_NO_FATAL_FAILURE(InitState());
903
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600905 // Zero struct memory, effectively setting sType to
906 // VK_STRUCTURE_TYPE_APPLICATION_INFO
907 // Expected to trigger an error with
908 // parameter_validation::validate_struct_type
909 VkMemoryAllocateInfo alloc_info = {};
910 VkDeviceMemory memory = VK_NULL_HANDLE;
911 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
912 m_errorMonitor->VerifyFound();
913
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915 // Zero struct memory, effectively setting sType to
916 // VK_STRUCTURE_TYPE_APPLICATION_INFO
917 // Expected to trigger an error with
918 // parameter_validation::validate_struct_type_array
919 VkSubmitInfo submit_info = {};
920 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
921 m_errorMonitor->VerifyFound();
922}
923
924TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600925 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600926
927 ASSERT_NO_FATAL_FAILURE(InitState());
928
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600931 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600932 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600933 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600934 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600935 // Zero-initialization will provide the correct sType
936 VkApplicationInfo app_info = {};
937 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
938 event_alloc_info.pNext = &app_info;
939 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
940 m_errorMonitor->VerifyFound();
941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
943 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
945 // a function that has allowed pNext structure types and specify
946 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600947 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600949 VkMemoryAllocateInfo memory_alloc_info = {};
950 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
951 memory_alloc_info.pNext = &app_info;
952 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600954}
Dustin Graves5d33d532016-05-09 16:21:12 -0600955
956TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600957 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600958
959 ASSERT_NO_FATAL_FAILURE(InitState());
960
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
962 "range of the core VkFormat "
963 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 // Specify an invalid VkFormat value
965 // Expected to trigger an error with
966 // parameter_validation::validate_ranged_enum
967 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600968 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600969 m_errorMonitor->VerifyFound();
970
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 // Specify an invalid VkFlags bitmask value
973 // Expected to trigger an error with parameter_validation::validate_flags
974 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600975 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
976 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600977 m_errorMonitor->VerifyFound();
978
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 // Specify an invalid VkFlags array entry
981 // Expected to trigger an error with
982 // parameter_validation::validate_flags_array
983 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600984 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600985 VkSubmitInfo submit_info = {};
986 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
987 submit_info.waitSemaphoreCount = 1;
988 submit_info.pWaitSemaphores = &semaphore;
989 submit_info.pWaitDstStageMask = &stage_flags;
990 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
991 m_errorMonitor->VerifyFound();
992
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 // Specify an invalid VkBool32 value
995 // Expected to trigger a warning with
996 // parameter_validation::validate_bool32
997 VkSampler sampler = VK_NULL_HANDLE;
998 VkSamplerCreateInfo sampler_info = {};
999 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1000 sampler_info.pNext = NULL;
1001 sampler_info.magFilter = VK_FILTER_NEAREST;
1002 sampler_info.minFilter = VK_FILTER_NEAREST;
1003 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1004 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1005 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1006 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1007 sampler_info.mipLodBias = 1.0;
1008 sampler_info.maxAnisotropy = 1;
1009 sampler_info.compareEnable = VK_FALSE;
1010 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1011 sampler_info.minLod = 1.0;
1012 sampler_info.maxLod = 1.0;
1013 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1014 sampler_info.unnormalizedCoordinates = VK_FALSE;
1015 // Not VK_TRUE or VK_FALSE
1016 sampler_info.anisotropyEnable = 3;
1017 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1018 m_errorMonitor->VerifyFound();
1019}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001020
1021TEST_F(VkLayerTest, FailedReturnValue) {
1022 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1023
1024 ASSERT_NO_FATAL_FAILURE(InitState());
1025
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001026 // Find an unsupported image format
1027 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1028 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1029 VkFormat format = static_cast<VkFormat>(f);
1030 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001031 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 unsupported = format;
1033 break;
1034 }
1035 }
1036
1037 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1039 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001040 // Specify an unsupported VkFormat value to generate a
1041 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1042 // Expected to trigger a warning from
1043 // parameter_validation::validate_result
1044 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001045 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1046 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1048 m_errorMonitor->VerifyFound();
1049 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001050}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001051
1052TEST_F(VkLayerTest, UpdateBufferAlignment) {
1053 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055
1056 ASSERT_NO_FATAL_FAILURE(InitState());
1057
1058 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1059 vk_testing::Buffer buffer;
1060 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1061
1062 BeginCommandBuffer();
1063 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1071 m_errorMonitor->VerifyFound();
1072
1073 // Introduce failure by using dataSize that is < 0
1074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001075 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1077 m_errorMonitor->VerifyFound();
1078
1079 // Introduce failure by using dataSize that is > 65536
1080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001081 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001082 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1083 m_errorMonitor->VerifyFound();
1084
1085 EndCommandBuffer();
1086}
1087
1088TEST_F(VkLayerTest, FillBufferAlignment) {
1089 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1090
1091 ASSERT_NO_FATAL_FAILURE(InitState());
1092
1093 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1094 vk_testing::Buffer buffer;
1095 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1096
1097 BeginCommandBuffer();
1098
1099 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
1109 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1112 m_errorMonitor->VerifyFound();
1113
1114 EndCommandBuffer();
1115}
Dustin Graves40f35822016-06-23 11:12:53 -06001116
Cortd889ff92016-07-27 09:51:27 -07001117TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1118 VkResult err;
1119
1120 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001122
1123 ASSERT_NO_FATAL_FAILURE(InitState());
1124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1125
1126 std::vector<const char *> device_extension_names;
1127 auto features = m_device->phy().features();
1128 // Artificially disable support for non-solid fill modes
1129 features.fillModeNonSolid = false;
1130 // The sacrificial device object
1131 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1132
1133 VkRenderpassObj render_pass(&test_device);
1134
1135 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1136 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1137 pipeline_layout_ci.setLayoutCount = 0;
1138 pipeline_layout_ci.pSetLayouts = NULL;
1139
1140 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001141 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001142 ASSERT_VK_SUCCESS(err);
1143
1144 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1145 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1146 rs_ci.pNext = nullptr;
1147 rs_ci.lineWidth = 1.0f;
1148 rs_ci.rasterizerDiscardEnable = true;
1149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1151 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001152
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001153 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1155 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001156 {
1157 VkPipelineObj pipe(&test_device);
1158 pipe.AddShader(&vs);
1159 pipe.AddShader(&fs);
1160 pipe.AddColorAttachment();
1161 // Introduce failure by setting unsupported polygon mode
1162 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1163 pipe.SetRasterization(&rs_ci);
1164 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1165 }
1166 m_errorMonitor->VerifyFound();
1167
1168 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1170 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001171 {
1172 VkPipelineObj pipe(&test_device);
1173 pipe.AddShader(&vs);
1174 pipe.AddShader(&fs);
1175 pipe.AddColorAttachment();
1176 // Introduce failure by setting unsupported polygon mode
1177 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1178 pipe.SetRasterization(&rs_ci);
1179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1180 }
1181 m_errorMonitor->VerifyFound();
1182
Cortd889ff92016-07-27 09:51:27 -07001183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1184}
1185
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001186#endif // PARAMETER_VALIDATION_TESTS
1187
Tobin Ehlis0788f522015-05-26 16:11:58 -06001188#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001189#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001191{
1192 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193 VkFenceCreateInfo fenceInfo = {};
1194 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1195 fenceInfo.pNext = NULL;
1196 fenceInfo.flags = 0;
1197
Mike Weiblencce7ec72016-10-17 19:33:05 -06001198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001199
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001200 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001201
1202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1203 vk_testing::Buffer buffer;
1204 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
Tony Barbourfe3351b2015-07-28 10:17:20 -06001206 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001207 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001208 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209
1210 testFence.init(*m_device, fenceInfo);
1211
1212 // Bypass framework since it does the waits automatically
1213 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1216 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001217 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001218 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001219 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001220 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001221 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001222 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001223 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001224
1225 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226 ASSERT_VK_SUCCESS( err );
1227
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001231 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232}
1233
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001235{
1236 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001237 VkFenceCreateInfo fenceInfo = {};
1238 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1239 fenceInfo.pNext = NULL;
1240 fenceInfo.flags = 0;
1241
Mike Weiblencce7ec72016-10-17 19:33:05 -06001242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001243
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001244 ASSERT_NO_FATAL_FAILURE(InitState());
1245 ASSERT_NO_FATAL_FAILURE(InitViewport());
1246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1247
Tony Barbourfe3351b2015-07-28 10:17:20 -06001248 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001249 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001250 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251
1252 testFence.init(*m_device, fenceInfo);
1253
1254 // Bypass framework since it does the waits automatically
1255 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001257 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1258 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001261 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001262 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001263 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001264 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001265 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001266
1267 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268 ASSERT_VK_SUCCESS( err );
1269
Jon Ashburnf19916e2016-01-11 13:12:43 -07001270 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271 VkCommandBufferBeginInfo info = {};
1272 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1273 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001274 info.renderPass = VK_NULL_HANDLE;
1275 info.subpass = 0;
1276 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001277 info.occlusionQueryEnable = VK_FALSE;
1278 info.queryFlags = 0;
1279 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280
1281 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001282 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001284 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001285}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001286#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001287
Tobin Ehlisf11be982016-05-11 13:52:53 -06001288TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1289 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1290 "buffer and image to memory such that they will alias.");
1291 VkResult err;
1292 bool pass;
1293 ASSERT_NO_FATAL_FAILURE(InitState());
1294
Tobin Ehlis077ded32016-05-12 17:39:13 -06001295 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001296 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001297 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001298 VkDeviceMemory mem; // buffer will be bound first
1299 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001300 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001301
1302 VkBufferCreateInfo buf_info = {};
1303 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1304 buf_info.pNext = NULL;
1305 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1306 buf_info.size = 256;
1307 buf_info.queueFamilyIndexCount = 0;
1308 buf_info.pQueueFamilyIndices = NULL;
1309 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1310 buf_info.flags = 0;
1311 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1312 ASSERT_VK_SUCCESS(err);
1313
Tobin Ehlis077ded32016-05-12 17:39:13 -06001314 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001315
1316 VkImageCreateInfo image_create_info = {};
1317 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1318 image_create_info.pNext = NULL;
1319 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1320 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1321 image_create_info.extent.width = 64;
1322 image_create_info.extent.height = 64;
1323 image_create_info.extent.depth = 1;
1324 image_create_info.mipLevels = 1;
1325 image_create_info.arrayLayers = 1;
1326 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001327 // Image tiling must be optimal to trigger error when aliasing linear buffer
1328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001329 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1330 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1331 image_create_info.queueFamilyIndexCount = 0;
1332 image_create_info.pQueueFamilyIndices = NULL;
1333 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 image_create_info.flags = 0;
1335
Tobin Ehlisf11be982016-05-11 13:52:53 -06001336 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1337 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001338 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1339 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001340
Tobin Ehlis077ded32016-05-12 17:39:13 -06001341 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1342
1343 VkMemoryAllocateInfo alloc_info = {};
1344 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1345 alloc_info.pNext = NULL;
1346 alloc_info.memoryTypeIndex = 0;
1347 // Ensure memory is big enough for both bindings
1348 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001349 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1350 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001351 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001352 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 vkDestroyImage(m_device->device(), image, NULL);
1354 return;
1355 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001356 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1357 ASSERT_VK_SUCCESS(err);
1358 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1359 ASSERT_VK_SUCCESS(err);
1360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001362 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001363 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1364 m_errorMonitor->VerifyFound();
1365
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001366 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001367 // aliasing buffer2
1368 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1369 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001370 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1371 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001372 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is aliased with non-linear image 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001375 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001376 m_errorMonitor->VerifyFound();
1377
1378 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001379 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001381 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001382 vkFreeMemory(m_device->device(), mem, NULL);
1383 vkFreeMemory(m_device->device(), mem_img, NULL);
1384}
1385
Tobin Ehlis35372522016-05-12 08:32:31 -06001386TEST_F(VkLayerTest, InvalidMemoryMapping) {
1387 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1388 VkResult err;
1389 bool pass;
1390 ASSERT_NO_FATAL_FAILURE(InitState());
1391
1392 VkBuffer buffer;
1393 VkDeviceMemory mem;
1394 VkMemoryRequirements mem_reqs;
1395
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001396 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1397
Tobin Ehlis35372522016-05-12 08:32:31 -06001398 VkBufferCreateInfo buf_info = {};
1399 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1400 buf_info.pNext = NULL;
1401 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1402 buf_info.size = 256;
1403 buf_info.queueFamilyIndexCount = 0;
1404 buf_info.pQueueFamilyIndices = NULL;
1405 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1406 buf_info.flags = 0;
1407 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1408 ASSERT_VK_SUCCESS(err);
1409
1410 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1411 VkMemoryAllocateInfo alloc_info = {};
1412 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1413 alloc_info.pNext = NULL;
1414 alloc_info.memoryTypeIndex = 0;
1415
1416 // Ensure memory is big enough for both bindings
1417 static const VkDeviceSize allocation_size = 0x10000;
1418 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001419 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001420 if (!pass) {
1421 vkDestroyBuffer(m_device->device(), buffer, NULL);
1422 return;
1423 }
1424 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1425 ASSERT_VK_SUCCESS(err);
1426
1427 uint8_t *pData;
1428 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001430 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1431 m_errorMonitor->VerifyFound();
1432 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001433 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001434 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1436 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1437 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001438 m_errorMonitor->VerifyFound();
1439
1440 // Unmap the memory to avoid re-map error
1441 vkUnmapMemory(m_device->device(), mem);
1442 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1444 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1445 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001446 m_errorMonitor->VerifyFound();
1447 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1449 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001450 m_errorMonitor->VerifyFound();
1451 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001453 vkUnmapMemory(m_device->device(), mem);
1454 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001455
Tobin Ehlis35372522016-05-12 08:32:31 -06001456 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001457 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001458 ASSERT_VK_SUCCESS(err);
1459 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001460 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001462 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001464 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1465 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001466
Tobin Ehlis35372522016-05-12 08:32:31 -06001467 // Now flush range that oversteps mapped range
1468 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001469 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001471 mmr.offset = atom_size;
1472 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1474 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1475 m_errorMonitor->VerifyFound();
1476
1477 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1478 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001479 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001480 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001481 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001482 mmr.size = VK_WHOLE_SIZE;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001484 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1485 m_errorMonitor->VerifyFound();
1486
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001487 // Some platforms have an atomsize of 1 which makes the test meaningless
1488 if (atom_size > 3) {
1489 // Now with an offset NOT a multiple of the device limit
1490 vkUnmapMemory(m_device->device(), mem);
1491 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1492 ASSERT_VK_SUCCESS(err);
1493 mmr.offset = 3; // Not a multiple of atom_size
1494 mmr.size = VK_WHOLE_SIZE;
1495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1496 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1497 m_errorMonitor->VerifyFound();
1498
1499 // Now with a size NOT a multiple of the device limit
1500 vkUnmapMemory(m_device->device(), mem);
1501 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1502 ASSERT_VK_SUCCESS(err);
1503 mmr.offset = atom_size;
1504 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1506 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1507 m_errorMonitor->VerifyFound();
1508 }
1509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001510 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1511 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001512 if (!pass) {
1513 vkFreeMemory(m_device->device(), mem, NULL);
1514 vkDestroyBuffer(m_device->device(), buffer, NULL);
1515 return;
1516 }
1517 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1518 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1519
1520 vkDestroyBuffer(m_device->device(), buffer, NULL);
1521 vkFreeMemory(m_device->device(), mem, NULL);
1522}
1523
Ian Elliott1c32c772016-04-28 14:47:13 -06001524TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1525 VkResult err;
1526 bool pass;
1527
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001528 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1529 // following declaration (which is temporarily being moved below):
1530 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001531 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001532 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001533 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001534 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001535 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001536 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001537
1538 ASSERT_NO_FATAL_FAILURE(InitState());
1539
Ian Elliott3f06ce52016-04-29 14:46:21 -06001540#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1541#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1542 // Use the functions from the VK_KHR_android_surface extension without
1543 // enabling that extension:
1544
1545 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001546 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1548 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001549 pass = (err != VK_SUCCESS);
1550 ASSERT_TRUE(pass);
1551 m_errorMonitor->VerifyFound();
1552#endif // VK_USE_PLATFORM_ANDROID_KHR
1553
Ian Elliott3f06ce52016-04-29 14:46:21 -06001554#if defined(VK_USE_PLATFORM_MIR_KHR)
1555 // Use the functions from the VK_KHR_mir_surface extension without enabling
1556 // that extension:
1557
1558 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001559 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001561 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1562 pass = (err != VK_SUCCESS);
1563 ASSERT_TRUE(pass);
1564 m_errorMonitor->VerifyFound();
1565
1566 // Tell whether an mir_connection supports presentation:
1567 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1569 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001570 m_errorMonitor->VerifyFound();
1571#endif // VK_USE_PLATFORM_MIR_KHR
1572
Ian Elliott3f06ce52016-04-29 14:46:21 -06001573#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1574 // Use the functions from the VK_KHR_wayland_surface extension without
1575 // enabling that extension:
1576
1577 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001578 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1580 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001581 pass = (err != VK_SUCCESS);
1582 ASSERT_TRUE(pass);
1583 m_errorMonitor->VerifyFound();
1584
1585 // Tell whether an wayland_display supports presentation:
1586 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1588 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001589 m_errorMonitor->VerifyFound();
1590#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001591#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592
Ian Elliott3f06ce52016-04-29 14:46:21 -06001593#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001594 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1595 // TO NON-LINUX PLATFORMS:
1596 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001597 // Use the functions from the VK_KHR_win32_surface extension without
1598 // enabling that extension:
1599
1600 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001601 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1603 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001604 pass = (err != VK_SUCCESS);
1605 ASSERT_TRUE(pass);
1606 m_errorMonitor->VerifyFound();
1607
1608 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001610 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001611 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001612// Set this (for now, until all platforms are supported and tested):
1613#define NEED_TO_TEST_THIS_ON_PLATFORM
1614#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001615#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001616 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1617 // TO NON-LINUX PLATFORMS:
1618 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001619#endif
1620#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001621 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1622 // that extension:
1623
1624 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001625 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001627 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1628 pass = (err != VK_SUCCESS);
1629 ASSERT_TRUE(pass);
1630 m_errorMonitor->VerifyFound();
1631
1632 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001633 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001634 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1636 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001637 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001638// Set this (for now, until all platforms are supported and tested):
1639#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001640#endif // VK_USE_PLATFORM_XCB_KHR
1641
Ian Elliott12630812016-04-29 14:35:43 -06001642#if defined(VK_USE_PLATFORM_XLIB_KHR)
1643 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1644 // that extension:
1645
1646 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001647 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001649 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1650 pass = (err != VK_SUCCESS);
1651 ASSERT_TRUE(pass);
1652 m_errorMonitor->VerifyFound();
1653
1654 // Tell whether an Xlib VisualID supports presentation:
1655 Display *dpy = NULL;
1656 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001658 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1659 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001660// Set this (for now, until all platforms are supported and tested):
1661#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001662#endif // VK_USE_PLATFORM_XLIB_KHR
1663
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664// Use the functions from the VK_KHR_surface extension without enabling
1665// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001666
Ian Elliott489eec02016-05-05 14:12:44 -06001667#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001668 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001670 vkDestroySurfaceKHR(instance(), surface, NULL);
1671 m_errorMonitor->VerifyFound();
1672
1673 // Check if surface supports presentation:
1674 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001676 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1677 pass = (err != VK_SUCCESS);
1678 ASSERT_TRUE(pass);
1679 m_errorMonitor->VerifyFound();
1680
1681 // Check surface capabilities:
1682 VkSurfaceCapabilitiesKHR capabilities = {};
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 = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001685 pass = (err != VK_SUCCESS);
1686 ASSERT_TRUE(pass);
1687 m_errorMonitor->VerifyFound();
1688
1689 // Check surface formats:
1690 uint32_t format_count = 0;
1691 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1693 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001694 pass = (err != VK_SUCCESS);
1695 ASSERT_TRUE(pass);
1696 m_errorMonitor->VerifyFound();
1697
1698 // Check surface present modes:
1699 uint32_t present_mode_count = 0;
1700 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1702 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001703 pass = (err != VK_SUCCESS);
1704 ASSERT_TRUE(pass);
1705 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001706#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001707
Ian Elliott1c32c772016-04-28 14:47:13 -06001708 // Use the functions from the VK_KHR_swapchain extension without enabling
1709 // that extension:
1710
1711 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001713 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1714 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001715 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001716 pass = (err != VK_SUCCESS);
1717 ASSERT_TRUE(pass);
1718 m_errorMonitor->VerifyFound();
1719
1720 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1722 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001723 pass = (err != VK_SUCCESS);
1724 ASSERT_TRUE(pass);
1725 m_errorMonitor->VerifyFound();
1726
Chris Forbeseb7d5502016-09-13 18:19:21 +12001727 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1728 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1729 VkFence fence;
1730 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1731
Ian Elliott1c32c772016-04-28 14:47:13 -06001732 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001734 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001735 pass = (err != VK_SUCCESS);
1736 ASSERT_TRUE(pass);
1737 m_errorMonitor->VerifyFound();
1738
Chris Forbeseb7d5502016-09-13 18:19:21 +12001739 vkDestroyFence(m_device->device(), fence, nullptr);
1740
Ian Elliott1c32c772016-04-28 14:47:13 -06001741 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001742 //
1743 // NOTE: Currently can't test this because a real swapchain is needed (as
1744 // opposed to the fake one we created) in order for the layer to lookup the
1745 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001746
1747 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001749 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1750 m_errorMonitor->VerifyFound();
1751}
1752
Karl Schultz6addd812016-02-02 17:17:23 -07001753TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1754 VkResult err;
1755 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001756
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1758 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001759
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001760 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001761
1762 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001763 VkImage image;
1764 VkDeviceMemory mem;
1765 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001766
Karl Schultz6addd812016-02-02 17:17:23 -07001767 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1768 const int32_t tex_width = 32;
1769 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001770
Tony Barboureb254902015-07-15 12:50:33 -06001771 VkImageCreateInfo image_create_info = {};
1772 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001773 image_create_info.pNext = NULL;
1774 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1775 image_create_info.format = tex_format;
1776 image_create_info.extent.width = tex_width;
1777 image_create_info.extent.height = tex_height;
1778 image_create_info.extent.depth = 1;
1779 image_create_info.mipLevels = 1;
1780 image_create_info.arrayLayers = 1;
1781 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1782 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1783 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1784 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001785 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001786
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001787 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001788 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001789 mem_alloc.pNext = NULL;
1790 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001791
Chia-I Wuf7458c52015-10-26 21:10:41 +08001792 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001793 ASSERT_VK_SUCCESS(err);
1794
Karl Schultz6addd812016-02-02 17:17:23 -07001795 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001796
Mark Lobodzinski23065352015-05-29 09:32:35 -05001797 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001799 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 -07001800 if (!pass) { // If we can't find any unmappable memory this test doesn't
1801 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001802 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001803 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001804 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001805
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001806 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001807 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001808 ASSERT_VK_SUCCESS(err);
1809
1810 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001811 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001812 ASSERT_VK_SUCCESS(err);
1813
1814 // Map memory as if to initialize the image
1815 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001816 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001817
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001818 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001819
Chia-I Wuf7458c52015-10-26 21:10:41 +08001820 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001821 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001822}
1823
Karl Schultz6addd812016-02-02 17:17:23 -07001824TEST_F(VkLayerTest, RebindMemory) {
1825 VkResult err;
1826 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001827
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001829
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001830 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001831
1832 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001833 VkImage image;
1834 VkDeviceMemory mem1;
1835 VkDeviceMemory mem2;
1836 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001837
Karl Schultz6addd812016-02-02 17:17:23 -07001838 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1839 const int32_t tex_width = 32;
1840 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001841
Tony Barboureb254902015-07-15 12:50:33 -06001842 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001843 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1844 image_create_info.pNext = NULL;
1845 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1846 image_create_info.format = tex_format;
1847 image_create_info.extent.width = tex_width;
1848 image_create_info.extent.height = tex_height;
1849 image_create_info.extent.depth = 1;
1850 image_create_info.mipLevels = 1;
1851 image_create_info.arrayLayers = 1;
1852 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1853 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1854 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1855 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001856
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001857 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001858 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1859 mem_alloc.pNext = NULL;
1860 mem_alloc.allocationSize = 0;
1861 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001862
Karl Schultz6addd812016-02-02 17:17:23 -07001863 // Introduce failure, do NOT set memProps to
1864 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001865 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001866 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001867 ASSERT_VK_SUCCESS(err);
1868
Karl Schultz6addd812016-02-02 17:17:23 -07001869 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001870
1871 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001872 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001873 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001874
1875 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001876 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001877 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001878 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001879 ASSERT_VK_SUCCESS(err);
1880
1881 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001882 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001883 ASSERT_VK_SUCCESS(err);
1884
Karl Schultz6addd812016-02-02 17:17:23 -07001885 // Introduce validation failure, try to bind a different memory object to
1886 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001887 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001888
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001889 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001890
Chia-I Wuf7458c52015-10-26 21:10:41 +08001891 vkDestroyImage(m_device->device(), image, NULL);
1892 vkFreeMemory(m_device->device(), mem1, NULL);
1893 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001894}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001895
Karl Schultz6addd812016-02-02 17:17:23 -07001896TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001897 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001898
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1900 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001901
1902 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001903 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1904 fenceInfo.pNext = NULL;
1905 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001906
Tony Barbour300a6082015-04-07 13:44:53 -06001907 ASSERT_NO_FATAL_FAILURE(InitState());
1908 ASSERT_NO_FATAL_FAILURE(InitViewport());
1909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1910
Tony Barbourfe3351b2015-07-28 10:17:20 -06001911 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001912 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001913 EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001914
1915 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001916
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001917 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001918 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1919 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001920 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001921 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001922 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001923 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001924 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001925 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001926 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001927
1928 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001929 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001930
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001931 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001932}
Chris Forbes4e44c912016-06-16 10:20:00 +12001933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001934TEST_F(VkLayerTest, InvalidUsageBits) {
1935 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1936 "Initialize buffer with wrong usage then perform copy expecting errors "
1937 "from both the image and the buffer (2 calls)");
1938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001939
1940 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf92621a2016-05-02 14:28:12 -06001941 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001942 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 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 -06001944 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001945
Tony Barbourf92621a2016-05-02 14:28:12 -06001946 VkImageView dsv;
1947 VkImageViewCreateInfo dsvci = {};
1948 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1949 dsvci.image = image.handle();
1950 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
1951 dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT;
1952 dsvci.subresourceRange.layerCount = 1;
1953 dsvci.subresourceRange.baseMipLevel = 0;
1954 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001955 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001956
Tony Barbourf92621a2016-05-02 14:28:12 -06001957 // Create a view with depth / stencil aspect for image with different usage
1958 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001959
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001960 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001961
1962 // Initialize buffer with TRANSFER_DST usage
1963 vk_testing::Buffer buffer;
1964 VkMemoryPropertyFlags reqs = 0;
1965 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1966 VkBufferImageCopy region = {};
1967 region.bufferRowLength = 128;
1968 region.bufferImageHeight = 128;
1969 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1970 region.imageSubresource.layerCount = 1;
1971 region.imageExtent.height = 16;
1972 region.imageExtent.width = 16;
1973 region.imageExtent.depth = 1;
1974
Tony Barbourf92621a2016-05-02 14:28:12 -06001975 // Buffer usage not set to TRANSFER_SRC and image usage not set to
1976 // TRANSFER_DST
1977 BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06001978
Chris Forbesda581202016-10-06 18:25:26 +13001979 // two separate errors from this call:
1980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
1981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
1982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001983 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
1984 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06001985 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06001986}
Tony Barbour75d79f02016-08-30 09:39:07 -06001987
Tony Barbour75d79f02016-08-30 09:39:07 -06001988
Mark Lobodzinski209b5292015-09-17 09:44:05 -06001989#endif // MEM_TRACKER_TESTS
1990
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06001991#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001992
1993TEST_F(VkLayerTest, LeakAnObject) {
1994 VkResult err;
1995
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001996 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06001997
1998 // Note that we have to create a new device since destroying the
1999 // framework's device causes Teardown() to fail and just calling Teardown
2000 // will destroy the errorMonitor.
2001
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002003
2004 ASSERT_NO_FATAL_FAILURE(InitState());
2005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002006 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002007 std::vector<VkDeviceQueueCreateInfo> queue_info;
2008 queue_info.reserve(queue_props.size());
2009 std::vector<std::vector<float>> queue_priorities;
2010 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2011 VkDeviceQueueCreateInfo qi = {};
2012 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2013 qi.pNext = NULL;
2014 qi.queueFamilyIndex = i;
2015 qi.queueCount = queue_props[i].queueCount;
2016 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2017 qi.pQueuePriorities = queue_priorities[i].data();
2018 queue_info.push_back(qi);
2019 }
2020
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002021 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002022
2023 // The sacrificial device object
2024 VkDevice testDevice;
2025 VkDeviceCreateInfo device_create_info = {};
2026 auto features = m_device->phy().features();
2027 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2028 device_create_info.pNext = NULL;
2029 device_create_info.queueCreateInfoCount = queue_info.size();
2030 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002031 device_create_info.enabledLayerCount = 0;
2032 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002033 device_create_info.pEnabledFeatures = &features;
2034 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2035 ASSERT_VK_SUCCESS(err);
2036
2037 VkFence fence;
2038 VkFenceCreateInfo fence_create_info = {};
2039 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2040 fence_create_info.pNext = NULL;
2041 fence_create_info.flags = 0;
2042 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2043 ASSERT_VK_SUCCESS(err);
2044
2045 // Induce failure by not calling vkDestroyFence
2046 vkDestroyDevice(testDevice, NULL);
2047 m_errorMonitor->VerifyFound();
2048}
2049
2050TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2051
2052 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2053 "attempt to delete them from another.");
2054
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002056
Cody Northropc31a84f2016-08-22 10:41:47 -06002057 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002058 VkCommandPool command_pool_one;
2059 VkCommandPool command_pool_two;
2060
2061 VkCommandPoolCreateInfo pool_create_info{};
2062 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2063 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2064 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2065
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002066 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002067
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002068 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002069
2070 VkCommandBuffer command_buffer[9];
2071 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002072 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002073 command_buffer_allocate_info.commandPool = command_pool_one;
2074 command_buffer_allocate_info.commandBufferCount = 9;
2075 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002076 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002077
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002078 vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, &command_buffer[3]);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002079
2080 m_errorMonitor->VerifyFound();
2081
2082 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2083 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2084}
2085
2086TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2087 VkResult err;
2088
2089 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002090 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002091
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002093
2094 ASSERT_NO_FATAL_FAILURE(InitState());
2095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2096
2097 VkDescriptorPoolSize ds_type_count = {};
2098 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2099 ds_type_count.descriptorCount = 1;
2100
2101 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2102 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2103 ds_pool_ci.pNext = NULL;
2104 ds_pool_ci.flags = 0;
2105 ds_pool_ci.maxSets = 1;
2106 ds_pool_ci.poolSizeCount = 1;
2107 ds_pool_ci.pPoolSizes = &ds_type_count;
2108
2109 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002110 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002111 ASSERT_VK_SUCCESS(err);
2112
2113 // Create a second descriptor pool
2114 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002115 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002116 ASSERT_VK_SUCCESS(err);
2117
2118 VkDescriptorSetLayoutBinding dsl_binding = {};
2119 dsl_binding.binding = 0;
2120 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2121 dsl_binding.descriptorCount = 1;
2122 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2123 dsl_binding.pImmutableSamplers = NULL;
2124
2125 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2126 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2127 ds_layout_ci.pNext = NULL;
2128 ds_layout_ci.bindingCount = 1;
2129 ds_layout_ci.pBindings = &dsl_binding;
2130
2131 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002132 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002133 ASSERT_VK_SUCCESS(err);
2134
2135 VkDescriptorSet descriptorSet;
2136 VkDescriptorSetAllocateInfo alloc_info = {};
2137 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2138 alloc_info.descriptorSetCount = 1;
2139 alloc_info.descriptorPool = ds_pool_one;
2140 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002141 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002142 ASSERT_VK_SUCCESS(err);
2143
2144 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2145
2146 m_errorMonitor->VerifyFound();
2147
2148 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2149 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2150 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2151}
2152
2153TEST_F(VkLayerTest, CreateUnknownObject) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002157
2158 ASSERT_NO_FATAL_FAILURE(InitState());
2159
2160 // Pass bogus handle into GetImageMemoryRequirements
2161 VkMemoryRequirements mem_reqs;
2162 uint64_t fakeImageHandle = 0xCADECADE;
2163 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2164
2165 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2166
2167 m_errorMonitor->VerifyFound();
2168}
2169
Karl Schultz6addd812016-02-02 17:17:23 -07002170TEST_F(VkLayerTest, PipelineNotBound) {
2171 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002172
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002173 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002176
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002177 ASSERT_NO_FATAL_FAILURE(InitState());
2178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002179
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002180 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002181 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2182 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002183
2184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2186 ds_pool_ci.pNext = NULL;
2187 ds_pool_ci.maxSets = 1;
2188 ds_pool_ci.poolSizeCount = 1;
2189 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002190
2191 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002192 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002193 ASSERT_VK_SUCCESS(err);
2194
2195 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002196 dsl_binding.binding = 0;
2197 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2198 dsl_binding.descriptorCount = 1;
2199 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2200 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002201
2202 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002203 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2204 ds_layout_ci.pNext = NULL;
2205 ds_layout_ci.bindingCount = 1;
2206 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002207
2208 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002210 ASSERT_VK_SUCCESS(err);
2211
2212 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002213 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002214 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002215 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002216 alloc_info.descriptorPool = ds_pool;
2217 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002218 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002219 ASSERT_VK_SUCCESS(err);
2220
2221 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002222 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2223 pipeline_layout_ci.pNext = NULL;
2224 pipeline_layout_ci.setLayoutCount = 1;
2225 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002226
2227 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002229 ASSERT_VK_SUCCESS(err);
2230
Mark Youngad779052016-01-06 14:26:04 -07002231 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002232
2233 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002234 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002235
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002236 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002237
Chia-I Wuf7458c52015-10-26 21:10:41 +08002238 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2239 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2240 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002241}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002242
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002243TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2244 VkResult err;
2245
2246 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2247 "during bind[Buffer|Image]Memory time");
2248
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002249 ASSERT_NO_FATAL_FAILURE(InitState());
2250
2251 // Create an image, allocate memory, set a bad typeIndex and then try to
2252 // bind it
2253 VkImage image;
2254 VkDeviceMemory mem;
2255 VkMemoryRequirements mem_reqs;
2256 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2257 const int32_t tex_width = 32;
2258 const int32_t tex_height = 32;
2259
2260 VkImageCreateInfo image_create_info = {};
2261 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2262 image_create_info.pNext = NULL;
2263 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2264 image_create_info.format = tex_format;
2265 image_create_info.extent.width = tex_width;
2266 image_create_info.extent.height = tex_height;
2267 image_create_info.extent.depth = 1;
2268 image_create_info.mipLevels = 1;
2269 image_create_info.arrayLayers = 1;
2270 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2271 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2272 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2273 image_create_info.flags = 0;
2274
2275 VkMemoryAllocateInfo mem_alloc = {};
2276 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2277 mem_alloc.pNext = NULL;
2278 mem_alloc.allocationSize = 0;
2279 mem_alloc.memoryTypeIndex = 0;
2280
2281 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2282 ASSERT_VK_SUCCESS(err);
2283
2284 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2285 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002286
2287 // Introduce Failure, select invalid TypeIndex
2288 VkPhysicalDeviceMemoryProperties memory_info;
2289
2290 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2291 unsigned int i;
2292 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2293 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2294 mem_alloc.memoryTypeIndex = i;
2295 break;
2296 }
2297 }
2298 if (i >= memory_info.memoryTypeCount) {
2299 printf("No invalid memory type index could be found; skipped.\n");
2300 vkDestroyImage(m_device->device(), image, NULL);
2301 return;
2302 }
2303
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002304 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 -06002305
2306 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2307 ASSERT_VK_SUCCESS(err);
2308
2309 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2310 (void)err;
2311
2312 m_errorMonitor->VerifyFound();
2313
2314 vkDestroyImage(m_device->device(), image, NULL);
2315 vkFreeMemory(m_device->device(), mem, NULL);
2316}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002317
Karl Schultz6addd812016-02-02 17:17:23 -07002318TEST_F(VkLayerTest, BindInvalidMemory) {
2319 VkResult err;
2320 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002321
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Device Memory Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002323
Tobin Ehlisec598302015-09-15 15:02:17 -06002324 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002325
2326 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002327 VkImage image;
2328 VkDeviceMemory mem;
2329 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002330
Karl Schultz6addd812016-02-02 17:17:23 -07002331 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2332 const int32_t tex_width = 32;
2333 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002334
2335 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002336 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2337 image_create_info.pNext = NULL;
2338 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2339 image_create_info.format = tex_format;
2340 image_create_info.extent.width = tex_width;
2341 image_create_info.extent.height = tex_height;
2342 image_create_info.extent.depth = 1;
2343 image_create_info.mipLevels = 1;
2344 image_create_info.arrayLayers = 1;
2345 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2346 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2347 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2348 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002349
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002350 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002351 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2352 mem_alloc.pNext = NULL;
2353 mem_alloc.allocationSize = 0;
2354 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002355
Chia-I Wuf7458c52015-10-26 21:10:41 +08002356 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002357 ASSERT_VK_SUCCESS(err);
2358
Karl Schultz6addd812016-02-02 17:17:23 -07002359 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002360
2361 mem_alloc.allocationSize = mem_reqs.size;
2362
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002363 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002364 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002365
2366 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002367 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002368 ASSERT_VK_SUCCESS(err);
2369
2370 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002371 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002372
2373 // Try to bind free memory that has been freed
2374 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2375 // This may very well return an error.
2376 (void)err;
2377
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002378 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002379
Chia-I Wuf7458c52015-10-26 21:10:41 +08002380 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002381}
2382
Karl Schultz6addd812016-02-02 17:17:23 -07002383TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2384 VkResult err;
2385 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Image Object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002388
Tobin Ehlisec598302015-09-15 15:02:17 -06002389 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002390
Karl Schultz6addd812016-02-02 17:17:23 -07002391 // Create an image object, allocate memory, destroy the object and then try
2392 // to bind it
2393 VkImage image;
2394 VkDeviceMemory mem;
2395 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002396
Karl Schultz6addd812016-02-02 17:17:23 -07002397 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2398 const int32_t tex_width = 32;
2399 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002400
2401 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002402 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2403 image_create_info.pNext = NULL;
2404 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2405 image_create_info.format = tex_format;
2406 image_create_info.extent.width = tex_width;
2407 image_create_info.extent.height = tex_height;
2408 image_create_info.extent.depth = 1;
2409 image_create_info.mipLevels = 1;
2410 image_create_info.arrayLayers = 1;
2411 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2412 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2413 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2414 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002415
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002416 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002417 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2418 mem_alloc.pNext = NULL;
2419 mem_alloc.allocationSize = 0;
2420 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002421
Chia-I Wuf7458c52015-10-26 21:10:41 +08002422 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002423 ASSERT_VK_SUCCESS(err);
2424
Karl Schultz6addd812016-02-02 17:17:23 -07002425 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002426
2427 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002428 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002429 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002430
2431 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002432 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002433 ASSERT_VK_SUCCESS(err);
2434
2435 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002436 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002437 ASSERT_VK_SUCCESS(err);
2438
2439 // Now Try to bind memory to this destroyed object
2440 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2441 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002442 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002443
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002444 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002445
Chia-I Wuf7458c52015-10-26 21:10:41 +08002446 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002447}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002448
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002449#endif // OBJ_TRACKER_TESTS
2450
Tobin Ehlis0788f522015-05-26 16:11:58 -06002451#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002452
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002453TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2454 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2455
2456 ASSERT_NO_FATAL_FAILURE(InitState());
2457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2458
2459 VkVertexInputBindingDescription input_binding;
2460 memset(&input_binding, 0, sizeof(input_binding));
2461
2462 VkVertexInputAttributeDescription input_attribs;
2463 memset(&input_attribs, 0, sizeof(input_attribs));
2464
2465 // Pick a really bad format for this purpose and make sure it should fail
2466 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2467 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2468 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2469 printf("Format unsuitable for test; skipped.\n");
2470 return;
2471 }
2472
2473 input_attribs.location = 0;
2474 char const *vsSource = "#version 450\n"
2475 "\n"
2476 "out gl_PerVertex {\n"
2477 " vec4 gl_Position;\n"
2478 "};\n"
2479 "void main(){\n"
2480 " gl_Position = vec4(1);\n"
2481 "}\n";
2482 char const *fsSource = "#version 450\n"
2483 "\n"
2484 "layout(location=0) out vec4 color;\n"
2485 "void main(){\n"
2486 " color = vec4(1);\n"
2487 "}\n";
2488
2489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2490 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2491 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2492
2493 VkPipelineObj pipe(m_device);
2494 pipe.AddColorAttachment();
2495 pipe.AddShader(&vs);
2496 pipe.AddShader(&fs);
2497
2498 pipe.AddVertexInputBindings(&input_binding, 1);
2499 pipe.AddVertexInputAttribs(&input_attribs, 1);
2500
2501 VkDescriptorSetObj descriptorSet(m_device);
2502 descriptorSet.AppendDummy();
2503 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2504
2505 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2506
2507 m_errorMonitor->VerifyFound();
2508}
2509
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002510TEST_F(VkLayerTest, ImageSampleCounts) {
2511
2512 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2513 "validation errors.");
2514 ASSERT_NO_FATAL_FAILURE(InitState());
2515
2516 VkMemoryPropertyFlags reqs = 0;
2517 VkImageCreateInfo image_create_info = {};
2518 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2519 image_create_info.pNext = NULL;
2520 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2521 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2522 image_create_info.extent.width = 256;
2523 image_create_info.extent.height = 256;
2524 image_create_info.extent.depth = 1;
2525 image_create_info.mipLevels = 1;
2526 image_create_info.arrayLayers = 1;
2527 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2528 image_create_info.flags = 0;
2529
2530 VkImageBlit blit_region = {};
2531 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2532 blit_region.srcSubresource.baseArrayLayer = 0;
2533 blit_region.srcSubresource.layerCount = 1;
2534 blit_region.srcSubresource.mipLevel = 0;
2535 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2536 blit_region.dstSubresource.baseArrayLayer = 0;
2537 blit_region.dstSubresource.layerCount = 1;
2538 blit_region.dstSubresource.mipLevel = 0;
2539
2540 // Create two images, the source with sampleCount = 2, and attempt to blit
2541 // between them
2542 {
2543 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002544 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002545 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002546 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002547 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002548 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002549 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002550 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002551 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2553 "of VK_SAMPLE_COUNT_2_BIT but "
2554 "must be VK_SAMPLE_COUNT_1_BIT");
2555 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2556 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002557 m_errorMonitor->VerifyFound();
2558 m_commandBuffer->EndCommandBuffer();
2559 }
2560
2561 // Create two images, the dest with sampleCount = 4, and attempt to blit
2562 // between them
2563 {
2564 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002565 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002566 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002567 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002568 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002569 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002570 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002571 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002572 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2574 "of VK_SAMPLE_COUNT_4_BIT but "
2575 "must be VK_SAMPLE_COUNT_1_BIT");
2576 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2577 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002578 m_errorMonitor->VerifyFound();
2579 m_commandBuffer->EndCommandBuffer();
2580 }
2581
2582 VkBufferImageCopy copy_region = {};
2583 copy_region.bufferRowLength = 128;
2584 copy_region.bufferImageHeight = 128;
2585 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2586 copy_region.imageSubresource.layerCount = 1;
2587 copy_region.imageExtent.height = 64;
2588 copy_region.imageExtent.width = 64;
2589 copy_region.imageExtent.depth = 1;
2590
2591 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2592 // buffer to image
2593 {
2594 vk_testing::Buffer src_buffer;
2595 VkMemoryPropertyFlags reqs = 0;
2596 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2597 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002598 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002599 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2603 "of VK_SAMPLE_COUNT_8_BIT but "
2604 "must be VK_SAMPLE_COUNT_1_BIT");
2605 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2606 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002607 m_errorMonitor->VerifyFound();
2608 m_commandBuffer->EndCommandBuffer();
2609 }
2610
2611 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2612 // image to buffer
2613 {
2614 vk_testing::Buffer dst_buffer;
2615 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2616 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002617 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002618 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2622 "of VK_SAMPLE_COUNT_2_BIT but "
2623 "must be VK_SAMPLE_COUNT_1_BIT");
2624 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002625 dst_buffer.handle(), 1, &copy_region);
2626 m_errorMonitor->VerifyFound();
2627 m_commandBuffer->EndCommandBuffer();
2628 }
2629}
2630
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002631TEST_F(VkLayerTest, BlitImageFormats) {
2632
2633 // Image blit with mismatched formats
2634 const char * expected_message =
2635 "vkCmdBlitImage: If one of srcImage and dstImage images has signed/unsigned integer format,"
2636 " the other one must also have signed/unsigned integer format";
2637
2638 ASSERT_NO_FATAL_FAILURE(InitState());
2639
2640 VkImageObj src_image(m_device);
2641 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2642 VkImageObj dst_image(m_device);
2643 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2644 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002645 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 -06002646
2647 VkImageBlit blitRegion = {};
2648 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2649 blitRegion.srcSubresource.baseArrayLayer = 0;
2650 blitRegion.srcSubresource.layerCount = 1;
2651 blitRegion.srcSubresource.mipLevel = 0;
2652 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2653 blitRegion.dstSubresource.baseArrayLayer = 0;
2654 blitRegion.dstSubresource.layerCount = 1;
2655 blitRegion.dstSubresource.mipLevel = 0;
2656
2657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2658
2659 // Unsigned int vs not an int
2660 BeginCommandBuffer();
2661 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2662 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2663
2664 m_errorMonitor->VerifyFound();
2665
2666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, expected_message);
2667
2668 // Unsigned int vs signed int
2669 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2670 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2671
2672 m_errorMonitor->VerifyFound();
2673
2674 EndCommandBuffer();
2675}
2676
2677
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002678TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2679 VkResult err;
2680 bool pass;
2681
2682 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2683 ASSERT_NO_FATAL_FAILURE(InitState());
2684
2685 // If w/d/h granularity is 1, test is not meaningful
2686 // TODO: When virtual device limits are available, create a set of limits for this test that
2687 // will always have a granularity of > 1 for w, h, and d
2688 auto index = m_device->graphics_queue_node_index_;
2689 auto queue_family_properties = m_device->phy().queue_properties();
2690
2691 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2692 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2693 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2694 return;
2695 }
2696
2697 // Create two images of different types and try to copy between them
2698 VkImage srcImage;
2699 VkImage dstImage;
2700 VkDeviceMemory srcMem;
2701 VkDeviceMemory destMem;
2702 VkMemoryRequirements memReqs;
2703
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002704 VkImageCreateInfo image_create_info = {};
2705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2706 image_create_info.pNext = NULL;
2707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2708 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2709 image_create_info.extent.width = 32;
2710 image_create_info.extent.height = 32;
2711 image_create_info.extent.depth = 1;
2712 image_create_info.mipLevels = 1;
2713 image_create_info.arrayLayers = 4;
2714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2715 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2716 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2717 image_create_info.flags = 0;
2718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002719 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002720 ASSERT_VK_SUCCESS(err);
2721
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002722 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002723 ASSERT_VK_SUCCESS(err);
2724
2725 // Allocate memory
2726 VkMemoryAllocateInfo memAlloc = {};
2727 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2728 memAlloc.pNext = NULL;
2729 memAlloc.allocationSize = 0;
2730 memAlloc.memoryTypeIndex = 0;
2731
2732 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2733 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002734 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002735 ASSERT_TRUE(pass);
2736 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2737 ASSERT_VK_SUCCESS(err);
2738
2739 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2740 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002741 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002742 ASSERT_VK_SUCCESS(err);
2743 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2744 ASSERT_VK_SUCCESS(err);
2745
2746 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2747 ASSERT_VK_SUCCESS(err);
2748 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2749 ASSERT_VK_SUCCESS(err);
2750
2751 BeginCommandBuffer();
2752 VkImageCopy copyRegion;
2753 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2754 copyRegion.srcSubresource.mipLevel = 0;
2755 copyRegion.srcSubresource.baseArrayLayer = 0;
2756 copyRegion.srcSubresource.layerCount = 1;
2757 copyRegion.srcOffset.x = 0;
2758 copyRegion.srcOffset.y = 0;
2759 copyRegion.srcOffset.z = 0;
2760 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2761 copyRegion.dstSubresource.mipLevel = 0;
2762 copyRegion.dstSubresource.baseArrayLayer = 0;
2763 copyRegion.dstSubresource.layerCount = 1;
2764 copyRegion.dstOffset.x = 0;
2765 copyRegion.dstOffset.y = 0;
2766 copyRegion.dstOffset.z = 0;
2767 copyRegion.extent.width = 1;
2768 copyRegion.extent.height = 1;
2769 copyRegion.extent.depth = 1;
2770
2771 // Introduce failure by setting srcOffset to a bad granularity value
2772 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2774 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002775 m_errorMonitor->VerifyFound();
2776
2777 // Introduce failure by setting extent to a bad granularity value
2778 copyRegion.srcOffset.y = 0;
2779 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2781 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002782 m_errorMonitor->VerifyFound();
2783
2784 // Now do some buffer/image copies
2785 vk_testing::Buffer buffer;
2786 VkMemoryPropertyFlags reqs = 0;
2787 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2788 VkBufferImageCopy region = {};
2789 region.bufferOffset = 0;
2790 region.bufferRowLength = 3;
2791 region.bufferImageHeight = 128;
2792 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2793 region.imageSubresource.layerCount = 1;
2794 region.imageExtent.height = 16;
2795 region.imageExtent.width = 16;
2796 region.imageExtent.depth = 1;
2797 region.imageOffset.x = 0;
2798 region.imageOffset.y = 0;
2799 region.imageOffset.z = 0;
2800
2801 // Introduce failure by setting bufferRowLength to a bad granularity value
2802 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2804 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2805 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002806 m_errorMonitor->VerifyFound();
2807 region.bufferRowLength = 128;
2808
2809 // Introduce failure by setting bufferOffset to a bad granularity value
2810 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2812 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2813 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002814 m_errorMonitor->VerifyFound();
2815 region.bufferOffset = 0;
2816
2817 // Introduce failure by setting bufferImageHeight to a bad granularity value
2818 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2820 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2821 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002822 m_errorMonitor->VerifyFound();
2823 region.bufferImageHeight = 128;
2824
2825 // Introduce failure by setting imageExtent to a bad granularity value
2826 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2828 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2829 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002830 m_errorMonitor->VerifyFound();
2831 region.imageExtent.width = 16;
2832
2833 // Introduce failure by setting imageOffset to a bad granularity value
2834 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2836 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2837 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002838 m_errorMonitor->VerifyFound();
2839
2840 EndCommandBuffer();
2841
2842 vkDestroyImage(m_device->device(), srcImage, NULL);
2843 vkDestroyImage(m_device->device(), dstImage, NULL);
2844 vkFreeMemory(m_device->device(), srcMem, NULL);
2845 vkFreeMemory(m_device->device(), destMem, NULL);
2846}
2847
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002848TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002849 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2850 "attempt to submit them on a queue created in a different "
2851 "queue family.");
2852
Cody Northropc31a84f2016-08-22 10:41:47 -06002853 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002854 // This test is meaningless unless we have multiple queue families
2855 auto queue_family_properties = m_device->phy().queue_properties();
2856 if (queue_family_properties.size() < 2) {
2857 return;
2858 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002860 // Get safe index of another queue family
2861 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2862 ASSERT_NO_FATAL_FAILURE(InitState());
2863 // Create a second queue using a different queue family
2864 VkQueue other_queue;
2865 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2866
2867 // Record an empty cmd buffer
2868 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2869 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2870 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2871 vkEndCommandBuffer(m_commandBuffer->handle());
2872
2873 // And submit on the wrong queue
2874 VkSubmitInfo submit_info = {};
2875 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2876 submit_info.commandBufferCount = 1;
2877 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002878 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002879
2880 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002881}
2882
Chris Forbesa58c4522016-09-28 15:19:39 +13002883TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2884 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2885 ASSERT_NO_FATAL_FAILURE(InitState());
2886
2887 // A renderpass with two subpasses, both writing the same attachment.
2888 VkAttachmentDescription attach[] = {
2889 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2890 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2891 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2892 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2893 },
2894 };
2895 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2896 VkSubpassDescription subpasses[] = {
2897 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2898 1, &ref, nullptr, nullptr, 0, nullptr },
2899 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2900 1, &ref, nullptr, nullptr, 0, nullptr },
2901 };
2902 VkSubpassDependency dep = {
2903 0, 1,
2904 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2905 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2906 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2907 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2908 VK_DEPENDENCY_BY_REGION_BIT
2909 };
2910 VkRenderPassCreateInfo rpci = {
2911 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2912 0, 1, attach, 2, subpasses, 1, &dep
2913 };
2914 VkRenderPass rp;
2915 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2916 ASSERT_VK_SUCCESS(err);
2917
2918 VkImageObj image(m_device);
2919 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2920 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2921 VK_IMAGE_TILING_OPTIMAL, 0);
2922 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2923
2924 VkFramebufferCreateInfo fbci = {
2925 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2926 0, rp, 1, &imageView, 32, 32, 1
2927 };
2928 VkFramebuffer fb;
2929 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2930 ASSERT_VK_SUCCESS(err);
2931
2932 char const *vsSource =
2933 "#version 450\n"
2934 "void main() { gl_Position = vec4(1); }\n";
2935 char const *fsSource =
2936 "#version 450\n"
2937 "layout(location=0) out vec4 color;\n"
2938 "void main() { color = vec4(1); }\n";
2939
2940 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2941 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2942 VkPipelineObj pipe(m_device);
2943 pipe.AddColorAttachment();
2944 pipe.AddShader(&vs);
2945 pipe.AddShader(&fs);
2946 VkViewport view_port = {};
2947 m_viewports.push_back(view_port);
2948 pipe.SetViewport(m_viewports);
2949 VkRect2D rect = {};
2950 m_scissors.push_back(rect);
2951 pipe.SetScissor(m_scissors);
2952
2953 VkPipelineLayoutCreateInfo plci = {
2954 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
2955 0, 0, nullptr, 0, nullptr
2956 };
2957 VkPipelineLayout pl;
2958 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
2959 ASSERT_VK_SUCCESS(err);
2960 pipe.CreateVKPipeline(pl, rp);
2961
2962 BeginCommandBuffer();
2963
2964 VkRenderPassBeginInfo rpbi = {
2965 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
2966 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
2967 };
2968
2969 // subtest 1: bind in the wrong subpass
2970 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2971 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2973 "built for subpass 0 but used in subpass 1");
2974 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2975 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2976 m_errorMonitor->VerifyFound();
2977
2978 vkCmdEndRenderPass(m_commandBuffer->handle());
2979
2980 // subtest 2: bind in correct subpass, then transition to next subpass
2981 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
2982 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
2983 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
2984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2985 "built for subpass 0 but used in subpass 1");
2986 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
2987 m_errorMonitor->VerifyFound();
2988
2989 vkCmdEndRenderPass(m_commandBuffer->handle());
2990
2991 EndCommandBuffer();
2992
2993 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
2994 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
2995 vkDestroyRenderPass(m_device->device(), rp, nullptr);
2996}
2997
Tony Barbour4e919972016-08-09 13:27:40 -06002998TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
2999 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3000 "with extent outside of framebuffer");
3001 ASSERT_NO_FATAL_FAILURE(InitState());
3002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3005 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003006
3007 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3008 m_renderPassBeginInfo.renderArea.extent.width = 257;
3009 m_renderPassBeginInfo.renderArea.extent.height = 257;
3010 BeginCommandBuffer();
3011 m_errorMonitor->VerifyFound();
3012}
3013
3014TEST_F(VkLayerTest, DisabledIndependentBlend) {
3015 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3016 "blend and then specifying different blend states for two "
3017 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003018 VkPhysicalDeviceFeatures features = {};
3019 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003020 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003021
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3023 "Invalid Pipeline CreateInfo: If independent blend feature not "
3024 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003025
Cody Northropc31a84f2016-08-22 10:41:47 -06003026 VkDescriptorSetObj descriptorSet(m_device);
3027 descriptorSet.AppendDummy();
3028 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003029
Cody Northropc31a84f2016-08-22 10:41:47 -06003030 VkPipelineObj pipeline(m_device);
3031 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003032 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003033 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003034
Cody Northropc31a84f2016-08-22 10:41:47 -06003035 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3036 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3037 att_state1.blendEnable = VK_TRUE;
3038 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3039 att_state2.blendEnable = VK_FALSE;
3040 pipeline.AddColorAttachment(0, &att_state1);
3041 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003042 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003043 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003044}
3045
3046TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3047 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3048 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003049 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003050
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3052 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003053
3054 // Create a renderPass with a single color attachment
3055 VkAttachmentReference attach = {};
3056 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3057 VkSubpassDescription subpass = {};
3058 VkRenderPassCreateInfo rpci = {};
3059 rpci.subpassCount = 1;
3060 rpci.pSubpasses = &subpass;
3061 rpci.attachmentCount = 1;
3062 VkAttachmentDescription attach_desc = {};
3063 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3064 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3065 rpci.pAttachments = &attach_desc;
3066 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3067 VkRenderPass rp;
3068 subpass.pDepthStencilAttachment = &attach;
3069 subpass.pColorAttachments = NULL;
3070 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3071 m_errorMonitor->VerifyFound();
3072}
3073
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003074TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3075 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3076 "attachment reference of VK_ATTACHMENT_UNUSED");
3077
3078 ASSERT_NO_FATAL_FAILURE(InitState());
3079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3080
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003082
3083 VkAttachmentReference color_attach = {};
3084 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3085 color_attach.attachment = 0;
3086 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3087 VkSubpassDescription subpass = {};
3088 subpass.colorAttachmentCount = 1;
3089 subpass.pColorAttachments = &color_attach;
3090 subpass.preserveAttachmentCount = 1;
3091 subpass.pPreserveAttachments = &preserve_attachment;
3092
3093 VkRenderPassCreateInfo rpci = {};
3094 rpci.subpassCount = 1;
3095 rpci.pSubpasses = &subpass;
3096 rpci.attachmentCount = 1;
3097 VkAttachmentDescription attach_desc = {};
3098 attach_desc.format = VK_FORMAT_UNDEFINED;
3099 rpci.pAttachments = &attach_desc;
3100 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3101 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003102 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003103
3104 m_errorMonitor->VerifyFound();
3105
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003106 if (result == VK_SUCCESS) {
3107 vkDestroyRenderPass(m_device->device(), rp, NULL);
3108 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003109}
3110
Chris Forbesc5389742016-06-29 11:49:23 +12003111TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003112 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3113 "when the source of a subpass multisample resolve "
3114 "does not have multiple samples.");
3115
Chris Forbesc5389742016-06-29 11:49:23 +12003116 ASSERT_NO_FATAL_FAILURE(InitState());
3117
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3119 "Subpass 0 requests multisample resolve from attachment 0 which has "
3120 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003121
3122 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003123 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3124 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3125 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3126 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3127 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3128 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003129 };
3130
3131 VkAttachmentReference color = {
3132 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3133 };
3134
3135 VkAttachmentReference resolve = {
3136 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3137 };
3138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003139 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003141 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003142
3143 VkRenderPass rp;
3144 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3145
3146 m_errorMonitor->VerifyFound();
3147
3148 if (err == VK_SUCCESS)
3149 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3150}
3151
3152TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003153 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3154 "when a subpass multisample resolve operation is "
3155 "requested, and the destination of that resolve has "
3156 "multiple samples.");
3157
Chris Forbesc5389742016-06-29 11:49:23 +12003158 ASSERT_NO_FATAL_FAILURE(InitState());
3159
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3161 "Subpass 0 requests multisample resolve into attachment 1, which "
3162 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003163
3164 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003165 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3166 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3167 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3168 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3169 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3170 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003171 };
3172
3173 VkAttachmentReference color = {
3174 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3175 };
3176
3177 VkAttachmentReference resolve = {
3178 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3179 };
3180
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003181 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003182
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003183 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003184
3185 VkRenderPass rp;
3186 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3187
3188 m_errorMonitor->VerifyFound();
3189
3190 if (err == VK_SUCCESS)
3191 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3192}
3193
Chris Forbes3f128ef2016-06-29 14:58:53 +12003194TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003195 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3196 "when the color and depth attachments used by a subpass "
3197 "have inconsistent sample counts");
3198
Chris Forbes3f128ef2016-06-29 14:58:53 +12003199 ASSERT_NO_FATAL_FAILURE(InitState());
3200
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3202 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003203
3204 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003205 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3206 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3207 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3208 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3209 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3210 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003211 };
3212
3213 VkAttachmentReference color[] = {
3214 {
3215 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3216 },
3217 {
3218 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3219 },
3220 };
3221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003222 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003224 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003225
3226 VkRenderPass rp;
3227 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3228
3229 m_errorMonitor->VerifyFound();
3230
3231 if (err == VK_SUCCESS)
3232 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3233}
3234
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003235TEST_F(VkLayerTest, FramebufferCreateErrors) {
3236 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003237 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003238 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003239 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3240 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3241 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3242 " 6. Framebuffer attachment where dimensions don't match\n"
3243 " 7. Framebuffer attachment w/o identity swizzle\n"
3244 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003245
3246 ASSERT_NO_FATAL_FAILURE(InitState());
3247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3248
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3250 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3251 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003252
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003253 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003254 VkAttachmentReference attach = {};
3255 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3256 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003257 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003258 VkRenderPassCreateInfo rpci = {};
3259 rpci.subpassCount = 1;
3260 rpci.pSubpasses = &subpass;
3261 rpci.attachmentCount = 1;
3262 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003263 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003264 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003265 rpci.pAttachments = &attach_desc;
3266 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3267 VkRenderPass rp;
3268 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3269 ASSERT_VK_SUCCESS(err);
3270
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003271 VkImageView ivs[2];
3272 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3273 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003274 VkFramebufferCreateInfo fb_info = {};
3275 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3276 fb_info.pNext = NULL;
3277 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003278 // Set mis-matching attachmentCount
3279 fb_info.attachmentCount = 2;
3280 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003281 fb_info.width = 100;
3282 fb_info.height = 100;
3283 fb_info.layers = 1;
3284
3285 VkFramebuffer fb;
3286 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3287
3288 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003289 if (err == VK_SUCCESS) {
3290 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3291 }
3292 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003293
3294 // Create a renderPass with a depth-stencil attachment created with
3295 // IMAGE_USAGE_COLOR_ATTACHMENT
3296 // Add our color attachment to pDepthStencilAttachment
3297 subpass.pDepthStencilAttachment = &attach;
3298 subpass.pColorAttachments = NULL;
3299 VkRenderPass rp_ds;
3300 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3301 ASSERT_VK_SUCCESS(err);
3302 // Set correct attachment count, but attachment has COLOR usage bit set
3303 fb_info.attachmentCount = 1;
3304 fb_info.renderPass = rp_ds;
3305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003307 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3308
3309 m_errorMonitor->VerifyFound();
3310 if (err == VK_SUCCESS) {
3311 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3312 }
3313 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003314
3315 // Create new renderpass with alternate attachment format from fb
3316 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3317 subpass.pDepthStencilAttachment = NULL;
3318 subpass.pColorAttachments = &attach;
3319 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3320 ASSERT_VK_SUCCESS(err);
3321
3322 // Cause error due to mis-matched formats between rp & fb
3323 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3324 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3326 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003327 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3328
3329 m_errorMonitor->VerifyFound();
3330 if (err == VK_SUCCESS) {
3331 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3332 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003333 vkDestroyRenderPass(m_device->device(), rp, NULL);
3334
3335 // Create new renderpass with alternate sample count from fb
3336 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3337 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3338 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3339 ASSERT_VK_SUCCESS(err);
3340
3341 // Cause error due to mis-matched sample count between rp & fb
3342 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3344 "that do not match the "
3345 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -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 Ehlisd3bb23a2016-06-22 13:34:46 -06003352
3353 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003354
3355 // Create a custom imageView with non-1 mip levels
3356 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003357 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 -06003358 ASSERT_TRUE(image.initialized());
3359
3360 VkImageView view;
3361 VkImageViewCreateInfo ivci = {};
3362 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3363 ivci.image = image.handle();
3364 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3365 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3366 ivci.subresourceRange.layerCount = 1;
3367 ivci.subresourceRange.baseMipLevel = 0;
3368 // Set level count 2 (only 1 is allowed for FB attachment)
3369 ivci.subresourceRange.levelCount = 2;
3370 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3371 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3372 ASSERT_VK_SUCCESS(err);
3373 // Re-create renderpass to have matching sample count
3374 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3375 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3376 ASSERT_VK_SUCCESS(err);
3377
3378 fb_info.renderPass = rp;
3379 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003381 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3382
3383 m_errorMonitor->VerifyFound();
3384 if (err == VK_SUCCESS) {
3385 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3386 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003387 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003388 // Update view to original color buffer and grow FB dimensions too big
3389 fb_info.pAttachments = ivs;
3390 fb_info.height = 1024;
3391 fb_info.width = 1024;
3392 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3394 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003395 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3396
3397 m_errorMonitor->VerifyFound();
3398 if (err == VK_SUCCESS) {
3399 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3400 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003401 // Create view attachment with non-identity swizzle
3402 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3403 ivci.image = image.handle();
3404 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3405 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3406 ivci.subresourceRange.layerCount = 1;
3407 ivci.subresourceRange.baseMipLevel = 0;
3408 ivci.subresourceRange.levelCount = 1;
3409 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3410 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3411 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3412 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3413 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3414 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3415 ASSERT_VK_SUCCESS(err);
3416
3417 fb_info.pAttachments = &view;
3418 fb_info.height = 100;
3419 fb_info.width = 100;
3420 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3422 "framebuffer attachments must have "
3423 "been created with the identity "
3424 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003425 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3426
3427 m_errorMonitor->VerifyFound();
3428 if (err == VK_SUCCESS) {
3429 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3430 }
3431 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003432 // Request fb that exceeds max dimensions
3433 // reset attachment to color attachment
3434 fb_info.pAttachments = ivs;
3435 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
3436 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
3437 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Requested VkFramebufferCreateInfo "
3439 "dimensions exceed physical device "
3440 "limits. ");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003441 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3442
3443 m_errorMonitor->VerifyFound();
3444 if (err == VK_SUCCESS) {
3445 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3446 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003447
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003448 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003449}
3450
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003451TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003452 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3453 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003454
Cody Northropc31a84f2016-08-22 10:41:47 -06003455 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003456 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3458 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003459 m_errorMonitor->VerifyFound();
3460}
3461
3462TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003463 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3464 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003465
Cody Northropc31a84f2016-08-22 10:41:47 -06003466 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003467 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3469 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003470 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003471}
3472
3473TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003474 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3475 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003476
Cody Northropc31a84f2016-08-22 10:41:47 -06003477 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003478 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003479 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 -06003480 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003481 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003482}
3483
3484TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003485 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3486 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003487
Cody Northropc31a84f2016-08-22 10:41:47 -06003488 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003489 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003490 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 -06003491 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003492 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003493}
3494
Cortd713fe82016-07-27 09:51:27 -07003495TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003496 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3497 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003498
3499 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003500 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3502 "Dynamic blend constants state not set for this command buffer");
3503 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003504 m_errorMonitor->VerifyFound();
3505}
3506
3507TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003508 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3509 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003510
3511 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003512 if (!m_device->phy().features().depthBounds) {
3513 printf("Device does not support depthBounds test; skipped.\n");
3514 return;
3515 }
3516 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3518 "Dynamic depth bounds state not set for this command buffer");
3519 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003520 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003521}
3522
3523TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003524 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3525 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003526
3527 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003528 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3530 "Dynamic stencil read mask state not set for this command buffer");
3531 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003532 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003533}
3534
3535TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003536 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3537 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003538
3539 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003540 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3542 "Dynamic stencil write mask state not set for this command buffer");
3543 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003544 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003545}
3546
3547TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003548 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3549 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003550
3551 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003552 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3554 "Dynamic stencil reference state not set for this command buffer");
3555 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003556 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003557}
3558
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003559TEST_F(VkLayerTest, IndexBufferNotBound) {
3560 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003561
3562 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3564 "Index buffer object not bound to this command buffer when Indexed ");
3565 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003566 m_errorMonitor->VerifyFound();
3567}
3568
Karl Schultz6addd812016-02-02 17:17:23 -07003569TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3571 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3572 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003573
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003574 ASSERT_NO_FATAL_FAILURE(InitState());
3575 ASSERT_NO_FATAL_FAILURE(InitViewport());
3576 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3577
Karl Schultz6addd812016-02-02 17:17:23 -07003578 // We luck out b/c by default the framework creates CB w/ the
3579 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003580 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003581 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003582 EndCommandBuffer();
3583
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003584 // Bypass framework since it does the waits automatically
3585 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003586 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003587 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3588 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003589 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003590 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003591 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003592 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003593 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003594 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003595 submit_info.pSignalSemaphores = NULL;
3596
Chris Forbes40028e22016-06-13 09:59:34 +12003597 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003598 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003599 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003600
Karl Schultz6addd812016-02-02 17:17:23 -07003601 // Cause validation error by re-submitting cmd buffer that should only be
3602 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003603 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003604 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003605
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003606 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003607}
3608
Karl Schultz6addd812016-02-02 17:17:23 -07003609TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003610 // Initiate Draw w/o a PSO bound
Karl Schultz6addd812016-02-02 17:17:23 -07003611 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003612
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unable to allocate 1 descriptors of "
3614 "type "
3615 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003616
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003617 ASSERT_NO_FATAL_FAILURE(InitState());
3618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003619
Karl Schultz6addd812016-02-02 17:17:23 -07003620 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3621 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003622 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003623 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
3624 ds_type_count.descriptorCount = 1;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003625
3626 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003627 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3628 ds_pool_ci.pNext = NULL;
3629 ds_pool_ci.flags = 0;
3630 ds_pool_ci.maxSets = 1;
3631 ds_pool_ci.poolSizeCount = 1;
3632 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003633
3634 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003635 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003636 ASSERT_VK_SUCCESS(err);
3637
3638 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003639 dsl_binding.binding = 0;
3640 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3641 dsl_binding.descriptorCount = 1;
3642 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3643 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003644
3645 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003646 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3647 ds_layout_ci.pNext = NULL;
3648 ds_layout_ci.bindingCount = 1;
3649 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003650
3651 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003652 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003653 ASSERT_VK_SUCCESS(err);
3654
3655 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003656 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003657 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003658 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003659 alloc_info.descriptorPool = ds_pool;
3660 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003661 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003662
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003663 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003664
Chia-I Wuf7458c52015-10-26 21:10:41 +08003665 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3666 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003667}
3668
Karl Schultz6addd812016-02-02 17:17:23 -07003669TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3670 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003671
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3673 "It is invalid to call vkFreeDescriptorSets() with a pool created "
3674 "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003675
Tobin Ehlise735c692015-10-08 13:13:50 -06003676 ASSERT_NO_FATAL_FAILURE(InitState());
3677 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003678
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003679 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003680 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3681 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003682
3683 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003684 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3685 ds_pool_ci.pNext = NULL;
3686 ds_pool_ci.maxSets = 1;
3687 ds_pool_ci.poolSizeCount = 1;
3688 ds_pool_ci.flags = 0;
3689 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3690 // app can only call vkResetDescriptorPool on this pool.;
3691 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003692
3693 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003694 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003695 ASSERT_VK_SUCCESS(err);
3696
3697 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003698 dsl_binding.binding = 0;
3699 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3700 dsl_binding.descriptorCount = 1;
3701 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3702 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003703
3704 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003705 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3706 ds_layout_ci.pNext = NULL;
3707 ds_layout_ci.bindingCount = 1;
3708 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003709
3710 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003711 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003712 ASSERT_VK_SUCCESS(err);
3713
3714 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003715 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003716 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003717 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003718 alloc_info.descriptorPool = ds_pool;
3719 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003720 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003721 ASSERT_VK_SUCCESS(err);
3722
3723 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003724 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003725
Chia-I Wuf7458c52015-10-26 21:10:41 +08003726 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3727 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003728}
3729
Karl Schultz6addd812016-02-02 17:17:23 -07003730TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003731 // Attempt to clear Descriptor Pool with bad object.
3732 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003733
3734 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Pool Object 0xbaad6001");
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003736 uint64_t fake_pool_handle = 0xbaad6001;
3737 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3738 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003739 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003740}
3741
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06003742TEST_F(VkPositiveLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003743 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3744 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003745 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003746 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003747
3748 uint64_t fake_set_handle = 0xbaad6001;
3749 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003750 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06003752
3753 ASSERT_NO_FATAL_FAILURE(InitState());
3754
3755 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3756 layout_bindings[0].binding = 0;
3757 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3758 layout_bindings[0].descriptorCount = 1;
3759 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3760 layout_bindings[0].pImmutableSamplers = NULL;
3761
3762 VkDescriptorSetLayout descriptor_set_layout;
3763 VkDescriptorSetLayoutCreateInfo dslci = {};
3764 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3765 dslci.pNext = NULL;
3766 dslci.bindingCount = 1;
3767 dslci.pBindings = layout_bindings;
3768 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003769 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003770
3771 VkPipelineLayout pipeline_layout;
3772 VkPipelineLayoutCreateInfo plci = {};
3773 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3774 plci.pNext = NULL;
3775 plci.setLayoutCount = 1;
3776 plci.pSetLayouts = &descriptor_set_layout;
3777 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003778 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003779
3780 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3782 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003783 m_errorMonitor->VerifyFound();
3784 EndCommandBuffer();
3785 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3786 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003787}
3788
Karl Schultz6addd812016-02-02 17:17:23 -07003789TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003790 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3791 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003792 uint64_t fake_layout_handle = 0xbaad6001;
3793 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Descriptor Set Layout Object 0xbaad6001");
Cody Northropc31a84f2016-08-22 10:41:47 -06003795 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003796 VkPipelineLayout pipeline_layout;
3797 VkPipelineLayoutCreateInfo plci = {};
3798 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3799 plci.pNext = NULL;
3800 plci.setLayoutCount = 1;
3801 plci.pSetLayouts = &bad_layout;
3802 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3803
3804 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003805}
3806
Mark Muellerd4914412016-06-13 17:52:06 -06003807TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3808 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3809 "1) A uniform buffer update must have a valid buffer index."
3810 "2) When using an array of descriptors in a single WriteDescriptor,"
3811 " the descriptor types and stageflags must all be the same."
3812 "3) Immutable Sampler state must match across descriptors");
3813
3814 const char *invalid_BufferInfo_ErrorMessage =
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003815 "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, "
3816 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or "
3817 "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL";
3818 const char *stateFlag_ErrorMessage = "Attempting write update to descriptor set ";
3819 const char *immutable_ErrorMessage = "Attempting write update to descriptor set ";
Mark Muellerd4914412016-06-13 17:52:06 -06003820
Mark Muellerd4914412016-06-13 17:52:06 -06003821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage);
3822
3823 ASSERT_NO_FATAL_FAILURE(InitState());
3824 VkDescriptorPoolSize ds_type_count[4] = {};
3825 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3826 ds_type_count[0].descriptorCount = 1;
3827 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3828 ds_type_count[1].descriptorCount = 1;
3829 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
3830 ds_type_count[2].descriptorCount = 1;
3831 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3832 ds_type_count[3].descriptorCount = 1;
3833
3834 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3835 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3836 ds_pool_ci.maxSets = 1;
3837 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3838 ds_pool_ci.pPoolSizes = ds_type_count;
3839
3840 VkDescriptorPool ds_pool;
3841 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3842 ASSERT_VK_SUCCESS(err);
3843
Mark Muellerb9896722016-06-16 09:54:29 -06003844 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003845 layout_binding[0].binding = 0;
3846 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3847 layout_binding[0].descriptorCount = 1;
3848 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3849 layout_binding[0].pImmutableSamplers = NULL;
3850
3851 layout_binding[1].binding = 1;
3852 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3853 layout_binding[1].descriptorCount = 1;
3854 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3855 layout_binding[1].pImmutableSamplers = NULL;
3856
3857 VkSamplerCreateInfo sampler_ci = {};
3858 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3859 sampler_ci.pNext = NULL;
3860 sampler_ci.magFilter = VK_FILTER_NEAREST;
3861 sampler_ci.minFilter = VK_FILTER_NEAREST;
3862 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3863 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3864 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3865 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3866 sampler_ci.mipLodBias = 1.0;
3867 sampler_ci.anisotropyEnable = VK_FALSE;
3868 sampler_ci.maxAnisotropy = 1;
3869 sampler_ci.compareEnable = VK_FALSE;
3870 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3871 sampler_ci.minLod = 1.0;
3872 sampler_ci.maxLod = 1.0;
3873 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3874 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3875 VkSampler sampler;
3876
3877 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3878 ASSERT_VK_SUCCESS(err);
3879
3880 layout_binding[2].binding = 2;
3881 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3882 layout_binding[2].descriptorCount = 1;
3883 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3884 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3885
Mark Muellerd4914412016-06-13 17:52:06 -06003886 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3887 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3888 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3889 ds_layout_ci.pBindings = layout_binding;
3890 VkDescriptorSetLayout ds_layout;
3891 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3892 ASSERT_VK_SUCCESS(err);
3893
3894 VkDescriptorSetAllocateInfo alloc_info = {};
3895 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3896 alloc_info.descriptorSetCount = 1;
3897 alloc_info.descriptorPool = ds_pool;
3898 alloc_info.pSetLayouts = &ds_layout;
3899 VkDescriptorSet descriptorSet;
3900 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
3901 ASSERT_VK_SUCCESS(err);
3902
3903 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
3904 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3905 pipeline_layout_ci.pNext = NULL;
3906 pipeline_layout_ci.setLayoutCount = 1;
3907 pipeline_layout_ci.pSetLayouts = &ds_layout;
3908
3909 VkPipelineLayout pipeline_layout;
3910 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
3911 ASSERT_VK_SUCCESS(err);
3912
Mark Mueller5c838ce2016-06-16 09:54:29 -06003913 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003914 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
3915 descriptor_write.dstSet = descriptorSet;
3916 descriptor_write.dstBinding = 0;
3917 descriptor_write.descriptorCount = 1;
3918 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3919
Mark Mueller5c838ce2016-06-16 09:54:29 -06003920 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06003921 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3922 m_errorMonitor->VerifyFound();
3923
3924 // Create a buffer to update the descriptor with
3925 uint32_t qfi = 0;
3926 VkBufferCreateInfo buffCI = {};
3927 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
3928 buffCI.size = 1024;
3929 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
3930 buffCI.queueFamilyIndexCount = 1;
3931 buffCI.pQueueFamilyIndices = &qfi;
3932
3933 VkBuffer dyub;
3934 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
3935 ASSERT_VK_SUCCESS(err);
3936 VkDescriptorBufferInfo buffInfo = {};
3937 buffInfo.buffer = dyub;
3938 buffInfo.offset = 0;
3939 buffInfo.range = 1024;
3940
3941 descriptor_write.pBufferInfo = &buffInfo;
3942 descriptor_write.descriptorCount = 2;
3943
Mark Mueller5c838ce2016-06-16 09:54:29 -06003944 // 2) The stateFlags don't match between the first and second descriptor
Mark Muellerd4914412016-06-13 17:52:06 -06003945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage);
3946 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3947 m_errorMonitor->VerifyFound();
3948
Mark Mueller5c838ce2016-06-16 09:54:29 -06003949 // 3) The second descriptor has a null_ptr pImmutableSamplers and
3950 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06003951 descriptor_write.dstBinding = 1;
3952 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06003953
Mark Mueller5c838ce2016-06-16 09:54:29 -06003954 // Make pImageInfo index non-null to avoid complaints of it missing
3955 VkDescriptorImageInfo imageInfo = {};
3956 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3957 descriptor_write.pImageInfo = &imageInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06003958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage);
3959 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
3960 m_errorMonitor->VerifyFound();
3961
Mark Muellerd4914412016-06-13 17:52:06 -06003962 vkDestroyBuffer(m_device->device(), dyub, NULL);
3963 vkDestroySampler(m_device->device(), sampler, NULL);
3964 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
3965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
3967}
3968
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003969TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
3970 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
3971 "due to a buffer dependency being destroyed.");
3972 ASSERT_NO_FATAL_FAILURE(InitState());
3973
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003974 VkBuffer buffer;
3975 VkDeviceMemory mem;
3976 VkMemoryRequirements mem_reqs;
3977
3978 VkBufferCreateInfo buf_info = {};
3979 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12003980 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06003981 buf_info.size = 256;
3982 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
3983 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
3984 ASSERT_VK_SUCCESS(err);
3985
3986 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
3987
3988 VkMemoryAllocateInfo alloc_info = {};
3989 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3990 alloc_info.allocationSize = 256;
3991 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003992 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 -06003993 if (!pass) {
3994 vkDestroyBuffer(m_device->device(), buffer, NULL);
3995 return;
3996 }
3997 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
3998 ASSERT_VK_SUCCESS(err);
3999
4000 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4001 ASSERT_VK_SUCCESS(err);
4002
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004003 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004004 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004005 m_commandBuffer->EndCommandBuffer();
4006
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004008 // Destroy buffer dependency prior to submit to cause ERROR
4009 vkDestroyBuffer(m_device->device(), buffer, NULL);
4010
4011 VkSubmitInfo submit_info = {};
4012 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4013 submit_info.commandBufferCount = 1;
4014 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4015 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4016
4017 m_errorMonitor->VerifyFound();
4018 vkFreeMemory(m_device->handle(), mem, NULL);
4019}
4020
Tobin Ehlisea413442016-09-28 10:23:59 -06004021TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4022 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4023
4024 ASSERT_NO_FATAL_FAILURE(InitState());
4025 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4026
4027 VkDescriptorPoolSize ds_type_count;
4028 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4029 ds_type_count.descriptorCount = 1;
4030
4031 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4032 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4033 ds_pool_ci.maxSets = 1;
4034 ds_pool_ci.poolSizeCount = 1;
4035 ds_pool_ci.pPoolSizes = &ds_type_count;
4036
4037 VkDescriptorPool ds_pool;
4038 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4039 ASSERT_VK_SUCCESS(err);
4040
4041 VkDescriptorSetLayoutBinding layout_binding;
4042 layout_binding.binding = 0;
4043 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4044 layout_binding.descriptorCount = 1;
4045 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4046 layout_binding.pImmutableSamplers = NULL;
4047
4048 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4049 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4050 ds_layout_ci.bindingCount = 1;
4051 ds_layout_ci.pBindings = &layout_binding;
4052 VkDescriptorSetLayout ds_layout;
4053 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4054 ASSERT_VK_SUCCESS(err);
4055
4056 VkDescriptorSetAllocateInfo alloc_info = {};
4057 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4058 alloc_info.descriptorSetCount = 1;
4059 alloc_info.descriptorPool = ds_pool;
4060 alloc_info.pSetLayouts = &ds_layout;
4061 VkDescriptorSet descriptor_set;
4062 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4063 ASSERT_VK_SUCCESS(err);
4064
4065 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4066 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4067 pipeline_layout_ci.pNext = NULL;
4068 pipeline_layout_ci.setLayoutCount = 1;
4069 pipeline_layout_ci.pSetLayouts = &ds_layout;
4070
4071 VkPipelineLayout pipeline_layout;
4072 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4073 ASSERT_VK_SUCCESS(err);
4074
4075 VkBuffer buffer;
4076 uint32_t queue_family_index = 0;
4077 VkBufferCreateInfo buffer_create_info = {};
4078 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4079 buffer_create_info.size = 1024;
4080 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4081 buffer_create_info.queueFamilyIndexCount = 1;
4082 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4083
4084 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4085 ASSERT_VK_SUCCESS(err);
4086
4087 VkMemoryRequirements memory_reqs;
4088 VkDeviceMemory buffer_memory;
4089
4090 VkMemoryAllocateInfo memory_info = {};
4091 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4092 memory_info.allocationSize = 0;
4093 memory_info.memoryTypeIndex = 0;
4094
4095 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4096 memory_info.allocationSize = memory_reqs.size;
4097 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4098 ASSERT_TRUE(pass);
4099
4100 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4101 ASSERT_VK_SUCCESS(err);
4102 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4103 ASSERT_VK_SUCCESS(err);
4104
4105 VkBufferView view;
4106 VkBufferViewCreateInfo bvci = {};
4107 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4108 bvci.buffer = buffer;
4109 bvci.format = VK_FORMAT_R8_UNORM;
4110 bvci.range = VK_WHOLE_SIZE;
4111
4112 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4113 ASSERT_VK_SUCCESS(err);
4114
4115 VkWriteDescriptorSet descriptor_write = {};
4116 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4117 descriptor_write.dstSet = descriptor_set;
4118 descriptor_write.dstBinding = 0;
4119 descriptor_write.descriptorCount = 1;
4120 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4121 descriptor_write.pTexelBufferView = &view;
4122
4123 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4124
4125 char const *vsSource = "#version 450\n"
4126 "\n"
4127 "out gl_PerVertex { \n"
4128 " vec4 gl_Position;\n"
4129 "};\n"
4130 "void main(){\n"
4131 " gl_Position = vec4(1);\n"
4132 "}\n";
4133 char const *fsSource = "#version 450\n"
4134 "\n"
4135 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4136 "layout(location=0) out vec4 x;\n"
4137 "void main(){\n"
4138 " x = imageLoad(s, 0);\n"
4139 "}\n";
4140 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4141 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4142 VkPipelineObj pipe(m_device);
4143 pipe.AddShader(&vs);
4144 pipe.AddShader(&fs);
4145 pipe.AddColorAttachment();
4146 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4147
4148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4150
4151 BeginCommandBuffer();
4152 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4153 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4154 VkRect2D scissor = {{0, 0}, {16, 16}};
4155 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4156 // Bind pipeline to cmd buffer
4157 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4158 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4159 &descriptor_set, 0, nullptr);
4160 Draw(1, 0, 0, 0);
4161 EndCommandBuffer();
4162
4163 // Delete BufferView in order to invalidate cmd buffer
4164 vkDestroyBufferView(m_device->device(), view, NULL);
4165 // Now attempt submit of cmd buffer
4166 VkSubmitInfo submit_info = {};
4167 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4168 submit_info.commandBufferCount = 1;
4169 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4170 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4171 m_errorMonitor->VerifyFound();
4172
4173 // Clean-up
4174 vkDestroyBuffer(m_device->device(), buffer, NULL);
4175 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4176 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4177 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4178 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4179}
4180
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004181TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4182 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4183 "due to an image dependency being destroyed.");
4184 ASSERT_NO_FATAL_FAILURE(InitState());
4185
4186 VkImage image;
4187 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4188 VkImageCreateInfo image_create_info = {};
4189 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4190 image_create_info.pNext = NULL;
4191 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4192 image_create_info.format = tex_format;
4193 image_create_info.extent.width = 32;
4194 image_create_info.extent.height = 32;
4195 image_create_info.extent.depth = 1;
4196 image_create_info.mipLevels = 1;
4197 image_create_info.arrayLayers = 1;
4198 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4199 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004200 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004201 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004202 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004203 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004204 // Have to bind memory to image before recording cmd in cmd buffer using it
4205 VkMemoryRequirements mem_reqs;
4206 VkDeviceMemory image_mem;
4207 bool pass;
4208 VkMemoryAllocateInfo mem_alloc = {};
4209 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4210 mem_alloc.pNext = NULL;
4211 mem_alloc.memoryTypeIndex = 0;
4212 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4213 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004214 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004215 ASSERT_TRUE(pass);
4216 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4217 ASSERT_VK_SUCCESS(err);
4218 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4219 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004220
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004221 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004222 VkClearColorValue ccv;
4223 ccv.float32[0] = 1.0f;
4224 ccv.float32[1] = 1.0f;
4225 ccv.float32[2] = 1.0f;
4226 ccv.float32[3] = 1.0f;
4227 VkImageSubresourceRange isr = {};
4228 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004229 isr.baseArrayLayer = 0;
4230 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004231 isr.layerCount = 1;
4232 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004233 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004234 m_commandBuffer->EndCommandBuffer();
4235
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004237 // Destroy image dependency prior to submit to cause ERROR
4238 vkDestroyImage(m_device->device(), image, NULL);
4239
4240 VkSubmitInfo submit_info = {};
4241 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4242 submit_info.commandBufferCount = 1;
4243 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4244 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4245
4246 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004247 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004248}
4249
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004250TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4251 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4252 "due to a framebuffer image dependency being destroyed.");
4253 VkFormatProperties format_properties;
4254 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004255 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4256 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004257 return;
4258 }
4259
4260 ASSERT_NO_FATAL_FAILURE(InitState());
4261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4262
4263 VkImageCreateInfo image_ci = {};
4264 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4265 image_ci.pNext = NULL;
4266 image_ci.imageType = VK_IMAGE_TYPE_2D;
4267 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4268 image_ci.extent.width = 32;
4269 image_ci.extent.height = 32;
4270 image_ci.extent.depth = 1;
4271 image_ci.mipLevels = 1;
4272 image_ci.arrayLayers = 1;
4273 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4274 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004275 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004276 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4277 image_ci.flags = 0;
4278 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004279 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004280
4281 VkMemoryRequirements memory_reqs;
4282 VkDeviceMemory image_memory;
4283 bool pass;
4284 VkMemoryAllocateInfo memory_info = {};
4285 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4286 memory_info.pNext = NULL;
4287 memory_info.allocationSize = 0;
4288 memory_info.memoryTypeIndex = 0;
4289 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4290 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004291 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004292 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004293 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004294 ASSERT_VK_SUCCESS(err);
4295 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4296 ASSERT_VK_SUCCESS(err);
4297
4298 VkImageViewCreateInfo ivci = {
4299 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4300 nullptr,
4301 0,
4302 image,
4303 VK_IMAGE_VIEW_TYPE_2D,
4304 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004305 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004306 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4307 };
4308 VkImageView view;
4309 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4310 ASSERT_VK_SUCCESS(err);
4311
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004312 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004313 VkFramebuffer fb;
4314 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4315 ASSERT_VK_SUCCESS(err);
4316
4317 // Just use default renderpass with our framebuffer
4318 m_renderPassBeginInfo.framebuffer = fb;
4319 // Create Null cmd buffer for submit
4320 BeginCommandBuffer();
4321 EndCommandBuffer();
4322 // Destroy image attached to framebuffer to invalidate cmd buffer
4323 vkDestroyImage(m_device->device(), image, NULL);
4324 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004326 QueueCommandBuffer(false);
4327 m_errorMonitor->VerifyFound();
4328
4329 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4330 vkDestroyImageView(m_device->device(), view, nullptr);
4331 vkFreeMemory(m_device->device(), image_memory, nullptr);
4332}
4333
Tobin Ehlisb329f992016-10-12 13:20:29 -06004334TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4335 TEST_DESCRIPTION("Delete in-use framebuffer.");
4336 VkFormatProperties format_properties;
4337 VkResult err = VK_SUCCESS;
4338 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4339
4340 ASSERT_NO_FATAL_FAILURE(InitState());
4341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4342
4343 VkImageObj image(m_device);
4344 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4345 ASSERT_TRUE(image.initialized());
4346 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4347
4348 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4349 VkFramebuffer fb;
4350 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4351 ASSERT_VK_SUCCESS(err);
4352
4353 // Just use default renderpass with our framebuffer
4354 m_renderPassBeginInfo.framebuffer = fb;
4355 // Create Null cmd buffer for submit
4356 BeginCommandBuffer();
4357 EndCommandBuffer();
4358 // Submit cmd buffer to put it in-flight
4359 VkSubmitInfo submit_info = {};
4360 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4361 submit_info.commandBufferCount = 1;
4362 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4363 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4364 // Destroy framebuffer while in-flight
4365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete framebuffer 0x");
4366 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4367 m_errorMonitor->VerifyFound();
4368 // Wait for queue to complete so we can safely destroy everything
4369 vkQueueWaitIdle(m_device->m_queue);
4370 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4371}
4372
Tobin Ehlis88becd72016-09-21 14:33:41 -06004373TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4374 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4375 VkFormatProperties format_properties;
4376 VkResult err = VK_SUCCESS;
4377 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004378
4379 ASSERT_NO_FATAL_FAILURE(InitState());
4380 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4381
4382 VkImageCreateInfo image_ci = {};
4383 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4384 image_ci.pNext = NULL;
4385 image_ci.imageType = VK_IMAGE_TYPE_2D;
4386 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4387 image_ci.extent.width = 256;
4388 image_ci.extent.height = 256;
4389 image_ci.extent.depth = 1;
4390 image_ci.mipLevels = 1;
4391 image_ci.arrayLayers = 1;
4392 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4393 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004394 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004395 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4396 image_ci.flags = 0;
4397 VkImage image;
4398 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4399
4400 VkMemoryRequirements memory_reqs;
4401 VkDeviceMemory image_memory;
4402 bool pass;
4403 VkMemoryAllocateInfo memory_info = {};
4404 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4405 memory_info.pNext = NULL;
4406 memory_info.allocationSize = 0;
4407 memory_info.memoryTypeIndex = 0;
4408 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4409 memory_info.allocationSize = memory_reqs.size;
4410 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4411 ASSERT_TRUE(pass);
4412 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4413 ASSERT_VK_SUCCESS(err);
4414 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4415 ASSERT_VK_SUCCESS(err);
4416
4417 VkImageViewCreateInfo ivci = {
4418 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4419 nullptr,
4420 0,
4421 image,
4422 VK_IMAGE_VIEW_TYPE_2D,
4423 VK_FORMAT_B8G8R8A8_UNORM,
4424 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4425 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4426 };
4427 VkImageView view;
4428 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4429 ASSERT_VK_SUCCESS(err);
4430
4431 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4432 VkFramebuffer fb;
4433 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4434 ASSERT_VK_SUCCESS(err);
4435
4436 // Just use default renderpass with our framebuffer
4437 m_renderPassBeginInfo.framebuffer = fb;
4438 // Create Null cmd buffer for submit
4439 BeginCommandBuffer();
4440 EndCommandBuffer();
4441 // Submit cmd buffer to put it (and attached imageView) in-flight
4442 VkSubmitInfo submit_info = {};
4443 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4444 submit_info.commandBufferCount = 1;
4445 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4446 // Submit cmd buffer to put framebuffer and children in-flight
4447 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4448 // Destroy image attached to framebuffer while in-flight
4449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image 0x");
4450 vkDestroyImage(m_device->device(), image, NULL);
4451 m_errorMonitor->VerifyFound();
4452 // Wait for queue to complete so we can safely destroy image and other objects
4453 vkQueueWaitIdle(m_device->m_queue);
4454 vkDestroyImage(m_device->device(), image, NULL);
4455 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4456 vkDestroyImageView(m_device->device(), view, nullptr);
4457 vkFreeMemory(m_device->device(), image_memory, nullptr);
4458}
4459
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004460TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4461 TEST_DESCRIPTION("Delete in-use renderPass.");
4462
4463 ASSERT_NO_FATAL_FAILURE(InitState());
4464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4465
4466 // Create simple renderpass
4467 VkAttachmentReference attach = {};
4468 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4469 VkSubpassDescription subpass = {};
4470 subpass.pColorAttachments = &attach;
4471 VkRenderPassCreateInfo rpci = {};
4472 rpci.subpassCount = 1;
4473 rpci.pSubpasses = &subpass;
4474 rpci.attachmentCount = 1;
4475 VkAttachmentDescription attach_desc = {};
4476 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4477 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4478 rpci.pAttachments = &attach_desc;
4479 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4480 VkRenderPass rp;
4481 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4482 ASSERT_VK_SUCCESS(err);
4483
4484 // Create a pipeline that uses the given renderpass
4485 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4486 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4487
4488 VkPipelineLayout pipeline_layout;
4489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4490 ASSERT_VK_SUCCESS(err);
4491
4492 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4493 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4494 vp_state_ci.viewportCount = 1;
4495 VkViewport vp = {}; // Just need dummy vp to point to
4496 vp_state_ci.pViewports = &vp;
4497 vp_state_ci.scissorCount = 1;
4498 VkRect2D scissors = {}; // Dummy scissors to point to
4499 vp_state_ci.pScissors = &scissors;
4500
4501 VkPipelineShaderStageCreateInfo shaderStages[2];
4502 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4503
4504 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4505 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4506 // but add it to be able to run on more devices
4507 shaderStages[0] = vs.GetStageCreateInfo();
4508 shaderStages[1] = fs.GetStageCreateInfo();
4509
4510 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4511 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4512
4513 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4514 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4515 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4516
4517 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4518 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4519 rs_ci.rasterizerDiscardEnable = true;
4520 rs_ci.lineWidth = 1.0f;
4521
4522 VkPipelineColorBlendAttachmentState att = {};
4523 att.blendEnable = VK_FALSE;
4524 att.colorWriteMask = 0xf;
4525
4526 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4527 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4528 cb_ci.attachmentCount = 1;
4529 cb_ci.pAttachments = &att;
4530
4531 VkGraphicsPipelineCreateInfo gp_ci = {};
4532 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4533 gp_ci.stageCount = 2;
4534 gp_ci.pStages = shaderStages;
4535 gp_ci.pVertexInputState = &vi_ci;
4536 gp_ci.pInputAssemblyState = &ia_ci;
4537 gp_ci.pViewportState = &vp_state_ci;
4538 gp_ci.pRasterizationState = &rs_ci;
4539 gp_ci.pColorBlendState = &cb_ci;
4540 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4541 gp_ci.layout = pipeline_layout;
4542 gp_ci.renderPass = rp;
4543
4544 VkPipelineCacheCreateInfo pc_ci = {};
4545 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4546
4547 VkPipeline pipeline;
4548 VkPipelineCache pipe_cache;
4549 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4550 ASSERT_VK_SUCCESS(err);
4551
4552 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4553 ASSERT_VK_SUCCESS(err);
4554 // Bind pipeline to cmd buffer, will also bind renderpass
4555 m_commandBuffer->BeginCommandBuffer();
4556 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4557 m_commandBuffer->EndCommandBuffer();
4558
4559 VkSubmitInfo submit_info = {};
4560 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4561 submit_info.commandBufferCount = 1;
4562 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4563 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4564
4565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4566 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4567 m_errorMonitor->VerifyFound();
4568
4569 // Wait for queue to complete so we can safely destroy everything
4570 vkQueueWaitIdle(m_device->m_queue);
4571 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4572 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4573 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4574 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4575}
4576
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004577TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004578 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004579 ASSERT_NO_FATAL_FAILURE(InitState());
4580
4581 VkImage image;
4582 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4583 VkImageCreateInfo image_create_info = {};
4584 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4585 image_create_info.pNext = NULL;
4586 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4587 image_create_info.format = tex_format;
4588 image_create_info.extent.width = 32;
4589 image_create_info.extent.height = 32;
4590 image_create_info.extent.depth = 1;
4591 image_create_info.mipLevels = 1;
4592 image_create_info.arrayLayers = 1;
4593 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4594 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004595 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004596 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004597 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004598 ASSERT_VK_SUCCESS(err);
4599 // Have to bind memory to image before recording cmd in cmd buffer using it
4600 VkMemoryRequirements mem_reqs;
4601 VkDeviceMemory image_mem;
4602 bool pass;
4603 VkMemoryAllocateInfo mem_alloc = {};
4604 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4605 mem_alloc.pNext = NULL;
4606 mem_alloc.memoryTypeIndex = 0;
4607 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4608 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004609 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004610 ASSERT_TRUE(pass);
4611 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4612 ASSERT_VK_SUCCESS(err);
4613
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004614 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004616 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004617
4618 m_commandBuffer->BeginCommandBuffer();
4619 VkClearColorValue ccv;
4620 ccv.float32[0] = 1.0f;
4621 ccv.float32[1] = 1.0f;
4622 ccv.float32[2] = 1.0f;
4623 ccv.float32[3] = 1.0f;
4624 VkImageSubresourceRange isr = {};
4625 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4626 isr.baseArrayLayer = 0;
4627 isr.baseMipLevel = 0;
4628 isr.layerCount = 1;
4629 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004630 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004631 m_commandBuffer->EndCommandBuffer();
4632
4633 m_errorMonitor->VerifyFound();
4634 vkDestroyImage(m_device->device(), image, NULL);
4635 vkFreeMemory(m_device->device(), image_mem, nullptr);
4636}
4637
4638TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004639 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004640 ASSERT_NO_FATAL_FAILURE(InitState());
4641
4642 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004643 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 -06004644 VK_IMAGE_TILING_OPTIMAL, 0);
4645 ASSERT_TRUE(image.initialized());
4646
4647 VkBuffer buffer;
4648 VkDeviceMemory mem;
4649 VkMemoryRequirements mem_reqs;
4650
4651 VkBufferCreateInfo buf_info = {};
4652 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004653 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004654 buf_info.size = 256;
4655 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4656 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4657 ASSERT_VK_SUCCESS(err);
4658
4659 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4660
4661 VkMemoryAllocateInfo alloc_info = {};
4662 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4663 alloc_info.allocationSize = 256;
4664 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004665 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 -06004666 if (!pass) {
4667 vkDestroyBuffer(m_device->device(), buffer, NULL);
4668 return;
4669 }
4670 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4671 ASSERT_VK_SUCCESS(err);
4672
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004673 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004675 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004676 VkBufferImageCopy region = {};
4677 region.bufferRowLength = 128;
4678 region.bufferImageHeight = 128;
4679 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4680
4681 region.imageSubresource.layerCount = 1;
4682 region.imageExtent.height = 4;
4683 region.imageExtent.width = 4;
4684 region.imageExtent.depth = 1;
4685 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004686 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4687 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004688 m_commandBuffer->EndCommandBuffer();
4689
4690 m_errorMonitor->VerifyFound();
4691
4692 vkDestroyBuffer(m_device->device(), buffer, NULL);
4693 vkFreeMemory(m_device->handle(), mem, NULL);
4694}
4695
Tobin Ehlis85940f52016-07-07 16:57:21 -06004696TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4697 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4698 "due to an event dependency being destroyed.");
4699 ASSERT_NO_FATAL_FAILURE(InitState());
4700
4701 VkEvent event;
4702 VkEventCreateInfo evci = {};
4703 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4704 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4705 ASSERT_VK_SUCCESS(result);
4706
4707 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004708 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004709 m_commandBuffer->EndCommandBuffer();
4710
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004712 // Destroy event dependency prior to submit to cause ERROR
4713 vkDestroyEvent(m_device->device(), event, NULL);
4714
4715 VkSubmitInfo submit_info = {};
4716 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4717 submit_info.commandBufferCount = 1;
4718 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4719 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4720
4721 m_errorMonitor->VerifyFound();
4722}
4723
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004724TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4725 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4726 "due to a query pool dependency being destroyed.");
4727 ASSERT_NO_FATAL_FAILURE(InitState());
4728
4729 VkQueryPool query_pool;
4730 VkQueryPoolCreateInfo qpci{};
4731 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4732 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4733 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004734 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004735 ASSERT_VK_SUCCESS(result);
4736
4737 m_commandBuffer->BeginCommandBuffer();
4738 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4739 m_commandBuffer->EndCommandBuffer();
4740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004742 // Destroy query pool dependency prior to submit to cause ERROR
4743 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4744
4745 VkSubmitInfo submit_info = {};
4746 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4747 submit_info.commandBufferCount = 1;
4748 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4749 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4750
4751 m_errorMonitor->VerifyFound();
4752}
4753
Tobin Ehlis24130d92016-07-08 15:50:53 -06004754TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4755 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4756 "due to a pipeline dependency being destroyed.");
4757 ASSERT_NO_FATAL_FAILURE(InitState());
4758 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4759
4760 VkResult err;
4761
4762 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4763 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4764
4765 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004766 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004767 ASSERT_VK_SUCCESS(err);
4768
4769 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4770 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4771 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004772 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004773 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004774 vp_state_ci.scissorCount = 1;
4775 VkRect2D scissors = {}; // Dummy scissors to point to
4776 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004777
4778 VkPipelineShaderStageCreateInfo shaderStages[2];
4779 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4780
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004781 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4782 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4783 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004784 shaderStages[0] = vs.GetStageCreateInfo();
4785 shaderStages[1] = fs.GetStageCreateInfo();
4786
4787 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4788 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4789
4790 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4791 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4792 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4793
4794 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4795 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004796 rs_ci.rasterizerDiscardEnable = true;
4797 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004798
4799 VkPipelineColorBlendAttachmentState att = {};
4800 att.blendEnable = VK_FALSE;
4801 att.colorWriteMask = 0xf;
4802
4803 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4804 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4805 cb_ci.attachmentCount = 1;
4806 cb_ci.pAttachments = &att;
4807
4808 VkGraphicsPipelineCreateInfo gp_ci = {};
4809 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4810 gp_ci.stageCount = 2;
4811 gp_ci.pStages = shaderStages;
4812 gp_ci.pVertexInputState = &vi_ci;
4813 gp_ci.pInputAssemblyState = &ia_ci;
4814 gp_ci.pViewportState = &vp_state_ci;
4815 gp_ci.pRasterizationState = &rs_ci;
4816 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004817 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4818 gp_ci.layout = pipeline_layout;
4819 gp_ci.renderPass = renderPass();
4820
4821 VkPipelineCacheCreateInfo pc_ci = {};
4822 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4823
4824 VkPipeline pipeline;
4825 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004826 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004827 ASSERT_VK_SUCCESS(err);
4828
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004829 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004830 ASSERT_VK_SUCCESS(err);
4831
4832 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004833 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004834 m_commandBuffer->EndCommandBuffer();
4835 // Now destroy pipeline in order to cause error when submitting
4836 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004839
4840 VkSubmitInfo submit_info = {};
4841 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4842 submit_info.commandBufferCount = 1;
4843 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4844 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4845
4846 m_errorMonitor->VerifyFound();
4847 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4848 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4849}
4850
Tobin Ehlis31289162016-08-17 14:57:58 -06004851TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4852 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4853 "due to a bound descriptor set with a buffer dependency "
4854 "being destroyed.");
4855 ASSERT_NO_FATAL_FAILURE(InitState());
4856 ASSERT_NO_FATAL_FAILURE(InitViewport());
4857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4858
4859 VkDescriptorPoolSize ds_type_count = {};
4860 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4861 ds_type_count.descriptorCount = 1;
4862
4863 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4864 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4865 ds_pool_ci.pNext = NULL;
4866 ds_pool_ci.maxSets = 1;
4867 ds_pool_ci.poolSizeCount = 1;
4868 ds_pool_ci.pPoolSizes = &ds_type_count;
4869
4870 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004871 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06004872 ASSERT_VK_SUCCESS(err);
4873
4874 VkDescriptorSetLayoutBinding dsl_binding = {};
4875 dsl_binding.binding = 0;
4876 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4877 dsl_binding.descriptorCount = 1;
4878 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4879 dsl_binding.pImmutableSamplers = NULL;
4880
4881 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4882 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4883 ds_layout_ci.pNext = NULL;
4884 ds_layout_ci.bindingCount = 1;
4885 ds_layout_ci.pBindings = &dsl_binding;
4886 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004888 ASSERT_VK_SUCCESS(err);
4889
4890 VkDescriptorSet descriptorSet;
4891 VkDescriptorSetAllocateInfo alloc_info = {};
4892 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4893 alloc_info.descriptorSetCount = 1;
4894 alloc_info.descriptorPool = ds_pool;
4895 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004896 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06004897 ASSERT_VK_SUCCESS(err);
4898
4899 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4900 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4901 pipeline_layout_ci.pNext = NULL;
4902 pipeline_layout_ci.setLayoutCount = 1;
4903 pipeline_layout_ci.pSetLayouts = &ds_layout;
4904
4905 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004906 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06004907 ASSERT_VK_SUCCESS(err);
4908
4909 // Create a buffer to update the descriptor with
4910 uint32_t qfi = 0;
4911 VkBufferCreateInfo buffCI = {};
4912 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4913 buffCI.size = 1024;
4914 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4915 buffCI.queueFamilyIndexCount = 1;
4916 buffCI.pQueueFamilyIndices = &qfi;
4917
4918 VkBuffer buffer;
4919 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
4920 ASSERT_VK_SUCCESS(err);
4921 // Allocate memory and bind to buffer so we can make it to the appropriate
4922 // error
4923 VkMemoryAllocateInfo mem_alloc = {};
4924 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4925 mem_alloc.pNext = NULL;
4926 mem_alloc.allocationSize = 1024;
4927 mem_alloc.memoryTypeIndex = 0;
4928
4929 VkMemoryRequirements memReqs;
4930 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004931 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06004932 if (!pass) {
4933 vkDestroyBuffer(m_device->device(), buffer, NULL);
4934 return;
4935 }
4936
4937 VkDeviceMemory mem;
4938 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
4939 ASSERT_VK_SUCCESS(err);
4940 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4941 ASSERT_VK_SUCCESS(err);
4942 // Correctly update descriptor to avoid "NOT_UPDATED" error
4943 VkDescriptorBufferInfo buffInfo = {};
4944 buffInfo.buffer = buffer;
4945 buffInfo.offset = 0;
4946 buffInfo.range = 1024;
4947
4948 VkWriteDescriptorSet descriptor_write;
4949 memset(&descriptor_write, 0, sizeof(descriptor_write));
4950 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4951 descriptor_write.dstSet = descriptorSet;
4952 descriptor_write.dstBinding = 0;
4953 descriptor_write.descriptorCount = 1;
4954 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4955 descriptor_write.pBufferInfo = &buffInfo;
4956
4957 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4958
4959 // Create PSO to be used for draw-time errors below
4960 char const *vsSource = "#version 450\n"
4961 "\n"
4962 "out gl_PerVertex { \n"
4963 " vec4 gl_Position;\n"
4964 "};\n"
4965 "void main(){\n"
4966 " gl_Position = vec4(1);\n"
4967 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004968 char const *fsSource = "#version 450\n"
4969 "\n"
4970 "layout(location=0) out vec4 x;\n"
4971 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
4972 "void main(){\n"
4973 " x = vec4(bar.y);\n"
4974 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06004975 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4976 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4977 VkPipelineObj pipe(m_device);
4978 pipe.AddShader(&vs);
4979 pipe.AddShader(&fs);
4980 pipe.AddColorAttachment();
4981 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4982
4983 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004984 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4985 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4986 &descriptorSet, 0, NULL);
Tobin Ehlis31289162016-08-17 14:57:58 -06004987 Draw(1, 0, 0, 0);
4988 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06004990 // Destroy buffer should invalidate the cmd buffer, causing error on submit
4991 vkDestroyBuffer(m_device->device(), buffer, NULL);
4992 // Attempt to submit cmd buffer
4993 VkSubmitInfo submit_info = {};
4994 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4995 submit_info.commandBufferCount = 1;
4996 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4997 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4998 m_errorMonitor->VerifyFound();
4999 // Cleanup
5000 vkFreeMemory(m_device->device(), mem, NULL);
5001
5002 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5003 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5004 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5005}
5006
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005007TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5008 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5009 "due to a bound descriptor sets with a combined image "
5010 "sampler having their image, sampler, and descriptor set "
5011 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005012 "submit associated cmd buffers. Attempt to destroy a "
5013 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005014 ASSERT_NO_FATAL_FAILURE(InitState());
5015 ASSERT_NO_FATAL_FAILURE(InitViewport());
5016 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5017
5018 VkDescriptorPoolSize ds_type_count = {};
5019 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5020 ds_type_count.descriptorCount = 1;
5021
5022 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5023 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5024 ds_pool_ci.pNext = NULL;
5025 ds_pool_ci.maxSets = 1;
5026 ds_pool_ci.poolSizeCount = 1;
5027 ds_pool_ci.pPoolSizes = &ds_type_count;
5028
5029 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005030 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005031 ASSERT_VK_SUCCESS(err);
5032
5033 VkDescriptorSetLayoutBinding dsl_binding = {};
5034 dsl_binding.binding = 0;
5035 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5036 dsl_binding.descriptorCount = 1;
5037 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5038 dsl_binding.pImmutableSamplers = NULL;
5039
5040 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5041 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5042 ds_layout_ci.pNext = NULL;
5043 ds_layout_ci.bindingCount = 1;
5044 ds_layout_ci.pBindings = &dsl_binding;
5045 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005046 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005047 ASSERT_VK_SUCCESS(err);
5048
5049 VkDescriptorSet descriptorSet;
5050 VkDescriptorSetAllocateInfo alloc_info = {};
5051 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5052 alloc_info.descriptorSetCount = 1;
5053 alloc_info.descriptorPool = ds_pool;
5054 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005055 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005056 ASSERT_VK_SUCCESS(err);
5057
5058 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5059 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5060 pipeline_layout_ci.pNext = NULL;
5061 pipeline_layout_ci.setLayoutCount = 1;
5062 pipeline_layout_ci.pSetLayouts = &ds_layout;
5063
5064 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005065 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005066 ASSERT_VK_SUCCESS(err);
5067
5068 // Create images to update the descriptor with
5069 VkImage image;
5070 VkImage image2;
5071 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5072 const int32_t tex_width = 32;
5073 const int32_t tex_height = 32;
5074 VkImageCreateInfo image_create_info = {};
5075 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5076 image_create_info.pNext = NULL;
5077 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5078 image_create_info.format = tex_format;
5079 image_create_info.extent.width = tex_width;
5080 image_create_info.extent.height = tex_height;
5081 image_create_info.extent.depth = 1;
5082 image_create_info.mipLevels = 1;
5083 image_create_info.arrayLayers = 1;
5084 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5085 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5086 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5087 image_create_info.flags = 0;
5088 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5089 ASSERT_VK_SUCCESS(err);
5090 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5091 ASSERT_VK_SUCCESS(err);
5092
5093 VkMemoryRequirements memory_reqs;
5094 VkDeviceMemory image_memory;
5095 bool pass;
5096 VkMemoryAllocateInfo memory_info = {};
5097 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5098 memory_info.pNext = NULL;
5099 memory_info.allocationSize = 0;
5100 memory_info.memoryTypeIndex = 0;
5101 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5102 // Allocate enough memory for both images
5103 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005104 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005105 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005106 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005107 ASSERT_VK_SUCCESS(err);
5108 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5109 ASSERT_VK_SUCCESS(err);
5110 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005111 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005112 ASSERT_VK_SUCCESS(err);
5113
5114 VkImageViewCreateInfo image_view_create_info = {};
5115 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5116 image_view_create_info.image = image;
5117 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5118 image_view_create_info.format = tex_format;
5119 image_view_create_info.subresourceRange.layerCount = 1;
5120 image_view_create_info.subresourceRange.baseMipLevel = 0;
5121 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005122 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005123
5124 VkImageView view;
5125 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005126 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005127 ASSERT_VK_SUCCESS(err);
5128 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005129 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005130 ASSERT_VK_SUCCESS(err);
5131 // Create Samplers
5132 VkSamplerCreateInfo sampler_ci = {};
5133 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5134 sampler_ci.pNext = NULL;
5135 sampler_ci.magFilter = VK_FILTER_NEAREST;
5136 sampler_ci.minFilter = VK_FILTER_NEAREST;
5137 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5138 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5139 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5140 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5141 sampler_ci.mipLodBias = 1.0;
5142 sampler_ci.anisotropyEnable = VK_FALSE;
5143 sampler_ci.maxAnisotropy = 1;
5144 sampler_ci.compareEnable = VK_FALSE;
5145 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5146 sampler_ci.minLod = 1.0;
5147 sampler_ci.maxLod = 1.0;
5148 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5149 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5150 VkSampler sampler;
5151 VkSampler sampler2;
5152 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5153 ASSERT_VK_SUCCESS(err);
5154 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5155 ASSERT_VK_SUCCESS(err);
5156 // Update descriptor with image and sampler
5157 VkDescriptorImageInfo img_info = {};
5158 img_info.sampler = sampler;
5159 img_info.imageView = view;
5160 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5161
5162 VkWriteDescriptorSet descriptor_write;
5163 memset(&descriptor_write, 0, sizeof(descriptor_write));
5164 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5165 descriptor_write.dstSet = descriptorSet;
5166 descriptor_write.dstBinding = 0;
5167 descriptor_write.descriptorCount = 1;
5168 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5169 descriptor_write.pImageInfo = &img_info;
5170
5171 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5172
5173 // Create PSO to be used for draw-time errors below
5174 char const *vsSource = "#version 450\n"
5175 "\n"
5176 "out gl_PerVertex { \n"
5177 " vec4 gl_Position;\n"
5178 "};\n"
5179 "void main(){\n"
5180 " gl_Position = vec4(1);\n"
5181 "}\n";
5182 char const *fsSource = "#version 450\n"
5183 "\n"
5184 "layout(set=0, binding=0) uniform sampler2D s;\n"
5185 "layout(location=0) out vec4 x;\n"
5186 "void main(){\n"
5187 " x = texture(s, vec2(1));\n"
5188 "}\n";
5189 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5190 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5191 VkPipelineObj pipe(m_device);
5192 pipe.AddShader(&vs);
5193 pipe.AddShader(&fs);
5194 pipe.AddColorAttachment();
5195 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5196
5197 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005199 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005200 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5201 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5202 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005203 Draw(1, 0, 0, 0);
5204 EndCommandBuffer();
5205 // Destroy sampler invalidates the cmd buffer, causing error on submit
5206 vkDestroySampler(m_device->device(), sampler, NULL);
5207 // Attempt to submit cmd buffer
5208 VkSubmitInfo submit_info = {};
5209 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5210 submit_info.commandBufferCount = 1;
5211 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5212 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5213 m_errorMonitor->VerifyFound();
5214 // Now re-update descriptor with valid sampler and delete image
5215 img_info.sampler = sampler2;
5216 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005218 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005219 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5220 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5221 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005222 Draw(1, 0, 0, 0);
5223 EndCommandBuffer();
5224 // Destroy image invalidates the cmd buffer, causing error on submit
5225 vkDestroyImage(m_device->device(), image, NULL);
5226 // Attempt to submit cmd buffer
5227 submit_info = {};
5228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5229 submit_info.commandBufferCount = 1;
5230 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5231 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5232 m_errorMonitor->VerifyFound();
5233 // Now update descriptor to be valid, but then free descriptor
5234 img_info.imageView = view2;
5235 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005237 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005238 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5239 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5240 &descriptorSet, 0, NULL);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005241 Draw(1, 0, 0, 0);
5242 EndCommandBuffer();
5243 // Destroy descriptor set invalidates the cb, causing error on submit
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005245 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005246 m_errorMonitor->VerifyFound();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005247 // Attempt to submit cmd buffer
5248 submit_info = {};
5249 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5250 submit_info.commandBufferCount = 1;
5251 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5252 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5253 m_errorMonitor->VerifyFound();
5254 // Cleanup
5255 vkFreeMemory(m_device->device(), image_memory, NULL);
5256 vkDestroySampler(m_device->device(), sampler2, NULL);
5257 vkDestroyImage(m_device->device(), image2, NULL);
5258 vkDestroyImageView(m_device->device(), view, NULL);
5259 vkDestroyImageView(m_device->device(), view2, NULL);
5260 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5261 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5262 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5263}
5264
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005265TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5266 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5267 ASSERT_NO_FATAL_FAILURE(InitState());
5268 ASSERT_NO_FATAL_FAILURE(InitViewport());
5269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5270
5271 VkDescriptorPoolSize ds_type_count = {};
5272 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5273 ds_type_count.descriptorCount = 1;
5274
5275 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5276 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5277 ds_pool_ci.pNext = NULL;
5278 ds_pool_ci.maxSets = 1;
5279 ds_pool_ci.poolSizeCount = 1;
5280 ds_pool_ci.pPoolSizes = &ds_type_count;
5281
5282 VkDescriptorPool ds_pool;
5283 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5284 ASSERT_VK_SUCCESS(err);
5285
5286 VkDescriptorSetLayoutBinding dsl_binding = {};
5287 dsl_binding.binding = 0;
5288 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5289 dsl_binding.descriptorCount = 1;
5290 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5291 dsl_binding.pImmutableSamplers = NULL;
5292
5293 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5294 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5295 ds_layout_ci.pNext = NULL;
5296 ds_layout_ci.bindingCount = 1;
5297 ds_layout_ci.pBindings = &dsl_binding;
5298 VkDescriptorSetLayout ds_layout;
5299 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5300 ASSERT_VK_SUCCESS(err);
5301
5302 VkDescriptorSet descriptor_set;
5303 VkDescriptorSetAllocateInfo alloc_info = {};
5304 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5305 alloc_info.descriptorSetCount = 1;
5306 alloc_info.descriptorPool = ds_pool;
5307 alloc_info.pSetLayouts = &ds_layout;
5308 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5309 ASSERT_VK_SUCCESS(err);
5310
5311 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5312 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5313 pipeline_layout_ci.pNext = NULL;
5314 pipeline_layout_ci.setLayoutCount = 1;
5315 pipeline_layout_ci.pSetLayouts = &ds_layout;
5316
5317 VkPipelineLayout pipeline_layout;
5318 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5319 ASSERT_VK_SUCCESS(err);
5320
5321 // Create image to update the descriptor with
5322 VkImageObj image(m_device);
5323 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5324 ASSERT_TRUE(image.initialized());
5325
5326 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5327 // Create Sampler
5328 VkSamplerCreateInfo sampler_ci = {};
5329 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5330 sampler_ci.pNext = NULL;
5331 sampler_ci.magFilter = VK_FILTER_NEAREST;
5332 sampler_ci.minFilter = VK_FILTER_NEAREST;
5333 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5334 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5335 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5336 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5337 sampler_ci.mipLodBias = 1.0;
5338 sampler_ci.anisotropyEnable = VK_FALSE;
5339 sampler_ci.maxAnisotropy = 1;
5340 sampler_ci.compareEnable = VK_FALSE;
5341 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5342 sampler_ci.minLod = 1.0;
5343 sampler_ci.maxLod = 1.0;
5344 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5345 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5346 VkSampler sampler;
5347 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5348 ASSERT_VK_SUCCESS(err);
5349 // Update descriptor with image and sampler
5350 VkDescriptorImageInfo img_info = {};
5351 img_info.sampler = sampler;
5352 img_info.imageView = view;
5353 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5354
5355 VkWriteDescriptorSet descriptor_write;
5356 memset(&descriptor_write, 0, sizeof(descriptor_write));
5357 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5358 descriptor_write.dstSet = descriptor_set;
5359 descriptor_write.dstBinding = 0;
5360 descriptor_write.descriptorCount = 1;
5361 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5362 descriptor_write.pImageInfo = &img_info;
5363
5364 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5365
5366 // Create PSO to be used for draw-time errors below
5367 char const *vsSource = "#version 450\n"
5368 "\n"
5369 "out gl_PerVertex { \n"
5370 " vec4 gl_Position;\n"
5371 "};\n"
5372 "void main(){\n"
5373 " gl_Position = vec4(1);\n"
5374 "}\n";
5375 char const *fsSource = "#version 450\n"
5376 "\n"
5377 "layout(set=0, binding=0) uniform sampler2D s;\n"
5378 "layout(location=0) out vec4 x;\n"
5379 "void main(){\n"
5380 " x = texture(s, vec2(1));\n"
5381 "}\n";
5382 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5383 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5384 VkPipelineObj pipe(m_device);
5385 pipe.AddShader(&vs);
5386 pipe.AddShader(&fs);
5387 pipe.AddColorAttachment();
5388 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5389
5390 BeginCommandBuffer();
5391 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5392 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5393 &descriptor_set, 0, NULL);
5394 Draw(1, 0, 0, 0);
5395 EndCommandBuffer();
5396 // Submit cmd buffer to put pool in-flight
5397 VkSubmitInfo submit_info = {};
5398 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5399 submit_info.commandBufferCount = 1;
5400 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5401 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5402 // Destroy pool while in-flight, causing error
5403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5404 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5405 m_errorMonitor->VerifyFound();
5406 vkQueueWaitIdle(m_device->m_queue);
5407 // Cleanup
5408 vkDestroySampler(m_device->device(), sampler, NULL);
5409 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5410 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5411 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5412}
5413
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005414TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5415 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5416 ASSERT_NO_FATAL_FAILURE(InitState());
5417 ASSERT_NO_FATAL_FAILURE(InitViewport());
5418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5419
5420 VkDescriptorPoolSize ds_type_count = {};
5421 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5422 ds_type_count.descriptorCount = 1;
5423
5424 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5425 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5426 ds_pool_ci.pNext = NULL;
5427 ds_pool_ci.maxSets = 1;
5428 ds_pool_ci.poolSizeCount = 1;
5429 ds_pool_ci.pPoolSizes = &ds_type_count;
5430
5431 VkDescriptorPool ds_pool;
5432 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5433 ASSERT_VK_SUCCESS(err);
5434
5435 VkDescriptorSetLayoutBinding dsl_binding = {};
5436 dsl_binding.binding = 0;
5437 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5438 dsl_binding.descriptorCount = 1;
5439 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5440 dsl_binding.pImmutableSamplers = NULL;
5441
5442 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5443 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5444 ds_layout_ci.pNext = NULL;
5445 ds_layout_ci.bindingCount = 1;
5446 ds_layout_ci.pBindings = &dsl_binding;
5447 VkDescriptorSetLayout ds_layout;
5448 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5449 ASSERT_VK_SUCCESS(err);
5450
5451 VkDescriptorSet descriptorSet;
5452 VkDescriptorSetAllocateInfo alloc_info = {};
5453 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5454 alloc_info.descriptorSetCount = 1;
5455 alloc_info.descriptorPool = ds_pool;
5456 alloc_info.pSetLayouts = &ds_layout;
5457 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5458 ASSERT_VK_SUCCESS(err);
5459
5460 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5461 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5462 pipeline_layout_ci.pNext = NULL;
5463 pipeline_layout_ci.setLayoutCount = 1;
5464 pipeline_layout_ci.pSetLayouts = &ds_layout;
5465
5466 VkPipelineLayout pipeline_layout;
5467 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5468 ASSERT_VK_SUCCESS(err);
5469
5470 // Create images to update the descriptor with
5471 VkImage image;
5472 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5473 const int32_t tex_width = 32;
5474 const int32_t tex_height = 32;
5475 VkImageCreateInfo image_create_info = {};
5476 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5477 image_create_info.pNext = NULL;
5478 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5479 image_create_info.format = tex_format;
5480 image_create_info.extent.width = tex_width;
5481 image_create_info.extent.height = tex_height;
5482 image_create_info.extent.depth = 1;
5483 image_create_info.mipLevels = 1;
5484 image_create_info.arrayLayers = 1;
5485 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5486 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5487 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5488 image_create_info.flags = 0;
5489 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5490 ASSERT_VK_SUCCESS(err);
5491 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5492 VkMemoryRequirements memory_reqs;
5493 VkDeviceMemory image_memory;
5494 bool pass;
5495 VkMemoryAllocateInfo memory_info = {};
5496 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5497 memory_info.pNext = NULL;
5498 memory_info.allocationSize = 0;
5499 memory_info.memoryTypeIndex = 0;
5500 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5501 // Allocate enough memory for image
5502 memory_info.allocationSize = memory_reqs.size;
5503 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5504 ASSERT_TRUE(pass);
5505 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5506 ASSERT_VK_SUCCESS(err);
5507 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5508 ASSERT_VK_SUCCESS(err);
5509
5510 VkImageViewCreateInfo image_view_create_info = {};
5511 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5512 image_view_create_info.image = image;
5513 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5514 image_view_create_info.format = tex_format;
5515 image_view_create_info.subresourceRange.layerCount = 1;
5516 image_view_create_info.subresourceRange.baseMipLevel = 0;
5517 image_view_create_info.subresourceRange.levelCount = 1;
5518 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5519
5520 VkImageView view;
5521 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5522 ASSERT_VK_SUCCESS(err);
5523 // Create Samplers
5524 VkSamplerCreateInfo sampler_ci = {};
5525 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5526 sampler_ci.pNext = NULL;
5527 sampler_ci.magFilter = VK_FILTER_NEAREST;
5528 sampler_ci.minFilter = VK_FILTER_NEAREST;
5529 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5530 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5531 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5532 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5533 sampler_ci.mipLodBias = 1.0;
5534 sampler_ci.anisotropyEnable = VK_FALSE;
5535 sampler_ci.maxAnisotropy = 1;
5536 sampler_ci.compareEnable = VK_FALSE;
5537 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5538 sampler_ci.minLod = 1.0;
5539 sampler_ci.maxLod = 1.0;
5540 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5541 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5542 VkSampler sampler;
5543 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5544 ASSERT_VK_SUCCESS(err);
5545 // Update descriptor with image and sampler
5546 VkDescriptorImageInfo img_info = {};
5547 img_info.sampler = sampler;
5548 img_info.imageView = view;
5549 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5550
5551 VkWriteDescriptorSet descriptor_write;
5552 memset(&descriptor_write, 0, sizeof(descriptor_write));
5553 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5554 descriptor_write.dstSet = descriptorSet;
5555 descriptor_write.dstBinding = 0;
5556 descriptor_write.descriptorCount = 1;
5557 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5558 descriptor_write.pImageInfo = &img_info;
5559 // Break memory binding and attempt update
5560 vkFreeMemory(m_device->device(), image_memory, nullptr);
5561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005562 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5564 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5565 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5566 m_errorMonitor->VerifyFound();
5567 // Cleanup
5568 vkDestroyImage(m_device->device(), image, NULL);
5569 vkDestroySampler(m_device->device(), sampler, NULL);
5570 vkDestroyImageView(m_device->device(), view, NULL);
5571 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5572 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5573 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5574}
5575
Karl Schultz6addd812016-02-02 17:17:23 -07005576TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005577 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5578 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005579 // Create a valid cmd buffer
5580 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005581 uint64_t fake_pipeline_handle = 0xbaad6001;
5582 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005583 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5585
5586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Object 0xbaad6001");
Karl Schultzbdb75952016-04-19 11:36:49 -06005587 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005588 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005589 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005590
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005591 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005592 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 -06005593 Draw(1, 0, 0, 0);
5594 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005595
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005596 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005597 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 +12005598 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005599 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5600 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005601}
5602
Karl Schultz6addd812016-02-02 17:17:23 -07005603TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005604 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005605 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005606
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005608
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005609 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005610 ASSERT_NO_FATAL_FAILURE(InitViewport());
5611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005612 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005613 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5614 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005615
5616 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005617 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5618 ds_pool_ci.pNext = NULL;
5619 ds_pool_ci.maxSets = 1;
5620 ds_pool_ci.poolSizeCount = 1;
5621 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005622
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005623 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005624 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005625 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005626
Tony Barboureb254902015-07-15 12:50:33 -06005627 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005628 dsl_binding.binding = 0;
5629 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5630 dsl_binding.descriptorCount = 1;
5631 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5632 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005633
Tony Barboureb254902015-07-15 12:50:33 -06005634 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005635 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5636 ds_layout_ci.pNext = NULL;
5637 ds_layout_ci.bindingCount = 1;
5638 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005639 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005640 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005641 ASSERT_VK_SUCCESS(err);
5642
5643 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005644 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005645 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005646 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005647 alloc_info.descriptorPool = ds_pool;
5648 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005649 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005650 ASSERT_VK_SUCCESS(err);
5651
Tony Barboureb254902015-07-15 12:50:33 -06005652 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005653 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5654 pipeline_layout_ci.pNext = NULL;
5655 pipeline_layout_ci.setLayoutCount = 1;
5656 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005657
5658 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005659 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005660 ASSERT_VK_SUCCESS(err);
5661
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005662 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005663 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005664 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005665 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005666
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005667 VkPipelineObj pipe(m_device);
5668 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005669 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005670 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005671 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005672
5673 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005674 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5675 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5676 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005677
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005678 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005679
Chia-I Wuf7458c52015-10-26 21:10:41 +08005680 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5681 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5682 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005683}
5684
Karl Schultz6addd812016-02-02 17:17:23 -07005685TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005686 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005687 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005688
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer "
5690 "descriptor with invalid buffer view");
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005691
5692 ASSERT_NO_FATAL_FAILURE(InitState());
5693 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005694 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5695 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005696
5697 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005698 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5699 ds_pool_ci.pNext = NULL;
5700 ds_pool_ci.maxSets = 1;
5701 ds_pool_ci.poolSizeCount = 1;
5702 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005703
5704 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005705 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005706 ASSERT_VK_SUCCESS(err);
5707
5708 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005709 dsl_binding.binding = 0;
5710 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5711 dsl_binding.descriptorCount = 1;
5712 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5713 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005714
5715 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005716 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5717 ds_layout_ci.pNext = NULL;
5718 ds_layout_ci.bindingCount = 1;
5719 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005720 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005721 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005722 ASSERT_VK_SUCCESS(err);
5723
5724 VkDescriptorSet descriptorSet;
5725 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005726 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005727 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005728 alloc_info.descriptorPool = ds_pool;
5729 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005730 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005731 ASSERT_VK_SUCCESS(err);
5732
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005733 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005734 VkWriteDescriptorSet descriptor_write;
5735 memset(&descriptor_write, 0, sizeof(descriptor_write));
5736 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5737 descriptor_write.dstSet = descriptorSet;
5738 descriptor_write.dstBinding = 0;
5739 descriptor_write.descriptorCount = 1;
5740 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5741 descriptor_write.pTexelBufferView = &view;
5742
5743 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5744
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005745 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005746
5747 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5748 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5749}
5750
Mark Youngd339ba32016-05-30 13:28:35 -06005751TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005752 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 -06005753
5754 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005756 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005757
5758 ASSERT_NO_FATAL_FAILURE(InitState());
5759
5760 // Create a buffer with no bound memory and then attempt to create
5761 // a buffer view.
5762 VkBufferCreateInfo buff_ci = {};
5763 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005764 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005765 buff_ci.size = 256;
5766 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5767 VkBuffer buffer;
5768 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5769 ASSERT_VK_SUCCESS(err);
5770
5771 VkBufferViewCreateInfo buff_view_ci = {};
5772 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5773 buff_view_ci.buffer = buffer;
5774 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5775 buff_view_ci.range = VK_WHOLE_SIZE;
5776 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005777 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005778
5779 m_errorMonitor->VerifyFound();
5780 vkDestroyBuffer(m_device->device(), buffer, NULL);
5781 // If last error is success, it still created the view, so delete it.
5782 if (err == VK_SUCCESS) {
5783 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5784 }
5785}
5786
Karl Schultz6addd812016-02-02 17:17:23 -07005787TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5788 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5789 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005790 // 1. No dynamicOffset supplied
5791 // 2. Too many dynamicOffsets supplied
5792 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005793 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5795 "0 dynamicOffsets are left in "
5796 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005797
5798 ASSERT_NO_FATAL_FAILURE(InitState());
5799 ASSERT_NO_FATAL_FAILURE(InitViewport());
5800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5801
5802 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005803 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5804 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005805
5806 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005807 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5808 ds_pool_ci.pNext = NULL;
5809 ds_pool_ci.maxSets = 1;
5810 ds_pool_ci.poolSizeCount = 1;
5811 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005812
5813 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005814 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005815 ASSERT_VK_SUCCESS(err);
5816
5817 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005818 dsl_binding.binding = 0;
5819 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5820 dsl_binding.descriptorCount = 1;
5821 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5822 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005823
5824 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005825 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5826 ds_layout_ci.pNext = NULL;
5827 ds_layout_ci.bindingCount = 1;
5828 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005829 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005830 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005831 ASSERT_VK_SUCCESS(err);
5832
5833 VkDescriptorSet descriptorSet;
5834 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005835 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005836 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005837 alloc_info.descriptorPool = ds_pool;
5838 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005839 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005840 ASSERT_VK_SUCCESS(err);
5841
5842 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005843 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5844 pipeline_layout_ci.pNext = NULL;
5845 pipeline_layout_ci.setLayoutCount = 1;
5846 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005847
5848 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005849 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005850 ASSERT_VK_SUCCESS(err);
5851
5852 // Create a buffer to update the descriptor with
5853 uint32_t qfi = 0;
5854 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005855 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5856 buffCI.size = 1024;
5857 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5858 buffCI.queueFamilyIndexCount = 1;
5859 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005860
5861 VkBuffer dyub;
5862 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
5863 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005864 // Allocate memory and bind to buffer so we can make it to the appropriate
5865 // error
5866 VkMemoryAllocateInfo mem_alloc = {};
5867 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5868 mem_alloc.pNext = NULL;
5869 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12005870 mem_alloc.memoryTypeIndex = 0;
5871
5872 VkMemoryRequirements memReqs;
5873 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005874 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12005875 if (!pass) {
5876 vkDestroyBuffer(m_device->device(), dyub, NULL);
5877 return;
5878 }
5879
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005880 VkDeviceMemory mem;
5881 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5882 ASSERT_VK_SUCCESS(err);
5883 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
5884 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005885 // Correctly update descriptor to avoid "NOT_UPDATED" error
5886 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005887 buffInfo.buffer = dyub;
5888 buffInfo.offset = 0;
5889 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005890
5891 VkWriteDescriptorSet descriptor_write;
5892 memset(&descriptor_write, 0, sizeof(descriptor_write));
5893 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5894 descriptor_write.dstSet = descriptorSet;
5895 descriptor_write.dstBinding = 0;
5896 descriptor_write.descriptorCount = 1;
5897 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5898 descriptor_write.pBufferInfo = &buffInfo;
5899
5900 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5901
5902 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005903 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5904 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005905 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005906 uint32_t pDynOff[2] = {512, 756};
5907 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5909 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
5910 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5911 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12005912 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07005913 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
5915 "offset 0 and range 1024 that "
5916 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07005917 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005918 char const *vsSource = "#version 450\n"
5919 "\n"
5920 "out gl_PerVertex { \n"
5921 " vec4 gl_Position;\n"
5922 "};\n"
5923 "void main(){\n"
5924 " gl_Position = vec4(1);\n"
5925 "}\n";
5926 char const *fsSource = "#version 450\n"
5927 "\n"
5928 "layout(location=0) out vec4 x;\n"
5929 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5930 "void main(){\n"
5931 " x = vec4(bar.y);\n"
5932 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07005933 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5934 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5935 VkPipelineObj pipe(m_device);
5936 pipe.AddShader(&vs);
5937 pipe.AddShader(&fs);
5938 pipe.AddColorAttachment();
5939 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5940
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005941 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07005942 // This update should succeed, but offset size of 512 will overstep buffer
5943 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005944 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5945 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07005946 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005947 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005948
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005949 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06005950 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005951
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005952 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06005953 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005954 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5955}
5956
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005957TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
5958 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
5959 "that doesn't have memory bound");
5960 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005962 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5964 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005965
5966 ASSERT_NO_FATAL_FAILURE(InitState());
5967 ASSERT_NO_FATAL_FAILURE(InitViewport());
5968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5969
5970 VkDescriptorPoolSize ds_type_count = {};
5971 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5972 ds_type_count.descriptorCount = 1;
5973
5974 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5975 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5976 ds_pool_ci.pNext = NULL;
5977 ds_pool_ci.maxSets = 1;
5978 ds_pool_ci.poolSizeCount = 1;
5979 ds_pool_ci.pPoolSizes = &ds_type_count;
5980
5981 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005982 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005983 ASSERT_VK_SUCCESS(err);
5984
5985 VkDescriptorSetLayoutBinding dsl_binding = {};
5986 dsl_binding.binding = 0;
5987 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5988 dsl_binding.descriptorCount = 1;
5989 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5990 dsl_binding.pImmutableSamplers = NULL;
5991
5992 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5993 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5994 ds_layout_ci.pNext = NULL;
5995 ds_layout_ci.bindingCount = 1;
5996 ds_layout_ci.pBindings = &dsl_binding;
5997 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005998 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06005999 ASSERT_VK_SUCCESS(err);
6000
6001 VkDescriptorSet descriptorSet;
6002 VkDescriptorSetAllocateInfo alloc_info = {};
6003 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6004 alloc_info.descriptorSetCount = 1;
6005 alloc_info.descriptorPool = ds_pool;
6006 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006007 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006008 ASSERT_VK_SUCCESS(err);
6009
6010 // Create a buffer to update the descriptor with
6011 uint32_t qfi = 0;
6012 VkBufferCreateInfo buffCI = {};
6013 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6014 buffCI.size = 1024;
6015 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6016 buffCI.queueFamilyIndexCount = 1;
6017 buffCI.pQueueFamilyIndices = &qfi;
6018
6019 VkBuffer dyub;
6020 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6021 ASSERT_VK_SUCCESS(err);
6022
6023 // Attempt to update descriptor without binding memory to it
6024 VkDescriptorBufferInfo buffInfo = {};
6025 buffInfo.buffer = dyub;
6026 buffInfo.offset = 0;
6027 buffInfo.range = 1024;
6028
6029 VkWriteDescriptorSet descriptor_write;
6030 memset(&descriptor_write, 0, sizeof(descriptor_write));
6031 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6032 descriptor_write.dstSet = descriptorSet;
6033 descriptor_write.dstBinding = 0;
6034 descriptor_write.descriptorCount = 1;
6035 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6036 descriptor_write.pBufferInfo = &buffInfo;
6037
6038 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6039 m_errorMonitor->VerifyFound();
6040
6041 vkDestroyBuffer(m_device->device(), dyub, NULL);
6042 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6043 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6044}
6045
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006046TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006047 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006048 ASSERT_NO_FATAL_FAILURE(InitState());
6049 ASSERT_NO_FATAL_FAILURE(InitViewport());
6050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6051
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006052 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006053 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006054 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6055 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6056 pipeline_layout_ci.pushConstantRangeCount = 1;
6057 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6058
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006059 //
6060 // Check for invalid push constant ranges in pipeline layouts.
6061 //
6062 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006063 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006064 char const *msg;
6065 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006066
Karl Schultzc81037d2016-05-12 08:11:23 -06006067 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6068 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6069 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6070 "vkCreatePipelineLayout() call has push constants index 0 with "
6071 "size 0."},
6072 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6073 "vkCreatePipelineLayout() call has push constants index 0 with "
6074 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006075 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006076 "vkCreatePipelineLayout() call has push constants index 0 with "
6077 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006078 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006079 "vkCreatePipelineLayout() call has push constants index 0 with "
6080 "size 0."},
6081 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6082 "vkCreatePipelineLayout() call has push constants index 0 with "
6083 "offset 1. Offset must"},
6084 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6085 "vkCreatePipelineLayout() call has push constants index 0 "
6086 "with offset "},
6087 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6088 "vkCreatePipelineLayout() call has push constants "
6089 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006090 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006091 "vkCreatePipelineLayout() call has push constants index 0 "
6092 "with offset "},
6093 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6094 "vkCreatePipelineLayout() call has push "
6095 "constants index 0 with offset "},
6096 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6097 "vkCreatePipelineLayout() call has push "
6098 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006099 }};
6100
6101 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006102 for (const auto &iter : range_tests) {
6103 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6105 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006106 m_errorMonitor->VerifyFound();
6107 if (VK_SUCCESS == err) {
6108 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6109 }
6110 }
6111
6112 // Check for invalid stage flag
6113 pc_range.offset = 0;
6114 pc_range.size = 16;
6115 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006116 m_errorMonitor->SetDesiredFailureMsg(
6117 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6118 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006119 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006120 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006121 if (VK_SUCCESS == err) {
6122 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6123 }
6124
6125 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006126 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006127 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006128 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006129 char const *msg;
6130 };
6131
Karl Schultzc81037d2016-05-12 08:11:23 -06006132 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006133 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6134 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6135 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6136 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6137 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006138 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006139 {
6140 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6141 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6142 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6143 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6144 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006145 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006146 },
6147 {
6148 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6149 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6150 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6151 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6152 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006153 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006154 },
6155 {
6156 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6157 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6158 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6159 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6160 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006161 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006162 },
6163 {
6164 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6165 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6166 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6167 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6168 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006169 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006170 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006171
Karl Schultzc81037d2016-05-12 08:11:23 -06006172 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006173 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006174 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6176 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006177 m_errorMonitor->VerifyFound();
6178 if (VK_SUCCESS == err) {
6179 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6180 }
6181 }
6182
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006183 //
6184 // CmdPushConstants tests
6185 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006186 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006187
6188 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006189 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6190 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006191 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6192 "vkCmdPushConstants() call has push constants with size 1. Size "
6193 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006194 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006195 "vkCmdPushConstants() call has push constants with size 1. Size "
6196 "must be greater than zero and a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006197 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006198 "vkCmdPushConstants() call has push constants with offset 1. "
6199 "Offset must be a multiple of 4."},
6200 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6201 "vkCmdPushConstants() call has push constants with offset 1. "
6202 "Offset must be a multiple of 4."},
6203 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6204 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6205 "0x1 not within flag-matching ranges in pipeline layout"},
6206 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6207 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6208 "0x1 not within flag-matching ranges in pipeline layout"},
6209 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6210 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6211 "0x1 not within flag-matching ranges in pipeline layout"},
6212 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6213 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6214 "0x1 not within flag-matching ranges in pipeline layout"},
6215 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6216 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6217 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006218 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006219 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6220 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006221 }};
6222
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006223 BeginCommandBuffer();
6224
6225 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006226 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006227 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006228 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006229 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006230 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006231 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006232 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006233 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6235 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006236 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006237 m_errorMonitor->VerifyFound();
6238 }
6239
6240 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006242 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006243 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006244 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006245
Karl Schultzc81037d2016-05-12 08:11:23 -06006246 // overlapping range tests with cmd
6247 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6248 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6249 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6250 "0x1 not within flag-matching ranges in pipeline layout"},
6251 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6252 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6253 "0x1 not within flag-matching ranges in pipeline layout"},
6254 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6255 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6256 "0x1 not within flag-matching ranges in pipeline layout"},
6257 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006258 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006259 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006260 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6261 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006262 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006263 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006264 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006265 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006266 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006267 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6269 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006270 iter.range.size, dummy_values);
6271 m_errorMonitor->VerifyFound();
6272 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006273 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6274
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006275 EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006276}
6277
Karl Schultz6addd812016-02-02 17:17:23 -07006278TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006279 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006280 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006281
6282 ASSERT_NO_FATAL_FAILURE(InitState());
6283 ASSERT_NO_FATAL_FAILURE(InitViewport());
6284 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6285
Mike Stroyanb8a61002016-06-20 16:00:28 -06006286 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6287 VkImageTiling tiling;
6288 VkFormatProperties format_properties;
6289 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006290 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006291 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006292 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006293 tiling = VK_IMAGE_TILING_OPTIMAL;
6294 } else {
6295 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6296 "skipped.\n");
6297 return;
6298 }
6299
Tobin Ehlis559c6382015-11-05 09:52:49 -07006300 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6301 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006302 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6303 ds_type_count[0].descriptorCount = 10;
6304 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6305 ds_type_count[1].descriptorCount = 2;
6306 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6307 ds_type_count[2].descriptorCount = 2;
6308 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6309 ds_type_count[3].descriptorCount = 5;
6310 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6311 // type
6312 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6313 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6314 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006315
6316 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006317 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6318 ds_pool_ci.pNext = NULL;
6319 ds_pool_ci.maxSets = 5;
6320 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6321 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006322
6323 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006324 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006325 ASSERT_VK_SUCCESS(err);
6326
6327 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6328 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006329 dsl_binding[0].binding = 0;
6330 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6331 dsl_binding[0].descriptorCount = 5;
6332 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6333 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006334
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006335 // Create layout identical to set0 layout but w/ different stageFlags
6336 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006337 dsl_fs_stage_only.binding = 0;
6338 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6339 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006340 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6341 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006342 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006343 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006344 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6345 ds_layout_ci.pNext = NULL;
6346 ds_layout_ci.bindingCount = 1;
6347 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006348 static const uint32_t NUM_LAYOUTS = 4;
6349 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006350 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006351 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6352 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006354 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006355 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006356 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006357 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006358 dsl_binding[0].binding = 0;
6359 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006360 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006361 dsl_binding[1].binding = 1;
6362 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6363 dsl_binding[1].descriptorCount = 2;
6364 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6365 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006366 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006367 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006368 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006369 ASSERT_VK_SUCCESS(err);
6370 dsl_binding[0].binding = 0;
6371 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006372 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006373 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006374 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006375 ASSERT_VK_SUCCESS(err);
6376 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006377 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006378 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006379 ASSERT_VK_SUCCESS(err);
6380
6381 static const uint32_t NUM_SETS = 4;
6382 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6383 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006384 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006385 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006386 alloc_info.descriptorPool = ds_pool;
6387 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006388 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006389 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006390 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006391 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006392 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006393 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006394 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006395
6396 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006397 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6398 pipeline_layout_ci.pNext = NULL;
6399 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6400 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006401
6402 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006403 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006404 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006405 // Create pipelineLayout with only one setLayout
6406 pipeline_layout_ci.setLayoutCount = 1;
6407 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006408 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006409 ASSERT_VK_SUCCESS(err);
6410 // Create pipelineLayout with 2 descriptor setLayout at index 0
6411 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6412 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006413 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006414 ASSERT_VK_SUCCESS(err);
6415 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6416 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6417 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006419 ASSERT_VK_SUCCESS(err);
6420 // Create pipelineLayout with UB type, but stageFlags for FS only
6421 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6422 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006423 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006424 ASSERT_VK_SUCCESS(err);
6425 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6426 VkDescriptorSetLayout pl_bad_s0[2] = {};
6427 pl_bad_s0[0] = ds_layout_fs_only;
6428 pl_bad_s0[1] = ds_layout[1];
6429 pipeline_layout_ci.setLayoutCount = 2;
6430 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6431 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006432 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006433 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006434
6435 // Create a buffer to update the descriptor with
6436 uint32_t qfi = 0;
6437 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006438 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6439 buffCI.size = 1024;
6440 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6441 buffCI.queueFamilyIndexCount = 1;
6442 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006443
6444 VkBuffer dyub;
6445 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6446 ASSERT_VK_SUCCESS(err);
6447 // Correctly update descriptor to avoid "NOT_UPDATED" error
6448 static const uint32_t NUM_BUFFS = 5;
6449 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006450 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006451 buffInfo[i].buffer = dyub;
6452 buffInfo[i].offset = 0;
6453 buffInfo[i].range = 1024;
6454 }
Karl Schultz6addd812016-02-02 17:17:23 -07006455 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006456 const int32_t tex_width = 32;
6457 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006458 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006459 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6460 image_create_info.pNext = NULL;
6461 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6462 image_create_info.format = tex_format;
6463 image_create_info.extent.width = tex_width;
6464 image_create_info.extent.height = tex_height;
6465 image_create_info.extent.depth = 1;
6466 image_create_info.mipLevels = 1;
6467 image_create_info.arrayLayers = 1;
6468 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006469 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006470 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006471 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006472 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6473 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006474
Karl Schultz6addd812016-02-02 17:17:23 -07006475 VkMemoryRequirements memReqs;
6476 VkDeviceMemory imageMem;
6477 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006478 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006479 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6480 memAlloc.pNext = NULL;
6481 memAlloc.allocationSize = 0;
6482 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006483 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6484 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006485 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006486 ASSERT_TRUE(pass);
6487 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6488 ASSERT_VK_SUCCESS(err);
6489 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6490 ASSERT_VK_SUCCESS(err);
6491
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006492 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006493 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6494 image_view_create_info.image = image;
6495 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6496 image_view_create_info.format = tex_format;
6497 image_view_create_info.subresourceRange.layerCount = 1;
6498 image_view_create_info.subresourceRange.baseMipLevel = 0;
6499 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006500 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006501
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006502 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006503 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006504 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006505 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006506 imageInfo[0].imageView = view;
6507 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6508 imageInfo[1].imageView = view;
6509 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006510 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006511 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006512 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006513 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006514
6515 static const uint32_t NUM_SET_UPDATES = 3;
6516 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6517 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6518 descriptor_write[0].dstSet = descriptorSet[0];
6519 descriptor_write[0].dstBinding = 0;
6520 descriptor_write[0].descriptorCount = 5;
6521 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6522 descriptor_write[0].pBufferInfo = buffInfo;
6523 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6524 descriptor_write[1].dstSet = descriptorSet[1];
6525 descriptor_write[1].dstBinding = 0;
6526 descriptor_write[1].descriptorCount = 2;
6527 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6528 descriptor_write[1].pImageInfo = imageInfo;
6529 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6530 descriptor_write[2].dstSet = descriptorSet[1];
6531 descriptor_write[2].dstBinding = 1;
6532 descriptor_write[2].descriptorCount = 2;
6533 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006534 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006535
6536 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006537
Tobin Ehlis88452832015-12-03 09:40:56 -07006538 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006539 char const *vsSource = "#version 450\n"
6540 "\n"
6541 "out gl_PerVertex {\n"
6542 " vec4 gl_Position;\n"
6543 "};\n"
6544 "void main(){\n"
6545 " gl_Position = vec4(1);\n"
6546 "}\n";
6547 char const *fsSource = "#version 450\n"
6548 "\n"
6549 "layout(location=0) out vec4 x;\n"
6550 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6551 "void main(){\n"
6552 " x = vec4(bar.y);\n"
6553 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006554 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006556 VkPipelineObj pipe(m_device);
6557 pipe.AddShader(&vs);
6558 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006559 pipe.AddColorAttachment();
6560 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006561
6562 BeginCommandBuffer();
Tobin Ehlis88452832015-12-03 09:40:56 -07006563
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006564 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006565 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6566 // of PSO
6567 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6568 // cmd_pipeline.c
6569 // due to the fact that cmd_alloc_dset_data() has not been called in
6570 // cmd_bind_graphics_pipeline()
6571 // TODO : Want to cause various binding incompatibility issues here to test
6572 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006573 // First cause various verify_layout_compatibility() fails
6574 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006575 // verify_set_layout_compatibility fail cases:
6576 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline Layout Object ");
6578 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6579 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006580 m_errorMonitor->VerifyFound();
6581
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006582 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6584 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6585 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006586 m_errorMonitor->VerifyFound();
6587
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006588 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006589 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6590 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6592 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6593 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006594 m_errorMonitor->VerifyFound();
6595
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006596 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6597 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6599 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6600 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006601 m_errorMonitor->VerifyFound();
6602
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006603 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6604 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6606 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6607 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6608 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006609 m_errorMonitor->VerifyFound();
6610
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006611 // Cause INFO messages due to disturbing previously bound Sets
6612 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006613 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6614 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006615 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6617 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6618 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006619 m_errorMonitor->VerifyFound();
6620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6622 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006623 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6625 "any subsequent sets were disturbed ");
6626 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6627 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006628 m_errorMonitor->VerifyFound();
6629
Tobin Ehlis10fad692016-07-07 12:00:36 -06006630 // Now that we're done actively using the pipelineLayout that gfx pipeline
6631 // was created with, we should be able to delete it. Do that now to verify
6632 // that validation obeys pipelineLayout lifetime
6633 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6634
Tobin Ehlis88452832015-12-03 09:40:56 -07006635 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006636 // 1. Error due to not binding required set (we actually use same code as
6637 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006638 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6639 &descriptorSet[0], 0, NULL);
6640 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6641 &descriptorSet[1], 0, NULL);
6642 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 -07006643 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006644 m_errorMonitor->VerifyFound();
6645
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006646 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006647 // 2. Error due to bound set not being compatible with PSO's
6648 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006649 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6650 &descriptorSet[0], 0, NULL);
6651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006652 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006653 m_errorMonitor->VerifyFound();
6654
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006655 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006656 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006657 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6658 }
6659 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006660 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006661 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6662 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006663 vkFreeMemory(m_device->device(), imageMem, NULL);
6664 vkDestroyImage(m_device->device(), image, NULL);
6665 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006666}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006667
Karl Schultz6addd812016-02-02 17:17:23 -07006668TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006669
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6671 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006672
6673 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006674 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006675 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006676 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006677
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006678 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006679}
6680
Karl Schultz6addd812016-02-02 17:17:23 -07006681TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6682 VkResult err;
6683 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006684
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must specify a valid renderpass parameter.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006686
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006687 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006688
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006689 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006690 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006691 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006692 cmd.commandPool = m_commandPool;
6693 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006694 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006695
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006696 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006697 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006698
6699 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006700 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006701 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006702 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006703 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006704 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 -07006705 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006706
6707 // The error should be caught by validation of the BeginCommandBuffer call
6708 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6709
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006710 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006711 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006712}
6713
Karl Schultz6addd812016-02-02 17:17:23 -07006714TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006715 // Cause error due to Begin while recording CB
6716 // Then cause 2 errors for attempting to reset CB w/o having
6717 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6718 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006720
6721 ASSERT_NO_FATAL_FAILURE(InitState());
6722
6723 // Calls AllocateCommandBuffers
6724 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6725
Karl Schultz6addd812016-02-02 17:17:23 -07006726 // Force the failure by setting the Renderpass and Framebuffer fields with
6727 // (fake) data
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006728 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006729 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006730 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6731 cmd_buf_info.pNext = NULL;
6732 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006733 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006734
6735 // Begin CB to transition to recording state
6736 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6737 // Can't re-begin. This should trigger error
6738 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006739 m_errorMonitor->VerifyFound();
6740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to reset command buffer ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006742 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6743 // Reset attempt will trigger error due to incorrect CommandPool state
6744 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006745 m_errorMonitor->VerifyFound();
6746
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempts to implicitly reset cmdBuffer created from ");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006748 // Transition CB to RECORDED state
6749 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6750 // Now attempting to Begin will implicitly reset, which triggers error
6751 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006752 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006753}
6754
Karl Schultz6addd812016-02-02 17:17:23 -07006755TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006756 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006757 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006758
Mike Weiblencce7ec72016-10-17 19:33:05 -06006759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006760
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006761 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006763
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006764 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006765 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6766 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006767
6768 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006769 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6770 ds_pool_ci.pNext = NULL;
6771 ds_pool_ci.maxSets = 1;
6772 ds_pool_ci.poolSizeCount = 1;
6773 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006774
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006775 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006776 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006777 ASSERT_VK_SUCCESS(err);
6778
Tony Barboureb254902015-07-15 12:50:33 -06006779 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006780 dsl_binding.binding = 0;
6781 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6782 dsl_binding.descriptorCount = 1;
6783 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6784 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006785
Tony Barboureb254902015-07-15 12:50:33 -06006786 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006787 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6788 ds_layout_ci.pNext = NULL;
6789 ds_layout_ci.bindingCount = 1;
6790 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006791
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006792 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006794 ASSERT_VK_SUCCESS(err);
6795
6796 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006797 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006799 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006800 alloc_info.descriptorPool = ds_pool;
6801 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006802 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006803 ASSERT_VK_SUCCESS(err);
6804
Tony Barboureb254902015-07-15 12:50:33 -06006805 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006806 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6807 pipeline_layout_ci.setLayoutCount = 1;
6808 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006809
6810 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006811 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006812 ASSERT_VK_SUCCESS(err);
6813
Tobin Ehlise68360f2015-10-01 11:15:13 -06006814 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006815 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006816
6817 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006818 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6819 vp_state_ci.scissorCount = 1;
6820 vp_state_ci.pScissors = &sc;
6821 vp_state_ci.viewportCount = 1;
6822 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006823
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006824 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6825 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6826 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6827 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6828 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6829 rs_state_ci.depthClampEnable = VK_FALSE;
6830 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6831 rs_state_ci.depthBiasEnable = VK_FALSE;
6832
Tony Barboureb254902015-07-15 12:50:33 -06006833 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006834 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6835 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006836 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006837 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6838 gp_ci.layout = pipeline_layout;
6839 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006840
6841 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006842 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6843 pc_ci.initialDataSize = 0;
6844 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006845
6846 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006847 VkPipelineCache pipelineCache;
6848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006849 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006850 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006851 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006852
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006853 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006854
Chia-I Wuf7458c52015-10-26 21:10:41 +08006855 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6856 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6857 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6858 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006859}
Tobin Ehlis912df022015-09-17 08:46:18 -06006860/*// TODO : This test should be good, but needs Tess support in compiler to run
6861TEST_F(VkLayerTest, InvalidPatchControlPoints)
6862{
6863 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006864 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006865
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006867 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6868primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006869
Tobin Ehlis912df022015-09-17 08:46:18 -06006870 ASSERT_NO_FATAL_FAILURE(InitState());
6871 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006872
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006873 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006874 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006875 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006876
6877 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6878 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6879 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006880 ds_pool_ci.poolSizeCount = 1;
6881 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006882
6883 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006884 err = vkCreateDescriptorPool(m_device->device(),
6885VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006886 ASSERT_VK_SUCCESS(err);
6887
6888 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006889 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006890 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006891 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006892 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6893 dsl_binding.pImmutableSamplers = NULL;
6894
6895 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006896 ds_layout_ci.sType =
6897VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006898 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006899 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006900 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06006901
6902 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006903 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
6904&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006905 ASSERT_VK_SUCCESS(err);
6906
6907 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07006908 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
6909VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06006910 ASSERT_VK_SUCCESS(err);
6911
6912 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006913 pipeline_layout_ci.sType =
6914VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06006915 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006916 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006917 pipeline_layout_ci.pSetLayouts = &ds_layout;
6918
6919 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07006920 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
6921&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06006922 ASSERT_VK_SUCCESS(err);
6923
6924 VkPipelineShaderStageCreateInfo shaderStages[3];
6925 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
6926
Karl Schultz6addd812016-02-02 17:17:23 -07006927 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
6928this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006929 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07006930 VkShaderObj
6931tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
6932this);
6933 VkShaderObj
6934te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
6935this);
Tobin Ehlis912df022015-09-17 08:46:18 -06006936
Karl Schultz6addd812016-02-02 17:17:23 -07006937 shaderStages[0].sType =
6938VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006939 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006940 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006941 shaderStages[1].sType =
6942VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006943 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006944 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07006945 shaderStages[2].sType =
6946VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06006947 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06006948 shaderStages[2].shader = te.handle();
6949
6950 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006951 iaCI.sType =
6952VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08006953 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06006954
6955 VkPipelineTessellationStateCreateInfo tsCI = {};
6956 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
6957 tsCI.patchControlPoints = 0; // This will cause an error
6958
6959 VkGraphicsPipelineCreateInfo gp_ci = {};
6960 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6961 gp_ci.pNext = NULL;
6962 gp_ci.stageCount = 3;
6963 gp_ci.pStages = shaderStages;
6964 gp_ci.pVertexInputState = NULL;
6965 gp_ci.pInputAssemblyState = &iaCI;
6966 gp_ci.pTessellationState = &tsCI;
6967 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006968 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06006969 gp_ci.pMultisampleState = NULL;
6970 gp_ci.pDepthStencilState = NULL;
6971 gp_ci.pColorBlendState = NULL;
6972 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6973 gp_ci.layout = pipeline_layout;
6974 gp_ci.renderPass = renderPass();
6975
6976 VkPipelineCacheCreateInfo pc_ci = {};
6977 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6978 pc_ci.pNext = NULL;
6979 pc_ci.initialSize = 0;
6980 pc_ci.initialData = 0;
6981 pc_ci.maxSize = 0;
6982
6983 VkPipeline pipeline;
6984 VkPipelineCache pipelineCache;
6985
Karl Schultz6addd812016-02-02 17:17:23 -07006986 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
6987&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06006988 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07006989 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
6990&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06006991
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006992 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006993
Chia-I Wuf7458c52015-10-26 21:10:41 +08006994 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6995 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6996 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6997 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06006998}
6999*/
Tobin Ehlise68360f2015-10-01 11:15:13 -06007000// Set scissor and viewport counts to different numbers
Karl Schultz6addd812016-02-02 17:17:23 -07007001TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -07007002 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7005 "Gfx Pipeline viewport count (1) must match scissor count (0).");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007006
Tobin Ehlise68360f2015-10-01 11:15:13 -06007007 ASSERT_NO_FATAL_FAILURE(InitState());
7008 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007009
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007010 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007011 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7012 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007013
7014 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007015 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7016 ds_pool_ci.maxSets = 1;
7017 ds_pool_ci.poolSizeCount = 1;
7018 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007019
7020 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007021 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007022 ASSERT_VK_SUCCESS(err);
7023
7024 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007025 dsl_binding.binding = 0;
7026 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7027 dsl_binding.descriptorCount = 1;
7028 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007029
7030 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007031 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7032 ds_layout_ci.bindingCount = 1;
7033 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007034
7035 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007036 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007037 ASSERT_VK_SUCCESS(err);
7038
7039 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007040 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007041 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007042 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007043 alloc_info.descriptorPool = ds_pool;
7044 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007045 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007046 ASSERT_VK_SUCCESS(err);
7047
7048 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007049 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7050 pipeline_layout_ci.setLayoutCount = 1;
7051 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007052
7053 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007054 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007055 ASSERT_VK_SUCCESS(err);
7056
7057 VkViewport vp = {}; // Just need dummy vp to point to
7058
7059 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007060 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7061 vp_state_ci.scissorCount = 0;
7062 vp_state_ci.viewportCount = 1; // Count mismatch should cause error
7063 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007064
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007065 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7066 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7067 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7068 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7069 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7070 rs_state_ci.depthClampEnable = VK_FALSE;
7071 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7072 rs_state_ci.depthBiasEnable = VK_FALSE;
7073
Cody Northropeb3a6c12015-10-05 14:44:45 -06007074 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007075 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007076
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007077 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7078 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7079 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007080 shaderStages[0] = vs.GetStageCreateInfo();
7081 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007082
7083 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007084 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7085 gp_ci.stageCount = 2;
7086 gp_ci.pStages = shaderStages;
7087 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007088 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007089 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7090 gp_ci.layout = pipeline_layout;
7091 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007092
7093 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007094 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007095
7096 VkPipeline pipeline;
7097 VkPipelineCache pipelineCache;
7098
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007099 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007100 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007101 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007102
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007103 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007104
Chia-I Wuf7458c52015-10-26 21:10:41 +08007105 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7106 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7107 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7108 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007109}
Karl Schultz6addd812016-02-02 17:17:23 -07007110// Don't set viewport state in PSO. This is an error b/c we always need this
7111// state
Tobin Ehlisd332f282015-10-02 11:00:56 -06007112// for the counts even if the data is going to be set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007113TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Tobin Ehlise68360f2015-10-01 11:15:13 -06007114 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007115 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007116
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Gfx Pipeline pViewportState is null. Even if ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007118
Tobin Ehlise68360f2015-10-01 11:15:13 -06007119 ASSERT_NO_FATAL_FAILURE(InitState());
7120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007121
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007122 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007123 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7124 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007125
7126 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007127 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7128 ds_pool_ci.maxSets = 1;
7129 ds_pool_ci.poolSizeCount = 1;
7130 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007131
7132 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007133 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134 ASSERT_VK_SUCCESS(err);
7135
7136 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007137 dsl_binding.binding = 0;
7138 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7139 dsl_binding.descriptorCount = 1;
7140 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007141
7142 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007143 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7144 ds_layout_ci.bindingCount = 1;
7145 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007146
7147 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007148 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149 ASSERT_VK_SUCCESS(err);
7150
7151 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007152 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007153 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007154 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007155 alloc_info.descriptorPool = ds_pool;
7156 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007157 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007158 ASSERT_VK_SUCCESS(err);
7159
7160 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007161 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7162 pipeline_layout_ci.setLayoutCount = 1;
7163 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007164
7165 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007166 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007167 ASSERT_VK_SUCCESS(err);
7168
7169 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7170 // Set scissor as dynamic to avoid second error
7171 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007172 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7173 dyn_state_ci.dynamicStateCount = 1;
7174 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007175
Cody Northropeb3a6c12015-10-05 14:44:45 -06007176 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007177 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007178
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007179 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7180 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7181 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007182 shaderStages[0] = vs.GetStageCreateInfo();
7183 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007184
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007185 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7186 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7187 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7188 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7189 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7190 rs_state_ci.depthClampEnable = VK_FALSE;
7191 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7192 rs_state_ci.depthBiasEnable = VK_FALSE;
7193
Tobin Ehlise68360f2015-10-01 11:15:13 -06007194 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007195 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7196 gp_ci.stageCount = 2;
7197 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007198 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007199 gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state
7200 // should cause validation error
7201 gp_ci.pDynamicState = &dyn_state_ci;
7202 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7203 gp_ci.layout = pipeline_layout;
7204 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007205
7206 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007207 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007208
7209 VkPipeline pipeline;
7210 VkPipelineCache pipelineCache;
7211
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007212 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007213 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007214 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007215
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007216 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007217
Chia-I Wuf7458c52015-10-26 21:10:41 +08007218 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7219 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7220 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7221 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007222}
7223// Create PSO w/o non-zero viewportCount but no viewport data
Karl Schultz6addd812016-02-02 17:17:23 -07007224// Then run second test where dynamic scissor count doesn't match PSO scissor
7225// count
7226TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7227 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007228
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7230 "Gfx Pipeline viewportCount is 1, but pViewports is NULL. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007231
Tobin Ehlise68360f2015-10-01 11:15:13 -06007232 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007233
7234 if (!m_device->phy().features().multiViewport) {
7235 printf("Device does not support multiple viewports/scissors; skipped.\n");
7236 return;
7237 }
7238
Tobin Ehlise68360f2015-10-01 11:15:13 -06007239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007240
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007241 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007242 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7243 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007244
7245 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007246 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7247 ds_pool_ci.maxSets = 1;
7248 ds_pool_ci.poolSizeCount = 1;
7249 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007250
7251 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007252 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007253 ASSERT_VK_SUCCESS(err);
7254
7255 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007256 dsl_binding.binding = 0;
7257 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7258 dsl_binding.descriptorCount = 1;
7259 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007260
7261 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007262 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7263 ds_layout_ci.bindingCount = 1;
7264 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007265
7266 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007267 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007268 ASSERT_VK_SUCCESS(err);
7269
7270 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007271 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007272 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007273 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007274 alloc_info.descriptorPool = ds_pool;
7275 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007276 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007277 ASSERT_VK_SUCCESS(err);
7278
7279 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007280 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7281 pipeline_layout_ci.setLayoutCount = 1;
7282 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007283
7284 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007285 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007286 ASSERT_VK_SUCCESS(err);
7287
7288 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007289 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7290 vp_state_ci.viewportCount = 1;
7291 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7292 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007293 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007294
7295 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7296 // Set scissor as dynamic to avoid that error
7297 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007298 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7299 dyn_state_ci.dynamicStateCount = 1;
7300 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007301
Cody Northropeb3a6c12015-10-05 14:44:45 -06007302 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007303 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007304
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007305 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7306 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7307 // but add it to be able to run on more devices
Chia-I Wu28e06912015-10-31 00:31:16 +08007308 shaderStages[0] = vs.GetStageCreateInfo();
7309 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007310
Cody Northropf6622dc2015-10-06 10:33:21 -06007311 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7312 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7313 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007314 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007315 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007316 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007317 vi_ci.pVertexAttributeDescriptions = nullptr;
7318
7319 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7320 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7321 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7322
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007323 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007324 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Cody Northropf6622dc2015-10-06 10:33:21 -06007325 rs_ci.pNext = nullptr;
7326
Mark Youngc89c6312016-03-31 16:03:20 -06007327 VkPipelineColorBlendAttachmentState att = {};
7328 att.blendEnable = VK_FALSE;
7329 att.colorWriteMask = 0xf;
7330
Cody Northropf6622dc2015-10-06 10:33:21 -06007331 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7332 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7333 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007334 cb_ci.attachmentCount = 1;
7335 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007336
Tobin Ehlise68360f2015-10-01 11:15:13 -06007337 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007338 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7339 gp_ci.stageCount = 2;
7340 gp_ci.pStages = shaderStages;
7341 gp_ci.pVertexInputState = &vi_ci;
7342 gp_ci.pInputAssemblyState = &ia_ci;
7343 gp_ci.pViewportState = &vp_state_ci;
7344 gp_ci.pRasterizationState = &rs_ci;
7345 gp_ci.pColorBlendState = &cb_ci;
7346 gp_ci.pDynamicState = &dyn_state_ci;
7347 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7348 gp_ci.layout = pipeline_layout;
7349 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007350
7351 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007352 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007353
7354 VkPipeline pipeline;
7355 VkPipelineCache pipelineCache;
7356
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007357 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007358 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007359 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007361 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007362
Tobin Ehlisd332f282015-10-02 11:00:56 -06007363 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007364 // First need to successfully create the PSO from above by setting
7365 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007366 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 -07007367
7368 VkViewport vp = {}; // Just need dummy vp to point to
7369 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007370 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007371 ASSERT_VK_SUCCESS(err);
7372 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007373 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007374 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007375 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007376 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007377 Draw(1, 0, 0, 0);
7378
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007379 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007380
7381 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7382 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7383 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7384 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007385 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007386}
7387// Create PSO w/o non-zero scissorCount but no scissor data
7388// Then run second test where dynamic viewportCount doesn't match PSO
7389// viewportCount
7390TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7391 VkResult err;
7392
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007393 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 -07007394
7395 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007396
7397 if (!m_device->phy().features().multiViewport) {
7398 printf("Device does not support multiple viewports/scissors; skipped.\n");
7399 return;
7400 }
7401
Karl Schultz6addd812016-02-02 17:17:23 -07007402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7403
7404 VkDescriptorPoolSize ds_type_count = {};
7405 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7406 ds_type_count.descriptorCount = 1;
7407
7408 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7409 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7410 ds_pool_ci.maxSets = 1;
7411 ds_pool_ci.poolSizeCount = 1;
7412 ds_pool_ci.pPoolSizes = &ds_type_count;
7413
7414 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007415 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007416 ASSERT_VK_SUCCESS(err);
7417
7418 VkDescriptorSetLayoutBinding dsl_binding = {};
7419 dsl_binding.binding = 0;
7420 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7421 dsl_binding.descriptorCount = 1;
7422 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7423
7424 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7425 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7426 ds_layout_ci.bindingCount = 1;
7427 ds_layout_ci.pBindings = &dsl_binding;
7428
7429 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007430 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007431 ASSERT_VK_SUCCESS(err);
7432
7433 VkDescriptorSet descriptorSet;
7434 VkDescriptorSetAllocateInfo alloc_info = {};
7435 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7436 alloc_info.descriptorSetCount = 1;
7437 alloc_info.descriptorPool = ds_pool;
7438 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007439 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007440 ASSERT_VK_SUCCESS(err);
7441
7442 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7443 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7444 pipeline_layout_ci.setLayoutCount = 1;
7445 pipeline_layout_ci.pSetLayouts = &ds_layout;
7446
7447 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007448 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007449 ASSERT_VK_SUCCESS(err);
7450
7451 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7452 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7453 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007454 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007455 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007456 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007457
7458 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7459 // Set scissor as dynamic to avoid that error
7460 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7461 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7462 dyn_state_ci.dynamicStateCount = 1;
7463 dyn_state_ci.pDynamicStates = &vp_state;
7464
7465 VkPipelineShaderStageCreateInfo shaderStages[2];
7466 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7467
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007468 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7469 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
7470 // but add it to be able to run on more devices
Karl Schultz6addd812016-02-02 17:17:23 -07007471 shaderStages[0] = vs.GetStageCreateInfo();
7472 shaderStages[1] = fs.GetStageCreateInfo();
7473
7474 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7475 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7476 vi_ci.pNext = nullptr;
7477 vi_ci.vertexBindingDescriptionCount = 0;
7478 vi_ci.pVertexBindingDescriptions = nullptr;
7479 vi_ci.vertexAttributeDescriptionCount = 0;
7480 vi_ci.pVertexAttributeDescriptions = nullptr;
7481
7482 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7483 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7484 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7485
7486 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7487 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7488 rs_ci.pNext = nullptr;
7489
Mark Youngc89c6312016-03-31 16:03:20 -06007490 VkPipelineColorBlendAttachmentState att = {};
7491 att.blendEnable = VK_FALSE;
7492 att.colorWriteMask = 0xf;
7493
Karl Schultz6addd812016-02-02 17:17:23 -07007494 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7495 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7496 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007497 cb_ci.attachmentCount = 1;
7498 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007499
7500 VkGraphicsPipelineCreateInfo gp_ci = {};
7501 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7502 gp_ci.stageCount = 2;
7503 gp_ci.pStages = shaderStages;
7504 gp_ci.pVertexInputState = &vi_ci;
7505 gp_ci.pInputAssemblyState = &ia_ci;
7506 gp_ci.pViewportState = &vp_state_ci;
7507 gp_ci.pRasterizationState = &rs_ci;
7508 gp_ci.pColorBlendState = &cb_ci;
7509 gp_ci.pDynamicState = &dyn_state_ci;
7510 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7511 gp_ci.layout = pipeline_layout;
7512 gp_ci.renderPass = renderPass();
7513
7514 VkPipelineCacheCreateInfo pc_ci = {};
7515 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7516
7517 VkPipeline pipeline;
7518 VkPipelineCache pipelineCache;
7519
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007520 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007521 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007522 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007523
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007524 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007525
7526 // Now hit second fail case where we set scissor w/ different count than PSO
7527 // First need to successfully create the PSO from above by setting
7528 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007529 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 -06007530
Tobin Ehlisd332f282015-10-02 11:00:56 -06007531 VkRect2D sc = {}; // Just need dummy vp to point to
7532 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007533 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007534 ASSERT_VK_SUCCESS(err);
7535 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007536 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007537 VkViewport viewports[1] = {}; // don't care about data
Tobin Ehlisd332f282015-10-02 11:00:56 -06007538 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007539 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007540 Draw(1, 0, 0, 0);
7541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007542 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007543
Chia-I Wuf7458c52015-10-26 21:10:41 +08007544 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7545 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7546 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7547 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007548 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007549}
7550
Mark Young7394fdd2016-03-31 14:56:43 -06007551TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7552 VkResult err;
7553
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007555
7556 ASSERT_NO_FATAL_FAILURE(InitState());
7557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7558
7559 VkDescriptorPoolSize ds_type_count = {};
7560 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7561 ds_type_count.descriptorCount = 1;
7562
7563 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7564 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7565 ds_pool_ci.maxSets = 1;
7566 ds_pool_ci.poolSizeCount = 1;
7567 ds_pool_ci.pPoolSizes = &ds_type_count;
7568
7569 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007570 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007571 ASSERT_VK_SUCCESS(err);
7572
7573 VkDescriptorSetLayoutBinding dsl_binding = {};
7574 dsl_binding.binding = 0;
7575 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7576 dsl_binding.descriptorCount = 1;
7577 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7578
7579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7581 ds_layout_ci.bindingCount = 1;
7582 ds_layout_ci.pBindings = &dsl_binding;
7583
7584 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007585 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007586 ASSERT_VK_SUCCESS(err);
7587
7588 VkDescriptorSet descriptorSet;
7589 VkDescriptorSetAllocateInfo alloc_info = {};
7590 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7591 alloc_info.descriptorSetCount = 1;
7592 alloc_info.descriptorPool = ds_pool;
7593 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007594 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007595 ASSERT_VK_SUCCESS(err);
7596
7597 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7598 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7599 pipeline_layout_ci.setLayoutCount = 1;
7600 pipeline_layout_ci.pSetLayouts = &ds_layout;
7601
7602 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007604 ASSERT_VK_SUCCESS(err);
7605
7606 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7607 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7608 vp_state_ci.scissorCount = 1;
7609 vp_state_ci.pScissors = NULL;
7610 vp_state_ci.viewportCount = 1;
7611 vp_state_ci.pViewports = NULL;
7612
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007613 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007614 // Set scissor as dynamic to avoid that error
7615 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7616 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7617 dyn_state_ci.dynamicStateCount = 2;
7618 dyn_state_ci.pDynamicStates = dynamic_states;
7619
7620 VkPipelineShaderStageCreateInfo shaderStages[2];
7621 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7622
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007623 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7624 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007625 this); // TODO - We shouldn't need a fragment shader
7626 // but add it to be able to run on more devices
7627 shaderStages[0] = vs.GetStageCreateInfo();
7628 shaderStages[1] = fs.GetStageCreateInfo();
7629
7630 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7631 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7632 vi_ci.pNext = nullptr;
7633 vi_ci.vertexBindingDescriptionCount = 0;
7634 vi_ci.pVertexBindingDescriptions = nullptr;
7635 vi_ci.vertexAttributeDescriptionCount = 0;
7636 vi_ci.pVertexAttributeDescriptions = nullptr;
7637
7638 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7639 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7640 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7641
7642 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7643 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7644 rs_ci.pNext = nullptr;
7645
Mark Young47107952016-05-02 15:59:55 -06007646 // Check too low (line width of -1.0f).
7647 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007648
7649 VkPipelineColorBlendAttachmentState att = {};
7650 att.blendEnable = VK_FALSE;
7651 att.colorWriteMask = 0xf;
7652
7653 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7654 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7655 cb_ci.pNext = nullptr;
7656 cb_ci.attachmentCount = 1;
7657 cb_ci.pAttachments = &att;
7658
7659 VkGraphicsPipelineCreateInfo gp_ci = {};
7660 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7661 gp_ci.stageCount = 2;
7662 gp_ci.pStages = shaderStages;
7663 gp_ci.pVertexInputState = &vi_ci;
7664 gp_ci.pInputAssemblyState = &ia_ci;
7665 gp_ci.pViewportState = &vp_state_ci;
7666 gp_ci.pRasterizationState = &rs_ci;
7667 gp_ci.pColorBlendState = &cb_ci;
7668 gp_ci.pDynamicState = &dyn_state_ci;
7669 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7670 gp_ci.layout = pipeline_layout;
7671 gp_ci.renderPass = renderPass();
7672
7673 VkPipelineCacheCreateInfo pc_ci = {};
7674 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7675
7676 VkPipeline pipeline;
7677 VkPipelineCache pipelineCache;
7678
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007679 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007680 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007681 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007682
7683 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007684 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007685
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007687
7688 // Check too high (line width of 65536.0f).
7689 rs_ci.lineWidth = 65536.0f;
7690
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007691 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007692 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007693 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007694
7695 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007696 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007697
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007699
7700 dyn_state_ci.dynamicStateCount = 3;
7701
7702 rs_ci.lineWidth = 1.0f;
7703
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007704 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007705 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007706 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007707 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007708 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007709
7710 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007711 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007712 m_errorMonitor->VerifyFound();
7713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007715
7716 // Check too high with dynamic setting.
7717 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7718 m_errorMonitor->VerifyFound();
7719 EndCommandBuffer();
7720
7721 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7722 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7723 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7724 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007725 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007726}
7727
Karl Schultz6addd812016-02-02 17:17:23 -07007728TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007729 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7731 "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007732
7733 ASSERT_NO_FATAL_FAILURE(InitState());
7734 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007735
Tony Barbourfe3351b2015-07-28 10:17:20 -06007736 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007737 // Don't care about RenderPass handle b/c error should be flagged before
7738 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007739 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007740
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007741 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007742}
7743
Karl Schultz6addd812016-02-02 17:17:23 -07007744TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007745 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7747 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007748
7749 ASSERT_NO_FATAL_FAILURE(InitState());
7750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007751
Tony Barbourfe3351b2015-07-28 10:17:20 -06007752 BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007753 // Just create a dummy Renderpass that's non-NULL so we can get to the
7754 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007755 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007756
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007757 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007758}
7759
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007760TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
7761 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
7762 "the number of renderPass attachments that use loadOp"
7763 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
7764
7765 ASSERT_NO_FATAL_FAILURE(InitState());
7766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7767
7768 // Create a renderPass with a single attachment that uses loadOp CLEAR
7769 VkAttachmentReference attach = {};
7770 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7771 VkSubpassDescription subpass = {};
7772 subpass.inputAttachmentCount = 1;
7773 subpass.pInputAttachments = &attach;
7774 VkRenderPassCreateInfo rpci = {};
7775 rpci.subpassCount = 1;
7776 rpci.pSubpasses = &subpass;
7777 rpci.attachmentCount = 1;
7778 VkAttachmentDescription attach_desc = {};
7779 attach_desc.format = VK_FORMAT_UNDEFINED;
7780 // Set loadOp to CLEAR
7781 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7782 rpci.pAttachments = &attach_desc;
7783 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7784 VkRenderPass rp;
7785 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7786
7787 VkCommandBufferInheritanceInfo hinfo = {};
7788 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7789 hinfo.renderPass = VK_NULL_HANDLE;
7790 hinfo.subpass = 0;
7791 hinfo.framebuffer = VK_NULL_HANDLE;
7792 hinfo.occlusionQueryEnable = VK_FALSE;
7793 hinfo.queryFlags = 0;
7794 hinfo.pipelineStatistics = 0;
7795 VkCommandBufferBeginInfo info = {};
7796 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
7797 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7798 info.pInheritanceInfo = &hinfo;
7799
7800 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
7801 VkRenderPassBeginInfo rp_begin = {};
7802 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
7803 rp_begin.pNext = NULL;
7804 rp_begin.renderPass = renderPass();
7805 rp_begin.framebuffer = framebuffer();
7806 rp_begin.clearValueCount = 0; // Should be 1
7807
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has a clearValueCount of 0 but "
7809 "there must be at least 1 entries in "
7810 "pClearValues array to account for ");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007811
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007813
7814 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06007815
7816 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007817}
7818
Cody Northrop3bb4d962016-05-09 16:15:57 -06007819TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
7820
7821 TEST_DESCRIPTION("End a command buffer with an active render pass");
7822
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7824 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06007825
7826 ASSERT_NO_FATAL_FAILURE(InitState());
7827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7828
7829 // The framework's BeginCommandBuffer calls CreateRenderPass
7830 BeginCommandBuffer();
7831
7832 // Call directly into vkEndCommandBuffer instead of the
7833 // the framework's EndCommandBuffer, which inserts a
7834 // vkEndRenderPass
7835 vkEndCommandBuffer(m_commandBuffer->GetBufferHandle());
7836
7837 m_errorMonitor->VerifyFound();
7838
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007839 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
7840 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06007841}
7842
Karl Schultz6addd812016-02-02 17:17:23 -07007843TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007844 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7846 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007847
7848 ASSERT_NO_FATAL_FAILURE(InitState());
7849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007850
7851 // Renderpass is started here
7852 BeginCommandBuffer();
7853
7854 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007855 vk_testing::Buffer dstBuffer;
7856 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007857
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007858 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
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, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007864 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7866 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007867
7868 ASSERT_NO_FATAL_FAILURE(InitState());
7869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007870
7871 // Renderpass is started here
7872 BeginCommandBuffer();
7873
7874 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007875 vk_testing::Buffer dstBuffer;
7876 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007877
Karl Schultz6addd812016-02-02 17:17:23 -07007878 VkDeviceSize dstOffset = 0;
7879 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06007880 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007881
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007882 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007883
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007884 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007885}
7886
Karl Schultz6addd812016-02-02 17:17:23 -07007887TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007888 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7890 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007891
7892 ASSERT_NO_FATAL_FAILURE(InitState());
7893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007894
7895 // Renderpass is started here
7896 BeginCommandBuffer();
7897
Michael Lentine0a369f62016-02-03 16:51:46 -06007898 VkClearColorValue clear_color;
7899 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07007900 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
7901 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
7902 const int32_t tex_width = 32;
7903 const int32_t tex_height = 32;
7904 VkImageCreateInfo image_create_info = {};
7905 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
7906 image_create_info.pNext = NULL;
7907 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7908 image_create_info.format = tex_format;
7909 image_create_info.extent.width = tex_width;
7910 image_create_info.extent.height = tex_height;
7911 image_create_info.extent.depth = 1;
7912 image_create_info.mipLevels = 1;
7913 image_create_info.arrayLayers = 1;
7914 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
7915 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
7916 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007917
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007918 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007919 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007920
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007924
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007925 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007926}
7927
Karl Schultz6addd812016-02-02 17:17:23 -07007928TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007929 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7931 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007932
7933 ASSERT_NO_FATAL_FAILURE(InitState());
7934 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007935
7936 // Renderpass is started here
7937 BeginCommandBuffer();
7938
7939 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07007940 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007941 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
7942 image_create_info.imageType = VK_IMAGE_TYPE_2D;
7943 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
7944 image_create_info.extent.width = 64;
7945 image_create_info.extent.height = 64;
7946 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
7947 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007948
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007949 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007950 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007952 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007953
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007954 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
7955 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007956
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007957 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007958}
7959
Karl Schultz6addd812016-02-02 17:17:23 -07007960TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007961 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07007962 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
7965 "must be issued inside an active "
7966 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007967
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007968 ASSERT_NO_FATAL_FAILURE(InitState());
7969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007970
7971 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007972 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007973 ASSERT_VK_SUCCESS(err);
7974
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06007975 VkClearAttachment color_attachment;
7976 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
7977 color_attachment.clearValue.color.float32[0] = 0;
7978 color_attachment.clearValue.color.float32[1] = 0;
7979 color_attachment.clearValue.color.float32[2] = 0;
7980 color_attachment.clearValue.color.float32[3] = 0;
7981 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07007982 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007983 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007984
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007985 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06007986}
7987
Chris Forbes3b97e932016-09-07 11:29:24 +12007988TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
7989 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
7990 "called too many times in a renderpass instance");
7991
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
7993 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12007994
7995 ASSERT_NO_FATAL_FAILURE(InitState());
7996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7997
7998 BeginCommandBuffer();
7999
8000 // error here.
8001 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8002 m_errorMonitor->VerifyFound();
8003
8004 EndCommandBuffer();
8005}
8006
Chris Forbes6d624702016-09-07 13:57:05 +12008007TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8008 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8009 "called before the final subpass has been reached");
8010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8012 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008013
8014 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008015 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8016 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008018 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008019
8020 VkRenderPass rp;
8021 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8022 ASSERT_VK_SUCCESS(err);
8023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008024 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008025
8026 VkFramebuffer fb;
8027 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8028 ASSERT_VK_SUCCESS(err);
8029
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008030 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008032 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 +12008033
8034 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8035
8036 // Error here.
8037 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8038 m_errorMonitor->VerifyFound();
8039
8040 // Clean up.
8041 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8042 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8043}
8044
Karl Schultz9e66a292016-04-21 15:57:51 -06008045TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8046 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8048 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008049
8050 ASSERT_NO_FATAL_FAILURE(InitState());
8051 BeginCommandBuffer();
8052
8053 VkBufferMemoryBarrier buf_barrier = {};
8054 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8055 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8056 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8057 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8058 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8059 buf_barrier.buffer = VK_NULL_HANDLE;
8060 buf_barrier.offset = 0;
8061 buf_barrier.size = VK_WHOLE_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);
Karl Schultz9e66a292016-04-21 15:57:51 -06008064
8065 m_errorMonitor->VerifyFound();
8066}
8067
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008068TEST_F(VkLayerTest, InvalidBarriers) {
8069 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8070
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008072
8073 ASSERT_NO_FATAL_FAILURE(InitState());
8074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8075
8076 VkMemoryBarrier mem_barrier = {};
8077 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8078 mem_barrier.pNext = NULL;
8079 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8080 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8081 BeginCommandBuffer();
8082 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008083 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008084 &mem_barrier, 0, nullptr, 0, nullptr);
8085 m_errorMonitor->VerifyFound();
8086
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008088 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008089 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 -06008090 ASSERT_TRUE(image.initialized());
8091 VkImageMemoryBarrier img_barrier = {};
8092 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8093 img_barrier.pNext = NULL;
8094 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8095 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8096 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8097 // New layout can't be UNDEFINED
8098 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8099 img_barrier.image = image.handle();
8100 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8101 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8102 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8103 img_barrier.subresourceRange.baseArrayLayer = 0;
8104 img_barrier.subresourceRange.baseMipLevel = 0;
8105 img_barrier.subresourceRange.layerCount = 1;
8106 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008107 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8108 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008109 m_errorMonitor->VerifyFound();
8110 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8111
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8113 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008114 // baseArrayLayer + layerCount must be <= image's arrayLayers
8115 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008116 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8117 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008118 m_errorMonitor->VerifyFound();
8119 img_barrier.subresourceRange.baseArrayLayer = 0;
8120
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008122 // baseMipLevel + levelCount must be <= image's mipLevels
8123 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008124 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8125 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008126 m_errorMonitor->VerifyFound();
8127 img_barrier.subresourceRange.baseMipLevel = 0;
8128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008129 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 -06008130 vk_testing::Buffer buffer;
8131 buffer.init(*m_device, 256);
8132 VkBufferMemoryBarrier buf_barrier = {};
8133 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8134 buf_barrier.pNext = NULL;
8135 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8136 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8137 buf_barrier.buffer = buffer.handle();
8138 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8139 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8140 buf_barrier.offset = 0;
8141 buf_barrier.size = VK_WHOLE_SIZE;
8142 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008143 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8144 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008145 m_errorMonitor->VerifyFound();
8146 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008149 buf_barrier.offset = 257;
8150 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008151 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8152 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008153 m_errorMonitor->VerifyFound();
8154 buf_barrier.offset = 0;
8155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008157 buf_barrier.size = 257;
8158 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008159 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8160 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008161 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008162
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008163 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008164 m_errorMonitor->SetDesiredFailureMsg(
8165 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8166 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8167 m_errorMonitor->SetDesiredFailureMsg(
8168 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8169 "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 -06008170 VkDepthStencilObj ds_image(m_device);
8171 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8172 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008173 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8174 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008175 img_barrier.image = ds_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008176 // Use of COLOR aspect on DS image is error
8177 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008178 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8179 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008180 m_errorMonitor->VerifyFound();
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008181 // Now test depth-only
8182 VkFormatProperties format_props;
8183
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008184 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8185 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8187 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8189 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008190 VkDepthStencilObj d_image(m_device);
8191 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8192 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008193 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008194 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008195 img_barrier.image = d_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008196 // Use of COLOR aspect on depth image is error
8197 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8199 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008200 m_errorMonitor->VerifyFound();
8201 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008202 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8203 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008204 // Now test stencil-only
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8206 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008207 VkDepthStencilObj s_image(m_device);
8208 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8209 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008210 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008211 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008212 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008213 // Use of COLOR aspect on depth image is error
8214 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008215 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8216 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008217 m_errorMonitor->VerifyFound();
8218 }
8219 // Finally test color
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8221 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8223 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008224 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008225 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 -06008226 ASSERT_TRUE(c_image.initialized());
8227 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8228 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8229 img_barrier.image = c_image.handle();
8230 // Set aspect to depth (non-color)
8231 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008232 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8233 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008234 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008235}
8236
Tony Barbour18ba25c2016-09-29 13:42:40 -06008237TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8238 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8239
8240 m_errorMonitor->SetDesiredFailureMsg(
8241 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8242 "must have required access bit");
8243 ASSERT_NO_FATAL_FAILURE(InitState());
8244 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008245 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 -06008246 ASSERT_TRUE(image.initialized());
8247
8248 VkImageMemoryBarrier barrier = {};
8249 VkImageSubresourceRange range;
8250 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8251 barrier.srcAccessMask = 0;
8252 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8253 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8254 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8255 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8256 barrier.image = image.handle();
8257 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8258 range.baseMipLevel = 0;
8259 range.levelCount = 1;
8260 range.baseArrayLayer = 0;
8261 range.layerCount = 1;
8262 barrier.subresourceRange = range;
8263 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8264 cmdbuf.BeginCommandBuffer();
8265 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8266 &barrier);
8267 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8268 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8269 barrier.srcAccessMask = 0;
8270 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8271 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8272 &barrier);
8273
8274 m_errorMonitor->VerifyFound();
8275}
8276
Karl Schultz6addd812016-02-02 17:17:23 -07008277TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008278 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008279 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008280
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008282
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008283 ASSERT_NO_FATAL_FAILURE(InitState());
8284 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008285 uint32_t qfi = 0;
8286 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008287 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8288 buffCI.size = 1024;
8289 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8290 buffCI.queueFamilyIndexCount = 1;
8291 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008292
8293 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008294 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008295 ASSERT_VK_SUCCESS(err);
8296
8297 BeginCommandBuffer();
8298 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008299 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8300 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008301 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008302 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008304 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008305
Chia-I Wuf7458c52015-10-26 21:10:41 +08008306 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008307}
8308
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008309TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8310 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8312 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8313 "of the indices specified when the device was created, via the "
8314 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008315
8316 ASSERT_NO_FATAL_FAILURE(InitState());
8317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8318 VkBufferCreateInfo buffCI = {};
8319 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8320 buffCI.size = 1024;
8321 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8322 buffCI.queueFamilyIndexCount = 1;
8323 // Introduce failure by specifying invalid queue_family_index
8324 uint32_t qfi = 777;
8325 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008326 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008327
8328 VkBuffer ib;
8329 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8330
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008331 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008332 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008333}
8334
Karl Schultz6addd812016-02-02 17:17:23 -07008335TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008336TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008337 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008338
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008339 ASSERT_NO_FATAL_FAILURE(InitState());
8340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008341
Chris Forbesf29a84f2016-10-06 18:39:28 +13008342 // An empty primary command buffer
8343 VkCommandBufferObj cb(m_device, m_commandPool);
8344 cb.BeginCommandBuffer();
8345 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008346
Chris Forbesf29a84f2016-10-06 18:39:28 +13008347 m_commandBuffer->BeginCommandBuffer();
8348 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8349 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008350
Chris Forbesf29a84f2016-10-06 18:39:28 +13008351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8352 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008353 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008354}
8355
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008356TEST_F(VkLayerTest, DSUsageBitsErrors) {
8357 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8358 "that do not have correct usage bits sets.");
8359 VkResult err;
8360
8361 ASSERT_NO_FATAL_FAILURE(InitState());
8362 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8363 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8364 ds_type_count[i].type = VkDescriptorType(i);
8365 ds_type_count[i].descriptorCount = 1;
8366 }
8367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8369 ds_pool_ci.pNext = NULL;
8370 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8371 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8372 ds_pool_ci.pPoolSizes = ds_type_count;
8373
8374 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008375 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008376 ASSERT_VK_SUCCESS(err);
8377
8378 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008379 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008380 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8381 dsl_binding[i].binding = 0;
8382 dsl_binding[i].descriptorType = VkDescriptorType(i);
8383 dsl_binding[i].descriptorCount = 1;
8384 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8385 dsl_binding[i].pImmutableSamplers = NULL;
8386 }
8387
8388 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8389 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8390 ds_layout_ci.pNext = NULL;
8391 ds_layout_ci.bindingCount = 1;
8392 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8393 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8394 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008396 ASSERT_VK_SUCCESS(err);
8397 }
8398 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8399 VkDescriptorSetAllocateInfo alloc_info = {};
8400 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8401 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8402 alloc_info.descriptorPool = ds_pool;
8403 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008404 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008405 ASSERT_VK_SUCCESS(err);
8406
8407 // Create a buffer & bufferView to be used for invalid updates
8408 VkBufferCreateInfo buff_ci = {};
8409 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8410 // This usage is not valid for any descriptor type
8411 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8412 buff_ci.size = 256;
8413 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8414 VkBuffer buffer;
8415 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8416 ASSERT_VK_SUCCESS(err);
8417
8418 VkBufferViewCreateInfo buff_view_ci = {};
8419 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8420 buff_view_ci.buffer = buffer;
8421 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8422 buff_view_ci.range = VK_WHOLE_SIZE;
8423 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008424 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008425 ASSERT_VK_SUCCESS(err);
8426
8427 // Create an image to be used for invalid updates
8428 VkImageCreateInfo image_ci = {};
8429 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8430 image_ci.imageType = VK_IMAGE_TYPE_2D;
8431 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8432 image_ci.extent.width = 64;
8433 image_ci.extent.height = 64;
8434 image_ci.extent.depth = 1;
8435 image_ci.mipLevels = 1;
8436 image_ci.arrayLayers = 1;
8437 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8438 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8439 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8440 // This usage is not valid for any descriptor type
8441 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8442 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8443 VkImage image;
8444 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8445 ASSERT_VK_SUCCESS(err);
8446 // Bind memory to image
8447 VkMemoryRequirements mem_reqs;
8448 VkDeviceMemory image_mem;
8449 bool pass;
8450 VkMemoryAllocateInfo mem_alloc = {};
8451 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8452 mem_alloc.pNext = NULL;
8453 mem_alloc.allocationSize = 0;
8454 mem_alloc.memoryTypeIndex = 0;
8455 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8456 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008457 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008458 ASSERT_TRUE(pass);
8459 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8460 ASSERT_VK_SUCCESS(err);
8461 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8462 ASSERT_VK_SUCCESS(err);
8463 // Now create view for image
8464 VkImageViewCreateInfo image_view_ci = {};
8465 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8466 image_view_ci.image = image;
8467 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8468 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8469 image_view_ci.subresourceRange.layerCount = 1;
8470 image_view_ci.subresourceRange.baseArrayLayer = 0;
8471 image_view_ci.subresourceRange.levelCount = 1;
8472 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8473 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008475 ASSERT_VK_SUCCESS(err);
8476
8477 VkDescriptorBufferInfo buff_info = {};
8478 buff_info.buffer = buffer;
8479 VkDescriptorImageInfo img_info = {};
8480 img_info.imageView = image_view;
8481 VkWriteDescriptorSet descriptor_write = {};
8482 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8483 descriptor_write.dstBinding = 0;
8484 descriptor_write.descriptorCount = 1;
8485 descriptor_write.pTexelBufferView = &buff_view;
8486 descriptor_write.pBufferInfo = &buff_info;
8487 descriptor_write.pImageInfo = &img_info;
8488
8489 // These error messages align with VkDescriptorType struct
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008490 const char *error_msgs[] = {"", // placeholder, no error for SAMPLER descriptor
8491 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8492 " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.",
8493 " does not have VK_IMAGE_USAGE_STORAGE_BIT set.",
8494 " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.",
8495 " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.",
8496 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8497 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8498 " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.",
8499 " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.",
8500 " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008501 // Start loop at 1 as SAMPLER desc type has no usage bit error
8502 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8503 descriptor_write.descriptorType = VkDescriptorType(i);
8504 descriptor_write.dstSet = descriptor_sets[i];
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msgs[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008506
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008507 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008508
8509 m_errorMonitor->VerifyFound();
8510 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8511 }
8512 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8513 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008514 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008515 vkDestroyImageView(m_device->device(), image_view, NULL);
8516 vkDestroyBuffer(m_device->device(), buffer, NULL);
8517 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 vkFreeDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008519 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8520}
8521
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008522TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008523 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8524 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8525 "1. offset value greater than buffer size\n"
8526 "2. range value of 0\n"
8527 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008528 VkResult err;
8529
8530 ASSERT_NO_FATAL_FAILURE(InitState());
8531 VkDescriptorPoolSize ds_type_count = {};
8532 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8533 ds_type_count.descriptorCount = 1;
8534
8535 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8536 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8537 ds_pool_ci.pNext = NULL;
8538 ds_pool_ci.maxSets = 1;
8539 ds_pool_ci.poolSizeCount = 1;
8540 ds_pool_ci.pPoolSizes = &ds_type_count;
8541
8542 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008543 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008544 ASSERT_VK_SUCCESS(err);
8545
8546 // Create layout with single uniform buffer descriptor
8547 VkDescriptorSetLayoutBinding dsl_binding = {};
8548 dsl_binding.binding = 0;
8549 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8550 dsl_binding.descriptorCount = 1;
8551 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8552 dsl_binding.pImmutableSamplers = NULL;
8553
8554 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8555 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8556 ds_layout_ci.pNext = NULL;
8557 ds_layout_ci.bindingCount = 1;
8558 ds_layout_ci.pBindings = &dsl_binding;
8559 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008560 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008561 ASSERT_VK_SUCCESS(err);
8562
8563 VkDescriptorSet descriptor_set = {};
8564 VkDescriptorSetAllocateInfo alloc_info = {};
8565 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8566 alloc_info.descriptorSetCount = 1;
8567 alloc_info.descriptorPool = ds_pool;
8568 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008569 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008570 ASSERT_VK_SUCCESS(err);
8571
8572 // Create a buffer to be used for invalid updates
8573 VkBufferCreateInfo buff_ci = {};
8574 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8575 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8576 buff_ci.size = 256;
8577 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8578 VkBuffer buffer;
8579 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8580 ASSERT_VK_SUCCESS(err);
8581 // Have to bind memory to buffer before descriptor update
8582 VkMemoryAllocateInfo mem_alloc = {};
8583 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8584 mem_alloc.pNext = NULL;
8585 mem_alloc.allocationSize = 256;
8586 mem_alloc.memoryTypeIndex = 0;
8587
8588 VkMemoryRequirements mem_reqs;
8589 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008590 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008591 if (!pass) {
8592 vkDestroyBuffer(m_device->device(), buffer, NULL);
8593 return;
8594 }
8595
8596 VkDeviceMemory mem;
8597 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
8598 ASSERT_VK_SUCCESS(err);
8599 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8600 ASSERT_VK_SUCCESS(err);
8601
8602 VkDescriptorBufferInfo buff_info = {};
8603 buff_info.buffer = buffer;
8604 // First make offset 1 larger than buffer size
8605 buff_info.offset = 257;
8606 buff_info.range = VK_WHOLE_SIZE;
8607 VkWriteDescriptorSet descriptor_write = {};
8608 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8609 descriptor_write.dstBinding = 0;
8610 descriptor_write.descriptorCount = 1;
8611 descriptor_write.pTexelBufferView = nullptr;
8612 descriptor_write.pBufferInfo = &buff_info;
8613 descriptor_write.pImageInfo = nullptr;
8614
8615 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8616 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " offset of 257 is greater than buffer ");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008618
8619 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8620
8621 m_errorMonitor->VerifyFound();
8622 // Now cause error due to range of 0
8623 buff_info.offset = 0;
8624 buff_info.range = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8626 " range is not VK_WHOLE_SIZE and is zero, which is not allowed.");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008627
8628 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8629
8630 m_errorMonitor->VerifyFound();
8631 // Now cause error due to range exceeding buffer size - offset
8632 buff_info.offset = 128;
8633 buff_info.range = 200;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008634 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 -06008635
8636 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8637
8638 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06008639 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008640 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8641 vkDestroyBuffer(m_device->device(), buffer, NULL);
8642 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8643 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8644}
8645
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008646TEST_F(VkLayerTest, DSAspectBitsErrors) {
8647 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
8648 // are set, but could expand this test to hit more cases.
8649 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
8650 "that do not have correct aspect bits sets.");
8651 VkResult err;
8652
8653 ASSERT_NO_FATAL_FAILURE(InitState());
8654 VkDescriptorPoolSize ds_type_count = {};
8655 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8656 ds_type_count.descriptorCount = 1;
8657
8658 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8659 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8660 ds_pool_ci.pNext = NULL;
8661 ds_pool_ci.maxSets = 5;
8662 ds_pool_ci.poolSizeCount = 1;
8663 ds_pool_ci.pPoolSizes = &ds_type_count;
8664
8665 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008666 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008667 ASSERT_VK_SUCCESS(err);
8668
8669 VkDescriptorSetLayoutBinding dsl_binding = {};
8670 dsl_binding.binding = 0;
8671 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8672 dsl_binding.descriptorCount = 1;
8673 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8674 dsl_binding.pImmutableSamplers = NULL;
8675
8676 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8677 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8678 ds_layout_ci.pNext = NULL;
8679 ds_layout_ci.bindingCount = 1;
8680 ds_layout_ci.pBindings = &dsl_binding;
8681 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008682 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008683 ASSERT_VK_SUCCESS(err);
8684
8685 VkDescriptorSet descriptor_set = {};
8686 VkDescriptorSetAllocateInfo alloc_info = {};
8687 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8688 alloc_info.descriptorSetCount = 1;
8689 alloc_info.descriptorPool = ds_pool;
8690 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008691 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008692 ASSERT_VK_SUCCESS(err);
8693
8694 // Create an image to be used for invalid updates
8695 VkImageCreateInfo image_ci = {};
8696 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8697 image_ci.imageType = VK_IMAGE_TYPE_2D;
8698 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8699 image_ci.extent.width = 64;
8700 image_ci.extent.height = 64;
8701 image_ci.extent.depth = 1;
8702 image_ci.mipLevels = 1;
8703 image_ci.arrayLayers = 1;
8704 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8705 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8706 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8707 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
8708 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8709 VkImage image;
8710 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8711 ASSERT_VK_SUCCESS(err);
8712 // Bind memory to image
8713 VkMemoryRequirements mem_reqs;
8714 VkDeviceMemory image_mem;
8715 bool pass;
8716 VkMemoryAllocateInfo mem_alloc = {};
8717 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8718 mem_alloc.pNext = NULL;
8719 mem_alloc.allocationSize = 0;
8720 mem_alloc.memoryTypeIndex = 0;
8721 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8722 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008723 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008724 ASSERT_TRUE(pass);
8725 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8726 ASSERT_VK_SUCCESS(err);
8727 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8728 ASSERT_VK_SUCCESS(err);
8729 // Now create view for image
8730 VkImageViewCreateInfo image_view_ci = {};
8731 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8732 image_view_ci.image = image;
8733 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
8734 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8735 image_view_ci.subresourceRange.layerCount = 1;
8736 image_view_ci.subresourceRange.baseArrayLayer = 0;
8737 image_view_ci.subresourceRange.levelCount = 1;
8738 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008740
8741 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008742 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008743 ASSERT_VK_SUCCESS(err);
8744
8745 VkDescriptorImageInfo img_info = {};
8746 img_info.imageView = image_view;
8747 VkWriteDescriptorSet descriptor_write = {};
8748 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8749 descriptor_write.dstBinding = 0;
8750 descriptor_write.descriptorCount = 1;
8751 descriptor_write.pTexelBufferView = NULL;
8752 descriptor_write.pBufferInfo = NULL;
8753 descriptor_write.pImageInfo = &img_info;
8754 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
8755 descriptor_write.dstSet = descriptor_set;
8756 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
8757 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06008759
8760 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8761
8762 m_errorMonitor->VerifyFound();
8763 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8764 vkDestroyImage(m_device->device(), image, NULL);
8765 vkFreeMemory(m_device->device(), image_mem, NULL);
8766 vkDestroyImageView(m_device->device(), image_view, NULL);
8767 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
8768 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8769}
8770
Karl Schultz6addd812016-02-02 17:17:23 -07008771TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008772 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07008773 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008774
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8776 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
8777 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008778
Tobin Ehlis3b780662015-05-28 12:11:26 -06008779 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008780 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008781 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008782 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8783 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008784
8785 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008786 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8787 ds_pool_ci.pNext = NULL;
8788 ds_pool_ci.maxSets = 1;
8789 ds_pool_ci.poolSizeCount = 1;
8790 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008791
Tobin Ehlis3b780662015-05-28 12:11:26 -06008792 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008793 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008794 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06008795 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008796 dsl_binding.binding = 0;
8797 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8798 dsl_binding.descriptorCount = 1;
8799 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8800 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008801
Tony Barboureb254902015-07-15 12:50:33 -06008802 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008803 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8804 ds_layout_ci.pNext = NULL;
8805 ds_layout_ci.bindingCount = 1;
8806 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008807
Tobin Ehlis3b780662015-05-28 12:11:26 -06008808 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008809 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008810 ASSERT_VK_SUCCESS(err);
8811
8812 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008813 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008814 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008815 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008816 alloc_info.descriptorPool = ds_pool;
8817 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008818 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008819 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008820
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008821 VkSamplerCreateInfo sampler_ci = {};
8822 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8823 sampler_ci.pNext = NULL;
8824 sampler_ci.magFilter = VK_FILTER_NEAREST;
8825 sampler_ci.minFilter = VK_FILTER_NEAREST;
8826 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8827 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8828 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8829 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8830 sampler_ci.mipLodBias = 1.0;
8831 sampler_ci.anisotropyEnable = VK_FALSE;
8832 sampler_ci.maxAnisotropy = 1;
8833 sampler_ci.compareEnable = VK_FALSE;
8834 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
8835 sampler_ci.minLod = 1.0;
8836 sampler_ci.maxLod = 1.0;
8837 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
8838 sampler_ci.unnormalizedCoordinates = VK_FALSE;
8839 VkSampler sampler;
8840 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
8841 ASSERT_VK_SUCCESS(err);
8842
8843 VkDescriptorImageInfo info = {};
8844 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008845
8846 VkWriteDescriptorSet descriptor_write;
8847 memset(&descriptor_write, 0, sizeof(descriptor_write));
8848 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008849 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008850 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008851 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008852 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06008853 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008854
8855 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8856
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008857 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008858
Chia-I Wuf7458c52015-10-26 21:10:41 +08008859 vkDestroySampler(m_device->device(), sampler, NULL);
8860 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8861 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008862}
8863
Karl Schultz6addd812016-02-02 17:17:23 -07008864TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008865 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07008866 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8869 " binding #0 with 1 total descriptors but update of 1 descriptors "
8870 "starting at binding offset of 0 combined with update array element "
8871 "offset of 1 oversteps the size of this descriptor set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008872
Tobin Ehlis3b780662015-05-28 12:11:26 -06008873 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008874 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008875 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008876 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8877 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008878
8879 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008880 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8881 ds_pool_ci.pNext = NULL;
8882 ds_pool_ci.maxSets = 1;
8883 ds_pool_ci.poolSizeCount = 1;
8884 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06008885
Tobin Ehlis3b780662015-05-28 12:11:26 -06008886 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008887 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008888 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008889
Tony Barboureb254902015-07-15 12:50:33 -06008890 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008891 dsl_binding.binding = 0;
8892 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8893 dsl_binding.descriptorCount = 1;
8894 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8895 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008896
8897 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008898 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8899 ds_layout_ci.pNext = NULL;
8900 ds_layout_ci.bindingCount = 1;
8901 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06008902
Tobin Ehlis3b780662015-05-28 12:11:26 -06008903 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008904 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008905 ASSERT_VK_SUCCESS(err);
8906
8907 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008908 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008909 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008910 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008911 alloc_info.descriptorPool = ds_pool;
8912 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008913 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008914 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008915
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008916 // Correctly update descriptor to avoid "NOT_UPDATED" error
8917 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008918 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06008919 buff_info.offset = 0;
8920 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008921
8922 VkWriteDescriptorSet descriptor_write;
8923 memset(&descriptor_write, 0, sizeof(descriptor_write));
8924 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008925 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008926 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08008927 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06008928 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8929 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08008930
8931 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
8932
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008933 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008934
Chia-I Wuf7458c52015-10-26 21:10:41 +08008935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008937}
8938
Karl Schultz6addd812016-02-02 17:17:23 -07008939TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
8940 // Create layout w/ count of 1 and attempt update to that layout w/ binding
8941 // index 2
8942 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " does not have binding 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008945
Tobin Ehlis3b780662015-05-28 12:11:26 -06008946 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07008947 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008948 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008949 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8950 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06008951
8952 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008953 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8954 ds_pool_ci.pNext = NULL;
8955 ds_pool_ci.maxSets = 1;
8956 ds_pool_ci.poolSizeCount = 1;
8957 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06008958
Tobin Ehlis3b780662015-05-28 12:11:26 -06008959 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008960 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008961 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008962
Tony Barboureb254902015-07-15 12:50:33 -06008963 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008964 dsl_binding.binding = 0;
8965 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8966 dsl_binding.descriptorCount = 1;
8967 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8968 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06008969
8970 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008971 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8972 ds_layout_ci.pNext = NULL;
8973 ds_layout_ci.bindingCount = 1;
8974 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06008975 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008977 ASSERT_VK_SUCCESS(err);
8978
8979 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008980 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008982 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008983 alloc_info.descriptorPool = ds_pool;
8984 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008986 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06008987
Tony Barboureb254902015-07-15 12:50:33 -06008988 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008989 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
8990 sampler_ci.pNext = NULL;
8991 sampler_ci.magFilter = VK_FILTER_NEAREST;
8992 sampler_ci.minFilter = VK_FILTER_NEAREST;
8993 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
8994 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8995 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8996 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
8997 sampler_ci.mipLodBias = 1.0;
8998 sampler_ci.anisotropyEnable = VK_FALSE;
8999 sampler_ci.maxAnisotropy = 1;
9000 sampler_ci.compareEnable = VK_FALSE;
9001 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9002 sampler_ci.minLod = 1.0;
9003 sampler_ci.maxLod = 1.0;
9004 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9005 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009006
Tobin Ehlis3b780662015-05-28 12:11:26 -06009007 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009008 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009009 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009010
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009011 VkDescriptorImageInfo info = {};
9012 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009013
9014 VkWriteDescriptorSet descriptor_write;
9015 memset(&descriptor_write, 0, sizeof(descriptor_write));
9016 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009017 descriptor_write.dstSet = descriptorSet;
9018 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009019 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009020 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009021 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009022 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009023
9024 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9025
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009026 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009027
Chia-I Wuf7458c52015-10-26 21:10:41 +08009028 vkDestroySampler(m_device->device(), sampler, NULL);
9029 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9030 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009031}
9032
Karl Schultz6addd812016-02-02 17:17:23 -07009033TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9034 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9035 // types
9036 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009037
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009038 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 -06009039
Tobin Ehlis3b780662015-05-28 12:11:26 -06009040 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009041
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009042 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009043 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9044 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009045
9046 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009047 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9048 ds_pool_ci.pNext = NULL;
9049 ds_pool_ci.maxSets = 1;
9050 ds_pool_ci.poolSizeCount = 1;
9051 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009052
Tobin Ehlis3b780662015-05-28 12:11:26 -06009053 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009054 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009055 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009056 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009057 dsl_binding.binding = 0;
9058 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9059 dsl_binding.descriptorCount = 1;
9060 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9061 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009062
Tony Barboureb254902015-07-15 12:50:33 -06009063 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009064 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9065 ds_layout_ci.pNext = NULL;
9066 ds_layout_ci.bindingCount = 1;
9067 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009068
Tobin Ehlis3b780662015-05-28 12:11:26 -06009069 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009070 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009071 ASSERT_VK_SUCCESS(err);
9072
9073 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009074 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009075 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009076 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009077 alloc_info.descriptorPool = ds_pool;
9078 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009079 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009080 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009081
Tony Barboureb254902015-07-15 12:50:33 -06009082 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009083 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9084 sampler_ci.pNext = NULL;
9085 sampler_ci.magFilter = VK_FILTER_NEAREST;
9086 sampler_ci.minFilter = VK_FILTER_NEAREST;
9087 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9088 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9089 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9090 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9091 sampler_ci.mipLodBias = 1.0;
9092 sampler_ci.anisotropyEnable = VK_FALSE;
9093 sampler_ci.maxAnisotropy = 1;
9094 sampler_ci.compareEnable = VK_FALSE;
9095 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9096 sampler_ci.minLod = 1.0;
9097 sampler_ci.maxLod = 1.0;
9098 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9099 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009100 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009101 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009102 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009103
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009104 VkDescriptorImageInfo info = {};
9105 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009106
9107 VkWriteDescriptorSet descriptor_write;
9108 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009109 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009110 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009111 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009112 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009113 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009114 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009115
9116 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9117
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009118 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009119
Chia-I Wuf7458c52015-10-26 21:10:41 +08009120 vkDestroySampler(m_device->device(), sampler, NULL);
9121 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009123}
9124
Karl Schultz6addd812016-02-02 17:17:23 -07009125TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009126 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009127 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009128
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9130 "Attempted write update to sampler descriptor with invalid sampler");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009131
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009132 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009133 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9134 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009135 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009136 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9137 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009138
9139 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009140 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9141 ds_pool_ci.pNext = NULL;
9142 ds_pool_ci.maxSets = 1;
9143 ds_pool_ci.poolSizeCount = 1;
9144 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009145
9146 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009147 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009148 ASSERT_VK_SUCCESS(err);
9149
9150 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009151 dsl_binding.binding = 0;
9152 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9153 dsl_binding.descriptorCount = 1;
9154 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9155 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009156
9157 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009158 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9159 ds_layout_ci.pNext = NULL;
9160 ds_layout_ci.bindingCount = 1;
9161 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009162 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009163 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009164 ASSERT_VK_SUCCESS(err);
9165
9166 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009167 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009168 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009169 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009170 alloc_info.descriptorPool = ds_pool;
9171 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009172 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009173 ASSERT_VK_SUCCESS(err);
9174
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009175 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009176
9177 VkDescriptorImageInfo descriptor_info;
9178 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9179 descriptor_info.sampler = sampler;
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_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 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9195 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009196}
9197
Karl Schultz6addd812016-02-02 17:17:23 -07009198TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9199 // Create a single combined Image/Sampler descriptor and send it an invalid
9200 // imageView
9201 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009202
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to combined "
9204 "image sampler descriptor failed due "
9205 "to: Invalid VkImageView:");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009206
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009207 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009208 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009209 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9210 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009211
9212 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009213 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9214 ds_pool_ci.pNext = NULL;
9215 ds_pool_ci.maxSets = 1;
9216 ds_pool_ci.poolSizeCount = 1;
9217 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009218
9219 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009220 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009221 ASSERT_VK_SUCCESS(err);
9222
9223 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009224 dsl_binding.binding = 0;
9225 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9226 dsl_binding.descriptorCount = 1;
9227 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9228 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009229
9230 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009231 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9232 ds_layout_ci.pNext = NULL;
9233 ds_layout_ci.bindingCount = 1;
9234 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009235 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009236 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009237 ASSERT_VK_SUCCESS(err);
9238
9239 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009240 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009241 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009242 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009243 alloc_info.descriptorPool = ds_pool;
9244 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009245 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009246 ASSERT_VK_SUCCESS(err);
9247
9248 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009249 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9250 sampler_ci.pNext = NULL;
9251 sampler_ci.magFilter = VK_FILTER_NEAREST;
9252 sampler_ci.minFilter = VK_FILTER_NEAREST;
9253 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9254 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9255 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9256 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9257 sampler_ci.mipLodBias = 1.0;
9258 sampler_ci.anisotropyEnable = VK_FALSE;
9259 sampler_ci.maxAnisotropy = 1;
9260 sampler_ci.compareEnable = VK_FALSE;
9261 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9262 sampler_ci.minLod = 1.0;
9263 sampler_ci.maxLod = 1.0;
9264 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9265 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009266
9267 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009268 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009269 ASSERT_VK_SUCCESS(err);
9270
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009271 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009272
9273 VkDescriptorImageInfo descriptor_info;
9274 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9275 descriptor_info.sampler = sampler;
9276 descriptor_info.imageView = view;
9277
9278 VkWriteDescriptorSet descriptor_write;
9279 memset(&descriptor_write, 0, sizeof(descriptor_write));
9280 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009281 descriptor_write.dstSet = descriptorSet;
9282 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009283 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009284 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9285 descriptor_write.pImageInfo = &descriptor_info;
9286
9287 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9288
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009289 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009290
Chia-I Wuf7458c52015-10-26 21:10:41 +08009291 vkDestroySampler(m_device->device(), sampler, NULL);
9292 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9293 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009294}
9295
Karl Schultz6addd812016-02-02 17:17:23 -07009296TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9297 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9298 // into the other
9299 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9302 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9303 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009304
Tobin Ehlis04356f92015-10-27 16:35:27 -06009305 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009306 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009307 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009308 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9309 ds_type_count[0].descriptorCount = 1;
9310 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9311 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009312
9313 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009314 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9315 ds_pool_ci.pNext = NULL;
9316 ds_pool_ci.maxSets = 1;
9317 ds_pool_ci.poolSizeCount = 2;
9318 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009319
9320 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009321 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009322 ASSERT_VK_SUCCESS(err);
9323 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009324 dsl_binding[0].binding = 0;
9325 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9326 dsl_binding[0].descriptorCount = 1;
9327 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9328 dsl_binding[0].pImmutableSamplers = NULL;
9329 dsl_binding[1].binding = 1;
9330 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9331 dsl_binding[1].descriptorCount = 1;
9332 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9333 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009334
9335 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009336 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9337 ds_layout_ci.pNext = NULL;
9338 ds_layout_ci.bindingCount = 2;
9339 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009340
9341 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009342 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009343 ASSERT_VK_SUCCESS(err);
9344
9345 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009346 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009347 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009348 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009349 alloc_info.descriptorPool = ds_pool;
9350 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009351 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009352 ASSERT_VK_SUCCESS(err);
9353
9354 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009355 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9356 sampler_ci.pNext = NULL;
9357 sampler_ci.magFilter = VK_FILTER_NEAREST;
9358 sampler_ci.minFilter = VK_FILTER_NEAREST;
9359 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9360 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9361 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9362 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9363 sampler_ci.mipLodBias = 1.0;
9364 sampler_ci.anisotropyEnable = VK_FALSE;
9365 sampler_ci.maxAnisotropy = 1;
9366 sampler_ci.compareEnable = VK_FALSE;
9367 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9368 sampler_ci.minLod = 1.0;
9369 sampler_ci.maxLod = 1.0;
9370 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9371 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009372
9373 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009374 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009375 ASSERT_VK_SUCCESS(err);
9376
9377 VkDescriptorImageInfo info = {};
9378 info.sampler = sampler;
9379
9380 VkWriteDescriptorSet descriptor_write;
9381 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9382 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009383 descriptor_write.dstSet = descriptorSet;
9384 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009385 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009386 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9387 descriptor_write.pImageInfo = &info;
9388 // This write update should succeed
9389 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9390 // Now perform a copy update that fails due to type mismatch
9391 VkCopyDescriptorSet copy_ds_update;
9392 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9393 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9394 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009395 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009396 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009397 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009398 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009399 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9400
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009401 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009402 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009403 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 -06009404 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9405 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9406 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009407 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009408 copy_ds_update.dstSet = descriptorSet;
9409 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009410 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009411 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9412
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009413 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009414
Tobin Ehlis04356f92015-10-27 16:35:27 -06009415 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9417 "update array offset of 0 and update of "
9418 "5 descriptors oversteps total number "
9419 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009420
Tobin Ehlis04356f92015-10-27 16:35:27 -06009421 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9422 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9423 copy_ds_update.srcSet = descriptorSet;
9424 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009425 copy_ds_update.dstSet = descriptorSet;
9426 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009427 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009428 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9429
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009430 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009431
Chia-I Wuf7458c52015-10-26 21:10:41 +08009432 vkDestroySampler(m_device->device(), sampler, NULL);
9433 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009435}
9436
Karl Schultz6addd812016-02-02 17:17:23 -07009437TEST_F(VkLayerTest, NumSamplesMismatch) {
9438 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9439 // sampleCount
9440 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009443
Tobin Ehlis3b780662015-05-28 12:11:26 -06009444 ASSERT_NO_FATAL_FAILURE(InitState());
9445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009446 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009447 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009448 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009449
9450 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009451 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9452 ds_pool_ci.pNext = NULL;
9453 ds_pool_ci.maxSets = 1;
9454 ds_pool_ci.poolSizeCount = 1;
9455 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009456
Tobin Ehlis3b780662015-05-28 12:11:26 -06009457 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009458 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009459 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009460
Tony Barboureb254902015-07-15 12:50:33 -06009461 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009462 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009463 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009464 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009465 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9466 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009467
Tony Barboureb254902015-07-15 12:50:33 -06009468 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9469 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9470 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009471 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009472 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009473
Tobin Ehlis3b780662015-05-28 12:11:26 -06009474 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009475 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009476 ASSERT_VK_SUCCESS(err);
9477
9478 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009479 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009480 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009481 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009482 alloc_info.descriptorPool = ds_pool;
9483 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009484 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009485 ASSERT_VK_SUCCESS(err);
9486
Tony Barboureb254902015-07-15 12:50:33 -06009487 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009488 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009489 pipe_ms_state_ci.pNext = NULL;
9490 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9491 pipe_ms_state_ci.sampleShadingEnable = 0;
9492 pipe_ms_state_ci.minSampleShading = 1.0;
9493 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009494
Tony Barboureb254902015-07-15 12:50:33 -06009495 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009496 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9497 pipeline_layout_ci.pNext = NULL;
9498 pipeline_layout_ci.setLayoutCount = 1;
9499 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009500
9501 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009502 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009503 ASSERT_VK_SUCCESS(err);
9504
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009505 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9506 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9507 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009508 VkPipelineObj pipe(m_device);
9509 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009510 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009511 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009512 pipe.SetMSAA(&pipe_ms_state_ci);
9513 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009514
Tony Barbourfe3351b2015-07-28 10:17:20 -06009515 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009516 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -06009517
Mark Young29927482016-05-04 14:38:51 -06009518 // Render triangle (the error should trigger on the attempt to draw).
9519 Draw(3, 1, 0, 0);
9520
9521 // Finalize recording of the command buffer
9522 EndCommandBuffer();
9523
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009524 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009525
Chia-I Wuf7458c52015-10-26 21:10:41 +08009526 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9527 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9528 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009529}
Mark Young29927482016-05-04 14:38:51 -06009530
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009531TEST_F(VkLayerTest, RenderPassIncompatible) {
9532 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
9533 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -06009534 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009535 VkResult err;
9536
9537 ASSERT_NO_FATAL_FAILURE(InitState());
9538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9539
9540 VkDescriptorSetLayoutBinding dsl_binding = {};
9541 dsl_binding.binding = 0;
9542 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9543 dsl_binding.descriptorCount = 1;
9544 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9545 dsl_binding.pImmutableSamplers = NULL;
9546
9547 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9548 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9549 ds_layout_ci.pNext = NULL;
9550 ds_layout_ci.bindingCount = 1;
9551 ds_layout_ci.pBindings = &dsl_binding;
9552
9553 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009554 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009555 ASSERT_VK_SUCCESS(err);
9556
9557 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9558 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9559 pipeline_layout_ci.pNext = NULL;
9560 pipeline_layout_ci.setLayoutCount = 1;
9561 pipeline_layout_ci.pSetLayouts = &ds_layout;
9562
9563 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009564 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009565 ASSERT_VK_SUCCESS(err);
9566
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009567 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9568 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9569 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009570 // Create a renderpass that will be incompatible with default renderpass
9571 VkAttachmentReference attach = {};
9572 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
9573 VkAttachmentReference color_att = {};
9574 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9575 VkSubpassDescription subpass = {};
9576 subpass.inputAttachmentCount = 1;
9577 subpass.pInputAttachments = &attach;
9578 subpass.colorAttachmentCount = 1;
9579 subpass.pColorAttachments = &color_att;
9580 VkRenderPassCreateInfo rpci = {};
9581 rpci.subpassCount = 1;
9582 rpci.pSubpasses = &subpass;
9583 rpci.attachmentCount = 1;
9584 VkAttachmentDescription attach_desc = {};
9585 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -06009586 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
9587 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009588 rpci.pAttachments = &attach_desc;
9589 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9590 VkRenderPass rp;
9591 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9592 VkPipelineObj pipe(m_device);
9593 pipe.AddShader(&vs);
9594 pipe.AddShader(&fs);
9595 pipe.AddColorAttachment();
9596 VkViewport view_port = {};
9597 m_viewports.push_back(view_port);
9598 pipe.SetViewport(m_viewports);
9599 VkRect2D rect = {};
9600 m_scissors.push_back(rect);
9601 pipe.SetScissor(m_scissors);
9602 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9603
9604 VkCommandBufferInheritanceInfo cbii = {};
9605 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9606 cbii.renderPass = rp;
9607 cbii.subpass = 0;
9608 VkCommandBufferBeginInfo cbbi = {};
9609 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9610 cbbi.pInheritanceInfo = &cbii;
9611 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
9612 VkRenderPassBeginInfo rpbi = {};
9613 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9614 rpbi.framebuffer = m_framebuffer;
9615 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009616 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9617 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009618
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -06009620 // Render triangle (the error should trigger on the attempt to draw).
9621 Draw(3, 1, 0, 0);
9622
9623 // Finalize recording of the command buffer
9624 EndCommandBuffer();
9625
9626 m_errorMonitor->VerifyFound();
9627
9628 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9629 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9630 vkDestroyRenderPass(m_device->device(), rp, NULL);
9631}
9632
Mark Youngc89c6312016-03-31 16:03:20 -06009633TEST_F(VkLayerTest, NumBlendAttachMismatch) {
9634 // Create Pipeline where the number of blend attachments doesn't match the
9635 // number of color attachments. In this case, we don't add any color
9636 // blend attachments even though we have a color attachment.
9637 VkResult err;
9638
9639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009640 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -06009641
9642 ASSERT_NO_FATAL_FAILURE(InitState());
9643 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9644 VkDescriptorPoolSize ds_type_count = {};
9645 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9646 ds_type_count.descriptorCount = 1;
9647
9648 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9649 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9650 ds_pool_ci.pNext = NULL;
9651 ds_pool_ci.maxSets = 1;
9652 ds_pool_ci.poolSizeCount = 1;
9653 ds_pool_ci.pPoolSizes = &ds_type_count;
9654
9655 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009656 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -06009657 ASSERT_VK_SUCCESS(err);
9658
9659 VkDescriptorSetLayoutBinding dsl_binding = {};
9660 dsl_binding.binding = 0;
9661 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9662 dsl_binding.descriptorCount = 1;
9663 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9664 dsl_binding.pImmutableSamplers = NULL;
9665
9666 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9667 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9668 ds_layout_ci.pNext = NULL;
9669 ds_layout_ci.bindingCount = 1;
9670 ds_layout_ci.pBindings = &dsl_binding;
9671
9672 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009673 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009674 ASSERT_VK_SUCCESS(err);
9675
9676 VkDescriptorSet descriptorSet;
9677 VkDescriptorSetAllocateInfo alloc_info = {};
9678 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9679 alloc_info.descriptorSetCount = 1;
9680 alloc_info.descriptorPool = ds_pool;
9681 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009682 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -06009683 ASSERT_VK_SUCCESS(err);
9684
9685 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009686 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -06009687 pipe_ms_state_ci.pNext = NULL;
9688 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9689 pipe_ms_state_ci.sampleShadingEnable = 0;
9690 pipe_ms_state_ci.minSampleShading = 1.0;
9691 pipe_ms_state_ci.pSampleMask = NULL;
9692
9693 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
9694 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9695 pipeline_layout_ci.pNext = NULL;
9696 pipeline_layout_ci.setLayoutCount = 1;
9697 pipeline_layout_ci.pSetLayouts = &ds_layout;
9698
9699 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009700 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -06009701 ASSERT_VK_SUCCESS(err);
9702
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009703 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9704 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9705 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -06009706 VkPipelineObj pipe(m_device);
9707 pipe.AddShader(&vs);
9708 pipe.AddShader(&fs);
9709 pipe.SetMSAA(&pipe_ms_state_ci);
9710 pipe.CreateVKPipeline(pipeline_layout, renderPass());
9711
9712 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009713 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -06009714
Mark Young29927482016-05-04 14:38:51 -06009715 // Render triangle (the error should trigger on the attempt to draw).
9716 Draw(3, 1, 0, 0);
9717
9718 // Finalize recording of the command buffer
9719 EndCommandBuffer();
9720
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009721 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -06009722
9723 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9724 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9725 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9726}
Mark Young29927482016-05-04 14:38:51 -06009727
Mark Muellerd4914412016-06-13 17:52:06 -06009728TEST_F(VkLayerTest, MissingClearAttachment) {
9729 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
9730 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -06009731 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesda6ae6f2016-09-09 14:36:33 +12009732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesfa79fc72016-11-01 10:18:12 +13009733 "vkCmdClearAttachments() color attachment index 1 out of range for active subpass 0");
Mark Muellerd4914412016-06-13 17:52:06 -06009734
9735 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
9736 m_errorMonitor->VerifyFound();
9737}
9738
Karl Schultz6addd812016-02-02 17:17:23 -07009739TEST_F(VkLayerTest, ClearCmdNoDraw) {
9740 // Create CommandBuffer where we add ClearCmd for FB Color attachment prior
9741 // to issuing a Draw
9742 VkResult err;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -06009745 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009746
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009747 ASSERT_NO_FATAL_FAILURE(InitState());
9748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009749
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009750 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009751 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9752 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009753
9754 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009755 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9756 ds_pool_ci.pNext = NULL;
9757 ds_pool_ci.maxSets = 1;
9758 ds_pool_ci.poolSizeCount = 1;
9759 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009760
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009761 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009762 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009763 ASSERT_VK_SUCCESS(err);
9764
Tony Barboureb254902015-07-15 12:50:33 -06009765 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009766 dsl_binding.binding = 0;
9767 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9768 dsl_binding.descriptorCount = 1;
9769 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9770 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009771
Tony Barboureb254902015-07-15 12:50:33 -06009772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9774 ds_layout_ci.pNext = NULL;
9775 ds_layout_ci.bindingCount = 1;
9776 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009777
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009778 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009779 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009780 ASSERT_VK_SUCCESS(err);
9781
9782 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009783 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009784 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009785 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009786 alloc_info.descriptorPool = ds_pool;
9787 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009788 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009789 ASSERT_VK_SUCCESS(err);
9790
Tony Barboureb254902015-07-15 12:50:33 -06009791 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009792 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009793 pipe_ms_state_ci.pNext = NULL;
9794 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9795 pipe_ms_state_ci.sampleShadingEnable = 0;
9796 pipe_ms_state_ci.minSampleShading = 1.0;
9797 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009798
Tony Barboureb254902015-07-15 12:50:33 -06009799 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009800 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9801 pipeline_layout_ci.pNext = NULL;
9802 pipeline_layout_ci.setLayoutCount = 1;
9803 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009804
9805 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009806 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009807 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009808
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009809 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06009810 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07009811 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009812 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009813
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009814 VkPipelineObj pipe(m_device);
9815 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009816 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009817 pipe.SetMSAA(&pipe_ms_state_ci);
9818 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009819
9820 BeginCommandBuffer();
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009821
Karl Schultz6addd812016-02-02 17:17:23 -07009822 // Main thing we care about for this test is that the VkImage obj we're
9823 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009824 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009825 VkClearAttachment color_attachment;
9826 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9827 color_attachment.clearValue.color.float32[0] = 1.0;
9828 color_attachment.clearValue.color.float32[1] = 1.0;
9829 color_attachment.clearValue.color.float32[2] = 1.0;
9830 color_attachment.clearValue.color.float32[3] = 1.0;
9831 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009832 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009833
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009834 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009835
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009836 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009837
Chia-I Wuf7458c52015-10-26 21:10:41 +08009838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9839 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9840 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -06009841}
9842
Karl Schultz6addd812016-02-02 17:17:23 -07009843TEST_F(VkLayerTest, VtxBufferBadIndex) {
9844 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009845
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
9847 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009848
Tobin Ehlis502480b2015-06-24 15:53:07 -06009849 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -06009850 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -06009851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -06009852
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009853 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009854 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9855 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009856
9857 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009858 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9859 ds_pool_ci.pNext = NULL;
9860 ds_pool_ci.maxSets = 1;
9861 ds_pool_ci.poolSizeCount = 1;
9862 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009863
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009864 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009865 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009866 ASSERT_VK_SUCCESS(err);
9867
Tony Barboureb254902015-07-15 12:50:33 -06009868 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009869 dsl_binding.binding = 0;
9870 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9871 dsl_binding.descriptorCount = 1;
9872 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9873 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009874
Tony Barboureb254902015-07-15 12:50:33 -06009875 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009876 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9877 ds_layout_ci.pNext = NULL;
9878 ds_layout_ci.bindingCount = 1;
9879 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009880
Tobin Ehlis502480b2015-06-24 15:53:07 -06009881 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009882 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009883 ASSERT_VK_SUCCESS(err);
9884
9885 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009886 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009887 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009888 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009889 alloc_info.descriptorPool = ds_pool;
9890 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009891 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009892 ASSERT_VK_SUCCESS(err);
9893
Tony Barboureb254902015-07-15 12:50:33 -06009894 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009896 pipe_ms_state_ci.pNext = NULL;
9897 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9898 pipe_ms_state_ci.sampleShadingEnable = 0;
9899 pipe_ms_state_ci.minSampleShading = 1.0;
9900 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009901
Tony Barboureb254902015-07-15 12:50:33 -06009902 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009903 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9904 pipeline_layout_ci.pNext = NULL;
9905 pipeline_layout_ci.setLayoutCount = 1;
9906 pipeline_layout_ci.pSetLayouts = &ds_layout;
9907 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -06009908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009909 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009910 ASSERT_VK_SUCCESS(err);
9911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009912 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9913 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
9914 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009915 VkPipelineObj pipe(m_device);
9916 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06009917 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06009918 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009919 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -06009920 pipe.SetViewport(m_viewports);
9921 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -06009922 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06009923
9924 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009925 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009926 // Don't care about actual data, just need to get to draw to flag error
9927 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009928 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -06009929 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -06009930 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009931
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009932 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009933
Chia-I Wuf7458c52015-10-26 21:10:41 +08009934 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
9935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -06009937}
Mark Muellerdfe37552016-07-07 14:47:42 -06009938
Mark Mueller2ee294f2016-08-04 12:59:48 -06009939TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
9940 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
9941 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -06009942 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -06009943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009944 const char *mismatch_count_message = "Call to vkEnumeratePhysicalDevices() "
9945 "w/ pPhysicalDeviceCount value ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009946
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009947 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
9948 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -06009951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, mismatch_count_message);
Mark Mueller880fce52016-08-17 15:23:23 -06009953 // The following test fails with recent NVidia drivers.
9954 // By the time core_validation is reached, the NVidia
9955 // driver has sanitized the invalid condition and core_validation
9956 // is not introduced to the failure condition. This is not the case
9957 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009958 // uint32_t count = static_cast<uint32_t>(~0);
9959 // VkPhysicalDevice physical_device;
9960 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
9961 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -06009962
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009964 float queue_priority = 0.0;
9965
9966 VkDeviceQueueCreateInfo queue_create_info = {};
9967 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
9968 queue_create_info.queueCount = 1;
9969 queue_create_info.pQueuePriorities = &queue_priority;
9970 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
9971
9972 VkPhysicalDeviceFeatures features = m_device->phy().features();
9973 VkDevice testDevice;
9974 VkDeviceCreateInfo device_create_info = {};
9975 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
9976 device_create_info.queueCreateInfoCount = 1;
9977 device_create_info.pQueueCreateInfos = &queue_create_info;
9978 device_create_info.pEnabledFeatures = &features;
9979 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9980 m_errorMonitor->VerifyFound();
9981
9982 queue_create_info.queueFamilyIndex = 1;
9983
9984 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
9985 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
9986 for (unsigned i = 0; i < feature_count; i++) {
9987 if (VK_FALSE == feature_array[i]) {
9988 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -06009990 device_create_info.pEnabledFeatures = &features;
9991 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
9992 m_errorMonitor->VerifyFound();
9993 break;
9994 }
9995 }
9996}
9997
9998TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
9999 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10000 "End a command buffer with a query still in progress.");
10001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010002 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10003 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10004 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010006 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010009
10010 ASSERT_NO_FATAL_FAILURE(InitState());
10011
10012 VkEvent event;
10013 VkEventCreateInfo event_create_info{};
10014 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10015 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10016
Mark Mueller2ee294f2016-08-04 12:59:48 -060010017 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010018 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010019
10020 BeginCommandBuffer();
10021
10022 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010023 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 -060010024 ASSERT_TRUE(image.initialized());
10025 VkImageMemoryBarrier img_barrier = {};
10026 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10027 img_barrier.pNext = NULL;
10028 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10029 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10030 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10031 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10032 img_barrier.image = image.handle();
10033 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010034
10035 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10036 // that layer validation catches the case when it is not.
10037 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010038 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10039 img_barrier.subresourceRange.baseArrayLayer = 0;
10040 img_barrier.subresourceRange.baseMipLevel = 0;
10041 img_barrier.subresourceRange.layerCount = 1;
10042 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010043 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10044 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010045 m_errorMonitor->VerifyFound();
10046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010048
10049 VkQueryPool query_pool;
10050 VkQueryPoolCreateInfo query_pool_create_info = {};
10051 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10052 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10053 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010054 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010055
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010056 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010057 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10058
10059 vkEndCommandBuffer(m_commandBuffer->handle());
10060 m_errorMonitor->VerifyFound();
10061
10062 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10063 vkDestroyEvent(m_device->device(), event, nullptr);
10064}
10065
Mark Muellerdfe37552016-07-07 14:47:42 -060010066TEST_F(VkLayerTest, VertexBufferInvalid) {
10067 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10068 "delete a buffer twice, use an invalid offset for each "
10069 "buffer type, and attempt to bind a null buffer");
10070
10071 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10072 "using deleted buffer ";
10073 const char *double_destroy_message = "Cannot free buffer 0x";
10074 const char *invalid_offset_message = "vkBindBufferMemory(): "
10075 "memoryOffset is 0x";
10076 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10077 "storage memoryOffset "
10078 "is 0x";
10079 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10080 "texel memoryOffset "
10081 "is 0x";
10082 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10083 "uniform memoryOffset "
10084 "is 0x";
10085 const char *bind_null_buffer_message = "In vkBindBufferMemory, attempting"
10086 " to Bind Obj(0x";
Tobin Ehlis02337352016-10-20 14:42:57 -060010087 const char *free_invalid_buffer_message = "Invalid Device Memory Object 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010088
10089 ASSERT_NO_FATAL_FAILURE(InitState());
10090 ASSERT_NO_FATAL_FAILURE(InitViewport());
10091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10092
10093 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010094 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010095 pipe_ms_state_ci.pNext = NULL;
10096 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10097 pipe_ms_state_ci.sampleShadingEnable = 0;
10098 pipe_ms_state_ci.minSampleShading = 1.0;
10099 pipe_ms_state_ci.pSampleMask = nullptr;
10100
10101 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10102 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10103 VkPipelineLayout pipeline_layout;
10104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010106 ASSERT_VK_SUCCESS(err);
10107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010108 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10109 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010110 VkPipelineObj pipe(m_device);
10111 pipe.AddShader(&vs);
10112 pipe.AddShader(&fs);
10113 pipe.AddColorAttachment();
10114 pipe.SetMSAA(&pipe_ms_state_ci);
10115 pipe.SetViewport(m_viewports);
10116 pipe.SetScissor(m_scissors);
10117 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10118
10119 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010120 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010121
10122 {
10123 // Create and bind a vertex buffer in a reduced scope, which will cause
10124 // it to be deleted upon leaving this scope
10125 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010126 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010127 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10128 draw_verticies.AddVertexInputToPipe(pipe);
10129 }
10130
10131 Draw(1, 0, 0, 0);
10132
10133 EndCommandBuffer();
10134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010136 QueueCommandBuffer(false);
10137 m_errorMonitor->VerifyFound();
10138
10139 {
10140 // Create and bind a vertex buffer in a reduced scope, and delete it
10141 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010142 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
10143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, double_destroy_message);
Mark Muellerdfe37552016-07-07 14:47:42 -060010144 buffer_test.TestDoubleDestroy();
10145 }
10146 m_errorMonitor->VerifyFound();
10147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010148 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010149 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10151 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10152 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010153 m_errorMonitor->VerifyFound();
10154 }
10155
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10157 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010158 // Create and bind a memory buffer with an invalid offset again,
10159 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10161 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10162 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010163 m_errorMonitor->VerifyFound();
10164 }
10165
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010166 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010167 // Create and bind a memory buffer with an invalid offset again, but
10168 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10170 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10171 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010172 m_errorMonitor->VerifyFound();
10173 }
10174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010175 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010176 // Create and bind a memory buffer with an invalid offset again, but
10177 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10179 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10180 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010181 m_errorMonitor->VerifyFound();
10182 }
10183
10184 {
10185 // Attempt to bind a null buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bind_null_buffer_message);
10187 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10188 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010189 m_errorMonitor->VerifyFound();
10190 }
10191
10192 {
10193 // Attempt to use an invalid handle to delete a buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, free_invalid_buffer_message);
10195 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10196 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010197 }
10198 m_errorMonitor->VerifyFound();
10199
10200 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10201}
10202
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010203// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10204TEST_F(VkLayerTest, InvalidImageLayout) {
10205 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010206 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10207 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010208 // 3 in ValidateCmdBufImageLayouts
10209 // * -1 Attempt to submit cmd buf w/ deleted image
10210 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10211 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10213 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010214
10215 ASSERT_NO_FATAL_FAILURE(InitState());
10216 // Create src & dst images to use for copy operations
10217 VkImage src_image;
10218 VkImage dst_image;
10219
10220 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10221 const int32_t tex_width = 32;
10222 const int32_t tex_height = 32;
10223
10224 VkImageCreateInfo image_create_info = {};
10225 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10226 image_create_info.pNext = NULL;
10227 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10228 image_create_info.format = tex_format;
10229 image_create_info.extent.width = tex_width;
10230 image_create_info.extent.height = tex_height;
10231 image_create_info.extent.depth = 1;
10232 image_create_info.mipLevels = 1;
10233 image_create_info.arrayLayers = 4;
10234 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10235 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10236 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
10237 image_create_info.flags = 0;
10238
10239 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10240 ASSERT_VK_SUCCESS(err);
10241 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10242 ASSERT_VK_SUCCESS(err);
10243
10244 BeginCommandBuffer();
10245 VkImageCopy copyRegion;
10246 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10247 copyRegion.srcSubresource.mipLevel = 0;
10248 copyRegion.srcSubresource.baseArrayLayer = 0;
10249 copyRegion.srcSubresource.layerCount = 1;
10250 copyRegion.srcOffset.x = 0;
10251 copyRegion.srcOffset.y = 0;
10252 copyRegion.srcOffset.z = 0;
10253 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10254 copyRegion.dstSubresource.mipLevel = 0;
10255 copyRegion.dstSubresource.baseArrayLayer = 0;
10256 copyRegion.dstSubresource.layerCount = 1;
10257 copyRegion.dstOffset.x = 0;
10258 copyRegion.dstOffset.y = 0;
10259 copyRegion.dstOffset.z = 0;
10260 copyRegion.extent.width = 1;
10261 copyRegion.extent.height = 1;
10262 copyRegion.extent.depth = 1;
10263 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10264 m_errorMonitor->VerifyFound();
10265 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10267 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10268 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010269 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10270 m_errorMonitor->VerifyFound();
10271 // Final src error is due to bad layout type
10272 m_errorMonitor->SetDesiredFailureMsg(
10273 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10274 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
10275 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10276 m_errorMonitor->VerifyFound();
10277 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10279 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010280 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
10281 m_errorMonitor->VerifyFound();
10282 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10284 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10285 "layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010286 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10287 m_errorMonitor->VerifyFound();
10288 m_errorMonitor->SetDesiredFailureMsg(
10289 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10290 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
10291 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, &copyRegion);
10292 m_errorMonitor->VerifyFound();
10293 // Now cause error due to bad image layout transition in PipelineBarrier
10294 VkImageMemoryBarrier image_barrier[1] = {};
10295 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10296 image_barrier[0].image = src_image;
10297 image_barrier[0].subresourceRange.layerCount = 2;
10298 image_barrier[0].subresourceRange.levelCount = 2;
10299 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout from "
10301 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10302 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10303 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10304 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010305 m_errorMonitor->VerifyFound();
10306
10307 // Finally some layout errors at RenderPass create time
10308 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10309 VkAttachmentReference attach = {};
10310 // perf warning for GENERAL layout w/ non-DS input attachment
10311 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10312 VkSubpassDescription subpass = {};
10313 subpass.inputAttachmentCount = 1;
10314 subpass.pInputAttachments = &attach;
10315 VkRenderPassCreateInfo rpci = {};
10316 rpci.subpassCount = 1;
10317 rpci.pSubpasses = &subpass;
10318 rpci.attachmentCount = 1;
10319 VkAttachmentDescription attach_desc = {};
10320 attach_desc.format = VK_FORMAT_UNDEFINED;
10321 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060010322 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010323 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10325 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010326 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10327 m_errorMonitor->VerifyFound();
10328 // error w/ non-general layout
10329 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10330
10331 m_errorMonitor->SetDesiredFailureMsg(
10332 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10333 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
10334 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10335 m_errorMonitor->VerifyFound();
10336 subpass.inputAttachmentCount = 0;
10337 subpass.colorAttachmentCount = 1;
10338 subpass.pColorAttachments = &attach;
10339 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10340 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10342 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010343 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10344 m_errorMonitor->VerifyFound();
10345 // error w/ non-color opt or GENERAL layout for color attachment
10346 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
10347 m_errorMonitor->SetDesiredFailureMsg(
10348 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10349 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
10350 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10351 m_errorMonitor->VerifyFound();
10352 subpass.colorAttachmentCount = 0;
10353 subpass.pDepthStencilAttachment = &attach;
10354 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10355 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10357 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010358 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10359 m_errorMonitor->VerifyFound();
10360 // error w/ non-ds opt or GENERAL layout for color attachment
10361 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10363 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
10364 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010365 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10366 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060010367 // For this error we need a valid renderpass so create default one
10368 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10369 attach.attachment = 0;
10370 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
10371 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
10372 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
10373 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
10374 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
10375 // Can't do a CLEAR load on READ_ONLY initialLayout
10376 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
10377 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
10378 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
10380 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
10381 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060010382 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10383 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010384
10385 vkDestroyImage(m_device->device(), src_image, NULL);
10386 vkDestroyImage(m_device->device(), dst_image, NULL);
10387}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060010388
Tobin Ehlise0936662016-10-11 08:10:51 -060010389TEST_F(VkLayerTest, InvalidStorageImageLayout) {
10390 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
10391 VkResult err;
10392
10393 ASSERT_NO_FATAL_FAILURE(InitState());
10394
10395 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
10396 VkImageTiling tiling;
10397 VkFormatProperties format_properties;
10398 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
10399 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10400 tiling = VK_IMAGE_TILING_LINEAR;
10401 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
10402 tiling = VK_IMAGE_TILING_OPTIMAL;
10403 } else {
10404 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
10405 "skipped.\n");
10406 return;
10407 }
10408
10409 VkDescriptorPoolSize ds_type = {};
10410 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10411 ds_type.descriptorCount = 1;
10412
10413 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10414 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10415 ds_pool_ci.maxSets = 1;
10416 ds_pool_ci.poolSizeCount = 1;
10417 ds_pool_ci.pPoolSizes = &ds_type;
10418 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
10419
10420 VkDescriptorPool ds_pool;
10421 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10422 ASSERT_VK_SUCCESS(err);
10423
10424 VkDescriptorSetLayoutBinding dsl_binding = {};
10425 dsl_binding.binding = 0;
10426 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10427 dsl_binding.descriptorCount = 1;
10428 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10429 dsl_binding.pImmutableSamplers = NULL;
10430
10431 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10432 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10433 ds_layout_ci.pNext = NULL;
10434 ds_layout_ci.bindingCount = 1;
10435 ds_layout_ci.pBindings = &dsl_binding;
10436
10437 VkDescriptorSetLayout ds_layout;
10438 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10439 ASSERT_VK_SUCCESS(err);
10440
10441 VkDescriptorSetAllocateInfo alloc_info = {};
10442 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10443 alloc_info.descriptorSetCount = 1;
10444 alloc_info.descriptorPool = ds_pool;
10445 alloc_info.pSetLayouts = &ds_layout;
10446 VkDescriptorSet descriptor_set;
10447 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10448 ASSERT_VK_SUCCESS(err);
10449
10450 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10451 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10452 pipeline_layout_ci.pNext = NULL;
10453 pipeline_layout_ci.setLayoutCount = 1;
10454 pipeline_layout_ci.pSetLayouts = &ds_layout;
10455 VkPipelineLayout pipeline_layout;
10456 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10457 ASSERT_VK_SUCCESS(err);
10458
10459 VkImageObj image(m_device);
10460 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
10461 ASSERT_TRUE(image.initialized());
10462 VkImageView view = image.targetView(tex_format);
10463
10464 VkDescriptorImageInfo image_info = {};
10465 image_info.imageView = view;
10466 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10467
10468 VkWriteDescriptorSet descriptor_write = {};
10469 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10470 descriptor_write.dstSet = descriptor_set;
10471 descriptor_write.dstBinding = 0;
10472 descriptor_write.descriptorCount = 1;
10473 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
10474 descriptor_write.pImageInfo = &image_info;
10475
10476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10477 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
10478 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
10479 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10480 m_errorMonitor->VerifyFound();
10481
10482 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10483 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10484 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10485 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10486}
10487
Mark Mueller93b938f2016-08-18 10:27:40 -060010488TEST_F(VkLayerTest, SimultaneousUse) {
10489 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10490 "in primary and secondary command buffers.");
10491
10492 ASSERT_NO_FATAL_FAILURE(InitState());
10493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10494
Mike Weiblen95dd0f92016-10-19 12:28:27 -060010495 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010496 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
10497 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060010498
10499 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010500 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010501 command_buffer_allocate_info.commandPool = m_commandPool;
10502 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
10503 command_buffer_allocate_info.commandBufferCount = 1;
10504
10505 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010506 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060010507 VkCommandBufferBeginInfo command_buffer_begin_info = {};
10508 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010509 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060010510 command_buffer_inheritance_info.renderPass = m_renderPass;
10511 command_buffer_inheritance_info.framebuffer = m_framebuffer;
10512 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010513 command_buffer_begin_info.flags =
10514 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010515 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
10516
10517 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010518 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10519 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller4042b652016-09-05 22:52:21 -060010520 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010521 vkEndCommandBuffer(secondary_command_buffer);
10522
Mark Mueller93b938f2016-08-18 10:27:40 -060010523 VkSubmitInfo submit_info = {};
10524 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10525 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010526 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller4042b652016-09-05 22:52:21 -060010527 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Mueller93b938f2016-08-18 10:27:40 -060010528
Mark Mueller4042b652016-09-05 22:52:21 -060010529 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010530 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
10532 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010533 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010534 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10535 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010536
10537 m_errorMonitor->SetDesiredFailureMsg(0, "");
Mark Mueller93b938f2016-08-18 10:27:40 -060010538 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10539
Mark Mueller4042b652016-09-05 22:52:21 -060010540 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060010541 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010542 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060010543
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
10545 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060010546 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060010547 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
10548 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060010549}
10550
Mark Mueller917f6bc2016-08-30 10:57:19 -060010551TEST_F(VkLayerTest, InUseDestroyedSignaled) {
10552 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
10553 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060010554 "Delete objects that are inuse. Call VkQueueSubmit "
10555 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060010556
10557 ASSERT_NO_FATAL_FAILURE(InitState());
10558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010560 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
10561 const char *cannot_delete_event_message = "Cannot delete event 0x";
10562 const char *cannot_delete_semaphore_message = "Cannot delete semaphore 0x";
10563 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060010564
10565 BeginCommandBuffer();
10566
10567 VkEvent event;
10568 VkEventCreateInfo event_create_info = {};
10569 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10570 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010571 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010572
Mark Muellerc8d441e2016-08-23 17:36:00 -060010573 EndCommandBuffer();
10574 vkDestroyEvent(m_device->device(), event, nullptr);
10575
10576 VkSubmitInfo submit_info = {};
10577 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10578 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010579 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010581 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10582 m_errorMonitor->VerifyFound();
10583
10584 m_errorMonitor->SetDesiredFailureMsg(0, "");
10585 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
10586
10587 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10588
Mark Mueller917f6bc2016-08-30 10:57:19 -060010589 VkSemaphoreCreateInfo semaphore_create_info = {};
10590 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
10591 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010592 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010593 VkFenceCreateInfo fence_create_info = {};
10594 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
10595 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010596 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010597
10598 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010599 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010600 descriptor_pool_type_count.descriptorCount = 1;
10601
10602 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
10603 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10604 descriptor_pool_create_info.maxSets = 1;
10605 descriptor_pool_create_info.poolSizeCount = 1;
10606 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010607 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010608
10609 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010610 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010611
10612 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060010613 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010614 descriptorset_layout_binding.descriptorCount = 1;
10615 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
10616
10617 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010618 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010619 descriptorset_layout_create_info.bindingCount = 1;
10620 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
10621
10622 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010623 ASSERT_VK_SUCCESS(
10624 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010625
10626 VkDescriptorSet descriptorset;
10627 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010628 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010629 descriptorset_allocate_info.descriptorSetCount = 1;
10630 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
10631 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010632 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010633
Mark Mueller4042b652016-09-05 22:52:21 -060010634 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10635
10636 VkDescriptorBufferInfo buffer_info = {};
10637 buffer_info.buffer = buffer_test.GetBuffer();
10638 buffer_info.offset = 0;
10639 buffer_info.range = 1024;
10640
10641 VkWriteDescriptorSet write_descriptor_set = {};
10642 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10643 write_descriptor_set.dstSet = descriptorset;
10644 write_descriptor_set.descriptorCount = 1;
10645 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10646 write_descriptor_set.pBufferInfo = &buffer_info;
10647
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010648 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060010649
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010650 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10651 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010652
10653 VkPipelineObj pipe(m_device);
10654 pipe.AddColorAttachment();
10655 pipe.AddShader(&vs);
10656 pipe.AddShader(&fs);
10657
10658 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010659 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060010660 pipeline_layout_create_info.setLayoutCount = 1;
10661 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
10662
10663 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010664 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060010665
10666 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
10667
Mark Muellerc8d441e2016-08-23 17:36:00 -060010668 BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010669 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010670
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010671 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10672 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10673 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010674
Mark Muellerc8d441e2016-08-23 17:36:00 -060010675 EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060010676
Mark Mueller917f6bc2016-08-30 10:57:19 -060010677 submit_info.signalSemaphoreCount = 1;
10678 submit_info.pSignalSemaphores = &semaphore;
10679 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Muellerc8d441e2016-08-23 17:36:00 -060010680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_event_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010682 vkDestroyEvent(m_device->device(), event, nullptr);
10683 m_errorMonitor->VerifyFound();
10684
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_delete_semaphore_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010686 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10687 m_errorMonitor->VerifyFound();
10688
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010690 vkDestroyFence(m_device->device(), fence, nullptr);
10691 m_errorMonitor->VerifyFound();
10692
Tobin Ehlis122207b2016-09-01 08:50:06 -070010693 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010694 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
10695 vkDestroyFence(m_device->device(), fence, nullptr);
10696 vkDestroyEvent(m_device->device(), event, nullptr);
10697 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010698 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060010699 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
10700}
10701
Tobin Ehlis2adda372016-09-01 08:51:06 -070010702TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
10703 TEST_DESCRIPTION("Delete in-use query pool.");
10704
10705 ASSERT_NO_FATAL_FAILURE(InitState());
10706 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10707
10708 VkQueryPool query_pool;
10709 VkQueryPoolCreateInfo query_pool_ci{};
10710 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10711 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
10712 query_pool_ci.queryCount = 1;
10713 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
10714 BeginCommandBuffer();
10715 // Reset query pool to create binding with cmd buffer
10716 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
10717
10718 EndCommandBuffer();
10719
10720 VkSubmitInfo submit_info = {};
10721 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10722 submit_info.commandBufferCount = 1;
10723 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10724 // Submit cmd buffer and then destroy query pool while in-flight
10725 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10726
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete query pool 0x");
Tobin Ehlis2adda372016-09-01 08:51:06 -070010728 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10729 m_errorMonitor->VerifyFound();
10730
10731 vkQueueWaitIdle(m_device->m_queue);
10732 // Now that cmd buffer done we can safely destroy query_pool
10733 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
10734}
10735
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010736TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
10737 TEST_DESCRIPTION("Delete in-use pipeline.");
10738
10739 ASSERT_NO_FATAL_FAILURE(InitState());
10740 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10741
10742 // Empty pipeline layout used for binding PSO
10743 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10744 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10745 pipeline_layout_ci.setLayoutCount = 0;
10746 pipeline_layout_ci.pSetLayouts = NULL;
10747
10748 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010749 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010750 ASSERT_VK_SUCCESS(err);
10751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete pipeline 0x");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010753 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010754 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10755 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010756 // Store pipeline handle so we can actually delete it before test finishes
10757 VkPipeline delete_this_pipeline;
10758 { // Scope pipeline so it will be auto-deleted
10759 VkPipelineObj pipe(m_device);
10760 pipe.AddShader(&vs);
10761 pipe.AddShader(&fs);
10762 pipe.AddColorAttachment();
10763 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10764 delete_this_pipeline = pipe.handle();
10765
10766 BeginCommandBuffer();
10767 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010768 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060010769
10770 EndCommandBuffer();
10771
10772 VkSubmitInfo submit_info = {};
10773 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10774 submit_info.commandBufferCount = 1;
10775 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10776 // Submit cmd buffer and then pipeline destroyed while in-flight
10777 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10778 } // Pipeline deletion triggered here
10779 m_errorMonitor->VerifyFound();
10780 // Make sure queue finished and then actually delete pipeline
10781 vkQueueWaitIdle(m_device->m_queue);
10782 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
10783 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
10784}
10785
Tobin Ehlis7d965da2016-09-19 16:15:45 -060010786TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
10787 TEST_DESCRIPTION("Delete in-use imageView.");
10788
10789 ASSERT_NO_FATAL_FAILURE(InitState());
10790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10791
10792 VkDescriptorPoolSize ds_type_count;
10793 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10794 ds_type_count.descriptorCount = 1;
10795
10796 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10797 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10798 ds_pool_ci.maxSets = 1;
10799 ds_pool_ci.poolSizeCount = 1;
10800 ds_pool_ci.pPoolSizes = &ds_type_count;
10801
10802 VkDescriptorPool ds_pool;
10803 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10804 ASSERT_VK_SUCCESS(err);
10805
10806 VkSamplerCreateInfo sampler_ci = {};
10807 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10808 sampler_ci.pNext = NULL;
10809 sampler_ci.magFilter = VK_FILTER_NEAREST;
10810 sampler_ci.minFilter = VK_FILTER_NEAREST;
10811 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10812 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10813 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10814 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10815 sampler_ci.mipLodBias = 1.0;
10816 sampler_ci.anisotropyEnable = VK_FALSE;
10817 sampler_ci.maxAnisotropy = 1;
10818 sampler_ci.compareEnable = VK_FALSE;
10819 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10820 sampler_ci.minLod = 1.0;
10821 sampler_ci.maxLod = 1.0;
10822 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10823 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10824 VkSampler sampler;
10825
10826 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10827 ASSERT_VK_SUCCESS(err);
10828
10829 VkDescriptorSetLayoutBinding layout_binding;
10830 layout_binding.binding = 0;
10831 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10832 layout_binding.descriptorCount = 1;
10833 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10834 layout_binding.pImmutableSamplers = NULL;
10835
10836 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10837 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10838 ds_layout_ci.bindingCount = 1;
10839 ds_layout_ci.pBindings = &layout_binding;
10840 VkDescriptorSetLayout ds_layout;
10841 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10842 ASSERT_VK_SUCCESS(err);
10843
10844 VkDescriptorSetAllocateInfo alloc_info = {};
10845 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10846 alloc_info.descriptorSetCount = 1;
10847 alloc_info.descriptorPool = ds_pool;
10848 alloc_info.pSetLayouts = &ds_layout;
10849 VkDescriptorSet descriptor_set;
10850 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10851 ASSERT_VK_SUCCESS(err);
10852
10853 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10854 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10855 pipeline_layout_ci.pNext = NULL;
10856 pipeline_layout_ci.setLayoutCount = 1;
10857 pipeline_layout_ci.pSetLayouts = &ds_layout;
10858
10859 VkPipelineLayout pipeline_layout;
10860 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
10861 ASSERT_VK_SUCCESS(err);
10862
10863 VkImageObj image(m_device);
10864 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
10865 ASSERT_TRUE(image.initialized());
10866
10867 VkImageView view;
10868 VkImageViewCreateInfo ivci = {};
10869 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10870 ivci.image = image.handle();
10871 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10872 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
10873 ivci.subresourceRange.layerCount = 1;
10874 ivci.subresourceRange.baseMipLevel = 0;
10875 ivci.subresourceRange.levelCount = 1;
10876 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10877
10878 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
10879 ASSERT_VK_SUCCESS(err);
10880
10881 VkDescriptorImageInfo image_info{};
10882 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10883 image_info.imageView = view;
10884 image_info.sampler = sampler;
10885
10886 VkWriteDescriptorSet descriptor_write = {};
10887 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10888 descriptor_write.dstSet = descriptor_set;
10889 descriptor_write.dstBinding = 0;
10890 descriptor_write.descriptorCount = 1;
10891 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10892 descriptor_write.pImageInfo = &image_info;
10893
10894 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10895
10896 // Create PSO to use the sampler
10897 char const *vsSource = "#version 450\n"
10898 "\n"
10899 "out gl_PerVertex { \n"
10900 " vec4 gl_Position;\n"
10901 "};\n"
10902 "void main(){\n"
10903 " gl_Position = vec4(1);\n"
10904 "}\n";
10905 char const *fsSource = "#version 450\n"
10906 "\n"
10907 "layout(set=0, binding=0) uniform sampler2D s;\n"
10908 "layout(location=0) out vec4 x;\n"
10909 "void main(){\n"
10910 " x = texture(s, vec2(1));\n"
10911 "}\n";
10912 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
10913 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
10914 VkPipelineObj pipe(m_device);
10915 pipe.AddShader(&vs);
10916 pipe.AddShader(&fs);
10917 pipe.AddColorAttachment();
10918 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10919
10920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete image view 0x");
10921
10922 BeginCommandBuffer();
10923 // Bind pipeline to cmd buffer
10924 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
10925 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
10926 &descriptor_set, 0, nullptr);
10927 Draw(1, 0, 0, 0);
10928 EndCommandBuffer();
10929 // Submit cmd buffer then destroy sampler
10930 VkSubmitInfo submit_info = {};
10931 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
10932 submit_info.commandBufferCount = 1;
10933 submit_info.pCommandBuffers = &m_commandBuffer->handle();
10934 // Submit cmd buffer and then destroy imageView while in-flight
10935 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
10936
10937 vkDestroyImageView(m_device->device(), view, nullptr);
10938 m_errorMonitor->VerifyFound();
10939 vkQueueWaitIdle(m_device->m_queue);
10940 // Now we can actually destroy imageView
10941 vkDestroyImageView(m_device->device(), view, NULL);
10942 vkDestroySampler(m_device->device(), sampler, nullptr);
10943 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10944 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10945 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10946}
10947
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060010948TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
10949 TEST_DESCRIPTION("Delete in-use bufferView.");
10950
10951 ASSERT_NO_FATAL_FAILURE(InitState());
10952 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10953
10954 VkDescriptorPoolSize ds_type_count;
10955 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10956 ds_type_count.descriptorCount = 1;
10957
10958 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10959 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10960 ds_pool_ci.maxSets = 1;
10961 ds_pool_ci.poolSizeCount = 1;
10962 ds_pool_ci.pPoolSizes = &ds_type_count;
10963
10964 VkDescriptorPool ds_pool;
10965 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10966 ASSERT_VK_SUCCESS(err);
10967
10968 VkDescriptorSetLayoutBinding layout_binding;
10969 layout_binding.binding = 0;
10970 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
10971 layout_binding.descriptorCount = 1;
10972 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
10973 layout_binding.pImmutableSamplers = NULL;
10974
10975 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10976 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10977 ds_layout_ci.bindingCount = 1;
10978 ds_layout_ci.pBindings = &layout_binding;
10979 VkDescriptorSetLayout ds_layout;
10980 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10981 ASSERT_VK_SUCCESS(err);
10982
10983 VkDescriptorSetAllocateInfo alloc_info = {};
10984 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10985 alloc_info.descriptorSetCount = 1;
10986 alloc_info.descriptorPool = ds_pool;
10987 alloc_info.pSetLayouts = &ds_layout;
10988 VkDescriptorSet descriptor_set;
10989 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10990 ASSERT_VK_SUCCESS(err);
10991
10992 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10993 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10994 pipeline_layout_ci.pNext = NULL;
10995 pipeline_layout_ci.setLayoutCount = 1;
10996 pipeline_layout_ci.pSetLayouts = &ds_layout;
10997
10998 VkPipelineLayout pipeline_layout;
10999 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11000 ASSERT_VK_SUCCESS(err);
11001
11002 VkBuffer buffer;
11003 uint32_t queue_family_index = 0;
11004 VkBufferCreateInfo buffer_create_info = {};
11005 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11006 buffer_create_info.size = 1024;
11007 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11008 buffer_create_info.queueFamilyIndexCount = 1;
11009 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11010
11011 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11012 ASSERT_VK_SUCCESS(err);
11013
11014 VkMemoryRequirements memory_reqs;
11015 VkDeviceMemory buffer_memory;
11016
11017 VkMemoryAllocateInfo memory_info = {};
11018 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11019 memory_info.allocationSize = 0;
11020 memory_info.memoryTypeIndex = 0;
11021
11022 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11023 memory_info.allocationSize = memory_reqs.size;
11024 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11025 ASSERT_TRUE(pass);
11026
11027 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11028 ASSERT_VK_SUCCESS(err);
11029 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11030 ASSERT_VK_SUCCESS(err);
11031
11032 VkBufferView view;
11033 VkBufferViewCreateInfo bvci = {};
11034 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11035 bvci.buffer = buffer;
11036 bvci.format = VK_FORMAT_R8_UNORM;
11037 bvci.range = VK_WHOLE_SIZE;
11038
11039 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11040 ASSERT_VK_SUCCESS(err);
11041
11042 VkWriteDescriptorSet descriptor_write = {};
11043 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11044 descriptor_write.dstSet = descriptor_set;
11045 descriptor_write.dstBinding = 0;
11046 descriptor_write.descriptorCount = 1;
11047 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11048 descriptor_write.pTexelBufferView = &view;
11049
11050 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11051
11052 char const *vsSource = "#version 450\n"
11053 "\n"
11054 "out gl_PerVertex { \n"
11055 " vec4 gl_Position;\n"
11056 "};\n"
11057 "void main(){\n"
11058 " gl_Position = vec4(1);\n"
11059 "}\n";
11060 char const *fsSource = "#version 450\n"
11061 "\n"
11062 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11063 "layout(location=0) out vec4 x;\n"
11064 "void main(){\n"
11065 " x = imageLoad(s, 0);\n"
11066 "}\n";
11067 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11068 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11069 VkPipelineObj pipe(m_device);
11070 pipe.AddShader(&vs);
11071 pipe.AddShader(&fs);
11072 pipe.AddColorAttachment();
11073 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11074
11075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete buffer view 0x");
11076
11077 BeginCommandBuffer();
11078 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11079 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11080 VkRect2D scissor = {{0, 0}, {16, 16}};
11081 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11082 // Bind pipeline to cmd buffer
11083 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11084 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11085 &descriptor_set, 0, nullptr);
11086 Draw(1, 0, 0, 0);
11087 EndCommandBuffer();
11088
11089 VkSubmitInfo submit_info = {};
11090 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11091 submit_info.commandBufferCount = 1;
11092 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11093 // Submit cmd buffer and then destroy bufferView while in-flight
11094 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11095
11096 vkDestroyBufferView(m_device->device(), view, nullptr);
11097 m_errorMonitor->VerifyFound();
11098 vkQueueWaitIdle(m_device->m_queue);
11099 // Now we can actually destroy bufferView
11100 vkDestroyBufferView(m_device->device(), view, NULL);
11101 vkDestroyBuffer(m_device->device(), buffer, NULL);
11102 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11103 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11104 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11105 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11106}
11107
Tobin Ehlis209532e2016-09-07 13:52:18 -060011108TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11109 TEST_DESCRIPTION("Delete in-use sampler.");
11110
11111 ASSERT_NO_FATAL_FAILURE(InitState());
11112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11113
11114 VkDescriptorPoolSize ds_type_count;
11115 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11116 ds_type_count.descriptorCount = 1;
11117
11118 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11119 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11120 ds_pool_ci.maxSets = 1;
11121 ds_pool_ci.poolSizeCount = 1;
11122 ds_pool_ci.pPoolSizes = &ds_type_count;
11123
11124 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011125 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011126 ASSERT_VK_SUCCESS(err);
11127
11128 VkSamplerCreateInfo sampler_ci = {};
11129 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11130 sampler_ci.pNext = NULL;
11131 sampler_ci.magFilter = VK_FILTER_NEAREST;
11132 sampler_ci.minFilter = VK_FILTER_NEAREST;
11133 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11134 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11135 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11136 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11137 sampler_ci.mipLodBias = 1.0;
11138 sampler_ci.anisotropyEnable = VK_FALSE;
11139 sampler_ci.maxAnisotropy = 1;
11140 sampler_ci.compareEnable = VK_FALSE;
11141 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11142 sampler_ci.minLod = 1.0;
11143 sampler_ci.maxLod = 1.0;
11144 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11145 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11146 VkSampler sampler;
11147
11148 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11149 ASSERT_VK_SUCCESS(err);
11150
11151 VkDescriptorSetLayoutBinding layout_binding;
11152 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011153 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011154 layout_binding.descriptorCount = 1;
11155 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11156 layout_binding.pImmutableSamplers = NULL;
11157
11158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11160 ds_layout_ci.bindingCount = 1;
11161 ds_layout_ci.pBindings = &layout_binding;
11162 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011163 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011164 ASSERT_VK_SUCCESS(err);
11165
11166 VkDescriptorSetAllocateInfo alloc_info = {};
11167 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11168 alloc_info.descriptorSetCount = 1;
11169 alloc_info.descriptorPool = ds_pool;
11170 alloc_info.pSetLayouts = &ds_layout;
11171 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011172 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011173 ASSERT_VK_SUCCESS(err);
11174
11175 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11176 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11177 pipeline_layout_ci.pNext = NULL;
11178 pipeline_layout_ci.setLayoutCount = 1;
11179 pipeline_layout_ci.pSetLayouts = &ds_layout;
11180
11181 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011182 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011183 ASSERT_VK_SUCCESS(err);
11184
11185 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011186 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 -060011187 ASSERT_TRUE(image.initialized());
11188
11189 VkImageView view;
11190 VkImageViewCreateInfo ivci = {};
11191 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11192 ivci.image = image.handle();
11193 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11194 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11195 ivci.subresourceRange.layerCount = 1;
11196 ivci.subresourceRange.baseMipLevel = 0;
11197 ivci.subresourceRange.levelCount = 1;
11198 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11199
11200 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11201 ASSERT_VK_SUCCESS(err);
11202
11203 VkDescriptorImageInfo image_info{};
11204 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11205 image_info.imageView = view;
11206 image_info.sampler = sampler;
11207
11208 VkWriteDescriptorSet descriptor_write = {};
11209 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11210 descriptor_write.dstSet = descriptor_set;
11211 descriptor_write.dstBinding = 0;
11212 descriptor_write.descriptorCount = 1;
11213 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11214 descriptor_write.pImageInfo = &image_info;
11215
11216 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11217
11218 // Create PSO to use the sampler
11219 char const *vsSource = "#version 450\n"
11220 "\n"
11221 "out gl_PerVertex { \n"
11222 " vec4 gl_Position;\n"
11223 "};\n"
11224 "void main(){\n"
11225 " gl_Position = vec4(1);\n"
11226 "}\n";
11227 char const *fsSource = "#version 450\n"
11228 "\n"
11229 "layout(set=0, binding=0) uniform sampler2D s;\n"
11230 "layout(location=0) out vec4 x;\n"
11231 "void main(){\n"
11232 " x = texture(s, vec2(1));\n"
11233 "}\n";
11234 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11235 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11236 VkPipelineObj pipe(m_device);
11237 pipe.AddShader(&vs);
11238 pipe.AddShader(&fs);
11239 pipe.AddColorAttachment();
11240 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete sampler 0x");
Tobin Ehlis209532e2016-09-07 13:52:18 -060011243
11244 BeginCommandBuffer();
11245 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011246 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11247 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11248 &descriptor_set, 0, nullptr);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011249 Draw(1, 0, 0, 0);
11250 EndCommandBuffer();
11251 // Submit cmd buffer then destroy sampler
11252 VkSubmitInfo submit_info = {};
11253 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11254 submit_info.commandBufferCount = 1;
11255 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11256 // Submit cmd buffer and then destroy sampler while in-flight
11257 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11258
11259 vkDestroySampler(m_device->device(), sampler, nullptr);
11260 m_errorMonitor->VerifyFound();
11261 vkQueueWaitIdle(m_device->m_queue);
11262 // Now we can actually destroy sampler
11263 vkDestroySampler(m_device->device(), sampler, nullptr);
11264 vkDestroyImageView(m_device->device(), view, NULL);
11265 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11266 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11267 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11268}
11269
Mark Mueller1cd9f412016-08-25 13:23:52 -060011270TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060011271 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060011272 "signaled but not waited on by the queue. Wait on a "
11273 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060011274
11275 ASSERT_NO_FATAL_FAILURE(InitState());
11276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011278 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
11279 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
11280 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060011281
11282 BeginCommandBuffer();
11283 EndCommandBuffer();
11284
11285 VkSemaphoreCreateInfo semaphore_create_info = {};
11286 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11287 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011288 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060011289 VkSubmitInfo submit_info = {};
11290 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11291 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011292 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060011293 submit_info.signalSemaphoreCount = 1;
11294 submit_info.pSignalSemaphores = &semaphore;
11295 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11296 m_errorMonitor->SetDesiredFailureMsg(0, "");
11297 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11298 BeginCommandBuffer();
11299 EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060011301 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11302 m_errorMonitor->VerifyFound();
11303
Mark Mueller1cd9f412016-08-25 13:23:52 -060011304 VkFenceCreateInfo fence_create_info = {};
11305 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11306 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011307 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060011308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060011310 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
11311 m_errorMonitor->VerifyFound();
11312
Mark Mueller4042b652016-09-05 22:52:21 -060011313 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060011314 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060011315 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11316}
11317
Tobin Ehlis4af23302016-07-19 10:50:30 -060011318TEST_F(VkLayerTest, FramebufferIncompatible) {
11319 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
11320 "that does not match the framebuffer for the active "
11321 "renderpass.");
11322 ASSERT_NO_FATAL_FAILURE(InitState());
11323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11324
11325 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011326 VkAttachmentDescription attachment = {0,
11327 VK_FORMAT_B8G8R8A8_UNORM,
11328 VK_SAMPLE_COUNT_1_BIT,
11329 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11330 VK_ATTACHMENT_STORE_OP_STORE,
11331 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
11332 VK_ATTACHMENT_STORE_OP_DONT_CARE,
11333 VK_IMAGE_LAYOUT_UNDEFINED,
11334 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011336 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011337
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011338 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011340 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011341
11342 VkRenderPass rp;
11343 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
11344 ASSERT_VK_SUCCESS(err);
11345
11346 // A compatible framebuffer.
11347 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011348 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 -060011349 ASSERT_TRUE(image.initialized());
11350
11351 VkImageViewCreateInfo ivci = {
11352 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
11353 nullptr,
11354 0,
11355 image.handle(),
11356 VK_IMAGE_VIEW_TYPE_2D,
11357 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011358 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
11359 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060011360 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
11361 };
11362 VkImageView view;
11363 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
11364 ASSERT_VK_SUCCESS(err);
11365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011366 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060011367 VkFramebuffer fb;
11368 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
11369 ASSERT_VK_SUCCESS(err);
11370
11371 VkCommandBufferAllocateInfo cbai = {};
11372 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11373 cbai.commandPool = m_commandPool;
11374 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11375 cbai.commandBufferCount = 1;
11376
11377 VkCommandBuffer sec_cb;
11378 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
11379 ASSERT_VK_SUCCESS(err);
11380 VkCommandBufferBeginInfo cbbi = {};
11381 VkCommandBufferInheritanceInfo cbii = {};
11382 cbii.renderPass = renderPass();
11383 cbii.framebuffer = fb;
11384 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11385 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011386 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 -060011387 cbbi.pInheritanceInfo = &cbii;
11388 vkBeginCommandBuffer(sec_cb, &cbbi);
11389 vkEndCommandBuffer(sec_cb);
11390
Chris Forbes3400bc52016-09-13 18:10:34 +120011391 VkCommandBufferBeginInfo cbbi2 = {
11392 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
11393 0, nullptr
11394 };
11395 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
11396 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060011397
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060011399 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060011400 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
11401 m_errorMonitor->VerifyFound();
11402 // Cleanup
11403 vkDestroyImageView(m_device->device(), view, NULL);
11404 vkDestroyRenderPass(m_device->device(), rp, NULL);
11405 vkDestroyFramebuffer(m_device->device(), fb, NULL);
11406}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011407
11408TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
11409 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
11410 "invalid value. If logicOp is not available, attempt to "
11411 "use it and verify that we see the correct error.");
11412 ASSERT_NO_FATAL_FAILURE(InitState());
11413 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11414
11415 auto features = m_device->phy().features();
11416 // Set the expected error depending on whether or not logicOp available
11417 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
11419 "enabled, logicOpEnable must be "
11420 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011421 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130011422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011423 }
11424 // Create a pipeline using logicOp
11425 VkResult err;
11426
11427 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11428 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11429
11430 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011431 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011432 ASSERT_VK_SUCCESS(err);
11433
11434 VkPipelineViewportStateCreateInfo vp_state_ci = {};
11435 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11436 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011437 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011438 vp_state_ci.pViewports = &vp;
11439 vp_state_ci.scissorCount = 1;
11440 VkRect2D scissors = {}; // Dummy scissors to point to
11441 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011442
11443 VkPipelineShaderStageCreateInfo shaderStages[2];
11444 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
11445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011446 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11447 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011448 shaderStages[0] = vs.GetStageCreateInfo();
11449 shaderStages[1] = fs.GetStageCreateInfo();
11450
11451 VkPipelineVertexInputStateCreateInfo vi_ci = {};
11452 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11453
11454 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
11455 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11456 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11457
11458 VkPipelineRasterizationStateCreateInfo rs_ci = {};
11459 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130011460 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011461
11462 VkPipelineColorBlendAttachmentState att = {};
11463 att.blendEnable = VK_FALSE;
11464 att.colorWriteMask = 0xf;
11465
11466 VkPipelineColorBlendStateCreateInfo cb_ci = {};
11467 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11468 // Enable logicOp & set logicOp to value 1 beyond allowed entries
11469 cb_ci.logicOpEnable = VK_TRUE;
11470 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
11471 cb_ci.attachmentCount = 1;
11472 cb_ci.pAttachments = &att;
11473
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011474 VkPipelineMultisampleStateCreateInfo ms_ci = {};
11475 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
11476 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11477
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011478 VkGraphicsPipelineCreateInfo gp_ci = {};
11479 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11480 gp_ci.stageCount = 2;
11481 gp_ci.pStages = shaderStages;
11482 gp_ci.pVertexInputState = &vi_ci;
11483 gp_ci.pInputAssemblyState = &ia_ci;
11484 gp_ci.pViewportState = &vp_state_ci;
11485 gp_ci.pRasterizationState = &rs_ci;
11486 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130011487 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011488 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11489 gp_ci.layout = pipeline_layout;
11490 gp_ci.renderPass = renderPass();
11491
11492 VkPipelineCacheCreateInfo pc_ci = {};
11493 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11494
11495 VkPipeline pipeline;
11496 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011497 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011498 ASSERT_VK_SUCCESS(err);
11499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011500 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011501 m_errorMonitor->VerifyFound();
11502 if (VK_SUCCESS == err) {
11503 vkDestroyPipeline(m_device->device(), pipeline, NULL);
11504 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060011505 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
11506 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11507}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011508#endif // DRAW_STATE_TESTS
11509
Tobin Ehlis0788f522015-05-26 16:11:58 -060011510#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060011511#if GTEST_IS_THREADSAFE
11512struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011513 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011514 VkEvent event;
11515 bool bailout;
11516};
11517
Karl Schultz6addd812016-02-02 17:17:23 -070011518extern "C" void *AddToCommandBuffer(void *arg) {
11519 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011520
Mike Stroyana6d14942016-07-13 15:10:05 -060011521 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011522 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011523 if (data->bailout) {
11524 break;
11525 }
11526 }
11527 return NULL;
11528}
11529
Karl Schultz6addd812016-02-02 17:17:23 -070011530TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011531 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011534
Mike Stroyanaccf7692015-05-12 16:00:45 -060011535 ASSERT_NO_FATAL_FAILURE(InitState());
11536 ASSERT_NO_FATAL_FAILURE(InitViewport());
11537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11538
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011539 // Calls AllocateCommandBuffers
11540 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011541
11542 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011543 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011544
11545 VkEventCreateInfo event_info;
11546 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060011547 VkResult err;
11548
11549 memset(&event_info, 0, sizeof(event_info));
11550 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11551
Chia-I Wuf7458c52015-10-26 21:10:41 +080011552 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011553 ASSERT_VK_SUCCESS(err);
11554
Mike Stroyanaccf7692015-05-12 16:00:45 -060011555 err = vkResetEvent(device(), event);
11556 ASSERT_VK_SUCCESS(err);
11557
11558 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011559 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011560 data.event = event;
11561 data.bailout = false;
11562 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060011563
11564 // First do some correct operations using multiple threads.
11565 // Add many entries to command buffer from another thread.
11566 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
11567 // Make non-conflicting calls from this thread at the same time.
11568 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060011569 uint32_t count;
11570 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060011571 }
11572 test_platform_thread_join(thread, NULL);
11573
11574 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060011575 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011576 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011577 // Add many entries to command buffer from this thread at the same time.
11578 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060011579
Mike Stroyan4268d1f2015-07-13 14:45:35 -060011580 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011581 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011582
Mike Stroyan10b8cb72016-01-22 15:22:03 -070011583 m_errorMonitor->SetBailout(NULL);
11584
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011585 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060011586
Chia-I Wuf7458c52015-10-26 21:10:41 +080011587 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060011588}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011589#endif // GTEST_IS_THREADSAFE
11590#endif // THREADING_TESTS
11591
Chris Forbes9f7ff632015-05-25 11:13:08 +120011592#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070011593TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011594 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11595 "with an impossible code size");
11596
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011598
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011599 ASSERT_NO_FATAL_FAILURE(InitState());
11600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11601
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011602 VkShaderModule module;
11603 VkShaderModuleCreateInfo moduleCreateInfo;
11604 struct icd_spv_header spv;
11605
11606 spv.magic = ICD_SPV_MAGIC;
11607 spv.version = ICD_SPV_VERSION;
11608 spv.gen_magic = 0;
11609
11610 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11611 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011612 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011613 moduleCreateInfo.codeSize = 4;
11614 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011615 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011616
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011617 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011618}
11619
Karl Schultz6addd812016-02-02 17:17:23 -070011620TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011621 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
11622 "with a bad magic number");
11623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011625
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011626 ASSERT_NO_FATAL_FAILURE(InitState());
11627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11628
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011629 VkShaderModule module;
11630 VkShaderModuleCreateInfo moduleCreateInfo;
11631 struct icd_spv_header spv;
11632
11633 spv.magic = ~ICD_SPV_MAGIC;
11634 spv.version = ICD_SPV_VERSION;
11635 spv.gen_magic = 0;
11636
11637 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11638 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070011639 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011640 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11641 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011642 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011643
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011644 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011645}
11646
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011647#if 0
11648// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070011649TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070011650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011651 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011652
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011653 ASSERT_NO_FATAL_FAILURE(InitState());
11654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11655
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011656 VkShaderModule module;
11657 VkShaderModuleCreateInfo moduleCreateInfo;
11658 struct icd_spv_header spv;
11659
11660 spv.magic = ICD_SPV_MAGIC;
11661 spv.version = ~ICD_SPV_VERSION;
11662 spv.gen_magic = 0;
11663
11664 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
11665 moduleCreateInfo.pNext = NULL;
11666
Karl Schultz6addd812016-02-02 17:17:23 -070011667 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011668 moduleCreateInfo.codeSize = sizeof(spv) + 10;
11669 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011670 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011671
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011672 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011673}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120011674#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060011675
Karl Schultz6addd812016-02-02 17:17:23 -070011676TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120011677 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
11678 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011680
Chris Forbes9f7ff632015-05-25 11:13:08 +120011681 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060011682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011683
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011684 char const *vsSource = "#version 450\n"
11685 "\n"
11686 "layout(location=0) out float x;\n"
11687 "out gl_PerVertex {\n"
11688 " vec4 gl_Position;\n"
11689 "};\n"
11690 "void main(){\n"
11691 " gl_Position = vec4(1);\n"
11692 " x = 0;\n"
11693 "}\n";
11694 char const *fsSource = "#version 450\n"
11695 "\n"
11696 "layout(location=0) out vec4 color;\n"
11697 "void main(){\n"
11698 " color = vec4(1);\n"
11699 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120011700
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060011701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011703
11704 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080011705 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011706 pipe.AddShader(&vs);
11707 pipe.AddShader(&fs);
11708
Chris Forbes9f7ff632015-05-25 11:13:08 +120011709 VkDescriptorSetObj descriptorSet(m_device);
11710 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011711 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120011712
Tony Barbour5781e8f2015-08-04 16:23:11 -060011713 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120011714
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011715 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120011716}
Chris Forbes9f7ff632015-05-25 11:13:08 +120011717
Mark Mueller098c9cb2016-09-08 09:01:57 -060011718TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
11719 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11720
11721 ASSERT_NO_FATAL_FAILURE(InitState());
11722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11723
11724 const char *bad_specialization_message =
11725 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
11726
11727 char const *vsSource =
11728 "#version 450\n"
11729 "\n"
11730 "out gl_PerVertex {\n"
11731 " vec4 gl_Position;\n"
11732 "};\n"
11733 "void main(){\n"
11734 " gl_Position = vec4(1);\n"
11735 "}\n";
11736
11737 char const *fsSource =
11738 "#version 450\n"
11739 "\n"
11740 "layout (constant_id = 0) const float r = 0.0f;\n"
11741 "layout(location = 0) out vec4 uFragColor;\n"
11742 "void main(){\n"
11743 " uFragColor = vec4(r,1,0,1);\n"
11744 "}\n";
11745
11746 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11747 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11748
11749 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11750 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11751
11752 VkPipelineLayout pipeline_layout;
11753 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11754
11755 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
11756 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
11757 vp_state_create_info.viewportCount = 1;
11758 VkViewport viewport = {};
11759 vp_state_create_info.pViewports = &viewport;
11760 vp_state_create_info.scissorCount = 1;
11761 VkRect2D scissors = {};
11762 vp_state_create_info.pScissors = &scissors;
11763
11764 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
11765
11766 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
11767 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
11768 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
11769 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
11770
11771 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
11772 vs.GetStageCreateInfo(),
11773 fs.GetStageCreateInfo()
11774 };
11775
11776 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
11777 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
11778
11779 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
11780 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
11781 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
11782
11783 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
11784 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
11785 rasterization_state_create_info.pNext = nullptr;
11786 rasterization_state_create_info.lineWidth = 1.0f;
11787 rasterization_state_create_info.rasterizerDiscardEnable = true;
11788
11789 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
11790 color_blend_attachment_state.blendEnable = VK_FALSE;
11791 color_blend_attachment_state.colorWriteMask = 0xf;
11792
11793 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
11794 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
11795 color_blend_state_create_info.attachmentCount = 1;
11796 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
11797
11798 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
11799 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
11800 graphicspipe_create_info.stageCount = 2;
11801 graphicspipe_create_info.pStages = shader_stage_create_info;
11802 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
11803 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
11804 graphicspipe_create_info.pViewportState = &vp_state_create_info;
11805 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
11806 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
11807 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
11808 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
11809 graphicspipe_create_info.layout = pipeline_layout;
11810 graphicspipe_create_info.renderPass = renderPass();
11811
11812 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
11813 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
11814
11815 VkPipelineCache pipelineCache;
11816 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
11817
11818 // This structure maps constant ids to data locations.
11819 const VkSpecializationMapEntry entry =
11820 // id, offset, size
11821 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
11822
11823 uint32_t data = 1;
11824
11825 // Set up the info describing spec map and data
11826 const VkSpecializationInfo specialization_info = {
11827 1,
11828 &entry,
11829 1 * sizeof(float),
11830 &data,
11831 };
11832 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
11833
11834 VkPipeline pipeline;
11835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
11836 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
11837 m_errorMonitor->VerifyFound();
11838
11839 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
11840 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11841}
11842
11843TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
11844 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
11845
11846 ASSERT_NO_FATAL_FAILURE(InitState());
11847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11848
11849 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
11850
11851 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
11852 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11853 descriptor_pool_type_count[0].descriptorCount = 1;
11854 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11855 descriptor_pool_type_count[1].descriptorCount = 1;
11856
11857 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11858 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11859 descriptor_pool_create_info.maxSets = 1;
11860 descriptor_pool_create_info.poolSizeCount = 2;
11861 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
11862 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11863
11864 VkDescriptorPool descriptorset_pool;
11865 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11866
11867 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11868 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
11869 descriptorset_layout_binding.descriptorCount = 1;
11870 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11871
11872 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11873 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11874 descriptorset_layout_create_info.bindingCount = 1;
11875 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11876
11877 VkDescriptorSetLayout descriptorset_layout;
11878 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
11879
11880 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11881 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11882 descriptorset_allocate_info.descriptorSetCount = 1;
11883 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11884 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11885 VkDescriptorSet descriptorset;
11886 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11887
11888 // Challenge core_validation with a non uniform buffer type.
11889 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
11890
Mark Mueller098c9cb2016-09-08 09:01:57 -060011891 char const *vsSource =
11892 "#version 450\n"
11893 "\n"
11894 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11895 " mat4 mvp;\n"
11896 "} ubuf;\n"
11897 "out gl_PerVertex {\n"
11898 " vec4 gl_Position;\n"
11899 "};\n"
11900 "void main(){\n"
11901 " gl_Position = ubuf.mvp * vec4(1);\n"
11902 "}\n";
11903
11904 char const *fsSource =
11905 "#version 450\n"
11906 "\n"
11907 "layout(location = 0) out vec4 uFragColor;\n"
11908 "void main(){\n"
11909 " uFragColor = vec4(0,1,0,1);\n"
11910 "}\n";
11911
11912 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11913 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11914
11915 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
11916 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11917 pipeline_layout_create_info.setLayoutCount = 1;
11918 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11919
11920 VkPipelineLayout pipeline_layout;
11921 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
11922
11923 VkPipelineObj pipe(m_device);
11924 pipe.AddColorAttachment();
11925 pipe.AddShader(&vs);
11926 pipe.AddShader(&fs);
11927
11928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
11929 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11930 m_errorMonitor->VerifyFound();
11931
11932 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11933 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
11934 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
11935}
11936
11937TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
11938 TEST_DESCRIPTION(
11939 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
11940
11941 ASSERT_NO_FATAL_FAILURE(InitState());
11942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11943
11944 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
11945
11946 VkDescriptorPoolSize descriptor_pool_type_count = {};
11947 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11948 descriptor_pool_type_count.descriptorCount = 1;
11949
11950 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11951 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11952 descriptor_pool_create_info.maxSets = 1;
11953 descriptor_pool_create_info.poolSizeCount = 1;
11954 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
11955 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11956
11957 VkDescriptorPool descriptorset_pool;
11958 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
11959
11960 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
11961 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11962 descriptorset_layout_binding.descriptorCount = 1;
11963 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
11964 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11965
11966 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
11967 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11968 descriptorset_layout_create_info.bindingCount = 1;
11969 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11970
11971 VkDescriptorSetLayout descriptorset_layout;
11972 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
11973 nullptr, &descriptorset_layout));
11974
11975 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
11976 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11977 descriptorset_allocate_info.descriptorSetCount = 1;
11978 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11979 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
11980 VkDescriptorSet descriptorset;
11981 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
11982
11983 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11984
Mark Mueller098c9cb2016-09-08 09:01:57 -060011985 char const *vsSource =
11986 "#version 450\n"
11987 "\n"
11988 "layout (std140, set = 0, binding = 0) uniform buf {\n"
11989 " mat4 mvp;\n"
11990 "} ubuf;\n"
11991 "out gl_PerVertex {\n"
11992 " vec4 gl_Position;\n"
11993 "};\n"
11994 "void main(){\n"
11995 " gl_Position = ubuf.mvp * vec4(1);\n"
11996 "}\n";
11997
11998 char const *fsSource =
11999 "#version 450\n"
12000 "\n"
12001 "layout(location = 0) out vec4 uFragColor;\n"
12002 "void main(){\n"
12003 " uFragColor = vec4(0,1,0,1);\n"
12004 "}\n";
12005
12006 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12007 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12008
12009 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12010 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12011 pipeline_layout_create_info.setLayoutCount = 1;
12012 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12013
12014 VkPipelineLayout pipeline_layout;
12015 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12016
12017 VkPipelineObj pipe(m_device);
12018 pipe.AddColorAttachment();
12019 pipe.AddShader(&vs);
12020 pipe.AddShader(&fs);
12021
12022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12023 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12024 m_errorMonitor->VerifyFound();
12025
12026 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12027 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12028 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12029}
12030
12031TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12032 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12033 "accessible from the current shader stage.");
12034
12035 ASSERT_NO_FATAL_FAILURE(InitState());
12036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12037
12038 const char *push_constant_not_accessible_message =
12039 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12040
12041 char const *vsSource =
12042 "#version 450\n"
12043 "\n"
12044 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12045 "out gl_PerVertex {\n"
12046 " vec4 gl_Position;\n"
12047 "};\n"
12048 "void main(){\n"
12049 " gl_Position = vec4(consts.x);\n"
12050 "}\n";
12051
12052 char const *fsSource =
12053 "#version 450\n"
12054 "\n"
12055 "layout(location = 0) out vec4 uFragColor;\n"
12056 "void main(){\n"
12057 " uFragColor = vec4(0,1,0,1);\n"
12058 "}\n";
12059
12060 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12061 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12062
12063 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12064 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12065
12066 // Set up a push constant range
12067 VkPushConstantRange push_constant_ranges = {};
12068 // Set to the wrong stage to challenge core_validation
12069 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12070 push_constant_ranges.size = 4;
12071
12072 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12073 pipeline_layout_create_info.pushConstantRangeCount = 1;
12074
12075 VkPipelineLayout pipeline_layout;
12076 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12077
12078 VkPipelineObj pipe(m_device);
12079 pipe.AddColorAttachment();
12080 pipe.AddShader(&vs);
12081 pipe.AddShader(&fs);
12082
12083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12084 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12085 m_errorMonitor->VerifyFound();
12086
12087 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12088}
12089
12090TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12091 TEST_DESCRIPTION(
12092 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12093
12094 ASSERT_NO_FATAL_FAILURE(InitState());
12095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12096
12097 const char *feature_not_enabled_message =
12098 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12099
12100 // Some awkward steps are required to test with custom device features.
12101 std::vector<const char *> device_extension_names;
12102 auto features = m_device->phy().features();
12103 // Disable support for 64 bit floats
12104 features.shaderFloat64 = false;
12105 // The sacrificial device object
12106 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12107
12108 char const *vsSource = "#version 450\n"
12109 "\n"
12110 "out gl_PerVertex {\n"
12111 " vec4 gl_Position;\n"
12112 "};\n"
12113 "void main(){\n"
12114 " gl_Position = vec4(1);\n"
12115 "}\n";
12116 char const *fsSource = "#version 450\n"
12117 "\n"
12118 "layout(location=0) out vec4 color;\n"
12119 "void main(){\n"
12120 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12121 " color = vec4(green);\n"
12122 "}\n";
12123
12124 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12125 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12126
12127 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012128
12129 VkPipelineObj pipe(&test_device);
12130 pipe.AddColorAttachment();
12131 pipe.AddShader(&vs);
12132 pipe.AddShader(&fs);
12133
12134 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12135 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12136 VkPipelineLayout pipeline_layout;
12137 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12138
12139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12140 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12141 m_errorMonitor->VerifyFound();
12142
12143 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12144}
12145
12146TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12147 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12148
12149 ASSERT_NO_FATAL_FAILURE(InitState());
12150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12151
12152 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12153
12154 char const *vsSource = "#version 450\n"
12155 "\n"
12156 "out gl_PerVertex {\n"
12157 " vec4 gl_Position;\n"
12158 "};\n"
12159 "layout(xfb_buffer = 1) out;"
12160 "void main(){\n"
12161 " gl_Position = vec4(1);\n"
12162 "}\n";
12163 char const *fsSource = "#version 450\n"
12164 "\n"
12165 "layout(location=0) out vec4 color;\n"
12166 "void main(){\n"
12167 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12168 " color = vec4(green);\n"
12169 "}\n";
12170
12171 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12172 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12173
12174 VkPipelineObj pipe(m_device);
12175 pipe.AddColorAttachment();
12176 pipe.AddShader(&vs);
12177 pipe.AddShader(&fs);
12178
12179 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12180 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12181 VkPipelineLayout pipeline_layout;
12182 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12183
12184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12185 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12186 m_errorMonitor->VerifyFound();
12187
12188 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12189}
12190
Karl Schultz6addd812016-02-02 17:17:23 -070012191TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012192 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12193 "which is not present in the outputs of the previous stage");
12194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012196
Chris Forbes59cb88d2015-05-25 11:13:13 +120012197 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012200 char const *vsSource = "#version 450\n"
12201 "\n"
12202 "out gl_PerVertex {\n"
12203 " vec4 gl_Position;\n"
12204 "};\n"
12205 "void main(){\n"
12206 " gl_Position = vec4(1);\n"
12207 "}\n";
12208 char const *fsSource = "#version 450\n"
12209 "\n"
12210 "layout(location=0) in float x;\n"
12211 "layout(location=0) out vec4 color;\n"
12212 "void main(){\n"
12213 " color = vec4(x);\n"
12214 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012215
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012216 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12217 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012218
12219 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012220 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012221 pipe.AddShader(&vs);
12222 pipe.AddShader(&fs);
12223
Chris Forbes59cb88d2015-05-25 11:13:13 +120012224 VkDescriptorSetObj descriptorSet(m_device);
12225 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012226 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012227
Tony Barbour5781e8f2015-08-04 16:23:11 -060012228 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012229
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012230 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012231}
12232
Karl Schultz6addd812016-02-02 17:17:23 -070012233TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012234 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12235 "within an interace block, which is not present in the outputs "
12236 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012238
12239 ASSERT_NO_FATAL_FAILURE(InitState());
12240 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012242 char const *vsSource = "#version 450\n"
12243 "\n"
12244 "out gl_PerVertex {\n"
12245 " vec4 gl_Position;\n"
12246 "};\n"
12247 "void main(){\n"
12248 " gl_Position = vec4(1);\n"
12249 "}\n";
12250 char const *fsSource = "#version 450\n"
12251 "\n"
12252 "in block { layout(location=0) float x; } ins;\n"
12253 "layout(location=0) out vec4 color;\n"
12254 "void main(){\n"
12255 " color = vec4(ins.x);\n"
12256 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012257
12258 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12259 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12260
12261 VkPipelineObj pipe(m_device);
12262 pipe.AddColorAttachment();
12263 pipe.AddShader(&vs);
12264 pipe.AddShader(&fs);
12265
12266 VkDescriptorSetObj descriptorSet(m_device);
12267 descriptorSet.AppendDummy();
12268 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12269
12270 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12271
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012272 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012273}
12274
Karl Schultz6addd812016-02-02 17:17:23 -070012275TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012276 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012277 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
12279 "output arr[2] of float32' vs 'ptr to "
12280 "input arr[3] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130012281
12282 ASSERT_NO_FATAL_FAILURE(InitState());
12283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012285 char const *vsSource = "#version 450\n"
12286 "\n"
12287 "layout(location=0) out float x[2];\n"
12288 "out gl_PerVertex {\n"
12289 " vec4 gl_Position;\n"
12290 "};\n"
12291 "void main(){\n"
12292 " x[0] = 0; x[1] = 0;\n"
12293 " gl_Position = vec4(1);\n"
12294 "}\n";
12295 char const *fsSource = "#version 450\n"
12296 "\n"
12297 "layout(location=0) in float x[3];\n"
12298 "layout(location=0) out vec4 color;\n"
12299 "void main(){\n"
12300 " color = vec4(x[0] + x[1] + x[2]);\n"
12301 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130012302
12303 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12304 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12305
12306 VkPipelineObj pipe(m_device);
12307 pipe.AddColorAttachment();
12308 pipe.AddShader(&vs);
12309 pipe.AddShader(&fs);
12310
12311 VkDescriptorSetObj descriptorSet(m_device);
12312 descriptorSet.AppendDummy();
12313 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12314
12315 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12316
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012317 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130012318}
12319
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060012320
Karl Schultz6addd812016-02-02 17:17:23 -070012321TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012322 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012323 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012325
Chris Forbesb56af562015-05-25 11:13:17 +120012326 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120012328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012329 char const *vsSource = "#version 450\n"
12330 "\n"
12331 "layout(location=0) out int x;\n"
12332 "out gl_PerVertex {\n"
12333 " vec4 gl_Position;\n"
12334 "};\n"
12335 "void main(){\n"
12336 " x = 0;\n"
12337 " gl_Position = vec4(1);\n"
12338 "}\n";
12339 char const *fsSource = "#version 450\n"
12340 "\n"
12341 "layout(location=0) in float x;\n" /* VS writes int */
12342 "layout(location=0) out vec4 color;\n"
12343 "void main(){\n"
12344 " color = vec4(x);\n"
12345 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120012346
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012347 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12348 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120012349
12350 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012351 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120012352 pipe.AddShader(&vs);
12353 pipe.AddShader(&fs);
12354
Chris Forbesb56af562015-05-25 11:13:17 +120012355 VkDescriptorSetObj descriptorSet(m_device);
12356 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012357 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120012358
Tony Barbour5781e8f2015-08-04 16:23:11 -060012359 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120012360
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012361 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120012362}
12363
Karl Schultz6addd812016-02-02 17:17:23 -070012364TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012365 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012366 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120012367 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130012369
12370 ASSERT_NO_FATAL_FAILURE(InitState());
12371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12372
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012373 char const *vsSource = "#version 450\n"
12374 "\n"
12375 "out block { layout(location=0) int x; } outs;\n"
12376 "out gl_PerVertex {\n"
12377 " vec4 gl_Position;\n"
12378 "};\n"
12379 "void main(){\n"
12380 " outs.x = 0;\n"
12381 " gl_Position = vec4(1);\n"
12382 "}\n";
12383 char const *fsSource = "#version 450\n"
12384 "\n"
12385 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
12386 "layout(location=0) out vec4 color;\n"
12387 "void main(){\n"
12388 " color = vec4(ins.x);\n"
12389 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130012390
12391 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12392 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12393
12394 VkPipelineObj pipe(m_device);
12395 pipe.AddColorAttachment();
12396 pipe.AddShader(&vs);
12397 pipe.AddShader(&fs);
12398
12399 VkDescriptorSetObj descriptorSet(m_device);
12400 descriptorSet.AppendDummy();
12401 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12402
12403 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12404
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012405 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012406}
12407
12408TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012409 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012410 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120012411 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012412 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 +130012413
12414 ASSERT_NO_FATAL_FAILURE(InitState());
12415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012417 char const *vsSource = "#version 450\n"
12418 "\n"
12419 "out block { layout(location=1) float x; } outs;\n"
12420 "out gl_PerVertex {\n"
12421 " vec4 gl_Position;\n"
12422 "};\n"
12423 "void main(){\n"
12424 " outs.x = 0;\n"
12425 " gl_Position = vec4(1);\n"
12426 "}\n";
12427 char const *fsSource = "#version 450\n"
12428 "\n"
12429 "in block { layout(location=0) float x; } ins;\n"
12430 "layout(location=0) out vec4 color;\n"
12431 "void main(){\n"
12432 " color = vec4(ins.x);\n"
12433 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012434
12435 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12436 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12437
12438 VkPipelineObj pipe(m_device);
12439 pipe.AddColorAttachment();
12440 pipe.AddShader(&vs);
12441 pipe.AddShader(&fs);
12442
12443 VkDescriptorSetObj descriptorSet(m_device);
12444 descriptorSet.AppendDummy();
12445 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12446
12447 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12448
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012449 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130012450}
12451
12452TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012453 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060012454 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120012455 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012456 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 +130012457
12458 ASSERT_NO_FATAL_FAILURE(InitState());
12459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12460
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012461 char const *vsSource = "#version 450\n"
12462 "\n"
12463 "out block { layout(location=0, component=0) float x; } outs;\n"
12464 "out gl_PerVertex {\n"
12465 " vec4 gl_Position;\n"
12466 "};\n"
12467 "void main(){\n"
12468 " outs.x = 0;\n"
12469 " gl_Position = vec4(1);\n"
12470 "}\n";
12471 char const *fsSource = "#version 450\n"
12472 "\n"
12473 "in block { layout(location=0, component=1) float x; } ins;\n"
12474 "layout(location=0) out vec4 color;\n"
12475 "void main(){\n"
12476 " color = vec4(ins.x);\n"
12477 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130012478
12479 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12480 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12481
12482 VkPipelineObj pipe(m_device);
12483 pipe.AddColorAttachment();
12484 pipe.AddShader(&vs);
12485 pipe.AddShader(&fs);
12486
12487 VkDescriptorSetObj descriptorSet(m_device);
12488 descriptorSet.AppendDummy();
12489 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12490
12491 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12492
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012493 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130012494}
12495
Karl Schultz6addd812016-02-02 17:17:23 -070012496TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012497 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
12498 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012500
Chris Forbesde136e02015-05-25 11:13:28 +120012501 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120012503
12504 VkVertexInputBindingDescription input_binding;
12505 memset(&input_binding, 0, sizeof(input_binding));
12506
12507 VkVertexInputAttributeDescription input_attrib;
12508 memset(&input_attrib, 0, sizeof(input_attrib));
12509 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12510
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012511 char const *vsSource = "#version 450\n"
12512 "\n"
12513 "out gl_PerVertex {\n"
12514 " vec4 gl_Position;\n"
12515 "};\n"
12516 "void main(){\n"
12517 " gl_Position = vec4(1);\n"
12518 "}\n";
12519 char const *fsSource = "#version 450\n"
12520 "\n"
12521 "layout(location=0) out vec4 color;\n"
12522 "void main(){\n"
12523 " color = vec4(1);\n"
12524 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120012525
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012526 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12527 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120012528
12529 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012530 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120012531 pipe.AddShader(&vs);
12532 pipe.AddShader(&fs);
12533
12534 pipe.AddVertexInputBindings(&input_binding, 1);
12535 pipe.AddVertexInputAttribs(&input_attrib, 1);
12536
Chris Forbesde136e02015-05-25 11:13:28 +120012537 VkDescriptorSetObj descriptorSet(m_device);
12538 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012539 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120012540
Tony Barbour5781e8f2015-08-04 16:23:11 -060012541 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120012542
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012543 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120012544}
12545
Karl Schultz6addd812016-02-02 17:17:23 -070012546TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012547 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
12548 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130012550
12551 ASSERT_NO_FATAL_FAILURE(InitState());
12552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12553
12554 VkVertexInputBindingDescription input_binding;
12555 memset(&input_binding, 0, sizeof(input_binding));
12556
12557 VkVertexInputAttributeDescription input_attrib;
12558 memset(&input_attrib, 0, sizeof(input_attrib));
12559 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12560
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012561 char const *vsSource = "#version 450\n"
12562 "\n"
12563 "layout(location=1) in float x;\n"
12564 "out gl_PerVertex {\n"
12565 " vec4 gl_Position;\n"
12566 "};\n"
12567 "void main(){\n"
12568 " gl_Position = vec4(x);\n"
12569 "}\n";
12570 char const *fsSource = "#version 450\n"
12571 "\n"
12572 "layout(location=0) out vec4 color;\n"
12573 "void main(){\n"
12574 " color = vec4(1);\n"
12575 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130012576
12577 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12578 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12579
12580 VkPipelineObj pipe(m_device);
12581 pipe.AddColorAttachment();
12582 pipe.AddShader(&vs);
12583 pipe.AddShader(&fs);
12584
12585 pipe.AddVertexInputBindings(&input_binding, 1);
12586 pipe.AddVertexInputAttribs(&input_attrib, 1);
12587
12588 VkDescriptorSetObj descriptorSet(m_device);
12589 descriptorSet.AppendDummy();
12590 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12591
12592 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12593
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012594 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130012595}
12596
Karl Schultz6addd812016-02-02 17:17:23 -070012597TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012598 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012599 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012600 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 -060012601
Chris Forbes62e8e502015-05-25 11:13:29 +120012602 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120012604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012605 char const *vsSource = "#version 450\n"
12606 "\n"
12607 "layout(location=0) in vec4 x;\n" /* not provided */
12608 "out gl_PerVertex {\n"
12609 " vec4 gl_Position;\n"
12610 "};\n"
12611 "void main(){\n"
12612 " gl_Position = x;\n"
12613 "}\n";
12614 char const *fsSource = "#version 450\n"
12615 "\n"
12616 "layout(location=0) out vec4 color;\n"
12617 "void main(){\n"
12618 " color = vec4(1);\n"
12619 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120012620
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012621 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12622 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120012623
12624 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012625 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120012626 pipe.AddShader(&vs);
12627 pipe.AddShader(&fs);
12628
Chris Forbes62e8e502015-05-25 11:13:29 +120012629 VkDescriptorSetObj descriptorSet(m_device);
12630 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012631 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120012632
Tony Barbour5781e8f2015-08-04 16:23:11 -060012633 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120012634
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012635 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120012636}
12637
Karl Schultz6addd812016-02-02 17:17:23 -070012638TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012639 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
12640 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060012641 "vertex shader input that consumes it");
12642 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 -060012643
Chris Forbesc97d98e2015-05-25 11:13:31 +120012644 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012646
12647 VkVertexInputBindingDescription input_binding;
12648 memset(&input_binding, 0, sizeof(input_binding));
12649
12650 VkVertexInputAttributeDescription input_attrib;
12651 memset(&input_attrib, 0, sizeof(input_attrib));
12652 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012654 char const *vsSource = "#version 450\n"
12655 "\n"
12656 "layout(location=0) in int x;\n" /* attrib provided float */
12657 "out gl_PerVertex {\n"
12658 " vec4 gl_Position;\n"
12659 "};\n"
12660 "void main(){\n"
12661 " gl_Position = vec4(x);\n"
12662 "}\n";
12663 char const *fsSource = "#version 450\n"
12664 "\n"
12665 "layout(location=0) out vec4 color;\n"
12666 "void main(){\n"
12667 " color = vec4(1);\n"
12668 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120012669
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012670 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12671 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012672
12673 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012674 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012675 pipe.AddShader(&vs);
12676 pipe.AddShader(&fs);
12677
12678 pipe.AddVertexInputBindings(&input_binding, 1);
12679 pipe.AddVertexInputAttribs(&input_attrib, 1);
12680
Chris Forbesc97d98e2015-05-25 11:13:31 +120012681 VkDescriptorSetObj descriptorSet(m_device);
12682 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012683 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120012684
Tony Barbour5781e8f2015-08-04 16:23:11 -060012685 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120012686
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012687 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120012688}
12689
Chris Forbesc68b43c2016-04-06 11:18:47 +120012690TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012691 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
12692 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12694 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120012695
12696 ASSERT_NO_FATAL_FAILURE(InitState());
12697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12698
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012699 char const *vsSource = "#version 450\n"
12700 "\n"
12701 "out gl_PerVertex {\n"
12702 " vec4 gl_Position;\n"
12703 "};\n"
12704 "void main(){\n"
12705 " gl_Position = vec4(1);\n"
12706 "}\n";
12707 char const *fsSource = "#version 450\n"
12708 "\n"
12709 "layout(location=0) out vec4 color;\n"
12710 "void main(){\n"
12711 " color = vec4(1);\n"
12712 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120012713
12714 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12715 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12716
12717 VkPipelineObj pipe(m_device);
12718 pipe.AddColorAttachment();
12719 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060012720 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120012721 pipe.AddShader(&fs);
12722
12723 VkDescriptorSetObj descriptorSet(m_device);
12724 descriptorSet.AppendDummy();
12725 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12726
12727 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12728
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012729 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120012730}
12731
Chris Forbes82ff92a2016-09-09 10:50:24 +120012732TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
12733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12734 "No entrypoint found named `foo`");
12735
12736 ASSERT_NO_FATAL_FAILURE(InitState());
12737 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12738
12739 char const *vsSource = "#version 450\n"
12740 "out gl_PerVertex {\n"
12741 " vec4 gl_Position;\n"
12742 "};\n"
12743 "void main(){\n"
12744 " gl_Position = vec4(0);\n"
12745 "}\n";
12746 char const *fsSource = "#version 450\n"
12747 "\n"
12748 "layout(location=0) out vec4 color;\n"
12749 "void main(){\n"
12750 " color = vec4(1);\n"
12751 "}\n";
12752
12753 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12754 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
12755
12756 VkPipelineObj pipe(m_device);
12757 pipe.AddColorAttachment();
12758 pipe.AddShader(&vs);
12759 pipe.AddShader(&fs);
12760
12761 VkDescriptorSetObj descriptorSet(m_device);
12762 descriptorSet.AppendDummy();
12763 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12764
12765 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12766
12767 m_errorMonitor->VerifyFound();
12768}
12769
Chris Forbesae9d8cd2016-09-13 16:32:57 +120012770TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
12771 m_errorMonitor->SetDesiredFailureMsg(
12772 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12773 "pDepthStencilState is NULL when rasterization is enabled and subpass "
12774 "uses a depth/stencil attachment");
12775
12776 ASSERT_NO_FATAL_FAILURE(InitState());
12777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12778
12779 char const *vsSource = "#version 450\n"
12780 "void main(){ gl_Position = vec4(0); }\n";
12781 char const *fsSource = "#version 450\n"
12782 "\n"
12783 "layout(location=0) out vec4 color;\n"
12784 "void main(){\n"
12785 " color = vec4(1);\n"
12786 "}\n";
12787
12788 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12789 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12790
12791 VkPipelineObj pipe(m_device);
12792 pipe.AddColorAttachment();
12793 pipe.AddShader(&vs);
12794 pipe.AddShader(&fs);
12795
12796 VkDescriptorSetObj descriptorSet(m_device);
12797 descriptorSet.AppendDummy();
12798 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12799
12800 VkAttachmentDescription attachments[] = {
12801 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
12802 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12803 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12804 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
12805 },
12806 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
12807 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12808 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
12809 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
12810 },
12811 };
12812 VkAttachmentReference refs[] = {
12813 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
12814 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
12815 };
12816 VkSubpassDescription subpass = {
12817 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
12818 1, &refs[0], nullptr, &refs[1],
12819 0, nullptr
12820 };
12821 VkRenderPassCreateInfo rpci = {
12822 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
12823 0, 2, attachments, 1, &subpass, 0, nullptr
12824 };
12825 VkRenderPass rp;
12826 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12827 ASSERT_VK_SUCCESS(err);
12828
12829 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
12830
12831 m_errorMonitor->VerifyFound();
12832
12833 vkDestroyRenderPass(m_device->device(), rp, nullptr);
12834}
12835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012836TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012837 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
12838 "the TCS without the patch decoration, but consumed in the TES "
12839 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
12841 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120012842
12843 ASSERT_NO_FATAL_FAILURE(InitState());
12844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12845
Chris Forbesc1e852d2016-04-04 19:26:42 +120012846 if (!m_device->phy().features().tessellationShader) {
12847 printf("Device does not support tessellation shaders; skipped.\n");
12848 return;
12849 }
12850
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012851 char const *vsSource = "#version 450\n"
12852 "void main(){}\n";
12853 char const *tcsSource = "#version 450\n"
12854 "layout(location=0) out int x[];\n"
12855 "layout(vertices=3) out;\n"
12856 "void main(){\n"
12857 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
12858 " gl_TessLevelInner[0] = 1;\n"
12859 " x[gl_InvocationID] = gl_InvocationID;\n"
12860 "}\n";
12861 char const *tesSource = "#version 450\n"
12862 "layout(triangles, equal_spacing, cw) in;\n"
12863 "layout(location=0) patch in int x;\n"
12864 "out gl_PerVertex { vec4 gl_Position; };\n"
12865 "void main(){\n"
12866 " gl_Position.xyz = gl_TessCoord;\n"
12867 " gl_Position.w = x;\n"
12868 "}\n";
12869 char const *fsSource = "#version 450\n"
12870 "layout(location=0) out vec4 color;\n"
12871 "void main(){\n"
12872 " color = vec4(1);\n"
12873 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120012874
12875 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12876 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
12877 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
12878 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012880 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
12881 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012883 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120012884
12885 VkPipelineObj pipe(m_device);
12886 pipe.SetInputAssembly(&iasci);
12887 pipe.SetTessellation(&tsci);
12888 pipe.AddColorAttachment();
12889 pipe.AddShader(&vs);
12890 pipe.AddShader(&tcs);
12891 pipe.AddShader(&tes);
12892 pipe.AddShader(&fs);
12893
12894 VkDescriptorSetObj descriptorSet(m_device);
12895 descriptorSet.AppendDummy();
12896 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
12897
12898 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
12899
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012900 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120012901}
12902
Karl Schultz6addd812016-02-02 17:17:23 -070012903TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012904 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
12905 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12907 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012908
Chris Forbes280ba2c2015-06-12 11:16:41 +120012909 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012911
12912 /* Two binding descriptions for binding 0 */
12913 VkVertexInputBindingDescription input_bindings[2];
12914 memset(input_bindings, 0, sizeof(input_bindings));
12915
12916 VkVertexInputAttributeDescription input_attrib;
12917 memset(&input_attrib, 0, sizeof(input_attrib));
12918 input_attrib.format = VK_FORMAT_R32_SFLOAT;
12919
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012920 char const *vsSource = "#version 450\n"
12921 "\n"
12922 "layout(location=0) in float x;\n" /* attrib provided float */
12923 "out gl_PerVertex {\n"
12924 " vec4 gl_Position;\n"
12925 "};\n"
12926 "void main(){\n"
12927 " gl_Position = vec4(x);\n"
12928 "}\n";
12929 char const *fsSource = "#version 450\n"
12930 "\n"
12931 "layout(location=0) out vec4 color;\n"
12932 "void main(){\n"
12933 " color = vec4(1);\n"
12934 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120012935
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012936 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12937 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012938
12939 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012940 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012941 pipe.AddShader(&vs);
12942 pipe.AddShader(&fs);
12943
12944 pipe.AddVertexInputBindings(input_bindings, 2);
12945 pipe.AddVertexInputAttribs(&input_attrib, 1);
12946
Chris Forbes280ba2c2015-06-12 11:16:41 +120012947 VkDescriptorSetObj descriptorSet(m_device);
12948 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012949 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120012950
Tony Barbour5781e8f2015-08-04 16:23:11 -060012951 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120012952
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012953 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120012954}
Chris Forbes8f68b562015-05-25 11:13:32 +120012955
Karl Schultz6addd812016-02-02 17:17:23 -070012956TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012957 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120012958 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060012959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012960
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012961 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012963 char const *vsSource = "#version 450\n"
12964 "\n"
12965 "out gl_PerVertex {\n"
12966 " vec4 gl_Position;\n"
12967 "};\n"
12968 "void main(){\n"
12969 " gl_Position = vec4(1);\n"
12970 "}\n";
12971 char const *fsSource = "#version 450\n"
12972 "\n"
12973 "void main(){\n"
12974 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012975
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012976 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12977 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012978
12979 VkPipelineObj pipe(m_device);
12980 pipe.AddShader(&vs);
12981 pipe.AddShader(&fs);
12982
Chia-I Wu08accc62015-07-07 11:50:03 +080012983 /* set up CB 0, not written */
12984 pipe.AddColorAttachment();
12985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012986
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012987 VkDescriptorSetObj descriptorSet(m_device);
12988 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012990
Tony Barbour5781e8f2015-08-04 16:23:11 -060012991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012992
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012993 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120012994}
12995
Karl Schultz6addd812016-02-02 17:17:23 -070012996TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060012997 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120012998 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013000 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013001
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013002 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013004 char const *vsSource = "#version 450\n"
13005 "\n"
13006 "out gl_PerVertex {\n"
13007 " vec4 gl_Position;\n"
13008 "};\n"
13009 "void main(){\n"
13010 " gl_Position = vec4(1);\n"
13011 "}\n";
13012 char const *fsSource = "#version 450\n"
13013 "\n"
13014 "layout(location=0) out vec4 x;\n"
13015 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13016 "void main(){\n"
13017 " x = vec4(1);\n"
13018 " y = vec4(1);\n"
13019 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013020
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013021 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13022 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013023
13024 VkPipelineObj pipe(m_device);
13025 pipe.AddShader(&vs);
13026 pipe.AddShader(&fs);
13027
Chia-I Wu08accc62015-07-07 11:50:03 +080013028 /* set up CB 0, not written */
13029 pipe.AddColorAttachment();
13030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013031 /* FS writes CB 1, but we don't configure it */
13032
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013033 VkDescriptorSetObj descriptorSet(m_device);
13034 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013035 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013036
Tony Barbour5781e8f2015-08-04 16:23:11 -060013037 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013038
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013039 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013040}
13041
Karl Schultz6addd812016-02-02 17:17:23 -070013042TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013043 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013044 "type of an fragment shader output variable, and the format of the corresponding attachment");
13045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013046
Chris Forbesa36d69e2015-05-25 11:13:44 +120013047 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013049 char const *vsSource = "#version 450\n"
13050 "\n"
13051 "out gl_PerVertex {\n"
13052 " vec4 gl_Position;\n"
13053 "};\n"
13054 "void main(){\n"
13055 " gl_Position = vec4(1);\n"
13056 "}\n";
13057 char const *fsSource = "#version 450\n"
13058 "\n"
13059 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13060 "void main(){\n"
13061 " x = ivec4(1);\n"
13062 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013063
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013064 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13065 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013066
13067 VkPipelineObj pipe(m_device);
13068 pipe.AddShader(&vs);
13069 pipe.AddShader(&fs);
13070
Chia-I Wu08accc62015-07-07 11:50:03 +080013071 /* set up CB 0; type is UNORM by default */
13072 pipe.AddColorAttachment();
13073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013074
Chris Forbesa36d69e2015-05-25 11:13:44 +120013075 VkDescriptorSetObj descriptorSet(m_device);
13076 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013077 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013078
Tony Barbour5781e8f2015-08-04 16:23:11 -060013079 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013080
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013081 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013082}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013083
Karl Schultz6addd812016-02-02 17:17:23 -070013084TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013085 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13086 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013088
Chris Forbes556c76c2015-08-14 12:04:59 +120013089 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013091 char const *vsSource = "#version 450\n"
13092 "\n"
13093 "out gl_PerVertex {\n"
13094 " vec4 gl_Position;\n"
13095 "};\n"
13096 "void main(){\n"
13097 " gl_Position = vec4(1);\n"
13098 "}\n";
13099 char const *fsSource = "#version 450\n"
13100 "\n"
13101 "layout(location=0) out vec4 x;\n"
13102 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13103 "void main(){\n"
13104 " x = vec4(bar.y);\n"
13105 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013106
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013107 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13108 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013109
Chris Forbes556c76c2015-08-14 12:04:59 +120013110 VkPipelineObj pipe(m_device);
13111 pipe.AddShader(&vs);
13112 pipe.AddShader(&fs);
13113
13114 /* set up CB 0; type is UNORM by default */
13115 pipe.AddColorAttachment();
13116 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13117
13118 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013119 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013120
13121 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13122
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013123 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013124}
13125
Chris Forbes5c59e902016-02-26 16:56:09 +130013126TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013127 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13128 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013130
13131 ASSERT_NO_FATAL_FAILURE(InitState());
13132
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013133 char const *vsSource = "#version 450\n"
13134 "\n"
13135 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13136 "out gl_PerVertex {\n"
13137 " vec4 gl_Position;\n"
13138 "};\n"
13139 "void main(){\n"
13140 " gl_Position = vec4(consts.x);\n"
13141 "}\n";
13142 char const *fsSource = "#version 450\n"
13143 "\n"
13144 "layout(location=0) out vec4 x;\n"
13145 "void main(){\n"
13146 " x = vec4(1);\n"
13147 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013148
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
13156 /* set up CB 0; type is UNORM by default */
13157 pipe.AddColorAttachment();
13158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13159
13160 VkDescriptorSetObj descriptorSet(m_device);
13161 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13162
13163 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13164
13165 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013166 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013167}
13168
Chris Forbes3fb17902016-08-22 14:57:55 +120013169TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13170 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13171 "which is not included in the subpass description");
13172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13173 "consumes input attachment index 0 but not provided in subpass");
13174
13175 ASSERT_NO_FATAL_FAILURE(InitState());
13176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013177 char const *vsSource = "#version 450\n"
13178 "\n"
13179 "out gl_PerVertex {\n"
13180 " vec4 gl_Position;\n"
13181 "};\n"
13182 "void main(){\n"
13183 " gl_Position = vec4(1);\n"
13184 "}\n";
13185 char const *fsSource = "#version 450\n"
13186 "\n"
13187 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13188 "layout(location=0) out vec4 color;\n"
13189 "void main() {\n"
13190 " color = subpassLoad(x);\n"
13191 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120013192
13193 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13194 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13195
13196 VkPipelineObj pipe(m_device);
13197 pipe.AddShader(&vs);
13198 pipe.AddShader(&fs);
13199 pipe.AddColorAttachment();
13200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13201
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013202 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13203 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120013204 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013205 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013206 ASSERT_VK_SUCCESS(err);
13207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013208 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120013209 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013210 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120013211 ASSERT_VK_SUCCESS(err);
13212
13213 // error here.
13214 pipe.CreateVKPipeline(pl, renderPass());
13215
13216 m_errorMonitor->VerifyFound();
13217
13218 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13219 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13220}
13221
Chris Forbes5a9a0472016-08-22 16:02:09 +120013222TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
13223 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13224 "with a format having a different fundamental type");
13225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13226 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
13227
13228 ASSERT_NO_FATAL_FAILURE(InitState());
13229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013230 char const *vsSource = "#version 450\n"
13231 "\n"
13232 "out gl_PerVertex {\n"
13233 " vec4 gl_Position;\n"
13234 "};\n"
13235 "void main(){\n"
13236 " gl_Position = vec4(1);\n"
13237 "}\n";
13238 char const *fsSource = "#version 450\n"
13239 "\n"
13240 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
13241 "layout(location=0) out vec4 color;\n"
13242 "void main() {\n"
13243 " color = subpassLoad(x);\n"
13244 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120013245
13246 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13247 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13248
13249 VkPipelineObj pipe(m_device);
13250 pipe.AddShader(&vs);
13251 pipe.AddShader(&fs);
13252 pipe.AddColorAttachment();
13253 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013255 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13256 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013257 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013258 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013259 ASSERT_VK_SUCCESS(err);
13260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013261 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013262 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013263 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120013264 ASSERT_VK_SUCCESS(err);
13265
13266 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013267 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13268 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13269 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
13270 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
13271 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 +120013272 };
13273 VkAttachmentReference color = {
13274 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13275 };
13276 VkAttachmentReference input = {
13277 1, VK_IMAGE_LAYOUT_GENERAL,
13278 };
13279
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013280 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013281
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013282 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120013283 VkRenderPass rp;
13284 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13285 ASSERT_VK_SUCCESS(err);
13286
13287 // error here.
13288 pipe.CreateVKPipeline(pl, rp);
13289
13290 m_errorMonitor->VerifyFound();
13291
13292 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13293 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13294 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13295}
13296
Chris Forbes541f7b02016-08-22 15:30:27 +120013297TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
13298 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13299 "which is not included in the subpass description -- array case");
13300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13301 "consumes input attachment index 1 but not provided in subpass");
13302
13303 ASSERT_NO_FATAL_FAILURE(InitState());
13304
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013305 char const *vsSource = "#version 450\n"
13306 "\n"
13307 "out gl_PerVertex {\n"
13308 " vec4 gl_Position;\n"
13309 "};\n"
13310 "void main(){\n"
13311 " gl_Position = vec4(1);\n"
13312 "}\n";
13313 char const *fsSource = "#version 450\n"
13314 "\n"
13315 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[2];\n"
13316 "layout(location=0) out vec4 color;\n"
13317 "void main() {\n"
13318 " color = subpassLoad(xs[1]);\n"
13319 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120013320
13321 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13322 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13323
13324 VkPipelineObj pipe(m_device);
13325 pipe.AddShader(&vs);
13326 pipe.AddShader(&fs);
13327 pipe.AddColorAttachment();
13328 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013330 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
13331 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120013332 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013333 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013334 ASSERT_VK_SUCCESS(err);
13335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013336 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120013337 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013338 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120013339 ASSERT_VK_SUCCESS(err);
13340
13341 // error here.
13342 pipe.CreateVKPipeline(pl, renderPass());
13343
13344 m_errorMonitor->VerifyFound();
13345
13346 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13347 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13348}
13349
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013350TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013351 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
13352 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013354
13355 ASSERT_NO_FATAL_FAILURE(InitState());
13356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013357 char const *csSource = "#version 450\n"
13358 "\n"
13359 "layout(local_size_x=1) in;\n"
13360 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13361 "void main(){\n"
13362 " x = vec4(1);\n"
13363 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013364
13365 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13366
13367 VkDescriptorSetObj descriptorSet(m_device);
13368 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013370 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13371 nullptr,
13372 0,
13373 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13374 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13375 descriptorSet.GetPipelineLayout(),
13376 VK_NULL_HANDLE,
13377 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013378
13379 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013380 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120013381
13382 m_errorMonitor->VerifyFound();
13383
13384 if (err == VK_SUCCESS) {
13385 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13386 }
13387}
13388
Chris Forbes22a9b092016-07-19 14:34:05 +120013389TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013390 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
13391 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13393 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120013394
13395 ASSERT_NO_FATAL_FAILURE(InitState());
13396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013397 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
13398 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120013399 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013400 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013401 ASSERT_VK_SUCCESS(err);
13402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013403 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120013404 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013405 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120013406 ASSERT_VK_SUCCESS(err);
13407
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013408 char const *csSource = "#version 450\n"
13409 "\n"
13410 "layout(local_size_x=1) in;\n"
13411 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
13412 "void main() {\n"
13413 " x.x = 1.0f;\n"
13414 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120013415 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
13416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013417 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
13418 nullptr,
13419 0,
13420 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
13421 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
13422 pl,
13423 VK_NULL_HANDLE,
13424 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120013425
13426 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013427 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120013428
13429 m_errorMonitor->VerifyFound();
13430
13431 if (err == VK_SUCCESS) {
13432 vkDestroyPipeline(m_device->device(), pipe, nullptr);
13433 }
13434
13435 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
13436 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
13437}
13438
Chris Forbes50020592016-07-27 13:52:41 +120013439TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
13440 TEST_DESCRIPTION("Test that an error is produced when an image view type "
13441 "does not match the dimensionality declared in the shader");
13442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013443 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 +120013444
13445 ASSERT_NO_FATAL_FAILURE(InitState());
13446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013448 char const *vsSource = "#version 450\n"
13449 "\n"
13450 "out gl_PerVertex { vec4 gl_Position; };\n"
13451 "void main() { gl_Position = vec4(0); }\n";
13452 char const *fsSource = "#version 450\n"
13453 "\n"
13454 "layout(set=0, binding=0) uniform sampler3D s;\n"
13455 "layout(location=0) out vec4 color;\n"
13456 "void main() {\n"
13457 " color = texture(s, vec3(0));\n"
13458 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120013459 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13460 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13461
13462 VkPipelineObj pipe(m_device);
13463 pipe.AddShader(&vs);
13464 pipe.AddShader(&fs);
13465 pipe.AddColorAttachment();
13466
13467 VkTextureObj texture(m_device, nullptr);
13468 VkSamplerObj sampler(m_device);
13469
13470 VkDescriptorSetObj descriptorSet(m_device);
13471 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13472 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13473
13474 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13475 ASSERT_VK_SUCCESS(err);
13476
13477 BeginCommandBuffer();
13478
13479 m_commandBuffer->BindPipeline(pipe);
13480 m_commandBuffer->BindDescriptorSet(descriptorSet);
13481
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013482 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120013483 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013484 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120013485 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13486
13487 // error produced here.
13488 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13489
13490 m_errorMonitor->VerifyFound();
13491
13492 EndCommandBuffer();
13493}
13494
Chris Forbes5533bfc2016-07-27 14:12:34 +120013495TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
13496 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
13497 "are consumed via singlesample images types in the shader, or vice versa.");
13498
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120013500
13501 ASSERT_NO_FATAL_FAILURE(InitState());
13502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13503
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013504 char const *vsSource = "#version 450\n"
13505 "\n"
13506 "out gl_PerVertex { vec4 gl_Position; };\n"
13507 "void main() { gl_Position = vec4(0); }\n";
13508 char const *fsSource = "#version 450\n"
13509 "\n"
13510 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
13511 "layout(location=0) out vec4 color;\n"
13512 "void main() {\n"
13513 " color = texelFetch(s, ivec2(0), 0);\n"
13514 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120013515 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13516 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13517
13518 VkPipelineObj pipe(m_device);
13519 pipe.AddShader(&vs);
13520 pipe.AddShader(&fs);
13521 pipe.AddColorAttachment();
13522
13523 VkTextureObj texture(m_device, nullptr);
13524 VkSamplerObj sampler(m_device);
13525
13526 VkDescriptorSetObj descriptorSet(m_device);
13527 descriptorSet.AppendSamplerTexture(&sampler, &texture);
13528 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13529
13530 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13531 ASSERT_VK_SUCCESS(err);
13532
13533 BeginCommandBuffer();
13534
13535 m_commandBuffer->BindPipeline(pipe);
13536 m_commandBuffer->BindDescriptorSet(descriptorSet);
13537
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013538 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013539 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013540 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120013541 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13542
13543 // error produced here.
13544 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
13545
13546 m_errorMonitor->VerifyFound();
13547
13548 EndCommandBuffer();
13549}
13550
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013551#endif // SHADER_CHECKER_TESTS
13552
13553#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060013554TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013556
13557 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013558
13559 // Create an image
13560 VkImage image;
13561
Karl Schultz6addd812016-02-02 17:17:23 -070013562 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13563 const int32_t tex_width = 32;
13564 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013565
13566 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013567 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13568 image_create_info.pNext = NULL;
13569 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13570 image_create_info.format = tex_format;
13571 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013572 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070013573 image_create_info.extent.depth = 1;
13574 image_create_info.mipLevels = 1;
13575 image_create_info.arrayLayers = 1;
13576 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13577 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13578 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13579 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013580
13581 // Introduce error by sending down a bogus width extent
13582 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013583 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013584
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013585 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060013586}
13587
Mark Youngc48c4c12016-04-11 14:26:49 -060013588TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13590 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060013591
13592 ASSERT_NO_FATAL_FAILURE(InitState());
13593
13594 // Create an image
13595 VkImage image;
13596
13597 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13598 const int32_t tex_width = 32;
13599 const int32_t tex_height = 32;
13600
13601 VkImageCreateInfo image_create_info = {};
13602 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13603 image_create_info.pNext = NULL;
13604 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13605 image_create_info.format = tex_format;
13606 image_create_info.extent.width = tex_width;
13607 image_create_info.extent.height = tex_height;
13608 image_create_info.extent.depth = 1;
13609 image_create_info.mipLevels = 1;
13610 image_create_info.arrayLayers = 1;
13611 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13612 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13613 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13614 image_create_info.flags = 0;
13615
13616 // Introduce error by sending down a bogus width extent
13617 image_create_info.extent.width = 0;
13618 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13619
13620 m_errorMonitor->VerifyFound();
13621}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013622#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120013623
Tobin Ehliscde08892015-09-22 10:11:37 -060013624#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070013625
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013626TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
13627 TEST_DESCRIPTION("Create a render pass with an attachment description "
13628 "format set to VK_FORMAT_UNDEFINED");
13629
13630 ASSERT_NO_FATAL_FAILURE(InitState());
13631 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13632
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060013634
13635 VkAttachmentReference color_attach = {};
13636 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
13637 color_attach.attachment = 0;
13638 VkSubpassDescription subpass = {};
13639 subpass.colorAttachmentCount = 1;
13640 subpass.pColorAttachments = &color_attach;
13641
13642 VkRenderPassCreateInfo rpci = {};
13643 rpci.subpassCount = 1;
13644 rpci.pSubpasses = &subpass;
13645 rpci.attachmentCount = 1;
13646 VkAttachmentDescription attach_desc = {};
13647 attach_desc.format = VK_FORMAT_UNDEFINED;
13648 rpci.pAttachments = &attach_desc;
13649 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
13650 VkRenderPass rp;
13651 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
13652
13653 m_errorMonitor->VerifyFound();
13654
13655 if (result == VK_SUCCESS) {
13656 vkDestroyRenderPass(m_device->device(), rp, NULL);
13657 }
13658}
13659
Karl Schultz6addd812016-02-02 17:17:23 -070013660TEST_F(VkLayerTest, InvalidImageView) {
13661 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060013662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel 10 ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013664
Tobin Ehliscde08892015-09-22 10:11:37 -060013665 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060013666
Mike Stroyana3082432015-09-25 13:39:21 -060013667 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070013668 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060013669
Karl Schultz6addd812016-02-02 17:17:23 -070013670 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13671 const int32_t tex_width = 32;
13672 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060013673
13674 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013675 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13676 image_create_info.pNext = NULL;
13677 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13678 image_create_info.format = tex_format;
13679 image_create_info.extent.width = tex_width;
13680 image_create_info.extent.height = tex_height;
13681 image_create_info.extent.depth = 1;
13682 image_create_info.mipLevels = 1;
13683 image_create_info.arrayLayers = 1;
13684 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13685 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13686 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13687 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060013688
Chia-I Wuf7458c52015-10-26 21:10:41 +080013689 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060013690 ASSERT_VK_SUCCESS(err);
13691
13692 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013693 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13694 image_view_create_info.image = image;
13695 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13696 image_view_create_info.format = tex_format;
13697 image_view_create_info.subresourceRange.layerCount = 1;
13698 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
13699 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013700 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060013701
13702 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013703 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060013704
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013705 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060013706 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060013707}
Mike Stroyana3082432015-09-25 13:39:21 -060013708
Mark Youngd339ba32016-05-30 13:28:35 -060013709TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
13710 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060013711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060013712 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060013713
13714 ASSERT_NO_FATAL_FAILURE(InitState());
13715
13716 // Create an image and try to create a view with no memory backing the image
13717 VkImage image;
13718
13719 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
13720 const int32_t tex_width = 32;
13721 const int32_t tex_height = 32;
13722
13723 VkImageCreateInfo image_create_info = {};
13724 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13725 image_create_info.pNext = NULL;
13726 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13727 image_create_info.format = tex_format;
13728 image_create_info.extent.width = tex_width;
13729 image_create_info.extent.height = tex_height;
13730 image_create_info.extent.depth = 1;
13731 image_create_info.mipLevels = 1;
13732 image_create_info.arrayLayers = 1;
13733 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13734 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
13735 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
13736 image_create_info.flags = 0;
13737
13738 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
13739 ASSERT_VK_SUCCESS(err);
13740
13741 VkImageViewCreateInfo image_view_create_info = {};
13742 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13743 image_view_create_info.image = image;
13744 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13745 image_view_create_info.format = tex_format;
13746 image_view_create_info.subresourceRange.layerCount = 1;
13747 image_view_create_info.subresourceRange.baseMipLevel = 0;
13748 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013749 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060013750
13751 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013752 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060013753
13754 m_errorMonitor->VerifyFound();
13755 vkDestroyImage(m_device->device(), image, NULL);
13756 // If last error is success, it still created the view, so delete it.
13757 if (err == VK_SUCCESS) {
13758 vkDestroyImageView(m_device->device(), view, NULL);
13759 }
Mark Youngd339ba32016-05-30 13:28:35 -060013760}
13761
Karl Schultz6addd812016-02-02 17:17:23 -070013762TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013763 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013765 "formats must have ONLY the "
13766 "VK_IMAGE_ASPECT_COLOR_BIT set");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13768 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013769
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013770 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013771
Karl Schultz6addd812016-02-02 17:17:23 -070013772 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013773 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013774 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013775 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013776
13777 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013778 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013779 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070013780 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
13781 image_view_create_info.format = tex_format;
13782 image_view_create_info.subresourceRange.baseMipLevel = 0;
13783 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013784 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070013785 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013786 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013787
13788 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060013789 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013790
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013791 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060013792}
13793
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013794TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070013795 VkResult err;
13796 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060013797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13799 "vkCmdCopyImage: number of layers in source and destination subresources for pRegions");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013800
Mike Stroyana3082432015-09-25 13:39:21 -060013801 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060013802
13803 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070013804 VkImage srcImage;
13805 VkImage dstImage;
13806 VkDeviceMemory srcMem;
13807 VkDeviceMemory destMem;
13808 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060013809
13810 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013811 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13812 image_create_info.pNext = NULL;
13813 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13814 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
13815 image_create_info.extent.width = 32;
13816 image_create_info.extent.height = 32;
13817 image_create_info.extent.depth = 1;
13818 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013819 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070013820 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13821 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13822 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13823 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013825 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013826 ASSERT_VK_SUCCESS(err);
13827
Mark Lobodzinski867787a2016-10-14 11:49:55 -060013828 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013829 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060013830 ASSERT_VK_SUCCESS(err);
13831
13832 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013833 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070013834 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13835 memAlloc.pNext = NULL;
13836 memAlloc.allocationSize = 0;
13837 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013838
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060013839 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013840 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013841 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060013842 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013843 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013844 ASSERT_VK_SUCCESS(err);
13845
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013846 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060013847 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013848 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013849 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013850 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060013851 ASSERT_VK_SUCCESS(err);
13852
13853 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
13854 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013855 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060013856 ASSERT_VK_SUCCESS(err);
13857
13858 BeginCommandBuffer();
13859 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013860 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060013861 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060013862 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013863 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060013864 copyRegion.srcOffset.x = 0;
13865 copyRegion.srcOffset.y = 0;
13866 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080013867 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013868 copyRegion.dstSubresource.mipLevel = 0;
13869 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060013870 // Introduce failure by forcing the dst layerCount to differ from src
13871 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013872 copyRegion.dstOffset.x = 0;
13873 copyRegion.dstOffset.y = 0;
13874 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060013875 copyRegion.extent.width = 1;
13876 copyRegion.extent.height = 1;
13877 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013878 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060013879 EndCommandBuffer();
13880
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013881 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060013882
Chia-I Wuf7458c52015-10-26 21:10:41 +080013883 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013884 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080013885 vkFreeMemory(m_device->device(), srcMem, NULL);
13886 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060013887}
13888
Tony Barbourd6673642016-05-05 14:46:39 -060013889TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
13890
13891 TEST_DESCRIPTION("Creating images with unsuported formats ");
13892
13893 ASSERT_NO_FATAL_FAILURE(InitState());
13894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13895 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013896 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 -060013897 VK_IMAGE_TILING_OPTIMAL, 0);
13898 ASSERT_TRUE(image.initialized());
13899
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013900 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
13901 VkImageCreateInfo image_create_info;
13902 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
13903 image_create_info.pNext = NULL;
13904 image_create_info.imageType = VK_IMAGE_TYPE_2D;
13905 image_create_info.format = VK_FORMAT_UNDEFINED;
13906 image_create_info.extent.width = 32;
13907 image_create_info.extent.height = 32;
13908 image_create_info.extent.depth = 1;
13909 image_create_info.mipLevels = 1;
13910 image_create_info.arrayLayers = 1;
13911 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
13912 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
13913 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
13914 image_create_info.flags = 0;
13915
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13917 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013918
13919 VkImage localImage;
13920 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
13921 m_errorMonitor->VerifyFound();
13922
Tony Barbourd6673642016-05-05 14:46:39 -060013923 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013924 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060013925 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
13926 VkFormat format = static_cast<VkFormat>(f);
13927 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013928 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060013929 unsupported = format;
13930 break;
13931 }
13932 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013933
Tony Barbourd6673642016-05-05 14:46:39 -060013934 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060013935 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060013937
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060013938 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060013939 m_errorMonitor->VerifyFound();
13940 }
13941}
13942
13943TEST_F(VkLayerTest, ImageLayerViewTests) {
13944 VkResult ret;
13945 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
13946
13947 ASSERT_NO_FATAL_FAILURE(InitState());
13948
13949 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013950 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060013951 VK_IMAGE_TILING_OPTIMAL, 0);
13952 ASSERT_TRUE(image.initialized());
13953
13954 VkImageView imgView;
13955 VkImageViewCreateInfo imgViewInfo = {};
13956 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13957 imgViewInfo.image = image.handle();
13958 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
13959 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
13960 imgViewInfo.subresourceRange.layerCount = 1;
13961 imgViewInfo.subresourceRange.baseMipLevel = 0;
13962 imgViewInfo.subresourceRange.levelCount = 1;
13963 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13964
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseMipLevel");
Tony Barbourd6673642016-05-05 14:46:39 -060013966 // View can't have baseMipLevel >= image's mipLevels - Expect
13967 // VIEW_CREATE_ERROR
13968 imgViewInfo.subresourceRange.baseMipLevel = 1;
13969 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13970 m_errorMonitor->VerifyFound();
13971 imgViewInfo.subresourceRange.baseMipLevel = 0;
13972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with baseArrayLayer");
Tony Barbourd6673642016-05-05 14:46:39 -060013974 // View can't have baseArrayLayer >= image's arraySize - Expect
13975 // VIEW_CREATE_ERROR
13976 imgViewInfo.subresourceRange.baseArrayLayer = 1;
13977 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13978 m_errorMonitor->VerifyFound();
13979 imgViewInfo.subresourceRange.baseArrayLayer = 0;
13980
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13982 "pCreateInfo->subresourceRange."
13983 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060013984 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
13985 imgViewInfo.subresourceRange.levelCount = 0;
13986 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13987 m_errorMonitor->VerifyFound();
13988 imgViewInfo.subresourceRange.levelCount = 1;
13989
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
13991 "pCreateInfo->subresourceRange."
13992 "layerCount");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060013993 m_errorMonitor->SetDesiredFailureMsg(
13994 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13995 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060013996 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
13997 imgViewInfo.subresourceRange.layerCount = 0;
13998 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
13999 m_errorMonitor->VerifyFound();
14000 imgViewInfo.subresourceRange.layerCount = 1;
14001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14004 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14005 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014006 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14007 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14008 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14009 m_errorMonitor->VerifyFound();
14010 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14013 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14014 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014015 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14016 // VIEW_CREATE_ERROR
14017 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14018 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14019 m_errorMonitor->VerifyFound();
14020 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
14023 "differing formats but they must be "
14024 "in the same compatibility class.");
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014025 // TODO: Update framework to easily passing mutable flag into ImageObj init
14026 // For now just allowing image for this one test to not have memory bound
14027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14028 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014029 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14030 // VIEW_CREATE_ERROR
14031 VkImageCreateInfo mutImgInfo = image.create_info();
14032 VkImage mutImage;
14033 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014034 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014035 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14036 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14037 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14038 ASSERT_VK_SUCCESS(ret);
14039 imgViewInfo.image = mutImage;
14040 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14041 m_errorMonitor->VerifyFound();
14042 imgViewInfo.image = image.handle();
14043 vkDestroyImage(m_device->handle(), mutImage, NULL);
14044}
14045
14046TEST_F(VkLayerTest, MiscImageLayerTests) {
14047
14048 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14049
14050 ASSERT_NO_FATAL_FAILURE(InitState());
14051
14052 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014053 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 -060014054 VK_IMAGE_TILING_OPTIMAL, 0);
14055 ASSERT_TRUE(image.initialized());
14056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "number of layers in image subresource is zero");
Tony Barbourd6673642016-05-05 14:46:39 -060014058 vk_testing::Buffer buffer;
14059 VkMemoryPropertyFlags reqs = 0;
14060 buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
14061 VkBufferImageCopy region = {};
14062 region.bufferRowLength = 128;
14063 region.bufferImageHeight = 128;
14064 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14065 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14066 region.imageSubresource.layerCount = 0;
14067 region.imageExtent.height = 4;
14068 region.imageExtent.width = 4;
14069 region.imageExtent.depth = 1;
14070 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014071 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14072 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014073 m_errorMonitor->VerifyFound();
14074 region.imageSubresource.layerCount = 1;
14075
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014076 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14077 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
14078 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of this format's texel size");
14080 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14081 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014082 m_errorMonitor->VerifyFound();
14083
14084 // BufferOffset must be a multiple of 4
14085 // Introduce failure by setting bufferOffset to a value not divisible by 4
14086 region.bufferOffset = 6;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be a multiple of 4");
14088 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14089 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014090 m_errorMonitor->VerifyFound();
14091
14092 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14093 region.bufferOffset = 0;
14094 region.imageExtent.height = 128;
14095 region.imageExtent.width = 128;
14096 // Introduce failure by setting bufferRowLength > 0 but less than width
14097 region.bufferRowLength = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14099 "must be zero or greater-than-or-equal-to imageExtent.width");
14100 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14101 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014102 m_errorMonitor->VerifyFound();
14103
14104 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14105 region.bufferRowLength = 128;
14106 // Introduce failure by setting bufferRowHeight > 0 but less than height
14107 region.bufferImageHeight = 64;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14109 "must be zero or greater-than-or-equal-to imageExtent.height");
14110 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14111 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014112 m_errorMonitor->VerifyFound();
14113
14114 region.bufferImageHeight = 128;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "aspectMasks for each region must "
14116 "specify only COLOR or DEPTH or "
14117 "STENCIL");
Tony Barbourd6673642016-05-05 14:46:39 -060014118 // Expect MISMATCHED_IMAGE_ASPECT
14119 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014120 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14121 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourd6673642016-05-05 14:46:39 -060014122 m_errorMonitor->VerifyFound();
14123 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14126 "If the format of srcImage is a depth, stencil, depth stencil or "
14127 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014128 // Expect INVALID_FILTER
14129 VkImageObj intImage1(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014130 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 -060014131 VkImageObj intImage2(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014132 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 -060014133 VkImageBlit blitRegion = {};
14134 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14135 blitRegion.srcSubresource.baseArrayLayer = 0;
14136 blitRegion.srcSubresource.layerCount = 1;
14137 blitRegion.srcSubresource.mipLevel = 0;
14138 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14139 blitRegion.dstSubresource.baseArrayLayer = 0;
14140 blitRegion.dstSubresource.layerCount = 1;
14141 blitRegion.dstSubresource.mipLevel = 0;
14142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014143 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14144 intImage2.layout(), 16, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014145 m_errorMonitor->VerifyFound();
14146
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014147 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14149 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14150 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014151 m_errorMonitor->VerifyFound();
14152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014154 VkImageMemoryBarrier img_barrier;
14155 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14156 img_barrier.pNext = NULL;
14157 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14158 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14159 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14160 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14161 img_barrier.image = image.handle();
14162 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14163 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
14164 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14165 img_barrier.subresourceRange.baseArrayLayer = 0;
14166 img_barrier.subresourceRange.baseMipLevel = 0;
14167 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
14168 img_barrier.subresourceRange.layerCount = 0;
14169 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014170 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
14171 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060014172 m_errorMonitor->VerifyFound();
14173 img_barrier.subresourceRange.layerCount = 1;
14174}
14175
14176TEST_F(VkLayerTest, ImageFormatLimits) {
14177
14178 TEST_DESCRIPTION("Exceed the limits of image format ");
14179
Cody Northropc31a84f2016-08-22 10:41:47 -060014180 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060014182 VkImageCreateInfo image_create_info = {};
14183 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14184 image_create_info.pNext = NULL;
14185 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14186 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14187 image_create_info.extent.width = 32;
14188 image_create_info.extent.height = 32;
14189 image_create_info.extent.depth = 1;
14190 image_create_info.mipLevels = 1;
14191 image_create_info.arrayLayers = 1;
14192 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14193 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14194 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14195 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14196 image_create_info.flags = 0;
14197
14198 VkImage nullImg;
14199 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014200 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
14201 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Tony Barbourd6673642016-05-05 14:46:39 -060014202 image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1;
14203 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14204 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14205 m_errorMonitor->VerifyFound();
14206 image_create_info.extent.depth = 1;
14207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014209 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
14210 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14211 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14212 m_errorMonitor->VerifyFound();
14213 image_create_info.mipLevels = 1;
14214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060014216 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
14217 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14218 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14219 m_errorMonitor->VerifyFound();
14220 image_create_info.arrayLayers = 1;
14221
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060014223 int samples = imgFmtProps.sampleCounts >> 1;
14224 image_create_info.samples = (VkSampleCountFlagBits)samples;
14225 // Expect INVALID_FORMAT_LIMITS_VIOLATION
14226 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14227 m_errorMonitor->VerifyFound();
14228 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14229
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
14231 "VK_IMAGE_LAYOUT_UNDEFINED or "
14232 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060014233 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14234 // Expect INVALID_LAYOUT
14235 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
14236 m_errorMonitor->VerifyFound();
14237 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
14238}
14239
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014240TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
14241
14242 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014244
14245 ASSERT_NO_FATAL_FAILURE(InitState());
14246
14247 VkImageObj src_image(m_device);
14248 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14249 VkImageObj dst_image(m_device);
14250 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14251
14252 BeginCommandBuffer();
14253 VkImageCopy copy_region;
14254 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14255 copy_region.srcSubresource.mipLevel = 0;
14256 copy_region.srcSubresource.baseArrayLayer = 0;
14257 copy_region.srcSubresource.layerCount = 0;
14258 copy_region.srcOffset.x = 0;
14259 copy_region.srcOffset.y = 0;
14260 copy_region.srcOffset.z = 0;
14261 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14262 copy_region.dstSubresource.mipLevel = 0;
14263 copy_region.dstSubresource.baseArrayLayer = 0;
14264 copy_region.dstSubresource.layerCount = 0;
14265 copy_region.dstOffset.x = 0;
14266 copy_region.dstOffset.y = 0;
14267 copy_region.dstOffset.z = 0;
14268 copy_region.extent.width = 64;
14269 copy_region.extent.height = 64;
14270 copy_region.extent.depth = 1;
14271 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14272 &copy_region);
14273 EndCommandBuffer();
14274
14275 m_errorMonitor->VerifyFound();
14276}
14277
14278TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
14279
14280 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060014281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060014282
14283 ASSERT_NO_FATAL_FAILURE(InitState());
14284
14285 VkImageObj src_image(m_device);
14286 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
14287 VkImageObj dst_image(m_device);
14288 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
14289
14290 BeginCommandBuffer();
14291 VkImageCopy copy_region;
14292 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14293 copy_region.srcSubresource.mipLevel = 0;
14294 copy_region.srcSubresource.baseArrayLayer = 0;
14295 copy_region.srcSubresource.layerCount = 0;
14296 copy_region.srcOffset.x = 0;
14297 copy_region.srcOffset.y = 0;
14298 copy_region.srcOffset.z = 0;
14299 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14300 copy_region.dstSubresource.mipLevel = 0;
14301 copy_region.dstSubresource.baseArrayLayer = 0;
14302 copy_region.dstSubresource.layerCount = 0;
14303 copy_region.dstOffset.x = 0;
14304 copy_region.dstOffset.y = 0;
14305 copy_region.dstOffset.z = 0;
14306 copy_region.extent.width = 64;
14307 copy_region.extent.height = 64;
14308 copy_region.extent.depth = 1;
14309 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
14310 &copy_region);
14311 EndCommandBuffer();
14312
14313 m_errorMonitor->VerifyFound();
14314}
14315
Karl Schultz6addd812016-02-02 17:17:23 -070014316TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060014317 VkResult err;
14318 bool pass;
14319
14320 // Create color images with different format sizes 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 format sizes");
Karl Schultzbdb75952016-04-19 11:36:49 -060014323
14324 ASSERT_NO_FATAL_FAILURE(InitState());
14325
14326 // Create two images of different types and try to copy between them
14327 VkImage srcImage;
14328 VkImage dstImage;
14329 VkDeviceMemory srcMem;
14330 VkDeviceMemory destMem;
14331 VkMemoryRequirements memReqs;
14332
14333 VkImageCreateInfo image_create_info = {};
14334 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;
14347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014348 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014349 ASSERT_VK_SUCCESS(err);
14350
14351 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14352 // Introduce failure by creating second image with a different-sized format.
14353 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
14354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014355 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060014356 ASSERT_VK_SUCCESS(err);
14357
14358 // Allocate memory
14359 VkMemoryAllocateInfo memAlloc = {};
14360 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14361 memAlloc.pNext = NULL;
14362 memAlloc.allocationSize = 0;
14363 memAlloc.memoryTypeIndex = 0;
14364
14365 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
14366 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014367 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014368 ASSERT_TRUE(pass);
14369 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
14370 ASSERT_VK_SUCCESS(err);
14371
14372 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
14373 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014374 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060014375 ASSERT_TRUE(pass);
14376 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
14377 ASSERT_VK_SUCCESS(err);
14378
14379 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14380 ASSERT_VK_SUCCESS(err);
14381 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
14382 ASSERT_VK_SUCCESS(err);
14383
14384 BeginCommandBuffer();
14385 VkImageCopy copyRegion;
14386 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14387 copyRegion.srcSubresource.mipLevel = 0;
14388 copyRegion.srcSubresource.baseArrayLayer = 0;
14389 copyRegion.srcSubresource.layerCount = 0;
14390 copyRegion.srcOffset.x = 0;
14391 copyRegion.srcOffset.y = 0;
14392 copyRegion.srcOffset.z = 0;
14393 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14394 copyRegion.dstSubresource.mipLevel = 0;
14395 copyRegion.dstSubresource.baseArrayLayer = 0;
14396 copyRegion.dstSubresource.layerCount = 0;
14397 copyRegion.dstOffset.x = 0;
14398 copyRegion.dstOffset.y = 0;
14399 copyRegion.dstOffset.z = 0;
14400 copyRegion.extent.width = 1;
14401 copyRegion.extent.height = 1;
14402 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014403 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Karl Schultzbdb75952016-04-19 11:36:49 -060014404 EndCommandBuffer();
14405
14406 m_errorMonitor->VerifyFound();
14407
14408 vkDestroyImage(m_device->device(), srcImage, NULL);
14409 vkDestroyImage(m_device->device(), dstImage, NULL);
14410 vkFreeMemory(m_device->device(), srcMem, NULL);
14411 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014412}
14413
Karl Schultz6addd812016-02-02 17:17:23 -070014414TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
14415 VkResult err;
14416 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014417
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014418 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14420 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014421
Mike Stroyana3082432015-09-25 13:39:21 -060014422 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014423
14424 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014425 VkImage srcImage;
14426 VkImage dstImage;
14427 VkDeviceMemory srcMem;
14428 VkDeviceMemory destMem;
14429 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014430
14431 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014432 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14433 image_create_info.pNext = NULL;
14434 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14435 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14436 image_create_info.extent.width = 32;
14437 image_create_info.extent.height = 32;
14438 image_create_info.extent.depth = 1;
14439 image_create_info.mipLevels = 1;
14440 image_create_info.arrayLayers = 1;
14441 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14442 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14443 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14444 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014445
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014446 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014447 ASSERT_VK_SUCCESS(err);
14448
Karl Schultzbdb75952016-04-19 11:36:49 -060014449 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
14450
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014451 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070014452 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014453 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014454 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014456 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014457 ASSERT_VK_SUCCESS(err);
14458
14459 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014460 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014461 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14462 memAlloc.pNext = NULL;
14463 memAlloc.allocationSize = 0;
14464 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014465
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014466 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014467 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014468 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014469 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014470 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014471 ASSERT_VK_SUCCESS(err);
14472
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014473 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014474 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014475 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014476 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014477 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014478 ASSERT_VK_SUCCESS(err);
14479
14480 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14481 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014482 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014483 ASSERT_VK_SUCCESS(err);
14484
14485 BeginCommandBuffer();
14486 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014487 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014488 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014489 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014490 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014491 copyRegion.srcOffset.x = 0;
14492 copyRegion.srcOffset.y = 0;
14493 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014494 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014495 copyRegion.dstSubresource.mipLevel = 0;
14496 copyRegion.dstSubresource.baseArrayLayer = 0;
14497 copyRegion.dstSubresource.layerCount = 0;
14498 copyRegion.dstOffset.x = 0;
14499 copyRegion.dstOffset.y = 0;
14500 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014501 copyRegion.extent.width = 1;
14502 copyRegion.extent.height = 1;
14503 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014504 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
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, ResolveImageLowSampleCount) {
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 source sample count less than 2.");
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
14524 // Create two images of sample count 1 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;
14541 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14542 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14543 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14544 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014545
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014546 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014547 ASSERT_VK_SUCCESS(err);
14548
Karl Schultz6addd812016-02-02 17:17:23 -070014549 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014550
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014552 ASSERT_VK_SUCCESS(err);
14553
14554 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014555 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014556 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14557 memAlloc.pNext = NULL;
14558 memAlloc.allocationSize = 0;
14559 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014560
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014561 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014562 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014563 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014564 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014565 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014566 ASSERT_VK_SUCCESS(err);
14567
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014568 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014569 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014570 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014571 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014572 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014573 ASSERT_VK_SUCCESS(err);
14574
14575 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14576 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014577 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014578 ASSERT_VK_SUCCESS(err);
14579
14580 BeginCommandBuffer();
14581 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014582 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14583 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014584 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014585 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014586 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014587 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014588 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014589 resolveRegion.srcOffset.x = 0;
14590 resolveRegion.srcOffset.y = 0;
14591 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014592 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014593 resolveRegion.dstSubresource.mipLevel = 0;
14594 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014595 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014596 resolveRegion.dstOffset.x = 0;
14597 resolveRegion.dstOffset.y = 0;
14598 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014599 resolveRegion.extent.width = 1;
14600 resolveRegion.extent.height = 1;
14601 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014602 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014603 EndCommandBuffer();
14604
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014605 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014606
Chia-I Wuf7458c52015-10-26 21:10:41 +080014607 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014608 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014609 vkFreeMemory(m_device->device(), srcMem, NULL);
14610 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014611}
14612
Karl Schultz6addd812016-02-02 17:17:23 -070014613TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
14614 VkResult err;
14615 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14618 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014619
Mike Stroyana3082432015-09-25 13:39:21 -060014620 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014621
Chris Forbesa7530692016-05-08 12:35:39 +120014622 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070014623 VkImage srcImage;
14624 VkImage dstImage;
14625 VkDeviceMemory srcMem;
14626 VkDeviceMemory destMem;
14627 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014628
14629 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014630 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14631 image_create_info.pNext = NULL;
14632 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14633 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14634 image_create_info.extent.width = 32;
14635 image_create_info.extent.height = 1;
14636 image_create_info.extent.depth = 1;
14637 image_create_info.mipLevels = 1;
14638 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120014639 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014640 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14641 // Note: Some implementations expect color attachment usage for any
14642 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014643 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014644 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014645
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014646 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014647 ASSERT_VK_SUCCESS(err);
14648
Karl Schultz6addd812016-02-02 17:17:23 -070014649 // Note: Some implementations expect color attachment usage for any
14650 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014651 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014653 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014654 ASSERT_VK_SUCCESS(err);
14655
14656 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014657 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014658 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14659 memAlloc.pNext = NULL;
14660 memAlloc.allocationSize = 0;
14661 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014662
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014663 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014664 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014665 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014666 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014667 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014668 ASSERT_VK_SUCCESS(err);
14669
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014670 vkGetImageMemoryRequirements(m_device->device(), dstImage, &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, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014675 ASSERT_VK_SUCCESS(err);
14676
14677 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14678 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014679 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014680 ASSERT_VK_SUCCESS(err);
14681
14682 BeginCommandBuffer();
14683 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014684 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14685 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014686 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014687 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014688 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014689 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014690 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014691 resolveRegion.srcOffset.x = 0;
14692 resolveRegion.srcOffset.y = 0;
14693 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014694 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014695 resolveRegion.dstSubresource.mipLevel = 0;
14696 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014697 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014698 resolveRegion.dstOffset.x = 0;
14699 resolveRegion.dstOffset.y = 0;
14700 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014701 resolveRegion.extent.width = 1;
14702 resolveRegion.extent.height = 1;
14703 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014704 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014705 EndCommandBuffer();
14706
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014707 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014708
Chia-I Wuf7458c52015-10-26 21:10:41 +080014709 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014710 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014711 vkFreeMemory(m_device->device(), srcMem, NULL);
14712 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014713}
14714
Karl Schultz6addd812016-02-02 17:17:23 -070014715TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
14716 VkResult err;
14717 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014718
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14720 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014721
Mike Stroyana3082432015-09-25 13:39:21 -060014722 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014723
14724 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014725 VkImage srcImage;
14726 VkImage dstImage;
14727 VkDeviceMemory srcMem;
14728 VkDeviceMemory destMem;
14729 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014730
14731 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014732 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14733 image_create_info.pNext = NULL;
14734 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14735 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14736 image_create_info.extent.width = 32;
14737 image_create_info.extent.height = 1;
14738 image_create_info.extent.depth = 1;
14739 image_create_info.mipLevels = 1;
14740 image_create_info.arrayLayers = 1;
14741 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14742 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14743 // Note: Some implementations expect color attachment usage for any
14744 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014745 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014746 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014747
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014748 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014749 ASSERT_VK_SUCCESS(err);
14750
Karl Schultz6addd812016-02-02 17:17:23 -070014751 // Set format to something other than source image
14752 image_create_info.format = VK_FORMAT_R32_SFLOAT;
14753 // Note: Some implementations expect color attachment usage for any
14754 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014755 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014756 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014757
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014758 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014759 ASSERT_VK_SUCCESS(err);
14760
14761 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014762 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014763 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14764 memAlloc.pNext = NULL;
14765 memAlloc.allocationSize = 0;
14766 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014767
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014768 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014769 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014770 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014771 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014772 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014773 ASSERT_VK_SUCCESS(err);
14774
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014775 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014776 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014777 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014778 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014779 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014780 ASSERT_VK_SUCCESS(err);
14781
14782 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14783 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014784 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014785 ASSERT_VK_SUCCESS(err);
14786
14787 BeginCommandBuffer();
14788 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014789 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14790 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014791 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014792 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014793 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014794 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014795 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014796 resolveRegion.srcOffset.x = 0;
14797 resolveRegion.srcOffset.y = 0;
14798 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014799 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014800 resolveRegion.dstSubresource.mipLevel = 0;
14801 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014802 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014803 resolveRegion.dstOffset.x = 0;
14804 resolveRegion.dstOffset.y = 0;
14805 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014806 resolveRegion.extent.width = 1;
14807 resolveRegion.extent.height = 1;
14808 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014809 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014810 EndCommandBuffer();
14811
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014812 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014813
Chia-I Wuf7458c52015-10-26 21:10:41 +080014814 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014815 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014816 vkFreeMemory(m_device->device(), srcMem, NULL);
14817 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014818}
14819
Karl Schultz6addd812016-02-02 17:17:23 -070014820TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
14821 VkResult err;
14822 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014823
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14825 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014826
Mike Stroyana3082432015-09-25 13:39:21 -060014827 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014828
14829 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014830 VkImage srcImage;
14831 VkImage dstImage;
14832 VkDeviceMemory srcMem;
14833 VkDeviceMemory destMem;
14834 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014835
14836 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014837 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14838 image_create_info.pNext = NULL;
14839 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14840 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14841 image_create_info.extent.width = 32;
14842 image_create_info.extent.height = 1;
14843 image_create_info.extent.depth = 1;
14844 image_create_info.mipLevels = 1;
14845 image_create_info.arrayLayers = 1;
14846 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
14847 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14848 // Note: Some implementations expect color attachment usage for any
14849 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014850 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014851 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014853 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014854 ASSERT_VK_SUCCESS(err);
14855
Karl Schultz6addd812016-02-02 17:17:23 -070014856 image_create_info.imageType = VK_IMAGE_TYPE_1D;
14857 // Note: Some implementations expect color attachment usage for any
14858 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014859 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014860 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014862 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014863 ASSERT_VK_SUCCESS(err);
14864
14865 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014866 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014867 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14868 memAlloc.pNext = NULL;
14869 memAlloc.allocationSize = 0;
14870 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014871
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014872 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014873 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014874 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014875 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014876 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014877 ASSERT_VK_SUCCESS(err);
14878
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014879 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014880 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014881 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014882 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014883 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014884 ASSERT_VK_SUCCESS(err);
14885
14886 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14887 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014888 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014889 ASSERT_VK_SUCCESS(err);
14890
14891 BeginCommandBuffer();
14892 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070014893 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
14894 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060014895 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014896 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014897 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014898 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014899 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014900 resolveRegion.srcOffset.x = 0;
14901 resolveRegion.srcOffset.y = 0;
14902 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014903 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014904 resolveRegion.dstSubresource.mipLevel = 0;
14905 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130014906 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014907 resolveRegion.dstOffset.x = 0;
14908 resolveRegion.dstOffset.y = 0;
14909 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014910 resolveRegion.extent.width = 1;
14911 resolveRegion.extent.height = 1;
14912 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014913 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Mike Stroyana3082432015-09-25 13:39:21 -060014914 EndCommandBuffer();
14915
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014916 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014917
Chia-I Wuf7458c52015-10-26 21:10:41 +080014918 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014919 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014920 vkFreeMemory(m_device->device(), srcMem, NULL);
14921 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014922}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014923
Karl Schultz6addd812016-02-02 17:17:23 -070014924TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014925 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070014926 // to using a DS format, then cause it to hit error due to COLOR_BIT not
14927 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014928 // The image format check comes 2nd in validation so we trigger it first,
14929 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070014930 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14933 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014934
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014935 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014936
Chia-I Wu1b99bb22015-10-27 19:25:11 +080014937 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014938 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14939 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014940
14941 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014942 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14943 ds_pool_ci.pNext = NULL;
14944 ds_pool_ci.maxSets = 1;
14945 ds_pool_ci.poolSizeCount = 1;
14946 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014947
14948 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014949 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014950 ASSERT_VK_SUCCESS(err);
14951
14952 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014953 dsl_binding.binding = 0;
14954 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
14955 dsl_binding.descriptorCount = 1;
14956 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
14957 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014958
14959 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014960 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14961 ds_layout_ci.pNext = NULL;
14962 ds_layout_ci.bindingCount = 1;
14963 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014964 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014965 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014966 ASSERT_VK_SUCCESS(err);
14967
14968 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014969 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080014970 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070014971 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014972 alloc_info.descriptorPool = ds_pool;
14973 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014974 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014975 ASSERT_VK_SUCCESS(err);
14976
Karl Schultz6addd812016-02-02 17:17:23 -070014977 VkImage image_bad;
14978 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014979 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060014980 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014981 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070014982 const int32_t tex_width = 32;
14983 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014984
14985 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014986 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14987 image_create_info.pNext = NULL;
14988 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14989 image_create_info.format = tex_format_bad;
14990 image_create_info.extent.width = tex_width;
14991 image_create_info.extent.height = tex_height;
14992 image_create_info.extent.depth = 1;
14993 image_create_info.mipLevels = 1;
14994 image_create_info.arrayLayers = 1;
14995 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14996 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014997 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070014998 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060014999
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015000 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015001 ASSERT_VK_SUCCESS(err);
15002 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015003 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15004 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015005 ASSERT_VK_SUCCESS(err);
15006
15007 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015008 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15009 image_view_create_info.image = image_bad;
15010 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15011 image_view_create_info.format = tex_format_bad;
15012 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15013 image_view_create_info.subresourceRange.baseMipLevel = 0;
15014 image_view_create_info.subresourceRange.layerCount = 1;
15015 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015017
15018 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015019 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015020
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015021 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015022
Chia-I Wuf7458c52015-10-26 21:10:41 +080015023 vkDestroyImage(m_device->device(), image_bad, NULL);
15024 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015025 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15026 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015027}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015028
15029TEST_F(VkLayerTest, ClearImageErrors) {
15030 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15031 "ClearDepthStencilImage with a color image.");
15032
15033 ASSERT_NO_FATAL_FAILURE(InitState());
15034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15035
15036 // Renderpass is started here so end it as Clear cmds can't be in renderpass
15037 BeginCommandBuffer();
15038 m_commandBuffer->EndRenderPass();
15039
15040 // Color image
15041 VkClearColorValue clear_color;
15042 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15043 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15044 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15045 const int32_t img_width = 32;
15046 const int32_t img_height = 32;
15047 VkImageCreateInfo image_create_info = {};
15048 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15049 image_create_info.pNext = NULL;
15050 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15051 image_create_info.format = color_format;
15052 image_create_info.extent.width = img_width;
15053 image_create_info.extent.height = img_height;
15054 image_create_info.extent.depth = 1;
15055 image_create_info.mipLevels = 1;
15056 image_create_info.arrayLayers = 1;
15057 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15058 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15059 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15060
15061 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015062 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015064 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015065
15066 // Depth/Stencil image
15067 VkClearDepthStencilValue clear_value = {0};
15068 reqs = 0; // don't need HOST_VISIBLE DS image
15069 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15070 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15071 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15072 ds_image_create_info.extent.width = 64;
15073 ds_image_create_info.extent.height = 64;
15074 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15075 ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
15076
15077 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015078 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015079
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015080 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 -060015081
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015084 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015085 &color_range);
15086
15087 m_errorMonitor->VerifyFound();
15088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15090 "image created without "
15091 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015093 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015094 &color_range);
15095
15096 m_errorMonitor->VerifyFound();
15097
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015098 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15100 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015102 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
15103 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015104
15105 m_errorMonitor->VerifyFound();
15106}
Tobin Ehliscde08892015-09-22 10:11:37 -060015107#endif // IMAGE_TESTS
15108
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015109
15110// WSI Enabled Tests
15111//
15112TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15113
15114#if defined(VK_USE_PLATFORM_XCB_KHR)
15115 VkSurfaceKHR surface = VK_NULL_HANDLE;
15116
15117 VkResult err;
15118 bool pass;
15119 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15120 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15121 // uint32_t swapchain_image_count = 0;
15122 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15123 // uint32_t image_index = 0;
15124 // VkPresentInfoKHR present_info = {};
15125
15126 ASSERT_NO_FATAL_FAILURE(InitState());
15127
15128 // Use the create function from one of the VK_KHR_*_surface extension in
15129 // order to create a surface, testing all known errors in the process,
15130 // before successfully creating a surface:
15131 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15133 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15134 pass = (err != VK_SUCCESS);
15135 ASSERT_TRUE(pass);
15136 m_errorMonitor->VerifyFound();
15137
15138 // Next, try to create a surface with the wrong
15139 // VkXcbSurfaceCreateInfoKHR::sType:
15140 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15141 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15143 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15144 pass = (err != VK_SUCCESS);
15145 ASSERT_TRUE(pass);
15146 m_errorMonitor->VerifyFound();
15147
15148 // Create a native window, and then correctly create a surface:
15149 xcb_connection_t *connection;
15150 xcb_screen_t *screen;
15151 xcb_window_t xcb_window;
15152 xcb_intern_atom_reply_t *atom_wm_delete_window;
15153
15154 const xcb_setup_t *setup;
15155 xcb_screen_iterator_t iter;
15156 int scr;
15157 uint32_t value_mask, value_list[32];
15158 int width = 1;
15159 int height = 1;
15160
15161 connection = xcb_connect(NULL, &scr);
15162 ASSERT_TRUE(connection != NULL);
15163 setup = xcb_get_setup(connection);
15164 iter = xcb_setup_roots_iterator(setup);
15165 while (scr-- > 0)
15166 xcb_screen_next(&iter);
15167 screen = iter.data;
15168
15169 xcb_window = xcb_generate_id(connection);
15170
15171 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
15172 value_list[0] = screen->black_pixel;
15173 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
15174
15175 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
15176 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
15177
15178 /* Magic code that will send notification when window is destroyed */
15179 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
15180 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
15181
15182 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
15183 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
15184 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
15185 free(reply);
15186
15187 xcb_map_window(connection, xcb_window);
15188
15189 // Force the x/y coordinates to 100,100 results are identical in consecutive
15190 // runs
15191 const uint32_t coords[] = { 100, 100 };
15192 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
15193
15194 // Finally, try to correctly create a surface:
15195 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
15196 xcb_create_info.pNext = NULL;
15197 xcb_create_info.flags = 0;
15198 xcb_create_info.connection = connection;
15199 xcb_create_info.window = xcb_window;
15200 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15201 pass = (err == VK_SUCCESS);
15202 ASSERT_TRUE(pass);
15203
15204 // Check if surface supports presentation:
15205
15206 // 1st, do so without having queried the queue families:
15207 VkBool32 supported = false;
15208 // TODO: Get the following error to come out:
15209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15210 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
15211 "function");
15212 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15213 pass = (err != VK_SUCCESS);
15214 // ASSERT_TRUE(pass);
15215 // m_errorMonitor->VerifyFound();
15216
15217 // Next, query a queue family index that's too large:
15218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15219 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
15220 pass = (err != VK_SUCCESS);
15221 ASSERT_TRUE(pass);
15222 m_errorMonitor->VerifyFound();
15223
15224 // Finally, do so correctly:
15225 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15226 // SUPPORTED
15227 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
15228 pass = (err == VK_SUCCESS);
15229 ASSERT_TRUE(pass);
15230
15231 // Before proceeding, try to create a swapchain without having called
15232 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
15233 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15234 swapchain_create_info.pNext = NULL;
15235 swapchain_create_info.flags = 0;
15236 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15237 swapchain_create_info.surface = surface;
15238 swapchain_create_info.imageArrayLayers = 1;
15239 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
15240 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
15241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15242 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
15243 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15244 pass = (err != VK_SUCCESS);
15245 ASSERT_TRUE(pass);
15246 m_errorMonitor->VerifyFound();
15247
15248 // Get the surface capabilities:
15249 VkSurfaceCapabilitiesKHR surface_capabilities;
15250
15251 // Do so correctly (only error logged by this entrypoint is if the
15252 // extension isn't enabled):
15253 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
15254 pass = (err == VK_SUCCESS);
15255 ASSERT_TRUE(pass);
15256
15257 // Get the surface formats:
15258 uint32_t surface_format_count;
15259
15260 // First, try without a pointer to surface_format_count:
15261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
15262 "specified as NULL");
15263 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
15264 pass = (err == VK_SUCCESS);
15265 ASSERT_TRUE(pass);
15266 m_errorMonitor->VerifyFound();
15267
15268 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
15269 // correctly done a 1st try (to get the count):
15270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15271 surface_format_count = 0;
15272 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
15273 pass = (err == VK_SUCCESS);
15274 ASSERT_TRUE(pass);
15275 m_errorMonitor->VerifyFound();
15276
15277 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15278 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15279 pass = (err == VK_SUCCESS);
15280 ASSERT_TRUE(pass);
15281
15282 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15283 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
15284
15285 // Next, do a 2nd try with surface_format_count being set too high:
15286 surface_format_count += 5;
15287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15288 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15289 pass = (err == VK_SUCCESS);
15290 ASSERT_TRUE(pass);
15291 m_errorMonitor->VerifyFound();
15292
15293 // Finally, do a correct 1st and 2nd try:
15294 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
15295 pass = (err == VK_SUCCESS);
15296 ASSERT_TRUE(pass);
15297 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
15298 pass = (err == VK_SUCCESS);
15299 ASSERT_TRUE(pass);
15300
15301 // Get the surface present modes:
15302 uint32_t surface_present_mode_count;
15303
15304 // First, try without a pointer to surface_format_count:
15305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
15306 "specified as NULL");
15307
15308 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
15309 pass = (err == VK_SUCCESS);
15310 ASSERT_TRUE(pass);
15311 m_errorMonitor->VerifyFound();
15312
15313 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
15314 // correctly done a 1st try (to get the count):
15315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
15316 surface_present_mode_count = 0;
15317 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
15318 (VkPresentModeKHR *)&surface_present_mode_count);
15319 pass = (err == VK_SUCCESS);
15320 ASSERT_TRUE(pass);
15321 m_errorMonitor->VerifyFound();
15322
15323 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
15324 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15325 pass = (err == VK_SUCCESS);
15326 ASSERT_TRUE(pass);
15327
15328 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
15329 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
15330
15331 // Next, do a 2nd try with surface_format_count being set too high:
15332 surface_present_mode_count += 5;
15333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
15334 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15335 pass = (err == VK_SUCCESS);
15336 ASSERT_TRUE(pass);
15337 m_errorMonitor->VerifyFound();
15338
15339 // Finally, do a correct 1st and 2nd try:
15340 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
15341 pass = (err == VK_SUCCESS);
15342 ASSERT_TRUE(pass);
15343 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
15344 pass = (err == VK_SUCCESS);
15345 ASSERT_TRUE(pass);
15346
15347 // Create a swapchain:
15348
15349 // First, try without a pointer to swapchain_create_info:
15350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
15351 "specified as NULL");
15352
15353 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
15354 pass = (err != VK_SUCCESS);
15355 ASSERT_TRUE(pass);
15356 m_errorMonitor->VerifyFound();
15357
15358 // Next, call with a non-NULL swapchain_create_info, that has the wrong
15359 // sType:
15360 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15362
15363 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15364 pass = (err != VK_SUCCESS);
15365 ASSERT_TRUE(pass);
15366 m_errorMonitor->VerifyFound();
15367
15368 // Next, call with a NULL swapchain pointer:
15369 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
15370 swapchain_create_info.pNext = NULL;
15371 swapchain_create_info.flags = 0;
15372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
15373 "specified as NULL");
15374
15375 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
15376 pass = (err != VK_SUCCESS);
15377 ASSERT_TRUE(pass);
15378 m_errorMonitor->VerifyFound();
15379
15380 // TODO: Enhance swapchain layer so that
15381 // swapchain_create_info.queueFamilyIndexCount is checked against something?
15382
15383 // Next, call with a queue family index that's too large:
15384 uint32_t queueFamilyIndex[2] = { 100000, 0 };
15385 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15386 swapchain_create_info.queueFamilyIndexCount = 2;
15387 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
15388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
15389 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15390 pass = (err != VK_SUCCESS);
15391 ASSERT_TRUE(pass);
15392 m_errorMonitor->VerifyFound();
15393
15394 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
15395 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
15396 swapchain_create_info.queueFamilyIndexCount = 1;
15397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15398 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
15399 "pCreateInfo->pQueueFamilyIndices).");
15400 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15401 pass = (err != VK_SUCCESS);
15402 ASSERT_TRUE(pass);
15403 m_errorMonitor->VerifyFound();
15404
15405 // Next, call with an invalid imageSharingMode:
15406 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
15407 swapchain_create_info.queueFamilyIndexCount = 1;
15408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15409 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
15410 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
15411 pass = (err != VK_SUCCESS);
15412 ASSERT_TRUE(pass);
15413 m_errorMonitor->VerifyFound();
15414 // Fix for the future:
15415 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
15416 // SUPPORTED
15417 swapchain_create_info.queueFamilyIndexCount = 0;
15418 queueFamilyIndex[0] = 0;
15419 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
15420
15421 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
15422 // Get the images from a swapchain:
15423 // Acquire an image from a swapchain:
15424 // Present an image to a swapchain:
15425 // Destroy the swapchain:
15426
15427 // TODOs:
15428 //
15429 // - Try destroying the device without first destroying the swapchain
15430 //
15431 // - Try destroying the device without first destroying the surface
15432 //
15433 // - Try destroying the surface without first destroying the swapchain
15434
15435 // Destroy the surface:
15436 vkDestroySurfaceKHR(instance(), surface, NULL);
15437
15438 // Tear down the window:
15439 xcb_destroy_window(connection, xcb_window);
15440 xcb_disconnect(connection);
15441
15442#else // VK_USE_PLATFORM_XCB_KHR
15443 return;
15444#endif // VK_USE_PLATFORM_XCB_KHR
15445}
15446
15447//
15448// POSITIVE VALIDATION TESTS
15449//
15450// These tests do not expect to encounter ANY validation errors pass only if this is true
15451
Tobin Ehlise0006882016-11-03 10:14:28 -060015452TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
15453 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
15454 "by a transition in the primary.");
15455 VkResult err;
15456 m_errorMonitor->ExpectSuccess();
15457 ASSERT_NO_FATAL_FAILURE(InitState());
15458 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15459 // Allocate a secondary and primary cmd buffer
15460 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
15461 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
15462 command_buffer_allocate_info.commandPool = m_commandPool;
15463 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
15464 command_buffer_allocate_info.commandBufferCount = 1;
15465
15466 VkCommandBuffer secondary_command_buffer;
15467 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
15468 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
15469 VkCommandBuffer primary_command_buffer;
15470 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
15471 VkCommandBufferBeginInfo command_buffer_begin_info = {};
15472 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
15473 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
15474 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
15475 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
15476 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
15477
15478 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
15479 ASSERT_VK_SUCCESS(err);
15480 VkImageObj image(m_device);
15481 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
15482 ASSERT_TRUE(image.initialized());
15483 VkImageMemoryBarrier img_barrier = {};
15484 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15485 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15486 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15487 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15488 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15489 img_barrier.image = image.handle();
15490 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15491 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15492 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15493 img_barrier.subresourceRange.baseArrayLayer = 0;
15494 img_barrier.subresourceRange.baseMipLevel = 0;
15495 img_barrier.subresourceRange.layerCount = 1;
15496 img_barrier.subresourceRange.levelCount = 1;
15497 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
15498 0, nullptr, 1, &img_barrier);
15499 err = vkEndCommandBuffer(secondary_command_buffer);
15500 ASSERT_VK_SUCCESS(err);
15501
15502 // Now update primary cmd buffer to execute secondary and transitions image
15503 command_buffer_begin_info.pInheritanceInfo = nullptr;
15504 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
15505 ASSERT_VK_SUCCESS(err);
15506 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
15507 VkImageMemoryBarrier img_barrier2 = {};
15508 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15509 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15510 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15511 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15512 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
15513 img_barrier2.image = image.handle();
15514 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15515 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15516 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
15517 img_barrier2.subresourceRange.baseArrayLayer = 0;
15518 img_barrier2.subresourceRange.baseMipLevel = 0;
15519 img_barrier2.subresourceRange.layerCount = 1;
15520 img_barrier2.subresourceRange.levelCount = 1;
15521 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
15522 nullptr, 1, &img_barrier2);
15523 err = vkEndCommandBuffer(primary_command_buffer);
15524 ASSERT_VK_SUCCESS(err);
15525 VkSubmitInfo submit_info = {};
15526 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15527 submit_info.commandBufferCount = 1;
15528 submit_info.pCommandBuffers = &primary_command_buffer;
15529 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
15530 ASSERT_VK_SUCCESS(err);
15531 m_errorMonitor->VerifyNotFound();
15532 err = vkDeviceWaitIdle(m_device->device());
15533 ASSERT_VK_SUCCESS(err);
15534 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
15535 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
15536}
15537
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015538// This is a positive test. No failures are expected.
15539TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
15540 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
15541 "is ignoring VkWriteDescriptorSet members that are not "
15542 "related to the descriptor type specified by "
15543 "VkWriteDescriptorSet::descriptorType. Correct "
15544 "validation behavior will result in the test running to "
15545 "completion without validation errors.");
15546
15547 const uintptr_t invalid_ptr = 0xcdcdcdcd;
15548
15549 ASSERT_NO_FATAL_FAILURE(InitState());
15550
15551 // Image Case
15552 {
15553 m_errorMonitor->ExpectSuccess();
15554
15555 VkImage image;
15556 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15557 const int32_t tex_width = 32;
15558 const int32_t tex_height = 32;
15559 VkImageCreateInfo image_create_info = {};
15560 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15561 image_create_info.pNext = NULL;
15562 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15563 image_create_info.format = tex_format;
15564 image_create_info.extent.width = tex_width;
15565 image_create_info.extent.height = tex_height;
15566 image_create_info.extent.depth = 1;
15567 image_create_info.mipLevels = 1;
15568 image_create_info.arrayLayers = 1;
15569 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15570 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15571 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15572 image_create_info.flags = 0;
15573 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15574 ASSERT_VK_SUCCESS(err);
15575
15576 VkMemoryRequirements memory_reqs;
15577 VkDeviceMemory image_memory;
15578 bool pass;
15579 VkMemoryAllocateInfo memory_info = {};
15580 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15581 memory_info.pNext = NULL;
15582 memory_info.allocationSize = 0;
15583 memory_info.memoryTypeIndex = 0;
15584 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
15585 memory_info.allocationSize = memory_reqs.size;
15586 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15587 ASSERT_TRUE(pass);
15588 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
15589 ASSERT_VK_SUCCESS(err);
15590 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
15591 ASSERT_VK_SUCCESS(err);
15592
15593 VkImageViewCreateInfo image_view_create_info = {};
15594 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15595 image_view_create_info.image = image;
15596 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15597 image_view_create_info.format = tex_format;
15598 image_view_create_info.subresourceRange.layerCount = 1;
15599 image_view_create_info.subresourceRange.baseMipLevel = 0;
15600 image_view_create_info.subresourceRange.levelCount = 1;
15601 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15602
15603 VkImageView view;
15604 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
15605 ASSERT_VK_SUCCESS(err);
15606
15607 VkDescriptorPoolSize ds_type_count = {};
15608 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15609 ds_type_count.descriptorCount = 1;
15610
15611 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15612 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15613 ds_pool_ci.pNext = NULL;
15614 ds_pool_ci.maxSets = 1;
15615 ds_pool_ci.poolSizeCount = 1;
15616 ds_pool_ci.pPoolSizes = &ds_type_count;
15617
15618 VkDescriptorPool ds_pool;
15619 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15620 ASSERT_VK_SUCCESS(err);
15621
15622 VkDescriptorSetLayoutBinding dsl_binding = {};
15623 dsl_binding.binding = 0;
15624 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15625 dsl_binding.descriptorCount = 1;
15626 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15627 dsl_binding.pImmutableSamplers = NULL;
15628
15629 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15630 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15631 ds_layout_ci.pNext = NULL;
15632 ds_layout_ci.bindingCount = 1;
15633 ds_layout_ci.pBindings = &dsl_binding;
15634 VkDescriptorSetLayout ds_layout;
15635 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15636 ASSERT_VK_SUCCESS(err);
15637
15638 VkDescriptorSet descriptor_set;
15639 VkDescriptorSetAllocateInfo alloc_info = {};
15640 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15641 alloc_info.descriptorSetCount = 1;
15642 alloc_info.descriptorPool = ds_pool;
15643 alloc_info.pSetLayouts = &ds_layout;
15644 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15645 ASSERT_VK_SUCCESS(err);
15646
15647 VkDescriptorImageInfo image_info = {};
15648 image_info.imageView = view;
15649 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
15650
15651 VkWriteDescriptorSet descriptor_write;
15652 memset(&descriptor_write, 0, sizeof(descriptor_write));
15653 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15654 descriptor_write.dstSet = descriptor_set;
15655 descriptor_write.dstBinding = 0;
15656 descriptor_write.descriptorCount = 1;
15657 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15658 descriptor_write.pImageInfo = &image_info;
15659
15660 // Set pBufferInfo and pTexelBufferView to invalid values, which should
15661 // be
15662 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
15663 // This will most likely produce a crash if the parameter_validation
15664 // layer
15665 // does not correctly ignore pBufferInfo.
15666 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15667 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15668
15669 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15670
15671 m_errorMonitor->VerifyNotFound();
15672
15673 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15674 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15675 vkDestroyImageView(m_device->device(), view, NULL);
15676 vkDestroyImage(m_device->device(), image, NULL);
15677 vkFreeMemory(m_device->device(), image_memory, NULL);
15678 }
15679
15680 // Buffer Case
15681 {
15682 m_errorMonitor->ExpectSuccess();
15683
15684 VkBuffer buffer;
15685 uint32_t queue_family_index = 0;
15686 VkBufferCreateInfo buffer_create_info = {};
15687 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15688 buffer_create_info.size = 1024;
15689 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
15690 buffer_create_info.queueFamilyIndexCount = 1;
15691 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15692
15693 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15694 ASSERT_VK_SUCCESS(err);
15695
15696 VkMemoryRequirements memory_reqs;
15697 VkDeviceMemory buffer_memory;
15698 bool pass;
15699 VkMemoryAllocateInfo memory_info = {};
15700 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15701 memory_info.pNext = NULL;
15702 memory_info.allocationSize = 0;
15703 memory_info.memoryTypeIndex = 0;
15704
15705 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15706 memory_info.allocationSize = memory_reqs.size;
15707 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15708 ASSERT_TRUE(pass);
15709
15710 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15711 ASSERT_VK_SUCCESS(err);
15712 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15713 ASSERT_VK_SUCCESS(err);
15714
15715 VkDescriptorPoolSize ds_type_count = {};
15716 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15717 ds_type_count.descriptorCount = 1;
15718
15719 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15720 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15721 ds_pool_ci.pNext = NULL;
15722 ds_pool_ci.maxSets = 1;
15723 ds_pool_ci.poolSizeCount = 1;
15724 ds_pool_ci.pPoolSizes = &ds_type_count;
15725
15726 VkDescriptorPool ds_pool;
15727 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15728 ASSERT_VK_SUCCESS(err);
15729
15730 VkDescriptorSetLayoutBinding dsl_binding = {};
15731 dsl_binding.binding = 0;
15732 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15733 dsl_binding.descriptorCount = 1;
15734 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15735 dsl_binding.pImmutableSamplers = NULL;
15736
15737 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15738 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15739 ds_layout_ci.pNext = NULL;
15740 ds_layout_ci.bindingCount = 1;
15741 ds_layout_ci.pBindings = &dsl_binding;
15742 VkDescriptorSetLayout ds_layout;
15743 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15744 ASSERT_VK_SUCCESS(err);
15745
15746 VkDescriptorSet descriptor_set;
15747 VkDescriptorSetAllocateInfo alloc_info = {};
15748 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15749 alloc_info.descriptorSetCount = 1;
15750 alloc_info.descriptorPool = ds_pool;
15751 alloc_info.pSetLayouts = &ds_layout;
15752 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15753 ASSERT_VK_SUCCESS(err);
15754
15755 VkDescriptorBufferInfo buffer_info = {};
15756 buffer_info.buffer = buffer;
15757 buffer_info.offset = 0;
15758 buffer_info.range = 1024;
15759
15760 VkWriteDescriptorSet descriptor_write;
15761 memset(&descriptor_write, 0, sizeof(descriptor_write));
15762 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15763 descriptor_write.dstSet = descriptor_set;
15764 descriptor_write.dstBinding = 0;
15765 descriptor_write.descriptorCount = 1;
15766 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15767 descriptor_write.pBufferInfo = &buffer_info;
15768
15769 // Set pImageInfo and pTexelBufferView to invalid values, which should
15770 // be
15771 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
15772 // This will most likely produce a crash if the parameter_validation
15773 // layer
15774 // does not correctly ignore pImageInfo.
15775 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15776 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
15777
15778 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15779
15780 m_errorMonitor->VerifyNotFound();
15781
15782 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15783 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15784 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15785 vkDestroyBuffer(m_device->device(), buffer, NULL);
15786 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15787 }
15788
15789 // Texel Buffer Case
15790 {
15791 m_errorMonitor->ExpectSuccess();
15792
15793 VkBuffer buffer;
15794 uint32_t queue_family_index = 0;
15795 VkBufferCreateInfo buffer_create_info = {};
15796 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
15797 buffer_create_info.size = 1024;
15798 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
15799 buffer_create_info.queueFamilyIndexCount = 1;
15800 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
15801
15802 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
15803 ASSERT_VK_SUCCESS(err);
15804
15805 VkMemoryRequirements memory_reqs;
15806 VkDeviceMemory buffer_memory;
15807 bool pass;
15808 VkMemoryAllocateInfo memory_info = {};
15809 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15810 memory_info.pNext = NULL;
15811 memory_info.allocationSize = 0;
15812 memory_info.memoryTypeIndex = 0;
15813
15814 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
15815 memory_info.allocationSize = memory_reqs.size;
15816 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
15817 ASSERT_TRUE(pass);
15818
15819 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
15820 ASSERT_VK_SUCCESS(err);
15821 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
15822 ASSERT_VK_SUCCESS(err);
15823
15824 VkBufferViewCreateInfo buff_view_ci = {};
15825 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
15826 buff_view_ci.buffer = buffer;
15827 buff_view_ci.format = VK_FORMAT_R8_UNORM;
15828 buff_view_ci.range = VK_WHOLE_SIZE;
15829 VkBufferView buffer_view;
15830 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
15831
15832 VkDescriptorPoolSize ds_type_count = {};
15833 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15834 ds_type_count.descriptorCount = 1;
15835
15836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
15837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15838 ds_pool_ci.pNext = NULL;
15839 ds_pool_ci.maxSets = 1;
15840 ds_pool_ci.poolSizeCount = 1;
15841 ds_pool_ci.pPoolSizes = &ds_type_count;
15842
15843 VkDescriptorPool ds_pool;
15844 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
15845 ASSERT_VK_SUCCESS(err);
15846
15847 VkDescriptorSetLayoutBinding dsl_binding = {};
15848 dsl_binding.binding = 0;
15849 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15850 dsl_binding.descriptorCount = 1;
15851 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15852 dsl_binding.pImmutableSamplers = NULL;
15853
15854 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15855 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15856 ds_layout_ci.pNext = NULL;
15857 ds_layout_ci.bindingCount = 1;
15858 ds_layout_ci.pBindings = &dsl_binding;
15859 VkDescriptorSetLayout ds_layout;
15860 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15861 ASSERT_VK_SUCCESS(err);
15862
15863 VkDescriptorSet descriptor_set;
15864 VkDescriptorSetAllocateInfo alloc_info = {};
15865 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
15866 alloc_info.descriptorSetCount = 1;
15867 alloc_info.descriptorPool = ds_pool;
15868 alloc_info.pSetLayouts = &ds_layout;
15869 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
15870 ASSERT_VK_SUCCESS(err);
15871
15872 VkWriteDescriptorSet descriptor_write;
15873 memset(&descriptor_write, 0, sizeof(descriptor_write));
15874 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15875 descriptor_write.dstSet = descriptor_set;
15876 descriptor_write.dstBinding = 0;
15877 descriptor_write.descriptorCount = 1;
15878 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
15879 descriptor_write.pTexelBufferView = &buffer_view;
15880
15881 // Set pImageInfo and pBufferInfo to invalid values, which should be
15882 // ignored for descriptorType ==
15883 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
15884 // This will most likely produce a crash if the parameter_validation
15885 // layer
15886 // does not correctly ignore pImageInfo and pBufferInfo.
15887 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
15888 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
15889
15890 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
15891
15892 m_errorMonitor->VerifyNotFound();
15893
15894 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
15895 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15896 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
15897 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
15898 vkDestroyBuffer(m_device->device(), buffer, NULL);
15899 vkFreeMemory(m_device->device(), buffer_memory, NULL);
15900 }
15901}
15902
Tobin Ehlisf7428442016-10-25 07:58:24 -060015903TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
15904 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
15905
15906 ASSERT_NO_FATAL_FAILURE(InitState());
15907 // Create layout where two binding #s are "1"
15908 static const uint32_t NUM_BINDINGS = 3;
15909 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
15910 dsl_binding[0].binding = 1;
15911 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15912 dsl_binding[0].descriptorCount = 1;
15913 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15914 dsl_binding[0].pImmutableSamplers = NULL;
15915 dsl_binding[1].binding = 0;
15916 dsl_binding[1].descriptorCount = 1;
15917 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15918 dsl_binding[1].descriptorCount = 1;
15919 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15920 dsl_binding[1].pImmutableSamplers = NULL;
15921 dsl_binding[2].binding = 1; // Duplicate binding should cause error
15922 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
15923 dsl_binding[2].descriptorCount = 1;
15924 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
15925 dsl_binding[2].pImmutableSamplers = NULL;
15926
15927 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
15928 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15929 ds_layout_ci.pNext = NULL;
15930 ds_layout_ci.bindingCount = NUM_BINDINGS;
15931 ds_layout_ci.pBindings = dsl_binding;
15932 VkDescriptorSetLayout ds_layout;
15933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
15934 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
15935 m_errorMonitor->VerifyFound();
15936}
15937
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015938TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015939 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
15940
15941 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015942
15943 BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015944
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060015945 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
15946
15947 {
15948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
15949 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
15950 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15951 m_errorMonitor->VerifyFound();
15952 }
15953
15954 {
15955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
15956 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
15957 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15958 m_errorMonitor->VerifyFound();
15959 }
15960
15961 {
15962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15963 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
15964 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15965 m_errorMonitor->VerifyFound();
15966 }
15967
15968 {
15969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
15970 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
15971 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15972 m_errorMonitor->VerifyFound();
15973 }
15974
15975 {
15976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
15977 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
15978 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15979 m_errorMonitor->VerifyFound();
15980 }
15981
15982 {
15983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
15984 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
15985 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
15986 m_errorMonitor->VerifyFound();
15987 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060015988
15989 {
15990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15991 VkRect2D scissor = {{-1, 0}, {16, 16}};
15992 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15993 m_errorMonitor->VerifyFound();
15994 }
15995
15996 {
15997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
15998 VkRect2D scissor = {{0, -2}, {16, 16}};
15999 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16000 m_errorMonitor->VerifyFound();
16001 }
16002
16003 {
16004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16005 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16006 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16007 m_errorMonitor->VerifyFound();
16008 }
16009
16010 {
16011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16012 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16013 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16014 m_errorMonitor->VerifyFound();
16015 }
16016
16017 EndCommandBuffer();
16018}
16019
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016020// This is a positive test. No failures are expected.
16021TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16022 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16023 VkResult err;
16024
16025 ASSERT_NO_FATAL_FAILURE(InitState());
16026 m_errorMonitor->ExpectSuccess();
16027 VkDescriptorPoolSize ds_type_count = {};
16028 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16029 ds_type_count.descriptorCount = 2;
16030
16031 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16032 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16033 ds_pool_ci.pNext = NULL;
16034 ds_pool_ci.maxSets = 1;
16035 ds_pool_ci.poolSizeCount = 1;
16036 ds_pool_ci.pPoolSizes = &ds_type_count;
16037
16038 VkDescriptorPool ds_pool;
16039 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16040 ASSERT_VK_SUCCESS(err);
16041
16042 // Create layout with two uniform buffer descriptors w/ empty binding between them
16043 static const uint32_t NUM_BINDINGS = 3;
16044 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16045 dsl_binding[0].binding = 0;
16046 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16047 dsl_binding[0].descriptorCount = 1;
16048 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16049 dsl_binding[0].pImmutableSamplers = NULL;
16050 dsl_binding[1].binding = 1;
16051 dsl_binding[1].descriptorCount = 0; // empty binding
16052 dsl_binding[2].binding = 2;
16053 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16054 dsl_binding[2].descriptorCount = 1;
16055 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16056 dsl_binding[2].pImmutableSamplers = NULL;
16057
16058 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16059 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16060 ds_layout_ci.pNext = NULL;
16061 ds_layout_ci.bindingCount = NUM_BINDINGS;
16062 ds_layout_ci.pBindings = dsl_binding;
16063 VkDescriptorSetLayout ds_layout;
16064 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16065 ASSERT_VK_SUCCESS(err);
16066
16067 VkDescriptorSet descriptor_set = {};
16068 VkDescriptorSetAllocateInfo alloc_info = {};
16069 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16070 alloc_info.descriptorSetCount = 1;
16071 alloc_info.descriptorPool = ds_pool;
16072 alloc_info.pSetLayouts = &ds_layout;
16073 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16074 ASSERT_VK_SUCCESS(err);
16075
16076 // Create a buffer to be used for update
16077 VkBufferCreateInfo buff_ci = {};
16078 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16079 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16080 buff_ci.size = 256;
16081 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16082 VkBuffer buffer;
16083 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16084 ASSERT_VK_SUCCESS(err);
16085 // Have to bind memory to buffer before descriptor update
16086 VkMemoryAllocateInfo mem_alloc = {};
16087 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16088 mem_alloc.pNext = NULL;
16089 mem_alloc.allocationSize = 512; // one allocation for both buffers
16090 mem_alloc.memoryTypeIndex = 0;
16091
16092 VkMemoryRequirements mem_reqs;
16093 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16094 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16095 if (!pass) {
16096 vkDestroyBuffer(m_device->device(), buffer, NULL);
16097 return;
16098 }
16099
16100 VkDeviceMemory mem;
16101 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16102 ASSERT_VK_SUCCESS(err);
16103 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16104 ASSERT_VK_SUCCESS(err);
16105
16106 // Only update the descriptor at binding 2
16107 VkDescriptorBufferInfo buff_info = {};
16108 buff_info.buffer = buffer;
16109 buff_info.offset = 0;
16110 buff_info.range = VK_WHOLE_SIZE;
16111 VkWriteDescriptorSet descriptor_write = {};
16112 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16113 descriptor_write.dstBinding = 2;
16114 descriptor_write.descriptorCount = 1;
16115 descriptor_write.pTexelBufferView = nullptr;
16116 descriptor_write.pBufferInfo = &buff_info;
16117 descriptor_write.pImageInfo = nullptr;
16118 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16119 descriptor_write.dstSet = descriptor_set;
16120
16121 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16122
16123 m_errorMonitor->VerifyNotFound();
16124 // Cleanup
16125 vkFreeMemory(m_device->device(), mem, NULL);
16126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16127 vkDestroyBuffer(m_device->device(), buffer, NULL);
16128 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16129}
16130
16131// This is a positive test. No failures are expected.
16132TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16133 VkResult err;
16134 bool pass;
16135
16136 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16137 "the buffer, create an image, and bind the same memory to "
16138 "it");
16139
16140 m_errorMonitor->ExpectSuccess();
16141
16142 ASSERT_NO_FATAL_FAILURE(InitState());
16143
16144 VkBuffer buffer;
16145 VkImage image;
16146 VkDeviceMemory mem;
16147 VkMemoryRequirements mem_reqs;
16148
16149 VkBufferCreateInfo buf_info = {};
16150 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16151 buf_info.pNext = NULL;
16152 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16153 buf_info.size = 256;
16154 buf_info.queueFamilyIndexCount = 0;
16155 buf_info.pQueueFamilyIndices = NULL;
16156 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16157 buf_info.flags = 0;
16158 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
16159 ASSERT_VK_SUCCESS(err);
16160
16161 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16162
16163 VkMemoryAllocateInfo alloc_info = {};
16164 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16165 alloc_info.pNext = NULL;
16166 alloc_info.memoryTypeIndex = 0;
16167
16168 // Ensure memory is big enough for both bindings
16169 alloc_info.allocationSize = 0x10000;
16170
16171 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16172 if (!pass) {
16173 vkDestroyBuffer(m_device->device(), buffer, NULL);
16174 return;
16175 }
16176
16177 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16178 ASSERT_VK_SUCCESS(err);
16179
16180 uint8_t *pData;
16181 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
16182 ASSERT_VK_SUCCESS(err);
16183
16184 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
16185
16186 vkUnmapMemory(m_device->device(), mem);
16187
16188 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16189 ASSERT_VK_SUCCESS(err);
16190
16191 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
16192 // memory. In fact, it was never used by the GPU.
16193 // Just be be sure, wait for idle.
16194 vkDestroyBuffer(m_device->device(), buffer, NULL);
16195 vkDeviceWaitIdle(m_device->device());
16196
16197 VkImageCreateInfo image_create_info = {};
16198 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16199 image_create_info.pNext = NULL;
16200 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16201 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
16202 image_create_info.extent.width = 64;
16203 image_create_info.extent.height = 64;
16204 image_create_info.extent.depth = 1;
16205 image_create_info.mipLevels = 1;
16206 image_create_info.arrayLayers = 1;
16207 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16208 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16209 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
16210 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16211 image_create_info.queueFamilyIndexCount = 0;
16212 image_create_info.pQueueFamilyIndices = NULL;
16213 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16214 image_create_info.flags = 0;
16215
16216 VkMemoryAllocateInfo mem_alloc = {};
16217 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16218 mem_alloc.pNext = NULL;
16219 mem_alloc.allocationSize = 0;
16220 mem_alloc.memoryTypeIndex = 0;
16221
16222 /* Create a mappable image. It will be the texture if linear images are ok
16223 * to be textures or it will be the staging image if they are not.
16224 */
16225 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16226 ASSERT_VK_SUCCESS(err);
16227
16228 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
16229
16230 mem_alloc.allocationSize = mem_reqs.size;
16231
16232 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
16233 if (!pass) {
16234 vkDestroyImage(m_device->device(), image, NULL);
16235 return;
16236 }
16237
16238 // VALIDATION FAILURE:
16239 err = vkBindImageMemory(m_device->device(), image, mem, 0);
16240 ASSERT_VK_SUCCESS(err);
16241
16242 m_errorMonitor->VerifyNotFound();
16243
16244 vkFreeMemory(m_device->device(), mem, NULL);
16245 vkDestroyBuffer(m_device->device(), buffer, NULL);
16246 vkDestroyImage(m_device->device(), image, NULL);
16247}
16248
16249TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
16250
16251 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
16252 "mapping while using VK_WHOLE_SIZE does not cause access "
16253 "violations");
16254 VkResult err;
16255 uint8_t *pData;
16256 ASSERT_NO_FATAL_FAILURE(InitState());
16257
16258 VkDeviceMemory mem;
16259 VkMemoryRequirements mem_reqs;
16260 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
16261 VkMemoryAllocateInfo alloc_info = {};
16262 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16263 alloc_info.pNext = NULL;
16264 alloc_info.memoryTypeIndex = 0;
16265
16266 static const VkDeviceSize allocation_size = 0x1000;
16267 alloc_info.allocationSize = allocation_size;
16268
16269 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
16270 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
16271 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16272 if (!pass) {
16273 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16274 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
16275 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16276 if (!pass) {
16277 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
16278 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
16279 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
16280 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
16281 if (!pass) {
16282 return;
16283 }
16284 }
16285 }
16286
16287 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
16288 ASSERT_VK_SUCCESS(err);
16289
16290 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire
16291 // mapped range
16292 m_errorMonitor->ExpectSuccess();
16293 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16294 ASSERT_VK_SUCCESS(err);
16295 VkMappedMemoryRange mmr = {};
16296 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16297 mmr.memory = mem;
16298 mmr.offset = 0;
16299 mmr.size = VK_WHOLE_SIZE;
16300 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16301 ASSERT_VK_SUCCESS(err);
16302 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16303 ASSERT_VK_SUCCESS(err);
16304 m_errorMonitor->VerifyNotFound();
16305 vkUnmapMemory(m_device->device(), mem);
16306
16307 // Map/Flush/Invalidate using WHOLE_SIZE and a prime offset and entire
16308 // mapped range
16309 m_errorMonitor->ExpectSuccess();
16310 err = vkMapMemory(m_device->device(), mem, 13, VK_WHOLE_SIZE, 0, (void **)&pData);
16311 ASSERT_VK_SUCCESS(err);
16312 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16313 mmr.memory = mem;
16314 mmr.offset = 13;
16315 mmr.size = VK_WHOLE_SIZE;
16316 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16317 ASSERT_VK_SUCCESS(err);
16318 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16319 ASSERT_VK_SUCCESS(err);
16320 m_errorMonitor->VerifyNotFound();
16321 vkUnmapMemory(m_device->device(), mem);
16322
16323 // Map with prime offset and size
16324 // Flush/Invalidate subrange of mapped area with prime offset and size
16325 m_errorMonitor->ExpectSuccess();
16326 err = vkMapMemory(m_device->device(), mem, allocation_size - 137, 109, 0, (void **)&pData);
16327 ASSERT_VK_SUCCESS(err);
16328 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16329 mmr.memory = mem;
16330 mmr.offset = allocation_size - 107;
16331 mmr.size = 61;
16332 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16333 ASSERT_VK_SUCCESS(err);
16334 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
16335 ASSERT_VK_SUCCESS(err);
16336 m_errorMonitor->VerifyNotFound();
16337 vkUnmapMemory(m_device->device(), mem);
16338
16339 // Map without offset and flush WHOLE_SIZE with two separate offsets
16340 m_errorMonitor->ExpectSuccess();
16341 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
16342 ASSERT_VK_SUCCESS(err);
16343 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
16344 mmr.memory = mem;
16345 mmr.offset = allocation_size - 100;
16346 mmr.size = VK_WHOLE_SIZE;
16347 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16348 ASSERT_VK_SUCCESS(err);
16349 mmr.offset = allocation_size - 200;
16350 mmr.size = VK_WHOLE_SIZE;
16351 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
16352 ASSERT_VK_SUCCESS(err);
16353 m_errorMonitor->VerifyNotFound();
16354 vkUnmapMemory(m_device->device(), mem);
16355
16356 vkFreeMemory(m_device->device(), mem, NULL);
16357}
16358
16359// This is a positive test. We used to expect error in this case but spec now allows it
16360TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
16361 m_errorMonitor->ExpectSuccess();
16362 vk_testing::Fence testFence;
16363 VkFenceCreateInfo fenceInfo = {};
16364 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
16365 fenceInfo.pNext = NULL;
16366
16367 ASSERT_NO_FATAL_FAILURE(InitState());
16368 testFence.init(*m_device, fenceInfo);
16369 VkFence fences[1] = { testFence.handle() };
16370 VkResult result = vkResetFences(m_device->device(), 1, fences);
16371 ASSERT_VK_SUCCESS(result);
16372
16373 m_errorMonitor->VerifyNotFound();
16374}
16375
16376TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
16377 m_errorMonitor->ExpectSuccess();
16378
16379 ASSERT_NO_FATAL_FAILURE(InitState());
16380 VkResult err;
16381
16382 // Record (empty!) command buffer that can be submitted multiple times
16383 // simultaneously.
16384 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
16385 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
16386 m_commandBuffer->BeginCommandBuffer(&cbbi);
16387 m_commandBuffer->EndCommandBuffer();
16388
16389 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16390 VkFence fence;
16391 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
16392 ASSERT_VK_SUCCESS(err);
16393
16394 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
16395 VkSemaphore s1, s2;
16396 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
16397 ASSERT_VK_SUCCESS(err);
16398 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
16399 ASSERT_VK_SUCCESS(err);
16400
16401 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
16402 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
16403 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
16404 ASSERT_VK_SUCCESS(err);
16405
16406 // Submit CB again, signaling s2.
16407 si.pSignalSemaphores = &s2;
16408 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
16409 ASSERT_VK_SUCCESS(err);
16410
16411 // Wait for fence.
16412 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
16413 ASSERT_VK_SUCCESS(err);
16414
16415 // CB is still in flight from second submission, but semaphore s1 is no
16416 // longer in flight. delete it.
16417 vkDestroySemaphore(m_device->device(), s1, nullptr);
16418
16419 m_errorMonitor->VerifyNotFound();
16420
16421 // Force device idle and clean up remaining objects
16422 vkDeviceWaitIdle(m_device->device());
16423 vkDestroySemaphore(m_device->device(), s2, nullptr);
16424 vkDestroyFence(m_device->device(), fence, nullptr);
16425}
16426
16427TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
16428 m_errorMonitor->ExpectSuccess();
16429
16430 ASSERT_NO_FATAL_FAILURE(InitState());
16431 VkResult err;
16432
16433 // A fence created signaled
16434 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
16435 VkFence f1;
16436 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
16437 ASSERT_VK_SUCCESS(err);
16438
16439 // A fence created not
16440 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
16441 VkFence f2;
16442 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
16443 ASSERT_VK_SUCCESS(err);
16444
16445 // Submit the unsignaled fence
16446 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
16447 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
16448
16449 // Wait on both fences, with signaled first.
16450 VkFence fences[] = { f1, f2 };
16451 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
16452
16453 // Should have both retired!
16454 vkDestroyFence(m_device->device(), f1, nullptr);
16455 vkDestroyFence(m_device->device(), f2, nullptr);
16456
16457 m_errorMonitor->VerifyNotFound();
16458}
16459
16460TEST_F(VkPositiveLayerTest, ValidUsage) {
16461 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
16462 "doesn't generate validation errors");
16463
16464 ASSERT_NO_FATAL_FAILURE(InitState());
16465
16466 m_errorMonitor->ExpectSuccess();
16467 // Verify that we can create a view with usage INPUT_ATTACHMENT
16468 VkImageObj image(m_device);
16469 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16470 ASSERT_TRUE(image.initialized());
16471 VkImageView imageView;
16472 VkImageViewCreateInfo ivci = {};
16473 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16474 ivci.image = image.handle();
16475 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
16476 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
16477 ivci.subresourceRange.layerCount = 1;
16478 ivci.subresourceRange.baseMipLevel = 0;
16479 ivci.subresourceRange.levelCount = 1;
16480 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16481
16482 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
16483 m_errorMonitor->VerifyNotFound();
16484 vkDestroyImageView(m_device->device(), imageView, NULL);
16485}
16486
16487// This is a positive test. No failures are expected.
16488TEST_F(VkPositiveLayerTest, BindSparse) {
16489 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
16490 "and then free the memory");
16491
16492 ASSERT_NO_FATAL_FAILURE(InitState());
16493
16494 auto index = m_device->graphics_queue_node_index_;
16495 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
16496 return;
16497
16498 m_errorMonitor->ExpectSuccess();
16499
16500 VkImage image;
16501 VkImageCreateInfo image_create_info = {};
16502 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16503 image_create_info.pNext = NULL;
16504 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16505 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16506 image_create_info.extent.width = 64;
16507 image_create_info.extent.height = 64;
16508 image_create_info.extent.depth = 1;
16509 image_create_info.mipLevels = 1;
16510 image_create_info.arrayLayers = 1;
16511 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16512 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16513 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
16514 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
16515 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16516 ASSERT_VK_SUCCESS(err);
16517
16518 VkMemoryRequirements memory_reqs;
16519 VkDeviceMemory memory_one, memory_two;
16520 bool pass;
16521 VkMemoryAllocateInfo memory_info = {};
16522 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16523 memory_info.pNext = NULL;
16524 memory_info.allocationSize = 0;
16525 memory_info.memoryTypeIndex = 0;
16526 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16527 // Find an image big enough to allow sparse mapping of 2 memory regions
16528 // Increase the image size until it is at least twice the
16529 // size of the required alignment, to ensure we can bind both
16530 // allocated memory blocks to the image on aligned offsets.
16531 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
16532 vkDestroyImage(m_device->device(), image, nullptr);
16533 image_create_info.extent.width *= 2;
16534 image_create_info.extent.height *= 2;
16535 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
16536 ASSERT_VK_SUCCESS(err);
16537 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16538 }
16539 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
16540 // at the end of the first
16541 memory_info.allocationSize = memory_reqs.alignment;
16542 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16543 ASSERT_TRUE(pass);
16544 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
16545 ASSERT_VK_SUCCESS(err);
16546 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
16547 ASSERT_VK_SUCCESS(err);
16548 VkSparseMemoryBind binds[2];
16549 binds[0].flags = 0;
16550 binds[0].memory = memory_one;
16551 binds[0].memoryOffset = 0;
16552 binds[0].resourceOffset = 0;
16553 binds[0].size = memory_info.allocationSize;
16554 binds[1].flags = 0;
16555 binds[1].memory = memory_two;
16556 binds[1].memoryOffset = 0;
16557 binds[1].resourceOffset = memory_info.allocationSize;
16558 binds[1].size = memory_info.allocationSize;
16559
16560 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
16561 opaqueBindInfo.image = image;
16562 opaqueBindInfo.bindCount = 2;
16563 opaqueBindInfo.pBinds = binds;
16564
16565 VkFence fence = VK_NULL_HANDLE;
16566 VkBindSparseInfo bindSparseInfo = {};
16567 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
16568 bindSparseInfo.imageOpaqueBindCount = 1;
16569 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
16570
16571 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
16572 vkQueueWaitIdle(m_device->m_queue);
16573 vkDestroyImage(m_device->device(), image, NULL);
16574 vkFreeMemory(m_device->device(), memory_one, NULL);
16575 vkFreeMemory(m_device->device(), memory_two, NULL);
16576 m_errorMonitor->VerifyNotFound();
16577}
16578
16579TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
16580 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
16581 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
16582 "the command buffer has prior knowledge of that "
16583 "attachment's layout.");
16584
16585 m_errorMonitor->ExpectSuccess();
16586
16587 ASSERT_NO_FATAL_FAILURE(InitState());
16588
16589 // A renderpass with one color attachment.
16590 VkAttachmentDescription attachment = { 0,
16591 VK_FORMAT_R8G8B8A8_UNORM,
16592 VK_SAMPLE_COUNT_1_BIT,
16593 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16594 VK_ATTACHMENT_STORE_OP_STORE,
16595 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16596 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16597 VK_IMAGE_LAYOUT_UNDEFINED,
16598 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16599
16600 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16601
16602 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16603
16604 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16605
16606 VkRenderPass rp;
16607 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16608 ASSERT_VK_SUCCESS(err);
16609
16610 // A compatible framebuffer.
16611 VkImageObj image(m_device);
16612 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16613 ASSERT_TRUE(image.initialized());
16614
16615 VkImageViewCreateInfo ivci = {
16616 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16617 nullptr,
16618 0,
16619 image.handle(),
16620 VK_IMAGE_VIEW_TYPE_2D,
16621 VK_FORMAT_R8G8B8A8_UNORM,
16622 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16623 VK_COMPONENT_SWIZZLE_IDENTITY },
16624 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16625 };
16626 VkImageView view;
16627 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16628 ASSERT_VK_SUCCESS(err);
16629
16630 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16631 VkFramebuffer fb;
16632 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16633 ASSERT_VK_SUCCESS(err);
16634
16635 // Record a single command buffer which uses this renderpass twice. The
16636 // bug is triggered at the beginning of the second renderpass, when the
16637 // command buffer already has a layout recorded for the attachment.
16638 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16639 BeginCommandBuffer();
16640 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16641 vkCmdEndRenderPass(m_commandBuffer->handle());
16642 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16643
16644 m_errorMonitor->VerifyNotFound();
16645
16646 vkCmdEndRenderPass(m_commandBuffer->handle());
16647 EndCommandBuffer();
16648
16649 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16650 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16651 vkDestroyImageView(m_device->device(), view, nullptr);
16652}
16653
16654TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
16655 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
16656 "command buffer, bind them together, then destroy "
16657 "command pool and framebuffer and verify there are no "
16658 "errors.");
16659
16660 m_errorMonitor->ExpectSuccess();
16661
16662 ASSERT_NO_FATAL_FAILURE(InitState());
16663
16664 // A renderpass with one color attachment.
16665 VkAttachmentDescription attachment = { 0,
16666 VK_FORMAT_R8G8B8A8_UNORM,
16667 VK_SAMPLE_COUNT_1_BIT,
16668 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16669 VK_ATTACHMENT_STORE_OP_STORE,
16670 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16671 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16672 VK_IMAGE_LAYOUT_UNDEFINED,
16673 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16674
16675 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16676
16677 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16678
16679 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
16680
16681 VkRenderPass rp;
16682 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16683 ASSERT_VK_SUCCESS(err);
16684
16685 // A compatible framebuffer.
16686 VkImageObj image(m_device);
16687 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16688 ASSERT_TRUE(image.initialized());
16689
16690 VkImageViewCreateInfo ivci = {
16691 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16692 nullptr,
16693 0,
16694 image.handle(),
16695 VK_IMAGE_VIEW_TYPE_2D,
16696 VK_FORMAT_R8G8B8A8_UNORM,
16697 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16698 VK_COMPONENT_SWIZZLE_IDENTITY },
16699 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16700 };
16701 VkImageView view;
16702 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16703 ASSERT_VK_SUCCESS(err);
16704
16705 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16706 VkFramebuffer fb;
16707 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16708 ASSERT_VK_SUCCESS(err);
16709
16710 // Explicitly create a command buffer to bind the FB to so that we can then
16711 // destroy the command pool in order to implicitly free command buffer
16712 VkCommandPool command_pool;
16713 VkCommandPoolCreateInfo pool_create_info{};
16714 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
16715 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
16716 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
16717 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
16718
16719 VkCommandBuffer command_buffer;
16720 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
16721 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16722 command_buffer_allocate_info.commandPool = command_pool;
16723 command_buffer_allocate_info.commandBufferCount = 1;
16724 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16725 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
16726
16727 // Begin our cmd buffer with renderpass using our framebuffer
16728 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16729 VkCommandBufferBeginInfo begin_info{};
16730 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16731 vkBeginCommandBuffer(command_buffer, &begin_info);
16732
16733 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16734 vkCmdEndRenderPass(command_buffer);
16735 vkEndCommandBuffer(command_buffer);
16736 vkDestroyImageView(m_device->device(), view, nullptr);
16737 // Destroy command pool to implicitly free command buffer
16738 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
16739 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16740 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16741 m_errorMonitor->VerifyNotFound();
16742}
16743
16744TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
16745 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
16746 "transitions for the first subpass");
16747
16748 m_errorMonitor->ExpectSuccess();
16749
16750 ASSERT_NO_FATAL_FAILURE(InitState());
16751
16752 // A renderpass with one color attachment.
16753 VkAttachmentDescription attachment = { 0,
16754 VK_FORMAT_R8G8B8A8_UNORM,
16755 VK_SAMPLE_COUNT_1_BIT,
16756 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16757 VK_ATTACHMENT_STORE_OP_STORE,
16758 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16759 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16760 VK_IMAGE_LAYOUT_UNDEFINED,
16761 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16762
16763 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16764
16765 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16766
16767 VkSubpassDependency dep = { 0,
16768 0,
16769 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16770 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16771 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16772 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16773 VK_DEPENDENCY_BY_REGION_BIT };
16774
16775 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16776
16777 VkResult err;
16778 VkRenderPass rp;
16779 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16780 ASSERT_VK_SUCCESS(err);
16781
16782 // A compatible framebuffer.
16783 VkImageObj image(m_device);
16784 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16785 ASSERT_TRUE(image.initialized());
16786
16787 VkImageViewCreateInfo ivci = {
16788 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16789 nullptr,
16790 0,
16791 image.handle(),
16792 VK_IMAGE_VIEW_TYPE_2D,
16793 VK_FORMAT_R8G8B8A8_UNORM,
16794 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
16795 VK_COMPONENT_SWIZZLE_IDENTITY },
16796 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
16797 };
16798 VkImageView view;
16799 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16800 ASSERT_VK_SUCCESS(err);
16801
16802 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16803 VkFramebuffer fb;
16804 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16805 ASSERT_VK_SUCCESS(err);
16806
16807 // Record a single command buffer which issues a pipeline barrier w/
16808 // image memory barrier for the attachment. This detects the previously
16809 // missing tracking of the subpass layout by throwing a validation error
16810 // if it doesn't occur.
16811 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16812 BeginCommandBuffer();
16813 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16814
16815 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
16816 nullptr,
16817 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16818 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16819 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16820 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16821 VK_QUEUE_FAMILY_IGNORED,
16822 VK_QUEUE_FAMILY_IGNORED,
16823 image.handle(),
16824 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
16825 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16826 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16827 &imb);
16828
16829 vkCmdEndRenderPass(m_commandBuffer->handle());
16830 m_errorMonitor->VerifyNotFound();
16831 EndCommandBuffer();
16832
16833 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16834 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16835 vkDestroyImageView(m_device->device(), view, nullptr);
16836}
16837
16838TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
16839 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
16840 "is used as a depth/stencil framebuffer attachment, the "
16841 "aspectMask is ignored and both depth and stencil image "
16842 "subresources are used.");
16843
16844 VkFormatProperties format_properties;
16845 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
16846 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
16847 return;
16848 }
16849
16850 m_errorMonitor->ExpectSuccess();
16851
16852 ASSERT_NO_FATAL_FAILURE(InitState());
16853
16854 VkAttachmentDescription attachment = { 0,
16855 VK_FORMAT_D32_SFLOAT_S8_UINT,
16856 VK_SAMPLE_COUNT_1_BIT,
16857 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16858 VK_ATTACHMENT_STORE_OP_STORE,
16859 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
16860 VK_ATTACHMENT_STORE_OP_DONT_CARE,
16861 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
16862 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16863
16864 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
16865
16866 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
16867
16868 VkSubpassDependency dep = { 0,
16869 0,
16870 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16871 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16872 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16873 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
16874 VK_DEPENDENCY_BY_REGION_BIT};
16875
16876 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
16877
16878 VkResult err;
16879 VkRenderPass rp;
16880 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16881 ASSERT_VK_SUCCESS(err);
16882
16883 VkImageObj image(m_device);
16884 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
16885 0x26, // usage
16886 VK_IMAGE_TILING_OPTIMAL, 0);
16887 ASSERT_TRUE(image.initialized());
16888 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
16889
16890 VkImageViewCreateInfo ivci = {
16891 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
16892 nullptr,
16893 0,
16894 image.handle(),
16895 VK_IMAGE_VIEW_TYPE_2D,
16896 VK_FORMAT_D32_SFLOAT_S8_UINT,
16897 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
16898 { 0x2, 0, 1, 0, 1 },
16899 };
16900 VkImageView view;
16901 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
16902 ASSERT_VK_SUCCESS(err);
16903
16904 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
16905 VkFramebuffer fb;
16906 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16907 ASSERT_VK_SUCCESS(err);
16908
16909 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16910 BeginCommandBuffer();
16911 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16912
16913 VkImageMemoryBarrier imb = {};
16914 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16915 imb.pNext = nullptr;
16916 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
16917 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16918 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16919 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16920 imb.srcQueueFamilyIndex = 0;
16921 imb.dstQueueFamilyIndex = 0;
16922 imb.image = image.handle();
16923 imb.subresourceRange.aspectMask = 0x6;
16924 imb.subresourceRange.baseMipLevel = 0;
16925 imb.subresourceRange.levelCount = 0x1;
16926 imb.subresourceRange.baseArrayLayer = 0;
16927 imb.subresourceRange.layerCount = 0x1;
16928
16929 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
16930 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
16931 &imb);
16932
16933 vkCmdEndRenderPass(m_commandBuffer->handle());
16934 EndCommandBuffer();
16935 QueueCommandBuffer(false);
16936 m_errorMonitor->VerifyNotFound();
16937
16938 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16939 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16940 vkDestroyImageView(m_device->device(), view, nullptr);
16941}
16942
16943TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
16944 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
16945 "errors, when an attachment reference is "
16946 "VK_ATTACHMENT_UNUSED");
16947
16948 m_errorMonitor->ExpectSuccess();
16949
16950 ASSERT_NO_FATAL_FAILURE(InitState());
16951
16952 // A renderpass with no attachments
16953 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
16954
16955 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
16956
16957 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
16958
16959 VkRenderPass rp;
16960 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16961 ASSERT_VK_SUCCESS(err);
16962
16963 // A compatible framebuffer.
16964 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
16965 VkFramebuffer fb;
16966 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
16967 ASSERT_VK_SUCCESS(err);
16968
16969 // Record a command buffer which just begins and ends the renderpass. The
16970 // bug manifests in BeginRenderPass.
16971 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
16972 BeginCommandBuffer();
16973 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
16974 vkCmdEndRenderPass(m_commandBuffer->handle());
16975 m_errorMonitor->VerifyNotFound();
16976 EndCommandBuffer();
16977
16978 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
16979 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16980}
16981
16982// This is a positive test. No errors are expected.
16983TEST_F(VkPositiveLayerTest, StencilLoadOp) {
16984 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
16985 "CLEAR. stencil[Load|Store]Op used to be ignored.");
16986 VkResult result = VK_SUCCESS;
16987 VkImageFormatProperties formatProps;
16988 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
16989 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
16990 &formatProps);
16991 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
16992 return;
16993 }
16994
16995 ASSERT_NO_FATAL_FAILURE(InitState());
16996 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
16997 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
16998 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
16999 VkAttachmentDescription att = {};
17000 VkAttachmentReference ref = {};
17001 att.format = depth_stencil_fmt;
17002 att.samples = VK_SAMPLE_COUNT_1_BIT;
17003 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
17004 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
17005 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
17006 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
17007 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17008 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17009
17010 VkClearValue clear;
17011 clear.depthStencil.depth = 1.0;
17012 clear.depthStencil.stencil = 0;
17013 ref.attachment = 0;
17014 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17015
17016 VkSubpassDescription subpass = {};
17017 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
17018 subpass.flags = 0;
17019 subpass.inputAttachmentCount = 0;
17020 subpass.pInputAttachments = NULL;
17021 subpass.colorAttachmentCount = 0;
17022 subpass.pColorAttachments = NULL;
17023 subpass.pResolveAttachments = NULL;
17024 subpass.pDepthStencilAttachment = &ref;
17025 subpass.preserveAttachmentCount = 0;
17026 subpass.pPreserveAttachments = NULL;
17027
17028 VkRenderPass rp;
17029 VkRenderPassCreateInfo rp_info = {};
17030 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
17031 rp_info.attachmentCount = 1;
17032 rp_info.pAttachments = &att;
17033 rp_info.subpassCount = 1;
17034 rp_info.pSubpasses = &subpass;
17035 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
17036 ASSERT_VK_SUCCESS(result);
17037
17038 VkImageView *depthView = m_depthStencil->BindInfo();
17039 VkFramebufferCreateInfo fb_info = {};
17040 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
17041 fb_info.pNext = NULL;
17042 fb_info.renderPass = rp;
17043 fb_info.attachmentCount = 1;
17044 fb_info.pAttachments = depthView;
17045 fb_info.width = 100;
17046 fb_info.height = 100;
17047 fb_info.layers = 1;
17048 VkFramebuffer fb;
17049 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
17050 ASSERT_VK_SUCCESS(result);
17051
17052 VkRenderPassBeginInfo rpbinfo = {};
17053 rpbinfo.clearValueCount = 1;
17054 rpbinfo.pClearValues = &clear;
17055 rpbinfo.pNext = NULL;
17056 rpbinfo.renderPass = rp;
17057 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
17058 rpbinfo.renderArea.extent.width = 100;
17059 rpbinfo.renderArea.extent.height = 100;
17060 rpbinfo.renderArea.offset.x = 0;
17061 rpbinfo.renderArea.offset.y = 0;
17062 rpbinfo.framebuffer = fb;
17063
17064 VkFence fence = {};
17065 VkFenceCreateInfo fence_ci = {};
17066 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17067 fence_ci.pNext = nullptr;
17068 fence_ci.flags = 0;
17069 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
17070 ASSERT_VK_SUCCESS(result);
17071
17072 m_commandBuffer->BeginCommandBuffer();
17073 m_commandBuffer->BeginRenderPass(rpbinfo);
17074 m_commandBuffer->EndRenderPass();
17075 m_commandBuffer->EndCommandBuffer();
17076 m_commandBuffer->QueueCommandBuffer(fence);
17077
17078 VkImageObj destImage(m_device);
17079 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17080 VK_IMAGE_TILING_OPTIMAL, 0);
17081 VkImageMemoryBarrier barrier = {};
17082 VkImageSubresourceRange range;
17083 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17084 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17085 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
17086 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17087 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
17088 barrier.image = m_depthStencil->handle();
17089 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17090 range.baseMipLevel = 0;
17091 range.levelCount = 1;
17092 range.baseArrayLayer = 0;
17093 range.layerCount = 1;
17094 barrier.subresourceRange = range;
17095 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17096 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
17097 cmdbuf.BeginCommandBuffer();
17098 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17099 &barrier);
17100 barrier.srcAccessMask = 0;
17101 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17102 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
17103 barrier.image = destImage.handle();
17104 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17105 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
17106 &barrier);
17107 VkImageCopy cregion;
17108 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17109 cregion.srcSubresource.mipLevel = 0;
17110 cregion.srcSubresource.baseArrayLayer = 0;
17111 cregion.srcSubresource.layerCount = 1;
17112 cregion.srcOffset.x = 0;
17113 cregion.srcOffset.y = 0;
17114 cregion.srcOffset.z = 0;
17115 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17116 cregion.dstSubresource.mipLevel = 0;
17117 cregion.dstSubresource.baseArrayLayer = 0;
17118 cregion.dstSubresource.layerCount = 1;
17119 cregion.dstOffset.x = 0;
17120 cregion.dstOffset.y = 0;
17121 cregion.dstOffset.z = 0;
17122 cregion.extent.width = 100;
17123 cregion.extent.height = 100;
17124 cregion.extent.depth = 1;
17125 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
17126 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
17127 cmdbuf.EndCommandBuffer();
17128
17129 VkSubmitInfo submit_info;
17130 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17131 submit_info.pNext = NULL;
17132 submit_info.waitSemaphoreCount = 0;
17133 submit_info.pWaitSemaphores = NULL;
17134 submit_info.pWaitDstStageMask = NULL;
17135 submit_info.commandBufferCount = 1;
17136 submit_info.pCommandBuffers = &cmdbuf.handle();
17137 submit_info.signalSemaphoreCount = 0;
17138 submit_info.pSignalSemaphores = NULL;
17139
17140 m_errorMonitor->ExpectSuccess();
17141 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17142 m_errorMonitor->VerifyNotFound();
17143
17144 vkQueueWaitIdle(m_device->m_queue);
17145 vkDestroyFence(m_device->device(), fence, nullptr);
17146 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17147 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17148}
17149
17150// This is a positive test. No errors should be generated.
17151TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
17152 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
17153
17154 m_errorMonitor->ExpectSuccess();
17155 ASSERT_NO_FATAL_FAILURE(InitState());
17156
17157 VkEvent event;
17158 VkEventCreateInfo event_create_info{};
17159 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17160 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17161
17162 VkCommandPool command_pool;
17163 VkCommandPoolCreateInfo pool_create_info{};
17164 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17165 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17166 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17167 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17168
17169 VkCommandBuffer command_buffer;
17170 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17171 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17172 command_buffer_allocate_info.commandPool = command_pool;
17173 command_buffer_allocate_info.commandBufferCount = 1;
17174 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17175 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17176
17177 VkQueue queue = VK_NULL_HANDLE;
17178 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17179
17180 {
17181 VkCommandBufferBeginInfo begin_info{};
17182 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17183 vkBeginCommandBuffer(command_buffer, &begin_info);
17184
17185 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
17186 nullptr, 0, nullptr);
17187 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
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 { vkSetEvent(m_device->device(), event); }
17200
17201 vkQueueWaitIdle(queue);
17202
17203 vkDestroyEvent(m_device->device(), event, nullptr);
17204 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17205 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17206
17207 m_errorMonitor->VerifyNotFound();
17208}
17209// This is a positive test. No errors should be generated.
17210TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
17211 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
17212
17213 ASSERT_NO_FATAL_FAILURE(InitState());
17214 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17215 return;
17216
17217 m_errorMonitor->ExpectSuccess();
17218
17219 VkQueryPool query_pool;
17220 VkQueryPoolCreateInfo query_pool_create_info{};
17221 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17222 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17223 query_pool_create_info.queryCount = 1;
17224 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17225
17226 VkCommandPool command_pool;
17227 VkCommandPoolCreateInfo pool_create_info{};
17228 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17229 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17230 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17231 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17232
17233 VkCommandBuffer command_buffer;
17234 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17235 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17236 command_buffer_allocate_info.commandPool = command_pool;
17237 command_buffer_allocate_info.commandBufferCount = 1;
17238 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17239 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17240
17241 VkCommandBuffer secondary_command_buffer;
17242 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17243 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
17244
17245 VkQueue queue = VK_NULL_HANDLE;
17246 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17247
17248 uint32_t qfi = 0;
17249 VkBufferCreateInfo buff_create_info = {};
17250 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17251 buff_create_info.size = 1024;
17252 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17253 buff_create_info.queueFamilyIndexCount = 1;
17254 buff_create_info.pQueueFamilyIndices = &qfi;
17255
17256 VkResult err;
17257 VkBuffer buffer;
17258 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17259 ASSERT_VK_SUCCESS(err);
17260 VkMemoryAllocateInfo mem_alloc = {};
17261 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17262 mem_alloc.pNext = NULL;
17263 mem_alloc.allocationSize = 1024;
17264 mem_alloc.memoryTypeIndex = 0;
17265
17266 VkMemoryRequirements memReqs;
17267 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17268 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17269 if (!pass) {
17270 vkDestroyBuffer(m_device->device(), buffer, NULL);
17271 return;
17272 }
17273
17274 VkDeviceMemory mem;
17275 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17276 ASSERT_VK_SUCCESS(err);
17277 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17278 ASSERT_VK_SUCCESS(err);
17279
17280 VkCommandBufferInheritanceInfo hinfo = {};
17281 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17282 hinfo.renderPass = VK_NULL_HANDLE;
17283 hinfo.subpass = 0;
17284 hinfo.framebuffer = VK_NULL_HANDLE;
17285 hinfo.occlusionQueryEnable = VK_FALSE;
17286 hinfo.queryFlags = 0;
17287 hinfo.pipelineStatistics = 0;
17288
17289 {
17290 VkCommandBufferBeginInfo begin_info{};
17291 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17292 begin_info.pInheritanceInfo = &hinfo;
17293 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
17294
17295 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
17296 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17297
17298 vkEndCommandBuffer(secondary_command_buffer);
17299
17300 begin_info.pInheritanceInfo = nullptr;
17301 vkBeginCommandBuffer(command_buffer, &begin_info);
17302
17303 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
17304 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
17305
17306 vkEndCommandBuffer(command_buffer);
17307 }
17308 {
17309 VkSubmitInfo submit_info{};
17310 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17311 submit_info.commandBufferCount = 1;
17312 submit_info.pCommandBuffers = &command_buffer;
17313 submit_info.signalSemaphoreCount = 0;
17314 submit_info.pSignalSemaphores = nullptr;
17315 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17316 }
17317
17318 vkQueueWaitIdle(queue);
17319
17320 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17321 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17322 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
17323 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17324 vkDestroyBuffer(m_device->device(), buffer, NULL);
17325 vkFreeMemory(m_device->device(), mem, NULL);
17326
17327 m_errorMonitor->VerifyNotFound();
17328}
17329
17330// This is a positive test. No errors should be generated.
17331TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
17332 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
17333
17334 ASSERT_NO_FATAL_FAILURE(InitState());
17335 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17336 return;
17337
17338 m_errorMonitor->ExpectSuccess();
17339
17340 VkQueryPool query_pool;
17341 VkQueryPoolCreateInfo query_pool_create_info{};
17342 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
17343 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
17344 query_pool_create_info.queryCount = 1;
17345 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
17346
17347 VkCommandPool command_pool;
17348 VkCommandPoolCreateInfo pool_create_info{};
17349 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17350 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17351 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17352 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17353
17354 VkCommandBuffer command_buffer[2];
17355 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17356 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17357 command_buffer_allocate_info.commandPool = command_pool;
17358 command_buffer_allocate_info.commandBufferCount = 2;
17359 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17360 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17361
17362 VkQueue queue = VK_NULL_HANDLE;
17363 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17364
17365 uint32_t qfi = 0;
17366 VkBufferCreateInfo buff_create_info = {};
17367 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17368 buff_create_info.size = 1024;
17369 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
17370 buff_create_info.queueFamilyIndexCount = 1;
17371 buff_create_info.pQueueFamilyIndices = &qfi;
17372
17373 VkResult err;
17374 VkBuffer buffer;
17375 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
17376 ASSERT_VK_SUCCESS(err);
17377 VkMemoryAllocateInfo mem_alloc = {};
17378 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17379 mem_alloc.pNext = NULL;
17380 mem_alloc.allocationSize = 1024;
17381 mem_alloc.memoryTypeIndex = 0;
17382
17383 VkMemoryRequirements memReqs;
17384 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
17385 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
17386 if (!pass) {
17387 vkDestroyBuffer(m_device->device(), buffer, NULL);
17388 return;
17389 }
17390
17391 VkDeviceMemory mem;
17392 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17393 ASSERT_VK_SUCCESS(err);
17394 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17395 ASSERT_VK_SUCCESS(err);
17396
17397 {
17398 VkCommandBufferBeginInfo begin_info{};
17399 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17400 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17401
17402 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
17403 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
17404
17405 vkEndCommandBuffer(command_buffer[0]);
17406
17407 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17408
17409 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
17410
17411 vkEndCommandBuffer(command_buffer[1]);
17412 }
17413 {
17414 VkSubmitInfo submit_info{};
17415 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17416 submit_info.commandBufferCount = 2;
17417 submit_info.pCommandBuffers = command_buffer;
17418 submit_info.signalSemaphoreCount = 0;
17419 submit_info.pSignalSemaphores = nullptr;
17420 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17421 }
17422
17423 vkQueueWaitIdle(queue);
17424
17425 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
17426 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
17427 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17428 vkDestroyBuffer(m_device->device(), buffer, NULL);
17429 vkFreeMemory(m_device->device(), mem, NULL);
17430
17431 m_errorMonitor->VerifyNotFound();
17432}
17433
Tony Barbourc46924f2016-11-04 11:49:52 -060017434TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017435 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
17436
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017437 ASSERT_NO_FATAL_FAILURE(InitState());
17438 VkEvent event;
17439 VkEventCreateInfo event_create_info{};
17440 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
17441 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
17442
17443 VkCommandPool command_pool;
17444 VkCommandPoolCreateInfo pool_create_info{};
17445 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17446 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17447 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17448 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17449
17450 VkCommandBuffer command_buffer;
17451 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17452 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17453 command_buffer_allocate_info.commandPool = command_pool;
17454 command_buffer_allocate_info.commandBufferCount = 1;
17455 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17456 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17457
17458 VkQueue queue = VK_NULL_HANDLE;
17459 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17460
17461 {
17462 VkCommandBufferBeginInfo begin_info{};
17463 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17464 vkBeginCommandBuffer(command_buffer, &begin_info);
17465
17466 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017467 vkEndCommandBuffer(command_buffer);
17468 }
17469 {
17470 VkSubmitInfo submit_info{};
17471 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17472 submit_info.commandBufferCount = 1;
17473 submit_info.pCommandBuffers = &command_buffer;
17474 submit_info.signalSemaphoreCount = 0;
17475 submit_info.pSignalSemaphores = nullptr;
17476 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17477 }
17478 {
17479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
17480 "command buffer.");
17481 vkSetEvent(m_device->device(), event);
17482 m_errorMonitor->VerifyFound();
17483 }
17484
17485 vkQueueWaitIdle(queue);
17486
17487 vkDestroyEvent(m_device->device(), event, nullptr);
17488 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
17489 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17490}
17491
17492// This is a positive test. No errors should be generated.
17493TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
17494 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
17495 "run through a Submit & WaitForFences cycle 3 times. This "
17496 "previously revealed a bug so running this positive test "
17497 "to prevent a regression.");
17498 m_errorMonitor->ExpectSuccess();
17499
17500 ASSERT_NO_FATAL_FAILURE(InitState());
17501 VkQueue queue = VK_NULL_HANDLE;
17502 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
17503
17504 static const uint32_t NUM_OBJECTS = 2;
17505 static const uint32_t NUM_FRAMES = 3;
17506 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
17507 VkFence fences[NUM_OBJECTS] = {};
17508
17509 VkCommandPool cmd_pool;
17510 VkCommandPoolCreateInfo cmd_pool_ci = {};
17511 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17512 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
17513 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17514 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
17515 ASSERT_VK_SUCCESS(err);
17516
17517 VkCommandBufferAllocateInfo cmd_buf_info = {};
17518 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17519 cmd_buf_info.commandPool = cmd_pool;
17520 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17521 cmd_buf_info.commandBufferCount = 1;
17522
17523 VkFenceCreateInfo fence_ci = {};
17524 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17525 fence_ci.pNext = nullptr;
17526 fence_ci.flags = 0;
17527
17528 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17529 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
17530 ASSERT_VK_SUCCESS(err);
17531 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
17532 ASSERT_VK_SUCCESS(err);
17533 }
17534
17535 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
17536 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
17537 // Create empty cmd buffer
17538 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
17539 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17540
17541 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
17542 ASSERT_VK_SUCCESS(err);
17543 err = vkEndCommandBuffer(cmd_buffers[obj]);
17544 ASSERT_VK_SUCCESS(err);
17545
17546 VkSubmitInfo submit_info = {};
17547 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17548 submit_info.commandBufferCount = 1;
17549 submit_info.pCommandBuffers = &cmd_buffers[obj];
17550 // Submit cmd buffer and wait for fence
17551 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
17552 ASSERT_VK_SUCCESS(err);
17553 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
17554 ASSERT_VK_SUCCESS(err);
17555 err = vkResetFences(m_device->device(), 1, &fences[obj]);
17556 ASSERT_VK_SUCCESS(err);
17557 }
17558 }
17559 m_errorMonitor->VerifyNotFound();
17560 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
17561 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
17562 vkDestroyFence(m_device->device(), fences[i], nullptr);
17563 }
17564}
17565// This is a positive test. No errors should be generated.
17566TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
17567
17568 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17569 "submitted on separate queues followed by a QueueWaitIdle.");
17570
17571 ASSERT_NO_FATAL_FAILURE(InitState());
17572 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17573 return;
17574
17575 m_errorMonitor->ExpectSuccess();
17576
17577 VkSemaphore semaphore;
17578 VkSemaphoreCreateInfo semaphore_create_info{};
17579 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17580 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17581
17582 VkCommandPool command_pool;
17583 VkCommandPoolCreateInfo pool_create_info{};
17584 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17585 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17586 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17587 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17588
17589 VkCommandBuffer command_buffer[2];
17590 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17591 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17592 command_buffer_allocate_info.commandPool = command_pool;
17593 command_buffer_allocate_info.commandBufferCount = 2;
17594 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17595 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17596
17597 VkQueue queue = VK_NULL_HANDLE;
17598 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17599
17600 {
17601 VkCommandBufferBeginInfo begin_info{};
17602 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17603 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17604
17605 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17606 nullptr, 0, nullptr, 0, nullptr);
17607
17608 VkViewport viewport{};
17609 viewport.maxDepth = 1.0f;
17610 viewport.minDepth = 0.0f;
17611 viewport.width = 512;
17612 viewport.height = 512;
17613 viewport.x = 0;
17614 viewport.y = 0;
17615 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17616 vkEndCommandBuffer(command_buffer[0]);
17617 }
17618 {
17619 VkCommandBufferBeginInfo begin_info{};
17620 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17621 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17622
17623 VkViewport viewport{};
17624 viewport.maxDepth = 1.0f;
17625 viewport.minDepth = 0.0f;
17626 viewport.width = 512;
17627 viewport.height = 512;
17628 viewport.x = 0;
17629 viewport.y = 0;
17630 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17631 vkEndCommandBuffer(command_buffer[1]);
17632 }
17633 {
17634 VkSubmitInfo submit_info{};
17635 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17636 submit_info.commandBufferCount = 1;
17637 submit_info.pCommandBuffers = &command_buffer[0];
17638 submit_info.signalSemaphoreCount = 1;
17639 submit_info.pSignalSemaphores = &semaphore;
17640 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17641 }
17642 {
17643 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17644 VkSubmitInfo submit_info{};
17645 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17646 submit_info.commandBufferCount = 1;
17647 submit_info.pCommandBuffers = &command_buffer[1];
17648 submit_info.waitSemaphoreCount = 1;
17649 submit_info.pWaitSemaphores = &semaphore;
17650 submit_info.pWaitDstStageMask = flags;
17651 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17652 }
17653
17654 vkQueueWaitIdle(m_device->m_queue);
17655
17656 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17657 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17658 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17659
17660 m_errorMonitor->VerifyNotFound();
17661}
17662
17663// This is a positive test. No errors should be generated.
17664TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
17665
17666 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17667 "submitted on separate queues, the second having a fence"
17668 "followed by a QueueWaitIdle.");
17669
17670 ASSERT_NO_FATAL_FAILURE(InitState());
17671 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17672 return;
17673
17674 m_errorMonitor->ExpectSuccess();
17675
17676 VkFence fence;
17677 VkFenceCreateInfo fence_create_info{};
17678 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17679 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17680
17681 VkSemaphore semaphore;
17682 VkSemaphoreCreateInfo semaphore_create_info{};
17683 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17684 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17685
17686 VkCommandPool command_pool;
17687 VkCommandPoolCreateInfo pool_create_info{};
17688 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17689 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17690 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17691 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17692
17693 VkCommandBuffer command_buffer[2];
17694 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17695 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17696 command_buffer_allocate_info.commandPool = command_pool;
17697 command_buffer_allocate_info.commandBufferCount = 2;
17698 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17699 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17700
17701 VkQueue queue = VK_NULL_HANDLE;
17702 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17703
17704 {
17705 VkCommandBufferBeginInfo begin_info{};
17706 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17707 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17708
17709 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17710 nullptr, 0, nullptr, 0, nullptr);
17711
17712 VkViewport viewport{};
17713 viewport.maxDepth = 1.0f;
17714 viewport.minDepth = 0.0f;
17715 viewport.width = 512;
17716 viewport.height = 512;
17717 viewport.x = 0;
17718 viewport.y = 0;
17719 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17720 vkEndCommandBuffer(command_buffer[0]);
17721 }
17722 {
17723 VkCommandBufferBeginInfo begin_info{};
17724 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17725 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17726
17727 VkViewport viewport{};
17728 viewport.maxDepth = 1.0f;
17729 viewport.minDepth = 0.0f;
17730 viewport.width = 512;
17731 viewport.height = 512;
17732 viewport.x = 0;
17733 viewport.y = 0;
17734 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17735 vkEndCommandBuffer(command_buffer[1]);
17736 }
17737 {
17738 VkSubmitInfo submit_info{};
17739 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17740 submit_info.commandBufferCount = 1;
17741 submit_info.pCommandBuffers = &command_buffer[0];
17742 submit_info.signalSemaphoreCount = 1;
17743 submit_info.pSignalSemaphores = &semaphore;
17744 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17745 }
17746 {
17747 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17748 VkSubmitInfo submit_info{};
17749 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17750 submit_info.commandBufferCount = 1;
17751 submit_info.pCommandBuffers = &command_buffer[1];
17752 submit_info.waitSemaphoreCount = 1;
17753 submit_info.pWaitSemaphores = &semaphore;
17754 submit_info.pWaitDstStageMask = flags;
17755 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17756 }
17757
17758 vkQueueWaitIdle(m_device->m_queue);
17759
17760 vkDestroyFence(m_device->device(), fence, nullptr);
17761 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17762 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17763 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17764
17765 m_errorMonitor->VerifyNotFound();
17766}
17767
17768// This is a positive test. No errors should be generated.
17769TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
17770
17771 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17772 "submitted on separate queues, the second having a fence"
17773 "followed by two consecutive WaitForFences calls on the same fence.");
17774
17775 ASSERT_NO_FATAL_FAILURE(InitState());
17776 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17777 return;
17778
17779 m_errorMonitor->ExpectSuccess();
17780
17781 VkFence fence;
17782 VkFenceCreateInfo fence_create_info{};
17783 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17784 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17785
17786 VkSemaphore semaphore;
17787 VkSemaphoreCreateInfo semaphore_create_info{};
17788 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17789 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17790
17791 VkCommandPool command_pool;
17792 VkCommandPoolCreateInfo pool_create_info{};
17793 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17794 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17795 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17796 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17797
17798 VkCommandBuffer command_buffer[2];
17799 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17800 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17801 command_buffer_allocate_info.commandPool = command_pool;
17802 command_buffer_allocate_info.commandBufferCount = 2;
17803 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17804 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17805
17806 VkQueue queue = VK_NULL_HANDLE;
17807 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17808
17809 {
17810 VkCommandBufferBeginInfo begin_info{};
17811 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17812 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17813
17814 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17815 nullptr, 0, nullptr, 0, nullptr);
17816
17817 VkViewport viewport{};
17818 viewport.maxDepth = 1.0f;
17819 viewport.minDepth = 0.0f;
17820 viewport.width = 512;
17821 viewport.height = 512;
17822 viewport.x = 0;
17823 viewport.y = 0;
17824 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
17825 vkEndCommandBuffer(command_buffer[0]);
17826 }
17827 {
17828 VkCommandBufferBeginInfo begin_info{};
17829 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17830 vkBeginCommandBuffer(command_buffer[1], &begin_info);
17831
17832 VkViewport viewport{};
17833 viewport.maxDepth = 1.0f;
17834 viewport.minDepth = 0.0f;
17835 viewport.width = 512;
17836 viewport.height = 512;
17837 viewport.x = 0;
17838 viewport.y = 0;
17839 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
17840 vkEndCommandBuffer(command_buffer[1]);
17841 }
17842 {
17843 VkSubmitInfo submit_info{};
17844 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17845 submit_info.commandBufferCount = 1;
17846 submit_info.pCommandBuffers = &command_buffer[0];
17847 submit_info.signalSemaphoreCount = 1;
17848 submit_info.pSignalSemaphores = &semaphore;
17849 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
17850 }
17851 {
17852 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
17853 VkSubmitInfo submit_info{};
17854 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17855 submit_info.commandBufferCount = 1;
17856 submit_info.pCommandBuffers = &command_buffer[1];
17857 submit_info.waitSemaphoreCount = 1;
17858 submit_info.pWaitSemaphores = &semaphore;
17859 submit_info.pWaitDstStageMask = flags;
17860 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
17861 }
17862
17863 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17864 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17865
17866 vkDestroyFence(m_device->device(), fence, nullptr);
17867 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
17868 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
17869 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17870
17871 m_errorMonitor->VerifyNotFound();
17872}
17873
17874TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
17875
17876 ASSERT_NO_FATAL_FAILURE(InitState());
17877 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
17878 printf("Test requires two queues, skipping\n");
17879 return;
17880 }
17881
17882 VkResult err;
17883
17884 m_errorMonitor->ExpectSuccess();
17885
17886 VkQueue q0 = m_device->m_queue;
17887 VkQueue q1 = nullptr;
17888 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
17889 ASSERT_NE(q1, nullptr);
17890
17891 // An (empty) command buffer. We must have work in the first submission --
17892 // the layer treats unfenced work differently from fenced work.
17893 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
17894 VkCommandPool pool;
17895 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
17896 ASSERT_VK_SUCCESS(err);
17897 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
17898 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
17899 VkCommandBuffer cb;
17900 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
17901 ASSERT_VK_SUCCESS(err);
17902 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
17903 err = vkBeginCommandBuffer(cb, &cbbi);
17904 ASSERT_VK_SUCCESS(err);
17905 err = vkEndCommandBuffer(cb);
17906 ASSERT_VK_SUCCESS(err);
17907
17908 // A semaphore
17909 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17910 VkSemaphore s;
17911 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
17912 ASSERT_VK_SUCCESS(err);
17913
17914 // First submission, to q0
17915 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
17916
17917 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
17918 ASSERT_VK_SUCCESS(err);
17919
17920 // Second submission, to q1, waiting on s
17921 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
17922 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
17923
17924 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
17925 ASSERT_VK_SUCCESS(err);
17926
17927 // Wait for q0 idle
17928 err = vkQueueWaitIdle(q0);
17929 ASSERT_VK_SUCCESS(err);
17930
17931 // Command buffer should have been completed (it was on q0); reset the pool.
17932 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
17933
17934 m_errorMonitor->VerifyNotFound();
17935
17936 // Force device completely idle and clean up resources
17937 vkDeviceWaitIdle(m_device->device());
17938 vkDestroyCommandPool(m_device->device(), pool, nullptr);
17939 vkDestroySemaphore(m_device->device(), s, nullptr);
17940}
17941
17942// This is a positive test. No errors should be generated.
17943TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
17944
17945 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
17946 "submitted on separate queues, the second having a fence, "
17947 "followed by a WaitForFences call.");
17948
17949 ASSERT_NO_FATAL_FAILURE(InitState());
17950 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
17951 return;
17952
17953 m_errorMonitor->ExpectSuccess();
17954
17955 ASSERT_NO_FATAL_FAILURE(InitState());
17956 VkFence fence;
17957 VkFenceCreateInfo fence_create_info{};
17958 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17959 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
17960
17961 VkSemaphore semaphore;
17962 VkSemaphoreCreateInfo semaphore_create_info{};
17963 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
17964 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
17965
17966 VkCommandPool command_pool;
17967 VkCommandPoolCreateInfo pool_create_info{};
17968 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17969 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17970 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17971 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17972
17973 VkCommandBuffer command_buffer[2];
17974 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17975 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17976 command_buffer_allocate_info.commandPool = command_pool;
17977 command_buffer_allocate_info.commandBufferCount = 2;
17978 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17979 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
17980
17981 VkQueue queue = VK_NULL_HANDLE;
17982 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
17983
17984 {
17985 VkCommandBufferBeginInfo begin_info{};
17986 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17987 vkBeginCommandBuffer(command_buffer[0], &begin_info);
17988
17989 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
17990 nullptr, 0, nullptr, 0, nullptr);
17991
17992 VkViewport viewport{};
17993 viewport.maxDepth = 1.0f;
17994 viewport.minDepth = 0.0f;
17995 viewport.width = 512;
17996 viewport.height = 512;
17997 viewport.x = 0;
17998 viewport.y = 0;
17999 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18000 vkEndCommandBuffer(command_buffer[0]);
18001 }
18002 {
18003 VkCommandBufferBeginInfo begin_info{};
18004 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18005 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18006
18007 VkViewport viewport{};
18008 viewport.maxDepth = 1.0f;
18009 viewport.minDepth = 0.0f;
18010 viewport.width = 512;
18011 viewport.height = 512;
18012 viewport.x = 0;
18013 viewport.y = 0;
18014 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18015 vkEndCommandBuffer(command_buffer[1]);
18016 }
18017 {
18018 VkSubmitInfo submit_info{};
18019 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18020 submit_info.commandBufferCount = 1;
18021 submit_info.pCommandBuffers = &command_buffer[0];
18022 submit_info.signalSemaphoreCount = 1;
18023 submit_info.pSignalSemaphores = &semaphore;
18024 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18025 }
18026 {
18027 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18028 VkSubmitInfo submit_info{};
18029 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18030 submit_info.commandBufferCount = 1;
18031 submit_info.pCommandBuffers = &command_buffer[1];
18032 submit_info.waitSemaphoreCount = 1;
18033 submit_info.pWaitSemaphores = &semaphore;
18034 submit_info.pWaitDstStageMask = flags;
18035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18036 }
18037
18038 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18039
18040 vkDestroyFence(m_device->device(), fence, nullptr);
18041 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18042 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18043 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18044
18045 m_errorMonitor->VerifyNotFound();
18046}
18047
18048// This is a positive test. No errors should be generated.
18049TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
18050
18051 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18052 "on the same queue, sharing a signal/wait semaphore, the "
18053 "second having a fence, "
18054 "followed by a WaitForFences call.");
18055
18056 m_errorMonitor->ExpectSuccess();
18057
18058 ASSERT_NO_FATAL_FAILURE(InitState());
18059 VkFence fence;
18060 VkFenceCreateInfo fence_create_info{};
18061 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18062 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18063
18064 VkSemaphore semaphore;
18065 VkSemaphoreCreateInfo semaphore_create_info{};
18066 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18067 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18068
18069 VkCommandPool command_pool;
18070 VkCommandPoolCreateInfo pool_create_info{};
18071 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18072 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18073 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18074 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18075
18076 VkCommandBuffer command_buffer[2];
18077 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18078 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18079 command_buffer_allocate_info.commandPool = command_pool;
18080 command_buffer_allocate_info.commandBufferCount = 2;
18081 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18082 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18083
18084 {
18085 VkCommandBufferBeginInfo begin_info{};
18086 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18087 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18088
18089 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18090 nullptr, 0, nullptr, 0, nullptr);
18091
18092 VkViewport viewport{};
18093 viewport.maxDepth = 1.0f;
18094 viewport.minDepth = 0.0f;
18095 viewport.width = 512;
18096 viewport.height = 512;
18097 viewport.x = 0;
18098 viewport.y = 0;
18099 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18100 vkEndCommandBuffer(command_buffer[0]);
18101 }
18102 {
18103 VkCommandBufferBeginInfo begin_info{};
18104 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18105 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18106
18107 VkViewport viewport{};
18108 viewport.maxDepth = 1.0f;
18109 viewport.minDepth = 0.0f;
18110 viewport.width = 512;
18111 viewport.height = 512;
18112 viewport.x = 0;
18113 viewport.y = 0;
18114 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18115 vkEndCommandBuffer(command_buffer[1]);
18116 }
18117 {
18118 VkSubmitInfo submit_info{};
18119 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18120 submit_info.commandBufferCount = 1;
18121 submit_info.pCommandBuffers = &command_buffer[0];
18122 submit_info.signalSemaphoreCount = 1;
18123 submit_info.pSignalSemaphores = &semaphore;
18124 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18125 }
18126 {
18127 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18128 VkSubmitInfo submit_info{};
18129 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18130 submit_info.commandBufferCount = 1;
18131 submit_info.pCommandBuffers = &command_buffer[1];
18132 submit_info.waitSemaphoreCount = 1;
18133 submit_info.pWaitSemaphores = &semaphore;
18134 submit_info.pWaitDstStageMask = flags;
18135 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18136 }
18137
18138 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18139
18140 vkDestroyFence(m_device->device(), fence, nullptr);
18141 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18142 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18143 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18144
18145 m_errorMonitor->VerifyNotFound();
18146}
18147
18148// This is a positive test. No errors should be generated.
18149TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
18150
18151 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18152 "on the same queue, no fences, followed by a third QueueSubmit with NO "
18153 "SubmitInfos but with a fence, followed by a WaitForFences call.");
18154
18155 m_errorMonitor->ExpectSuccess();
18156
18157 ASSERT_NO_FATAL_FAILURE(InitState());
18158 VkFence fence;
18159 VkFenceCreateInfo fence_create_info{};
18160 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18161 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18162
18163 VkCommandPool command_pool;
18164 VkCommandPoolCreateInfo pool_create_info{};
18165 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18166 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18167 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18168 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18169
18170 VkCommandBuffer command_buffer[2];
18171 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18172 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18173 command_buffer_allocate_info.commandPool = command_pool;
18174 command_buffer_allocate_info.commandBufferCount = 2;
18175 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18176 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18177
18178 {
18179 VkCommandBufferBeginInfo begin_info{};
18180 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18181 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18182
18183 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18184 nullptr, 0, nullptr, 0, nullptr);
18185
18186 VkViewport viewport{};
18187 viewport.maxDepth = 1.0f;
18188 viewport.minDepth = 0.0f;
18189 viewport.width = 512;
18190 viewport.height = 512;
18191 viewport.x = 0;
18192 viewport.y = 0;
18193 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18194 vkEndCommandBuffer(command_buffer[0]);
18195 }
18196 {
18197 VkCommandBufferBeginInfo begin_info{};
18198 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18199 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18200
18201 VkViewport viewport{};
18202 viewport.maxDepth = 1.0f;
18203 viewport.minDepth = 0.0f;
18204 viewport.width = 512;
18205 viewport.height = 512;
18206 viewport.x = 0;
18207 viewport.y = 0;
18208 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18209 vkEndCommandBuffer(command_buffer[1]);
18210 }
18211 {
18212 VkSubmitInfo submit_info{};
18213 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18214 submit_info.commandBufferCount = 1;
18215 submit_info.pCommandBuffers = &command_buffer[0];
18216 submit_info.signalSemaphoreCount = 0;
18217 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18218 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18219 }
18220 {
18221 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18222 VkSubmitInfo submit_info{};
18223 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18224 submit_info.commandBufferCount = 1;
18225 submit_info.pCommandBuffers = &command_buffer[1];
18226 submit_info.waitSemaphoreCount = 0;
18227 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18228 submit_info.pWaitDstStageMask = flags;
18229 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18230 }
18231
18232 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
18233
18234 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18235 ASSERT_VK_SUCCESS(err);
18236
18237 vkDestroyFence(m_device->device(), fence, nullptr);
18238 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18239 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18240
18241 m_errorMonitor->VerifyNotFound();
18242}
18243
18244// This is a positive test. No errors should be generated.
18245TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
18246
18247 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18248 "on the same queue, the second having a fence, followed "
18249 "by a WaitForFences call.");
18250
18251 m_errorMonitor->ExpectSuccess();
18252
18253 ASSERT_NO_FATAL_FAILURE(InitState());
18254 VkFence fence;
18255 VkFenceCreateInfo fence_create_info{};
18256 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18257 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18258
18259 VkCommandPool command_pool;
18260 VkCommandPoolCreateInfo pool_create_info{};
18261 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18262 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18263 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18264 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18265
18266 VkCommandBuffer command_buffer[2];
18267 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18268 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18269 command_buffer_allocate_info.commandPool = command_pool;
18270 command_buffer_allocate_info.commandBufferCount = 2;
18271 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18272 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18273
18274 {
18275 VkCommandBufferBeginInfo begin_info{};
18276 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18277 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18278
18279 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18280 nullptr, 0, nullptr, 0, nullptr);
18281
18282 VkViewport viewport{};
18283 viewport.maxDepth = 1.0f;
18284 viewport.minDepth = 0.0f;
18285 viewport.width = 512;
18286 viewport.height = 512;
18287 viewport.x = 0;
18288 viewport.y = 0;
18289 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18290 vkEndCommandBuffer(command_buffer[0]);
18291 }
18292 {
18293 VkCommandBufferBeginInfo begin_info{};
18294 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18295 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18296
18297 VkViewport viewport{};
18298 viewport.maxDepth = 1.0f;
18299 viewport.minDepth = 0.0f;
18300 viewport.width = 512;
18301 viewport.height = 512;
18302 viewport.x = 0;
18303 viewport.y = 0;
18304 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18305 vkEndCommandBuffer(command_buffer[1]);
18306 }
18307 {
18308 VkSubmitInfo submit_info{};
18309 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18310 submit_info.commandBufferCount = 1;
18311 submit_info.pCommandBuffers = &command_buffer[0];
18312 submit_info.signalSemaphoreCount = 0;
18313 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
18314 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18315 }
18316 {
18317 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18318 VkSubmitInfo submit_info{};
18319 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18320 submit_info.commandBufferCount = 1;
18321 submit_info.pCommandBuffers = &command_buffer[1];
18322 submit_info.waitSemaphoreCount = 0;
18323 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
18324 submit_info.pWaitDstStageMask = flags;
18325 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18326 }
18327
18328 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18329
18330 vkDestroyFence(m_device->device(), fence, nullptr);
18331 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18332 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18333
18334 m_errorMonitor->VerifyNotFound();
18335}
18336
18337// This is a positive test. No errors should be generated.
18338TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
18339
18340 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
18341 "QueueSubmit call followed by a WaitForFences call.");
18342 ASSERT_NO_FATAL_FAILURE(InitState());
18343
18344 m_errorMonitor->ExpectSuccess();
18345
18346 VkFence fence;
18347 VkFenceCreateInfo fence_create_info{};
18348 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18349 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18350
18351 VkSemaphore semaphore;
18352 VkSemaphoreCreateInfo semaphore_create_info{};
18353 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18354 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18355
18356 VkCommandPool command_pool;
18357 VkCommandPoolCreateInfo pool_create_info{};
18358 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18359 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18360 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18361 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18362
18363 VkCommandBuffer command_buffer[2];
18364 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18365 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18366 command_buffer_allocate_info.commandPool = command_pool;
18367 command_buffer_allocate_info.commandBufferCount = 2;
18368 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18369 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18370
18371 {
18372 VkCommandBufferBeginInfo begin_info{};
18373 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18374 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18375
18376 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18377 nullptr, 0, nullptr, 0, nullptr);
18378
18379 VkViewport viewport{};
18380 viewport.maxDepth = 1.0f;
18381 viewport.minDepth = 0.0f;
18382 viewport.width = 512;
18383 viewport.height = 512;
18384 viewport.x = 0;
18385 viewport.y = 0;
18386 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18387 vkEndCommandBuffer(command_buffer[0]);
18388 }
18389 {
18390 VkCommandBufferBeginInfo begin_info{};
18391 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18392 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18393
18394 VkViewport viewport{};
18395 viewport.maxDepth = 1.0f;
18396 viewport.minDepth = 0.0f;
18397 viewport.width = 512;
18398 viewport.height = 512;
18399 viewport.x = 0;
18400 viewport.y = 0;
18401 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18402 vkEndCommandBuffer(command_buffer[1]);
18403 }
18404 {
18405 VkSubmitInfo submit_info[2];
18406 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18407
18408 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18409 submit_info[0].pNext = NULL;
18410 submit_info[0].commandBufferCount = 1;
18411 submit_info[0].pCommandBuffers = &command_buffer[0];
18412 submit_info[0].signalSemaphoreCount = 1;
18413 submit_info[0].pSignalSemaphores = &semaphore;
18414 submit_info[0].waitSemaphoreCount = 0;
18415 submit_info[0].pWaitSemaphores = NULL;
18416 submit_info[0].pWaitDstStageMask = 0;
18417
18418 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18419 submit_info[1].pNext = NULL;
18420 submit_info[1].commandBufferCount = 1;
18421 submit_info[1].pCommandBuffers = &command_buffer[1];
18422 submit_info[1].waitSemaphoreCount = 1;
18423 submit_info[1].pWaitSemaphores = &semaphore;
18424 submit_info[1].pWaitDstStageMask = flags;
18425 submit_info[1].signalSemaphoreCount = 0;
18426 submit_info[1].pSignalSemaphores = NULL;
18427 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
18428 }
18429
18430 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18431
18432 vkDestroyFence(m_device->device(), fence, nullptr);
18433 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18434 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18435 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18436
18437 m_errorMonitor->VerifyNotFound();
18438}
18439
18440TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
18441 m_errorMonitor->ExpectSuccess();
18442
18443 ASSERT_NO_FATAL_FAILURE(InitState());
18444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18445
18446 BeginCommandBuffer(); // Framework implicitly begins the renderpass.
18447 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // End implicit.
18448
18449 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
18450 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18451 m_errorMonitor->VerifyNotFound();
18452 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
18453 m_errorMonitor->VerifyNotFound();
18454 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
18455 m_errorMonitor->VerifyNotFound();
18456
18457 m_commandBuffer->EndCommandBuffer();
18458 m_errorMonitor->VerifyNotFound();
18459}
18460
18461TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
18462 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
18463 "attachment that uses LOAD_OP_CLEAR, the first subpass "
18464 "has a valid layout, and a second subpass then uses a "
18465 "valid *READ_ONLY* layout.");
18466 m_errorMonitor->ExpectSuccess();
18467 ASSERT_NO_FATAL_FAILURE(InitState());
18468
18469 VkAttachmentReference attach[2] = {};
18470 attach[0].attachment = 0;
18471 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18472 attach[1].attachment = 0;
18473 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18474 VkSubpassDescription subpasses[2] = {};
18475 // First subpass clears DS attach on load
18476 subpasses[0].pDepthStencilAttachment = &attach[0];
18477 // 2nd subpass reads in DS as input attachment
18478 subpasses[1].inputAttachmentCount = 1;
18479 subpasses[1].pInputAttachments = &attach[1];
18480 VkAttachmentDescription attach_desc = {};
18481 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
18482 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
18483 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
18484 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18485 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18486 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18487 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18488 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
18489 VkRenderPassCreateInfo rpci = {};
18490 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18491 rpci.attachmentCount = 1;
18492 rpci.pAttachments = &attach_desc;
18493 rpci.subpassCount = 2;
18494 rpci.pSubpasses = subpasses;
18495
18496 // Now create RenderPass and verify no errors
18497 VkRenderPass rp;
18498 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
18499 m_errorMonitor->VerifyNotFound();
18500
18501 vkDestroyRenderPass(m_device->device(), rp, NULL);
18502}
18503
18504TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
18505 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
18506 "as vertex attributes");
18507 m_errorMonitor->ExpectSuccess();
18508
18509 ASSERT_NO_FATAL_FAILURE(InitState());
18510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18511
18512 VkVertexInputBindingDescription input_binding;
18513 memset(&input_binding, 0, sizeof(input_binding));
18514
18515 VkVertexInputAttributeDescription input_attribs[2];
18516 memset(input_attribs, 0, sizeof(input_attribs));
18517
18518 for (int i = 0; i < 2; i++) {
18519 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18520 input_attribs[i].location = i;
18521 }
18522
18523 char const *vsSource = "#version 450\n"
18524 "\n"
18525 "layout(location=0) in mat2x4 x;\n"
18526 "out gl_PerVertex {\n"
18527 " vec4 gl_Position;\n"
18528 "};\n"
18529 "void main(){\n"
18530 " gl_Position = x[0] + x[1];\n"
18531 "}\n";
18532 char const *fsSource = "#version 450\n"
18533 "\n"
18534 "layout(location=0) out vec4 color;\n"
18535 "void main(){\n"
18536 " color = vec4(1);\n"
18537 "}\n";
18538
18539 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18540 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18541
18542 VkPipelineObj pipe(m_device);
18543 pipe.AddColorAttachment();
18544 pipe.AddShader(&vs);
18545 pipe.AddShader(&fs);
18546
18547 pipe.AddVertexInputBindings(&input_binding, 1);
18548 pipe.AddVertexInputAttribs(input_attribs, 2);
18549
18550 VkDescriptorSetObj descriptorSet(m_device);
18551 descriptorSet.AppendDummy();
18552 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18553
18554 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18555
18556 /* expect success */
18557 m_errorMonitor->VerifyNotFound();
18558}
18559
18560TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
18561 m_errorMonitor->ExpectSuccess();
18562
18563 ASSERT_NO_FATAL_FAILURE(InitState());
18564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18565
18566 VkVertexInputBindingDescription input_binding;
18567 memset(&input_binding, 0, sizeof(input_binding));
18568
18569 VkVertexInputAttributeDescription input_attribs[2];
18570 memset(input_attribs, 0, sizeof(input_attribs));
18571
18572 for (int i = 0; i < 2; i++) {
18573 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18574 input_attribs[i].location = i;
18575 }
18576
18577 char const *vsSource = "#version 450\n"
18578 "\n"
18579 "layout(location=0) in vec4 x[2];\n"
18580 "out gl_PerVertex {\n"
18581 " vec4 gl_Position;\n"
18582 "};\n"
18583 "void main(){\n"
18584 " gl_Position = x[0] + x[1];\n"
18585 "}\n";
18586 char const *fsSource = "#version 450\n"
18587 "\n"
18588 "layout(location=0) out vec4 color;\n"
18589 "void main(){\n"
18590 " color = vec4(1);\n"
18591 "}\n";
18592
18593 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18594 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18595
18596 VkPipelineObj pipe(m_device);
18597 pipe.AddColorAttachment();
18598 pipe.AddShader(&vs);
18599 pipe.AddShader(&fs);
18600
18601 pipe.AddVertexInputBindings(&input_binding, 1);
18602 pipe.AddVertexInputAttribs(input_attribs, 2);
18603
18604 VkDescriptorSetObj descriptorSet(m_device);
18605 descriptorSet.AppendDummy();
18606 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18607
18608 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18609
18610 m_errorMonitor->VerifyNotFound();
18611}
18612
18613TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
18614 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
18615 "through multiple vertex shader inputs, each consuming a different "
18616 "subset of the components.");
18617 m_errorMonitor->ExpectSuccess();
18618
18619 ASSERT_NO_FATAL_FAILURE(InitState());
18620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18621
18622 VkVertexInputBindingDescription input_binding;
18623 memset(&input_binding, 0, sizeof(input_binding));
18624
18625 VkVertexInputAttributeDescription input_attribs[3];
18626 memset(input_attribs, 0, sizeof(input_attribs));
18627
18628 for (int i = 0; i < 3; i++) {
18629 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
18630 input_attribs[i].location = i;
18631 }
18632
18633 char const *vsSource = "#version 450\n"
18634 "\n"
18635 "layout(location=0) in vec4 x;\n"
18636 "layout(location=1) in vec3 y1;\n"
18637 "layout(location=1, component=3) in float y2;\n"
18638 "layout(location=2) in vec4 z;\n"
18639 "out gl_PerVertex {\n"
18640 " vec4 gl_Position;\n"
18641 "};\n"
18642 "void main(){\n"
18643 " gl_Position = x + vec4(y1, y2) + z;\n"
18644 "}\n";
18645 char const *fsSource = "#version 450\n"
18646 "\n"
18647 "layout(location=0) out vec4 color;\n"
18648 "void main(){\n"
18649 " color = vec4(1);\n"
18650 "}\n";
18651
18652 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18653 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18654
18655 VkPipelineObj pipe(m_device);
18656 pipe.AddColorAttachment();
18657 pipe.AddShader(&vs);
18658 pipe.AddShader(&fs);
18659
18660 pipe.AddVertexInputBindings(&input_binding, 1);
18661 pipe.AddVertexInputAttribs(input_attribs, 3);
18662
18663 VkDescriptorSetObj descriptorSet(m_device);
18664 descriptorSet.AppendDummy();
18665 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18666
18667 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18668
18669 m_errorMonitor->VerifyNotFound();
18670}
18671
18672TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
18673 m_errorMonitor->ExpectSuccess();
18674
18675 ASSERT_NO_FATAL_FAILURE(InitState());
18676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18677
18678 char const *vsSource = "#version 450\n"
18679 "out gl_PerVertex {\n"
18680 " vec4 gl_Position;\n"
18681 "};\n"
18682 "void main(){\n"
18683 " gl_Position = vec4(0);\n"
18684 "}\n";
18685 char const *fsSource = "#version 450\n"
18686 "\n"
18687 "layout(location=0) out vec4 color;\n"
18688 "void main(){\n"
18689 " color = vec4(1);\n"
18690 "}\n";
18691
18692 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18693 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18694
18695 VkPipelineObj pipe(m_device);
18696 pipe.AddColorAttachment();
18697 pipe.AddShader(&vs);
18698 pipe.AddShader(&fs);
18699
18700 VkDescriptorSetObj descriptorSet(m_device);
18701 descriptorSet.AppendDummy();
18702 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18703
18704 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18705
18706 m_errorMonitor->VerifyNotFound();
18707}
18708
18709TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
18710 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
18711 "set out in 14.1.3: fundamental type must match, and producer side must "
18712 "have at least as many components");
18713 m_errorMonitor->ExpectSuccess();
18714
18715 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
18716
18717 ASSERT_NO_FATAL_FAILURE(InitState());
18718 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18719
18720 char const *vsSource = "#version 450\n"
18721 "out gl_PerVertex {\n"
18722 " vec4 gl_Position;\n"
18723 "};\n"
18724 "layout(location=0) out vec3 x;\n"
18725 "layout(location=1) out ivec3 y;\n"
18726 "layout(location=2) out vec3 z;\n"
18727 "void main(){\n"
18728 " gl_Position = vec4(0);\n"
18729 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
18730 "}\n";
18731 char const *fsSource = "#version 450\n"
18732 "\n"
18733 "layout(location=0) out vec4 color;\n"
18734 "layout(location=0) in float x;\n"
18735 "layout(location=1) flat in int y;\n"
18736 "layout(location=2) in vec2 z;\n"
18737 "void main(){\n"
18738 " color = vec4(1 + x + y + z.x);\n"
18739 "}\n";
18740
18741 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18742 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18743
18744 VkPipelineObj pipe(m_device);
18745 pipe.AddColorAttachment();
18746 pipe.AddShader(&vs);
18747 pipe.AddShader(&fs);
18748
18749 VkDescriptorSetObj descriptorSet(m_device);
18750 descriptorSet.AppendDummy();
18751 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18752
18753 VkResult err = VK_SUCCESS;
18754 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18755 ASSERT_VK_SUCCESS(err);
18756
18757 m_errorMonitor->VerifyNotFound();
18758}
18759
18760TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
18761 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
18762 "passed between the TCS and TES stages");
18763 m_errorMonitor->ExpectSuccess();
18764
18765 ASSERT_NO_FATAL_FAILURE(InitState());
18766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18767
18768 if (!m_device->phy().features().tessellationShader) {
18769 printf("Device does not support tessellation shaders; skipped.\n");
18770 return;
18771 }
18772
18773 char const *vsSource = "#version 450\n"
18774 "void main(){}\n";
18775 char const *tcsSource = "#version 450\n"
18776 "layout(location=0) out int x[];\n"
18777 "layout(vertices=3) out;\n"
18778 "void main(){\n"
18779 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
18780 " gl_TessLevelInner[0] = 1;\n"
18781 " x[gl_InvocationID] = gl_InvocationID;\n"
18782 "}\n";
18783 char const *tesSource = "#version 450\n"
18784 "layout(triangles, equal_spacing, cw) in;\n"
18785 "layout(location=0) in int x[];\n"
18786 "out gl_PerVertex { vec4 gl_Position; };\n"
18787 "void main(){\n"
18788 " gl_Position.xyz = gl_TessCoord;\n"
18789 " gl_Position.w = x[0] + x[1] + x[2];\n"
18790 "}\n";
18791 char const *fsSource = "#version 450\n"
18792 "layout(location=0) out vec4 color;\n"
18793 "void main(){\n"
18794 " color = vec4(1);\n"
18795 "}\n";
18796
18797 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18798 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
18799 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
18800 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18801
18802 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
18803 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
18804
18805 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
18806
18807 VkPipelineObj pipe(m_device);
18808 pipe.SetInputAssembly(&iasci);
18809 pipe.SetTessellation(&tsci);
18810 pipe.AddColorAttachment();
18811 pipe.AddShader(&vs);
18812 pipe.AddShader(&tcs);
18813 pipe.AddShader(&tes);
18814 pipe.AddShader(&fs);
18815
18816 VkDescriptorSetObj descriptorSet(m_device);
18817 descriptorSet.AppendDummy();
18818 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18819
18820 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18821
18822 m_errorMonitor->VerifyNotFound();
18823}
18824
18825TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
18826 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
18827 "interface block passed into the geometry shader. This "
18828 "is interesting because the 'extra' array level is not "
18829 "present on the member type, but on the block instance.");
18830 m_errorMonitor->ExpectSuccess();
18831
18832 ASSERT_NO_FATAL_FAILURE(InitState());
18833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18834
18835 if (!m_device->phy().features().geometryShader) {
18836 printf("Device does not support geometry shaders; skipped.\n");
18837 return;
18838 }
18839
18840 char const *vsSource = "#version 450\n"
18841 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
18842 "void main(){\n"
18843 " vs_out.x = vec4(1);\n"
18844 "}\n";
18845 char const *gsSource = "#version 450\n"
18846 "layout(triangles) in;\n"
18847 "layout(triangle_strip, max_vertices=3) out;\n"
18848 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
18849 "out gl_PerVertex { vec4 gl_Position; };\n"
18850 "void main() {\n"
18851 " gl_Position = gs_in[0].x;\n"
18852 " EmitVertex();\n"
18853 "}\n";
18854 char const *fsSource = "#version 450\n"
18855 "layout(location=0) out vec4 color;\n"
18856 "void main(){\n"
18857 " color = vec4(1);\n"
18858 "}\n";
18859
18860 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18861 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
18862 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18863
18864 VkPipelineObj pipe(m_device);
18865 pipe.AddColorAttachment();
18866 pipe.AddShader(&vs);
18867 pipe.AddShader(&gs);
18868 pipe.AddShader(&fs);
18869
18870 VkDescriptorSetObj descriptorSet(m_device);
18871 descriptorSet.AppendDummy();
18872 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18873
18874 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18875
18876 m_errorMonitor->VerifyNotFound();
18877}
18878
18879TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
18880 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
18881 "attributes. This is interesting because they consume multiple "
18882 "locations.");
18883 m_errorMonitor->ExpectSuccess();
18884
18885 ASSERT_NO_FATAL_FAILURE(InitState());
18886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18887
18888 if (!m_device->phy().features().shaderFloat64) {
18889 printf("Device does not support 64bit vertex attributes; skipped.\n");
18890 return;
18891 }
18892
18893 VkVertexInputBindingDescription input_bindings[1];
18894 memset(input_bindings, 0, sizeof(input_bindings));
18895
18896 VkVertexInputAttributeDescription input_attribs[4];
18897 memset(input_attribs, 0, sizeof(input_attribs));
18898 input_attribs[0].location = 0;
18899 input_attribs[0].offset = 0;
18900 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18901 input_attribs[1].location = 2;
18902 input_attribs[1].offset = 32;
18903 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18904 input_attribs[2].location = 4;
18905 input_attribs[2].offset = 64;
18906 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18907 input_attribs[3].location = 6;
18908 input_attribs[3].offset = 96;
18909 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
18910
18911 char const *vsSource = "#version 450\n"
18912 "\n"
18913 "layout(location=0) in dmat4 x;\n"
18914 "out gl_PerVertex {\n"
18915 " vec4 gl_Position;\n"
18916 "};\n"
18917 "void main(){\n"
18918 " gl_Position = vec4(x[0][0]);\n"
18919 "}\n";
18920 char const *fsSource = "#version 450\n"
18921 "\n"
18922 "layout(location=0) out vec4 color;\n"
18923 "void main(){\n"
18924 " color = vec4(1);\n"
18925 "}\n";
18926
18927 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18928 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18929
18930 VkPipelineObj pipe(m_device);
18931 pipe.AddColorAttachment();
18932 pipe.AddShader(&vs);
18933 pipe.AddShader(&fs);
18934
18935 pipe.AddVertexInputBindings(input_bindings, 1);
18936 pipe.AddVertexInputAttribs(input_attribs, 4);
18937
18938 VkDescriptorSetObj descriptorSet(m_device);
18939 descriptorSet.AppendDummy();
18940 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
18941
18942 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
18943
18944 m_errorMonitor->VerifyNotFound();
18945}
18946
18947TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
18948 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
18949 m_errorMonitor->ExpectSuccess();
18950
18951 ASSERT_NO_FATAL_FAILURE(InitState());
18952
18953 char const *vsSource = "#version 450\n"
18954 "\n"
18955 "out gl_PerVertex {\n"
18956 " vec4 gl_Position;\n"
18957 "};\n"
18958 "void main(){\n"
18959 " gl_Position = vec4(1);\n"
18960 "}\n";
18961 char const *fsSource = "#version 450\n"
18962 "\n"
18963 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
18964 "layout(location=0) out vec4 color;\n"
18965 "void main() {\n"
18966 " color = subpassLoad(x);\n"
18967 "}\n";
18968
18969 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18970 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18971
18972 VkPipelineObj pipe(m_device);
18973 pipe.AddShader(&vs);
18974 pipe.AddShader(&fs);
18975 pipe.AddColorAttachment();
18976 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18977
18978 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
18979 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
18980 VkDescriptorSetLayout dsl;
18981 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
18982 ASSERT_VK_SUCCESS(err);
18983
18984 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
18985 VkPipelineLayout pl;
18986 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
18987 ASSERT_VK_SUCCESS(err);
18988
18989 VkAttachmentDescription descs[2] = {
18990 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18991 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18992 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
18993 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
18994 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
18995 };
18996 VkAttachmentReference color = {
18997 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18998 };
18999 VkAttachmentReference input = {
19000 1, VK_IMAGE_LAYOUT_GENERAL,
19001 };
19002
19003 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
19004
19005 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
19006 VkRenderPass rp;
19007 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19008 ASSERT_VK_SUCCESS(err);
19009
19010 // should be OK. would go wrong here if it's going to...
19011 pipe.CreateVKPipeline(pl, rp);
19012
19013 m_errorMonitor->VerifyNotFound();
19014
19015 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19016 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19017 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19018}
19019
19020TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
19021 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
19022 "descriptor-backed resource which is not provided, but the shader does not "
19023 "statically use it. This is interesting because it requires compute pipelines "
19024 "to have a proper descriptor use walk, which they didn't for some time.");
19025 m_errorMonitor->ExpectSuccess();
19026
19027 ASSERT_NO_FATAL_FAILURE(InitState());
19028
19029 char const *csSource = "#version 450\n"
19030 "\n"
19031 "layout(local_size_x=1) in;\n"
19032 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
19033 "void main(){\n"
19034 " // x is not used.\n"
19035 "}\n";
19036
19037 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19038
19039 VkDescriptorSetObj descriptorSet(m_device);
19040 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19041
19042 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19043 nullptr,
19044 0,
19045 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19046 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19047 descriptorSet.GetPipelineLayout(),
19048 VK_NULL_HANDLE,
19049 -1 };
19050
19051 VkPipeline pipe;
19052 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19053
19054 m_errorMonitor->VerifyNotFound();
19055
19056 if (err == VK_SUCCESS) {
19057 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19058 }
19059}
19060
19061TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
19062 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19063 "sampler portion of a combined image + sampler");
19064 m_errorMonitor->ExpectSuccess();
19065
19066 ASSERT_NO_FATAL_FAILURE(InitState());
19067
19068 VkDescriptorSetLayoutBinding bindings[] = {
19069 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19070 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19071 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19072 };
19073 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19074 VkDescriptorSetLayout dsl;
19075 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19076 ASSERT_VK_SUCCESS(err);
19077
19078 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19079 VkPipelineLayout pl;
19080 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19081 ASSERT_VK_SUCCESS(err);
19082
19083 char const *csSource = "#version 450\n"
19084 "\n"
19085 "layout(local_size_x=1) in;\n"
19086 "layout(set=0, binding=0) uniform sampler s;\n"
19087 "layout(set=0, binding=1) uniform texture2D t;\n"
19088 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19089 "void main() {\n"
19090 " x = texture(sampler2D(t, s), vec2(0));\n"
19091 "}\n";
19092 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19093
19094 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19095 nullptr,
19096 0,
19097 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19098 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19099 pl,
19100 VK_NULL_HANDLE,
19101 -1 };
19102
19103 VkPipeline pipe;
19104 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19105
19106 m_errorMonitor->VerifyNotFound();
19107
19108 if (err == VK_SUCCESS) {
19109 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19110 }
19111
19112 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19113 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19114}
19115
19116TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
19117 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
19118 "image portion of a combined image + sampler");
19119 m_errorMonitor->ExpectSuccess();
19120
19121 ASSERT_NO_FATAL_FAILURE(InitState());
19122
19123 VkDescriptorSetLayoutBinding bindings[] = {
19124 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19125 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19126 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19127 };
19128 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
19129 VkDescriptorSetLayout dsl;
19130 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19131 ASSERT_VK_SUCCESS(err);
19132
19133 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19134 VkPipelineLayout pl;
19135 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19136 ASSERT_VK_SUCCESS(err);
19137
19138 char const *csSource = "#version 450\n"
19139 "\n"
19140 "layout(local_size_x=1) in;\n"
19141 "layout(set=0, binding=0) uniform texture2D t;\n"
19142 "layout(set=0, binding=1) uniform sampler s;\n"
19143 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
19144 "void main() {\n"
19145 " x = texture(sampler2D(t, s), vec2(0));\n"
19146 "}\n";
19147 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19148
19149 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19150 nullptr,
19151 0,
19152 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19153 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19154 pl,
19155 VK_NULL_HANDLE,
19156 -1 };
19157
19158 VkPipeline pipe;
19159 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19160
19161 m_errorMonitor->VerifyNotFound();
19162
19163 if (err == VK_SUCCESS) {
19164 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19165 }
19166
19167 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19168 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19169}
19170
19171TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
19172 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
19173 "both the sampler and the image of a combined image+sampler "
19174 "but via separate variables");
19175 m_errorMonitor->ExpectSuccess();
19176
19177 ASSERT_NO_FATAL_FAILURE(InitState());
19178
19179 VkDescriptorSetLayoutBinding bindings[] = {
19180 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19181 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
19182 };
19183 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
19184 VkDescriptorSetLayout dsl;
19185 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
19186 ASSERT_VK_SUCCESS(err);
19187
19188 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
19189 VkPipelineLayout pl;
19190 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
19191 ASSERT_VK_SUCCESS(err);
19192
19193 char const *csSource = "#version 450\n"
19194 "\n"
19195 "layout(local_size_x=1) in;\n"
19196 "layout(set=0, binding=0) uniform texture2D t;\n"
19197 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
19198 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
19199 "void main() {\n"
19200 " x = texture(sampler2D(t, s), vec2(0));\n"
19201 "}\n";
19202 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
19203
19204 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
19205 nullptr,
19206 0,
19207 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
19208 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
19209 pl,
19210 VK_NULL_HANDLE,
19211 -1 };
19212
19213 VkPipeline pipe;
19214 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
19215
19216 m_errorMonitor->VerifyNotFound();
19217
19218 if (err == VK_SUCCESS) {
19219 vkDestroyPipeline(m_device->device(), pipe, nullptr);
19220 }
19221
19222 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
19223 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
19224}
19225
19226TEST_F(VkPositiveLayerTest, ValidStructPNext) {
19227 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
19228
19229 ASSERT_NO_FATAL_FAILURE(InitState());
19230
19231 // Positive test to check parameter_validation and unique_objects support
19232 // for NV_dedicated_allocation
19233 uint32_t extension_count = 0;
19234 bool supports_nv_dedicated_allocation = false;
19235 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
19236 ASSERT_VK_SUCCESS(err);
19237
19238 if (extension_count > 0) {
19239 std::vector<VkExtensionProperties> available_extensions(extension_count);
19240
19241 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
19242 ASSERT_VK_SUCCESS(err);
19243
19244 for (const auto &extension_props : available_extensions) {
19245 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
19246 supports_nv_dedicated_allocation = true;
19247 }
19248 }
19249 }
19250
19251 if (supports_nv_dedicated_allocation) {
19252 m_errorMonitor->ExpectSuccess();
19253
19254 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
19255 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
19256 dedicated_buffer_create_info.pNext = nullptr;
19257 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
19258
19259 uint32_t queue_family_index = 0;
19260 VkBufferCreateInfo buffer_create_info = {};
19261 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19262 buffer_create_info.pNext = &dedicated_buffer_create_info;
19263 buffer_create_info.size = 1024;
19264 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19265 buffer_create_info.queueFamilyIndexCount = 1;
19266 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19267
19268 VkBuffer buffer;
19269 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19270 ASSERT_VK_SUCCESS(err);
19271
19272 VkMemoryRequirements memory_reqs;
19273 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19274
19275 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
19276 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
19277 dedicated_memory_info.pNext = nullptr;
19278 dedicated_memory_info.buffer = buffer;
19279 dedicated_memory_info.image = VK_NULL_HANDLE;
19280
19281 VkMemoryAllocateInfo memory_info = {};
19282 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19283 memory_info.pNext = &dedicated_memory_info;
19284 memory_info.allocationSize = memory_reqs.size;
19285
19286 bool pass;
19287 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19288 ASSERT_TRUE(pass);
19289
19290 VkDeviceMemory buffer_memory;
19291 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19292 ASSERT_VK_SUCCESS(err);
19293
19294 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19295 ASSERT_VK_SUCCESS(err);
19296
19297 vkDestroyBuffer(m_device->device(), buffer, NULL);
19298 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19299
19300 m_errorMonitor->VerifyNotFound();
19301 }
19302}
19303
19304TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
19305 VkResult err;
19306
19307 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
19308
19309 ASSERT_NO_FATAL_FAILURE(InitState());
19310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19311
19312 std::vector<const char *> device_extension_names;
19313 auto features = m_device->phy().features();
19314 // Artificially disable support for non-solid fill modes
19315 features.fillModeNonSolid = false;
19316 // The sacrificial device object
19317 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
19318
19319 VkRenderpassObj render_pass(&test_device);
19320
19321 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19322 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19323 pipeline_layout_ci.setLayoutCount = 0;
19324 pipeline_layout_ci.pSetLayouts = NULL;
19325
19326 VkPipelineLayout pipeline_layout;
19327 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19328 ASSERT_VK_SUCCESS(err);
19329
19330 VkPipelineRasterizationStateCreateInfo rs_ci = {};
19331 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
19332 rs_ci.pNext = nullptr;
19333 rs_ci.lineWidth = 1.0f;
19334 rs_ci.rasterizerDiscardEnable = true;
19335
19336 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
19337 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19338
19339 // Set polygonMode=FILL. No error is expected
19340 m_errorMonitor->ExpectSuccess();
19341 {
19342 VkPipelineObj pipe(&test_device);
19343 pipe.AddShader(&vs);
19344 pipe.AddShader(&fs);
19345 pipe.AddColorAttachment();
19346 // Set polygonMode to a good value
19347 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
19348 pipe.SetRasterization(&rs_ci);
19349 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
19350 }
19351 m_errorMonitor->VerifyNotFound();
19352
19353 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
19354}
19355
19356TEST_F(VkPositiveLayerTest, ValidPushConstants) {
19357 VkResult err;
19358 ASSERT_NO_FATAL_FAILURE(InitState());
19359 ASSERT_NO_FATAL_FAILURE(InitViewport());
19360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19361
19362 VkPipelineLayout pipeline_layout;
19363 VkPushConstantRange pc_range = {};
19364 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19365 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19366 pipeline_layout_ci.pushConstantRangeCount = 1;
19367 pipeline_layout_ci.pPushConstantRanges = &pc_range;
19368
19369 //
19370 // Check for invalid push constant ranges in pipeline layouts.
19371 //
19372 struct PipelineLayoutTestCase {
19373 VkPushConstantRange const range;
19374 char const *msg;
19375 };
19376
19377 // Check for overlapping ranges
19378 const uint32_t ranges_per_test = 5;
19379 struct OverlappingRangeTestCase {
19380 VkPushConstantRange const ranges[ranges_per_test];
19381 char const *msg;
19382 };
19383
19384 // Run some positive tests to make sure overlap checking in the layer is OK
19385 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
19386 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
19387 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
19388 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
19389 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
19390 "" },
19391 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
19392 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
19393 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
19394 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
19395 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
19396 "" } } };
19397 for (const auto &iter : overlapping_range_tests_pos) {
19398 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
19399 m_errorMonitor->ExpectSuccess();
19400 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19401 m_errorMonitor->VerifyNotFound();
19402 if (VK_SUCCESS == err) {
19403 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19404 }
19405 }
19406
19407 //
19408 // CmdPushConstants tests
19409 //
19410 const uint8_t dummy_values[100] = {};
19411
19412 BeginCommandBuffer();
19413
19414 // positive overlapping range tests with cmd
19415 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
19416 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
19417 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
19418 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
19419 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
19420 } };
19421
19422 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
19423 const VkPushConstantRange pc_range4[] = {
19424 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
19425 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
19426 };
19427
19428 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
19429 pipeline_layout_ci.pPushConstantRanges = pc_range4;
19430 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19431 ASSERT_VK_SUCCESS(err);
19432 for (const auto &iter : cmd_overlap_tests_pos) {
19433 m_errorMonitor->ExpectSuccess();
19434 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
19435 iter.range.size, dummy_values);
19436 m_errorMonitor->VerifyNotFound();
19437 }
19438 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19439
19440 EndCommandBuffer();
19441}
19442
19443
19444
19445
19446
19447
19448
19449#if 0 // A few devices have issues with this test so disabling for now
19450TEST_F(VkPositiveLayerTest, LongFenceChain)
19451{
19452 m_errorMonitor->ExpectSuccess();
19453
19454 ASSERT_NO_FATAL_FAILURE(InitState());
19455 VkResult err;
19456
19457 std::vector<VkFence> fences;
19458
19459 const int chainLength = 32768;
19460
19461 for (int i = 0; i < chainLength; i++) {
19462 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
19463 VkFence fence;
19464 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19465 ASSERT_VK_SUCCESS(err);
19466
19467 fences.push_back(fence);
19468
19469 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
19470 0, nullptr, 0, nullptr };
19471 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19472 ASSERT_VK_SUCCESS(err);
19473
19474 }
19475
19476 // BOOM, stack overflow.
19477 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
19478
19479 for (auto fence : fences)
19480 vkDestroyFence(m_device->device(), fence, nullptr);
19481
19482 m_errorMonitor->VerifyNotFound();
19483}
19484#endif
19485
19486
Cody Northrop1242dfd2016-07-13 17:24:59 -060019487#if defined(ANDROID) && defined(VALIDATION_APK)
19488static bool initialized = false;
19489static bool active = false;
19490
19491// Convert Intents to argv
19492// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019493std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019494 std::vector<std::string> args;
19495 JavaVM &vm = *app.activity->vm;
19496 JNIEnv *p_env;
19497 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
19498 return args;
19499
19500 JNIEnv &env = *p_env;
19501 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019502 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019503 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019504 jmethodID get_string_extra_method =
19505 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060019506 jvalue get_string_extra_args;
19507 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019508 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060019509
19510 std::string args_str;
19511 if (extra_str) {
19512 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
19513 args_str = extra_utf;
19514 env.ReleaseStringUTFChars(extra_str, extra_utf);
19515 env.DeleteLocalRef(extra_str);
19516 }
19517
19518 env.DeleteLocalRef(get_string_extra_args.l);
19519 env.DeleteLocalRef(intent);
19520 vm.DetachCurrentThread();
19521
19522 // split args_str
19523 std::stringstream ss(args_str);
19524 std::string arg;
19525 while (std::getline(ss, arg, ' ')) {
19526 if (!arg.empty())
19527 args.push_back(arg);
19528 }
19529
19530 return args;
19531}
19532
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019533static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019535static void processCommand(struct android_app *app, int32_t cmd) {
19536 switch (cmd) {
19537 case APP_CMD_INIT_WINDOW: {
19538 if (app->window) {
19539 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019540 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019541 break;
19542 }
19543 case APP_CMD_GAINED_FOCUS: {
19544 active = true;
19545 break;
19546 }
19547 case APP_CMD_LOST_FOCUS: {
19548 active = false;
19549 break;
19550 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019551 }
19552}
19553
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019554void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019555 app_dummy();
19556
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019557 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060019558
19559 int vulkanSupport = InitVulkan();
19560 if (vulkanSupport == 0) {
19561 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
19562 return;
19563 }
19564
19565 app->onAppCmd = processCommand;
19566 app->onInputEvent = processInput;
19567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019568 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019569 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019570 struct android_poll_source *source;
19571 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060019572 if (source) {
19573 source->process(app, source);
19574 }
19575
19576 if (app->destroyRequested != 0) {
19577 VkTestFramework::Finish();
19578 return;
19579 }
19580 }
19581
19582 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019583 // Use the following key to send arguments to gtest, i.e.
19584 // --es args "--gtest_filter=-VkLayerTest.foo"
19585 const char key[] = "args";
19586 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019588 std::string filter = "";
19589 if (args.size() > 0) {
19590 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
19591 filter += args[0];
19592 } else {
19593 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
19594 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019596 int argc = 2;
19597 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
19598 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019599
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019600 // Route output to files until we can override the gtest output
19601 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
19602 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019604 ::testing::InitGoogleTest(&argc, argv);
19605 VkTestFramework::InitArgs(&argc, argv);
19606 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019607
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019608 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019610 if (result != 0) {
19611 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
19612 } else {
19613 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
19614 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060019615
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019616 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060019617
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019618 fclose(stdout);
19619 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019620
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019621 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060019622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060019623 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060019624 }
19625 }
19626}
19627#endif
19628
Tony Barbour300a6082015-04-07 13:44:53 -060019629int main(int argc, char **argv) {
19630 int result;
19631
Cody Northrop8e54a402016-03-08 22:25:52 -070019632#ifdef ANDROID
19633 int vulkanSupport = InitVulkan();
19634 if (vulkanSupport == 0)
19635 return 1;
19636#endif
19637
Tony Barbour300a6082015-04-07 13:44:53 -060019638 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060019639 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060019640
19641 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
19642
19643 result = RUN_ALL_TESTS();
19644
Tony Barbour6918cd52015-04-09 12:58:51 -060019645 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060019646 return result;
19647}